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))) {
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;
}
char line[200];
char *motd;
int version;
+ int i = -1;
set_socket_options(fd,"SO_KEEPALIVE");
io_printf(fd,"\n");
}
- while (1) {
- int i;
+ while (i == -1) {
line[0] = 0;
if (!read_line(fd, line, sizeof(line)-1)) {
io_printf(fd,"ERROR: Unknown module '%s'\n", line);
return -1;
}
-
- return rsync_module(fd, i);
}
- return 0;
+ return rsync_module(fd, i);
}
become_daemon();
- return start_accept_loop(rsync_port, start_daemon);
+ start_accept_loop(rsync_port, start_daemon);
+ return -1;
}
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
char *comment;
BOOL read_only;
BOOL list;
- int uid;
- int gid;
+ char *uid;
+ char *gid;
} service;
NULL, /* comment */
True, /* read only */
True, /* list */
- -2, /* uid */
- -2, /* gid */
+ "nobody",/* uid */
+ "nobody",/* gid */
};
{"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}
};
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 );
}
-int start_accept_loop(int port, int (*fn)(int ))
+void start_accept_loop(int port, int (*fn)(int ))
{
int s;
/* 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);
}
close(fd);
}
- return 0;
}
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;
}
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;
+}
+