version 1.1.1.2, 2013/10/14 07:51:14
|
version 1.1.1.3, 2016/11/01 09:54:32
|
Line 3
|
Line 3
|
* |
* |
* Copyright (C) 1998-2001 Andrew Tridgell <tridge@samba.org> |
* Copyright (C) 1998-2001 Andrew Tridgell <tridge@samba.org> |
* Copyright (C) 2001-2002 Martin Pool <mbp@samba.org> |
* Copyright (C) 2001-2002 Martin Pool <mbp@samba.org> |
* Copyright (C) 2002-2013 Wayne Davison | * Copyright (C) 2002-2015 Wayne Davison |
* |
* |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
Line 60 extern char *iconv_opt;
|
Line 60 extern char *iconv_opt;
|
extern iconv_t ic_send, ic_recv; |
extern iconv_t ic_send, ic_recv; |
#endif |
#endif |
|
|
#define MAX_GID_LIST 32 |
|
|
|
char *auth_user; |
char *auth_user; |
int read_only = 0; |
int read_only = 0; |
int module_id = -1; |
int module_id = -1; |
Line 81 static int rl_nulls = 0;
|
Line 79 static int rl_nulls = 0;
|
static struct sigaction sigact; |
static struct sigaction sigact; |
#endif |
#endif |
|
|
static gid_t gid_list[MAX_GID_LIST]; | static item_list gid_list = EMPTY_ITEM_LIST; |
static int gid_count = 0; | |
|
|
/* Used when "reverse lookup" is off. */ |
/* Used when "reverse lookup" is off. */ |
const char undetermined_hostname[] = "UNDETERMINED"; |
const char undetermined_hostname[] = "UNDETERMINED"; |
Line 438 static int path_failure(int f_out, const char *dir, BO
|
Line 435 static int path_failure(int f_out, const char *dir, BO
|
|
|
static int add_a_group(int f_out, const char *gname) |
static int add_a_group(int f_out, const char *gname) |
{ |
{ |
gid_t gid; | gid_t gid, *gid_p; |
if (!group_to_gid(gname, &gid, True)) { |
if (!group_to_gid(gname, &gid, True)) { |
rprintf(FLOG, "Invalid gid %s\n", gname); |
rprintf(FLOG, "Invalid gid %s\n", gname); |
io_printf(f_out, "@ERROR: invalid gid %s\n", gname); |
io_printf(f_out, "@ERROR: invalid gid %s\n", gname); |
return -1; |
return -1; |
} |
} |
if (gid_count == MAX_GID_LIST) { | gid_p = EXPAND_ITEM_LIST(&gid_list, gid_t, -32); |
rprintf(FLOG, "Too many groups specified via gid parameter.\n"); | *gid_p = gid; |
io_printf(f_out, "@ERROR: too many groups\n"); | |
return -1; | |
} | |
gid_list[gid_count++] = gid; | |
return 0; |
return 0; |
} |
} |
|
|
Line 457 static int add_a_group(int f_out, const char *gname)
|
Line 450 static int add_a_group(int f_out, const char *gname)
|
static int want_all_groups(int f_out, uid_t uid) |
static int want_all_groups(int f_out, uid_t uid) |
{ |
{ |
const char *err; |
const char *err; |
gid_count = MAX_GID_LIST; | if ((err = getallgroups(uid, &gid_list)) != NULL) { |
if ((err = getallgroups(uid, gid_list, &gid_count)) != NULL) { | |
rsyserr(FLOG, errno, "%s", err); |
rsyserr(FLOG, errno, "%s", err); |
io_printf(f_out, "@ERROR: %s\n", err); |
io_printf(f_out, "@ERROR: %s\n", err); |
return -1; |
return -1; |
Line 469 static int want_all_groups(int f_out, uid_t uid)
|
Line 461 static int want_all_groups(int f_out, uid_t uid)
|
static struct passwd *want_all_groups(int f_out, uid_t uid) |
static struct passwd *want_all_groups(int f_out, uid_t uid) |
{ |
{ |
struct passwd *pw; |
struct passwd *pw; |
|
gid_t *gid_p; |
if ((pw = getpwuid(uid)) == NULL) { |
if ((pw = getpwuid(uid)) == NULL) { |
rsyserr(FLOG, errno, "getpwuid failed"); |
rsyserr(FLOG, errno, "getpwuid failed"); |
io_printf(f_out, "@ERROR: getpwuid failed\n"); |
io_printf(f_out, "@ERROR: getpwuid failed\n"); |
return NULL; |
return NULL; |
} |
} |
/* Start with the default group and initgroups() will add the reset. */ | /* Start with the default group and initgroups() will add the rest. */ |
gid_count = 1; | gid_p = EXPAND_ITEM_LIST(&gid_list, gid_t, -32); |
gid_list[0] = pw->pw_gid; | *gid_p = pw->pw_gid; |
return pw; |
return pw; |
} |
} |
#endif |
#endif |
Line 818 static int rsync_module(int f_in, int f_out, int i, co
|
Line 811 static int rsync_module(int f_in, int f_out, int i, co
|
} |
} |
} |
} |
|
|
if (gid_count) { | if (gid_list.count) { |
if (setgid(gid_list[0])) { | gid_t *gid_array = gid_list.items; |
rsyserr(FLOG, errno, "setgid %ld failed", (long)gid_list[0]); | if (setgid(gid_array[0])) { |
| rsyserr(FLOG, errno, "setgid %ld failed", (long)gid_array[0]); |
io_printf(f_out, "@ERROR: setgid failed\n"); |
io_printf(f_out, "@ERROR: setgid failed\n"); |
return -1; |
return -1; |
} |
} |
#ifdef HAVE_SETGROUPS |
#ifdef HAVE_SETGROUPS |
/* Set the group(s) we want to be active. */ |
/* Set the group(s) we want to be active. */ |
if (setgroups(gid_count, gid_list)) { | if (setgroups(gid_list.count, gid_array)) { |
rsyserr(FLOG, errno, "setgroups failed"); |
rsyserr(FLOG, errno, "setgroups failed"); |
io_printf(f_out, "@ERROR: setgroups failed\n"); |
io_printf(f_out, "@ERROR: setgroups failed\n"); |
return -1; |
return -1; |