remove pointless dependency on passwd, and now it "actually works"!

sigsegv_dump
Greg Alexander 10 years ago
parent 8fb9669531
commit 0ad7144d15

@ -35,16 +35,8 @@ cleanup_exit(int i)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
struct passwd *user_pw;
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
sanitise_stdfd(); sanitise_stdfd();
if ((user_pw = getpwuid(getuid())) == NULL) { return (sftp_server_main(argc, argv));
fprintf(stderr, "No user found for uid %lu\n",
(u_long)getuid());
return 1;
}
return (sftp_server_main(argc, argv, user_pw));
} }

@ -33,11 +33,9 @@
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <pwd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <pwd.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <stdarg.h> #include <stdarg.h>
@ -56,7 +54,6 @@
#define get_string(lenp) buffer_get_string(&iqueue, lenp); #define get_string(lenp) buffer_get_string(&iqueue, lenp);
/* Our client */ /* Our client */
static struct passwd *pw = NULL;
static char *client_addr = NULL; static char *client_addr = NULL;
/* input and output queue */ /* input and output queue */
@ -1182,8 +1179,7 @@ process(void)
cp = buffer_ptr(&iqueue); cp = buffer_ptr(&iqueue);
msg_len = get_u32(cp); msg_len = get_u32(cp);
if (msg_len > SFTP_MAX_MSG_LENGTH) { if (msg_len > SFTP_MAX_MSG_LENGTH) {
error("bad message from %s local user %s", error("bad message from %s", client_addr);
client_addr, pw->pw_name);
sftp_server_cleanup_exit(11); sftp_server_cleanup_exit(11);
} }
if (buf_len < msg_len + 4) if (buf_len < msg_len + 4)
@ -1243,7 +1239,7 @@ sftp_server_cleanup_exit(int i)
} }
int int
sftp_server_main(int argc, char **argv, struct passwd *user_pw) sftp_server_main(int argc, char **argv)
{ {
fd_set rsetx, wsetx; fd_set rsetx, wsetx;
fd_set *rset = &rsetx, *wset = &wsetx; fd_set *rset = &rsetx, *wset = &wsetx;
@ -1254,8 +1250,6 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
extern char *optarg; extern char *optarg;
pw = pwcopy(user_pw);
while (!skipargs && (ch = getopt(argc, argv, while (!skipargs && (ch = getopt(argc, argv,
"d:f:l:P:p:Q:u:cehR")) != -1) { "d:f:l:P:p:Q:u:cehR")) != -1) {
switch (ch) { switch (ch) {
@ -1280,12 +1274,6 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
*/ */
skipargs = 1; skipargs = 1;
break; break;
case 'd':
cp = tilde_expand_filename(optarg, user_pw->pw_uid);
homedir = percent_expand(cp, "d", user_pw->pw_dir,
"u", user_pw->pw_name, (char *)NULL);
free(cp);
break;
case 'p': case 'p':
if (request_whitelist != NULL) if (request_whitelist != NULL)
fatal("Permitted requests already set"); fatal("Permitted requests already set");

@ -97,5 +97,5 @@
struct passwd; struct passwd;
int sftp_server_main(int, char **, struct passwd *); int sftp_server_main(int, char **);
void sftp_server_cleanup_exit(int) __attribute__((noreturn)); void sftp_server_cleanup_exit(int) __attribute__((noreturn));

Loading…
Cancel
Save