mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-08-02 16:57:40 -04:00
change to allow names or numbers to be used for uid and gid.
This commit is contained in:
@@ -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))) {
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -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)) {
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
16
loadparm.c
16
loadparm.c
@@ -114,8 +114,8 @@ typedef struct
|
||||
char *comment;
|
||||
BOOL read_only;
|
||||
BOOL list;
|
||||
int uid;
|
||||
int gid;
|
||||
char *uid;
|
||||
char *gid;
|
||||
} service;
|
||||
|
||||
|
||||
@@ -127,8 +127,8 @@ static service sDefault =
|
||||
NULL, /* comment */
|
||||
True, /* read only */
|
||||
True, /* list */
|
||||
-2, /* uid */
|
||||
-2, /* gid */
|
||||
"nobody",/* uid */
|
||||
"nobody",/* gid */
|
||||
};
|
||||
|
||||
|
||||
@@ -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}
|
||||
};
|
||||
|
||||
@@ -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 );
|
||||
|
||||
7
socket.c
7
socket.c
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,6 @@ int start_accept_loop(int port, int (*fn)(int ))
|
||||
|
||||
close(fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
31
uidlist.c
31
uidlist.c
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
27
util.c
27
util.c
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user