Skip to content

Commit

Permalink
change to allow names or numbers to be used for uid and gid.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Tridgell committed May 10, 1998
1 parent c596dad commit 8ef4ffd
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 45 deletions.
36 changes: 28 additions & 8 deletions clientserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,33 @@ static int rsync_module(int fd, int i)
char *argv[MAX_ARGS];
char **argp;
char line[1024];
uid_t uid;
gid_t gid;
char *p;

module_id = i;

if (lp_read_only(i))
read_only = 1;

p = lp_uid(i);
if (!name_to_uid(p, &uid)) {
if (!isdigit(*p)) {
rprintf(FERROR,"Invalid uid %s\n", p);
return -1;
}
uid = atoi(p);
}

p = lp_gid(i);
if (!name_to_gid(p, &gid)) {
if (!isdigit(*p)) {
rprintf(FERROR,"Invalid gid %s\n", p);
return -1;
}
gid = atoi(p);
}

rprintf(FERROR,"rsyncd starting\n");

if (chroot(lp_path(i))) {
Expand All @@ -114,12 +135,12 @@ static int rsync_module(int fd, int i)
return -1;
}

if (setgid(lp_gid(i))) {
if (setgid(gid)) {
io_printf(fd,"@ERROR: setgid failed\n");
return -1;
}

if (setuid(lp_uid(i))) {
if (setuid(uid)) {
io_printf(fd,"@ERROR: setuid failed\n");
return -1;
}
Expand Down Expand Up @@ -180,6 +201,7 @@ static int start_daemon(int fd)
char line[200];
char *motd;
int version;
int i = -1;

set_socket_options(fd,"SO_KEEPALIVE");

Expand Down Expand Up @@ -207,8 +229,7 @@ static int start_daemon(int fd)
io_printf(fd,"\n");
}

while (1) {
int i;
while (i == -1) {

line[0] = 0;
if (!read_line(fd, line, sizeof(line)-1)) {
Expand All @@ -231,11 +252,9 @@ static int start_daemon(int fd)
io_printf(fd,"ERROR: Unknown module '%s'\n", line);
return -1;
}

return rsync_module(fd, i);
}

return 0;
return rsync_module(fd, i);
}


Expand All @@ -254,6 +273,7 @@ int daemon_main(void)

become_daemon();

return start_accept_loop(rsync_port, start_daemon);
start_accept_loop(rsync_port, start_daemon);
return -1;
}

1 change: 1 addition & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ AC_TRY_COMPILE([#include <sys/types.h>
echo yes;AC_DEFINE(HAVE_UTIMBUF),
echo no)

# The following test taken from the cvs sources
# If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
# The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
# libsocket.so which has a bad implementation of gethostbyname (it
Expand Down
16 changes: 8 additions & 8 deletions loadparm.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ typedef struct
char *comment;
BOOL read_only;
BOOL list;
int uid;
int gid;
char *uid;
char *gid;
} service;


Expand All @@ -127,8 +127,8 @@ static service sDefault =
NULL, /* comment */
True, /* read only */
True, /* list */
-2, /* uid */
-2, /* gid */
"nobody",/* uid */
"nobody",/* gid */
};


Expand All @@ -151,8 +151,8 @@ static struct parm_struct parm_table[] =
{"path", P_STRING, P_LOCAL, &sDefault.path, NULL, 0},
{"read only", P_BOOL, P_LOCAL, &sDefault.read_only, NULL, 0},
{"list", P_BOOL, P_LOCAL, &sDefault.list, NULL, 0},
{"uid", P_INTEGER, P_LOCAL, &sDefault.uid, NULL, 0},
{"gid", P_INTEGER, P_LOCAL, &sDefault.gid, NULL, 0},
{"uid", P_STRING, P_LOCAL, &sDefault.uid, NULL, 0},
{"gid", P_STRING, P_LOCAL, &sDefault.gid, NULL, 0},
{NULL, P_BOOL, P_NONE, NULL, NULL, 0}
};

Expand Down Expand Up @@ -202,8 +202,8 @@ FN_LOCAL_STRING(lp_comment, comment)
FN_LOCAL_STRING(lp_path, path)
FN_LOCAL_BOOL(lp_read_only, read_only)
FN_LOCAL_BOOL(lp_list, list)
FN_LOCAL_INTEGER(lp_uid, uid)
FN_LOCAL_INTEGER(lp_gid, gid)
FN_LOCAL_STRING(lp_uid, uid)
FN_LOCAL_STRING(lp_gid, gid)

/* local prototypes */
static int strwicmp( char *psz1, char *psz2 );
Expand Down
7 changes: 3 additions & 4 deletions socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int is_a_socket(int fd)
}


int start_accept_loop(int port, int (*fn)(int ))
void start_accept_loop(int port, int (*fn)(int ))
{
int s;

Expand All @@ -125,12 +125,12 @@ int start_accept_loop(int port, int (*fn)(int ))
/* open an incoming socket */
s = open_socket_in(SOCK_STREAM, port);
if (s == -1)
return(-1);
exit(1);

/* ready to listen */
if (listen(s, 5) == -1) {
close(s);
return -1;
exit(1);
}


Expand Down Expand Up @@ -163,7 +163,6 @@ int start_accept_loop(int port, int (*fn)(int ))

close(fd);
}
return 0;
}


Expand Down
31 changes: 6 additions & 25 deletions uidlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,38 +67,19 @@ static char *gid_to_name(gid_t gid)
return NULL;
}


/* turn a user name into a uid */
static uid_t name_to_uid(char *name)
{
struct passwd *pass;
if (!name || !*name) return 0;
pass = getpwnam(name);
if (pass) return(pass->pw_uid);
return 0;
}

/* turn a group name into a gid */
static gid_t name_to_gid(char *name)
{
struct group *grp;
if (!name || !*name) return 0;
grp = getgrnam(name);
if (grp) return(grp->gr_gid);
return 0;
}

static int map_uid(int id, char *name)
{
uid_t uid = name_to_uid(name);
if (uid != 0) return uid;
uid_t uid;
if (name_to_uid(name, &uid) && uid != 0)
return uid;
return id;
}

static int map_gid(int id, char *name)
{
gid_t gid = name_to_gid(name);
if (gid != 0) return gid;
gid_t gid;
if (name_to_gid(name, &gid) && gid != 0)
return gid;
return id;
}

Expand Down
27 changes: 27 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,30 @@ void strlcpy(char *d, char *s, int maxlen)
memcpy(d, s, len);
d[len] = 0;
}

/* turn a user name into a uid */
int name_to_uid(char *name, uid_t *uid)
{
struct passwd *pass;
if (!name || !*name) return 0;
pass = getpwnam(name);
if (pass) {
*uid = pass->pw_uid;
return 1;
}
return 0;
}

/* turn a group name into a gid */
int name_to_gid(char *name, gid_t *gid)
{
struct group *grp;
if (!name || !*name) return 0;
grp = getgrnam(name);
if (grp) {
*gid = grp->gr_gid;
return 1;
}
return 0;
}

0 comments on commit 8ef4ffd

Please sign in to comment.