|
Lines 1154-1159
process(void)
Link Here
|
| 1154 |
buffer_consume(&iqueue, msg_len - consumed); |
1154 |
buffer_consume(&iqueue, msg_len - consumed); |
| 1155 |
} |
1155 |
} |
| 1156 |
|
1156 |
|
|
|
1157 |
static void |
| 1158 |
do_chroot(const char *chroot_path_template) |
| 1159 |
{ |
| 1160 |
char *cp, *chroot_path; |
| 1161 |
struct group *gr; |
| 1162 |
|
| 1163 |
if ((gr = getgrgid(pw->pw_gid)) == NULL) |
| 1164 |
fatal("No group found for gid %lu", (u_long)pw->pw_gid); |
| 1165 |
|
| 1166 |
cp = percent_expand(chroot_path_template, "d", pw->pw_dir, |
| 1167 |
"u", pw->pw_name, "g", gr->gr_name, (char *)NULL); |
| 1168 |
chroot_path = tilde_expand_filename(cp, getuid()); |
| 1169 |
xfree(cp); |
| 1170 |
|
| 1171 |
logit("chroot to %s", chroot_path); |
| 1172 |
|
| 1173 |
/* Ensure the user has rights to access the chroot path first */ |
| 1174 |
temporarily_use_uid(pw); |
| 1175 |
if (chdir(chroot_path) == -1) |
| 1176 |
fatal("chdir(\"%s\"): %s", chroot_path, strerror(errno)); |
| 1177 |
restore_uid(); |
| 1178 |
|
| 1179 |
if (chroot(chroot_path) == -1) |
| 1180 |
fatal("chroot(\"%s\"): %s", chroot_path, strerror(errno)); |
| 1181 |
if (chdir("/") == -1) |
| 1182 |
fatal("chdir(\"/\"): %s", strerror(errno)); |
| 1183 |
xfree(chroot_path); |
| 1184 |
} |
| 1185 |
|
| 1157 |
/* Cleanup handler that logs active handles upon normal exit */ |
1186 |
/* Cleanup handler that logs active handles upon normal exit */ |
| 1158 |
void |
1187 |
void |
| 1159 |
cleanup_exit(int i) |
1188 |
cleanup_exit(int i) |
|
Lines 1179-1185
main(int argc, char **argv)
Link Here
|
| 1179 |
int in, out, max, ch, skipargs = 0, log_stderr = 0; |
1208 |
int in, out, max, ch, skipargs = 0, log_stderr = 0; |
| 1180 |
ssize_t len, olen, set_size; |
1209 |
ssize_t len, olen, set_size; |
| 1181 |
SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; |
1210 |
SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; |
| 1182 |
char *cp; |
1211 |
char *cp, *chroot_path = NULL; |
| 1183 |
|
1212 |
|
| 1184 |
extern int optind; |
1213 |
extern int optind; |
| 1185 |
extern char *optarg; |
1214 |
extern char *optarg; |
|
Lines 1192-1197
main(int argc, char **argv)
Link Here
|
| 1192 |
|
1221 |
|
| 1193 |
while (!skipargs && (ch = getopt(argc, argv, "C:f:l:che")) != -1) { |
1222 |
while (!skipargs && (ch = getopt(argc, argv, "C:f:l:che")) != -1) { |
| 1194 |
switch (ch) { |
1223 |
switch (ch) { |
|
|
1224 |
case 'C': |
| 1225 |
chroot_path = optarg; |
| 1226 |
break; |
| 1195 |
case 'c': |
1227 |
case 'c': |
| 1196 |
/* |
1228 |
/* |
| 1197 |
* Ignore all arguments if we are invoked as a |
1229 |
* Ignore all arguments if we are invoked as a |
|
Lines 1236-1241
main(int argc, char **argv)
Link Here
|
| 1236 |
logit("session opened for client %s local user %s", |
1268 |
logit("session opened for client %s local user %s", |
| 1237 |
client_addr, pw->pw_name); |
1269 |
client_addr, pw->pw_name); |
| 1238 |
|
1270 |
|
|
|
1271 |
if (chroot_path != NULL) |
| 1272 |
do_chroot(chroot_path); |
| 1273 |
if (getuid() != geteuid()) |
| 1274 |
permanently_set_uid(pw); |
| 1275 |
|
| 1239 |
handle_init(); |
1276 |
handle_init(); |
| 1240 |
|
1277 |
|
| 1241 |
in = dup(STDIN_FILENO); |
1278 |
in = dup(STDIN_FILENO); |