|
Lines 27-32
Link Here
|
| 27 |
#include <stdio.h> |
27 |
#include <stdio.h> |
| 28 |
#include <string.h> |
28 |
#include <string.h> |
| 29 |
#include <pwd.h> |
29 |
#include <pwd.h> |
|
|
30 |
#include <grp.h> |
| 30 |
#include <time.h> |
31 |
#include <time.h> |
| 31 |
#include <unistd.h> |
32 |
#include <unistd.h> |
| 32 |
#include <stdarg.h> |
33 |
#include <stdarg.h> |
|
Lines 1161-1166
process(void)
Link Here
|
| 1161 |
buffer_consume(&iqueue, msg_len - consumed); |
1162 |
buffer_consume(&iqueue, msg_len - consumed); |
| 1162 |
} |
1163 |
} |
| 1163 |
|
1164 |
|
|
|
1165 |
static void |
| 1166 |
do_chroot(const char *chroot_path_template) |
| 1167 |
{ |
| 1168 |
char *cp, *chroot_path; |
| 1169 |
struct group *gr; |
| 1170 |
|
| 1171 |
if ((gr = getgrgid(pw->pw_gid)) == NULL) |
| 1172 |
fatal("No group found for gid %lu", (u_long)pw->pw_gid); |
| 1173 |
|
| 1174 |
cp = percent_expand(chroot_path_template, "d", pw->pw_dir, |
| 1175 |
"u", pw->pw_name, "g", gr->gr_name, (char *)NULL); |
| 1176 |
chroot_path = tilde_expand_filename(cp, getuid()); |
| 1177 |
xfree(cp); |
| 1178 |
|
| 1179 |
logit("chroot to %s", chroot_path); |
| 1180 |
|
| 1181 |
/* Ensure the user has rights to access the chroot path first */ |
| 1182 |
temporarily_use_uid(pw); |
| 1183 |
if (chdir(chroot_path) == -1) |
| 1184 |
fatal("chdir(\"%s\"): %s", chroot_path, strerror(errno)); |
| 1185 |
restore_uid(); |
| 1186 |
|
| 1187 |
if (chroot(chroot_path) == -1) |
| 1188 |
fatal("chroot(\"%s\"): %s", chroot_path, strerror(errno)); |
| 1189 |
if (chdir("/") == -1) |
| 1190 |
fatal("chdir(\"/\"): %s", strerror(errno)); |
| 1191 |
xfree(chroot_path); |
| 1192 |
} |
| 1193 |
|
| 1164 |
/* Cleanup handler that logs active handles upon normal exit */ |
1194 |
/* Cleanup handler that logs active handles upon normal exit */ |
| 1165 |
void |
1195 |
void |
| 1166 |
cleanup_exit(int i) |
1196 |
cleanup_exit(int i) |
|
Lines 1190-1196
main(int argc, char **argv)
Link Here
|
| 1190 |
int in, out, max, ch, skipargs = 0, log_stderr = 0; |
1220 |
int in, out, max, ch, skipargs = 0, log_stderr = 0; |
| 1191 |
ssize_t len, olen, set_size; |
1221 |
ssize_t len, olen, set_size; |
| 1192 |
SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; |
1222 |
SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; |
| 1193 |
char *cp; |
1223 |
char *cp, *chroot_path = NULL; |
| 1194 |
|
1224 |
|
| 1195 |
extern char *optarg; |
1225 |
extern char *optarg; |
| 1196 |
extern char *__progname; |
1226 |
extern char *__progname; |
|
Lines 1202-1207
main(int argc, char **argv)
Link Here
|
| 1202 |
|
1232 |
|
| 1203 |
while (!skipargs && (ch = getopt(argc, argv, "C:f:l:che")) != -1) { |
1233 |
while (!skipargs && (ch = getopt(argc, argv, "C:f:l:che")) != -1) { |
| 1204 |
switch (ch) { |
1234 |
switch (ch) { |
|
|
1235 |
case 'C': |
| 1236 |
chroot_path = optarg; |
| 1237 |
break; |
| 1205 |
case 'c': |
1238 |
case 'c': |
| 1206 |
/* |
1239 |
/* |
| 1207 |
* Ignore all arguments if we are invoked as a |
1240 |
* Ignore all arguments if we are invoked as a |
|
Lines 1246-1251
main(int argc, char **argv)
Link Here
|
| 1246 |
logit("session opened for local user %s from [%s]", |
1279 |
logit("session opened for local user %s from [%s]", |
| 1247 |
pw->pw_name, client_addr); |
1280 |
pw->pw_name, client_addr); |
| 1248 |
|
1281 |
|
|
|
1282 |
if (chroot_path != NULL) |
| 1283 |
do_chroot(chroot_path); |
| 1284 |
if (getuid() != geteuid()) |
| 1285 |
permanently_set_uid(pw); |
| 1286 |
|
| 1249 |
handle_init(); |
1287 |
handle_init(); |
| 1250 |
|
1288 |
|
| 1251 |
in = dup(STDIN_FILENO); |
1289 |
in = dup(STDIN_FILENO); |