uidlist.c

ソースコードを見る。


データ構造

struct  idlist

関数

static struct idlistadd_to_list (struct idlist **root, int id, char *name, int id2)
static char * uid_to_name (uid_t uid)
static char * gid_to_name (gid_t gid)
static int map_uid (int id, char *name)
static int map_gid (int id, char *name)
static int is_in_group (gid_t gid)
static struct idlistrecv_add_uid (int id, char *name)
static struct idlistrecv_add_gid (int id, char *name)
static uid_t match_uid (uid_t uid)
static gid_t match_gid (gid_t gid)
void add_uid (uid_t uid)
void add_gid (gid_t gid)
void send_uid_list (int f)
void recv_uid_list (int f, struct file_list *flist)

変数

int verbose
int preserve_uid
int preserve_gid
int preserve_acls
int numeric_ids
int am_root
static struct idlistuidlist
static struct idlistgidlist

関数

static struct idlist* add_to_list ( struct idlist **  root,
int  id,
char *  name,
int  id2 
) [static]

uidlist.c50 行で定義されています。

参照先 idlist::ididlist::id2idlist::nameidlist::nextout_of_memory().

参照元 add_gid()add_uid()recv_add_gid()recv_add_uid().

00052 {
00053         struct idlist *node = new(struct idlist);
00054         if (!node)
00055                 out_of_memory("add_to_list");
00056         node->next = *root;
00057         node->name = name;
00058         node->id = id;
00059         node->id2 = id2;
00060         *root = node;
00061         return node;
00062 }

static char* uid_to_name ( uid_t  uid  )  [static]

uidlist.c65 行で定義されています。

参照先 strdup().

参照元 add_uid().

00066 {
00067         struct passwd *pass = getpwuid(uid);
00068         if (pass)
00069                 return strdup(pass->pw_name);
00070         return NULL;
00071 }

static char* gid_to_name ( gid_t  gid  )  [static]

uidlist.c74 行で定義されています。

参照先 strdup().

参照元 add_gid().

00075 {
00076         struct group *grp = getgrgid(gid);
00077         if (grp)
00078                 return strdup(grp->gr_name);
00079         return NULL;
00080 }

static int map_uid ( int  id,
char *  name 
) [static]

uidlist.c82 行で定義されています。

参照先 name_to_uid().

参照元 recv_add_uid().

00083 {
00084         uid_t uid;
00085         if (id != 0 && name_to_uid(name, &uid))
00086                 return uid;
00087         return id;
00088 }

static int map_gid ( int  id,
char *  name 
) [static]

uidlist.c90 行で定義されています。

参照先 name_to_gid().

参照元 recv_add_gid().

00091 {
00092         gid_t gid;
00093         if (id != 0 && name_to_gid(name, &gid))
00094                 return gid;
00095         return id;
00096 }

static int is_in_group ( gid_t  gid  )  [static]

uidlist.c98 行で定義されています。

参照先 FINFOout_of_memory()rprintf()sprintf()verbose.

参照元 recv_add_gid().

00099 {
00100 #ifdef HAVE_GETGROUPS
00101         static gid_t last_in = GID_NONE, last_out;
00102         static int ngroups = -2;
00103         static GETGROUPS_T *gidset;
00104         int n;
00105 
00106         if (gid == last_in)
00107                 return last_out;
00108         if (ngroups < -1) {
00109                 gid_t mygid = MY_GID();
00110                 if ((ngroups = getgroups(0, NULL)) < 0)
00111                         ngroups = 0;
00112                 gidset = new_array(GETGROUPS_T, ngroups+1);
00113                 if (!gidset)
00114                         out_of_memory("is_in_group");
00115                 if (ngroups > 0)
00116                         ngroups = getgroups(ngroups, gidset);
00117                 /* The default gid might not be in the list on some systems. */
00118                 for (n = 0; n < ngroups; n++) {
00119                         if (gidset[n] == mygid)
00120                                 break;
00121                 }
00122                 if (n == ngroups)
00123                         gidset[ngroups++] = mygid;
00124                 if (verbose > 3) {
00125                         int pos;
00126                         char *gidbuf = new_array(char, ngroups*21+32);
00127                         if (!gidbuf)
00128                                 out_of_memory("is_in_group");
00129                         sprintf(gidbuf, "process has %d gid%s: ",
00130                             ngroups, ngroups == 1? "" : "s");
00131                         pos = strlen(gidbuf);
00132                         for (n = 0; n < ngroups; n++) {
00133                                 sprintf(gidbuf+pos, " %d", (int)gidset[n]);
00134                                 pos += strlen(gidbuf+pos);
00135                         }
00136                         rprintf(FINFO, "%s\n", gidbuf);
00137                         free(gidbuf);
00138                 }
00139         }
00140 
00141         last_in = gid;
00142         for (n = 0; n < ngroups; n++) {
00143                 if (gidset[n] == gid)
00144                         return last_out = 1;
00145         }
00146         return last_out = 0;
00147 
00148 #else
00149         static gid_t mygid = GID_NONE;
00150         if (mygid == GID_NONE) {
00151                 mygid = MY_GID();
00152                 if (verbose > 3)
00153                         rprintf(FINFO, "process has gid %d\n", (int)mygid);
00154         }
00155         return gid == mygid;
00156 #endif
00157 }

static struct idlist* recv_add_uid ( int  id,
char *  name 
) [static]

uidlist.c160 行で定義されています。

参照先 add_to_list()FINFOidlist::id2map_uid()rprintf()uidlistverbose.

参照元 recv_uid_list().

00161 {
00162         int id2 = name ? map_uid(id, name) : id;
00163         struct idlist *node;
00164 
00165         node = add_to_list(&uidlist, id, name, id2);
00166 
00167         if (verbose > 3) {
00168                 rprintf(FINFO, "uid %d(%s) maps to %d\n",
00169                     id, name ? name : "", id2);
00170         }
00171 
00172         return node;
00173 }

static struct idlist* recv_add_gid ( int  id,
char *  name 
) [static]

uidlist.c176 行で定義されています。

参照先 add_to_list()am_rootFINFOgidlistidlist::id2is_in_group()map_gid()rprintf()verbose.

参照元 match_gid()recv_uid_list().

00177 {
00178         int id2 = name ? map_gid(id, name) : id;
00179         struct idlist *node;
00180 
00181         if (!am_root && !is_in_group(id2))
00182                 id2 = GID_NONE;
00183         node = add_to_list(&gidlist, id, name, id2);
00184 
00185         if (verbose > 3) {
00186                 rprintf(FINFO, "gid %d(%s) maps to %d\n",
00187                     id, name ? name : "", id2);
00188         }
00189 
00190         return node;
00191 }

static uid_t match_uid ( uid_t  uid  )  [static]

uidlist.c194 行で定義されています。

参照先 idlist::ididlist::id2idlist::nextuidlist.

参照元 recv_uid_list().

00195 {
00196         static uid_t last_in, last_out;
00197         struct idlist *list;
00198 
00199         if (uid == 0)
00200                 return 0;
00201 
00202         if (uid == last_in)
00203                 return last_out;
00204 
00205         last_in = uid;
00206 
00207         for (list = uidlist; list; list = list->next) {
00208                 if (list->id == (int)uid)
00209                         return last_out = (uid_t)list->id2;
00210         }
00211 
00212         return last_out = uid;
00213 }

static gid_t match_gid ( gid_t  gid  )  [static]

uidlist.c215 行で定義されています。

参照先 gidlistidlist::ididlist::id2idlist::nextrecv_add_gid().

参照元 recv_uid_list().

00216 {
00217         static gid_t last_in = GID_NONE, last_out = GID_NONE;
00218         struct idlist *list;
00219 
00220         if (gid == GID_NONE)
00221                 return GID_NONE;
00222 
00223         if (gid == last_in)
00224                 return last_out;
00225 
00226         last_in = gid;
00227 
00228         for (list = gidlist; list; list = list->next) {
00229                 if (list->id == (int)gid)
00230                         return last_out = (gid_t)list->id2;
00231         }
00232 
00233         list = recv_add_gid(gid, NULL);
00234         return last_out = list->id2;
00235 }

void add_uid ( uid_t  uid  ) 

uidlist.c238 行で定義されています。

参照先 add_to_list()idlist::ididlist::nextuid_to_name()uidlist.

参照元 send_file_entry()send_ida_list().

00239 {
00240         struct idlist *list;
00241 
00242         if (uid == 0)   /* don't map root */
00243                 return;
00244 
00245         for (list = uidlist; list; list = list->next) {
00246                 if (list->id == (int)uid)
00247                         return;
00248         }
00249 
00250         add_to_list(&uidlist, (int)uid, uid_to_name(uid), 0);
00251 }

void add_gid ( gid_t  gid  ) 

uidlist.c254 行で定義されています。

参照先 add_to_list()gid_to_name()gidlistidlist::ididlist::next.

参照元 send_file_entry()send_ida_list().

00255 {
00256         struct idlist *list;
00257 
00258         if (gid == 0)   /* don't map root */
00259                 return;
00260 
00261         for (list = gidlist; list; list = list->next) {
00262                 if (list->id == (int)gid)
00263                         return;
00264         }
00265 
00266         add_to_list(&gidlist, (int)gid, gid_to_name(gid), 0);
00267 }

void send_uid_list ( int  f  ) 

uidlist.c271 行で定義されています。

参照先 gidlistidlist::ididlist::nameidlist::nextnumeric_idspreserve_aclspreserve_gidpreserve_uiduidlistwrite_buf()write_byte()write_int().

参照元 send_file_list().

00272 {
00273         struct idlist *list;
00274 
00275         if (numeric_ids)
00276                 return;
00277 
00278         if (preserve_uid || preserve_acls) {
00279                 int len;
00280                 /* we send sequences of uid/byte-length/name */
00281                 for (list = uidlist; list; list = list->next) {
00282                         if (!list->name)
00283                                 continue;
00284                         len = strlen(list->name);
00285                         write_int(f, list->id);
00286                         write_byte(f, len);
00287                         write_buf(f, list->name, len);
00288                 }
00289 
00290                 /* terminate the uid list with a 0 uid. We explicitly exclude
00291                  * 0 from the list */
00292                 write_int(f, 0);
00293         }
00294 
00295         if (preserve_gid || preserve_acls) {
00296                 int len;
00297                 for (list = gidlist; list; list = list->next) {
00298                         if (!list->name)
00299                                 continue;
00300                         len = strlen(list->name);
00301                         write_int(f, list->id);
00302                         write_byte(f, len);
00303                         write_buf(f, list->name, len);
00304                 }
00305                 write_int(f, 0);
00306         }
00307 }

void recv_uid_list ( int  f,
struct file_list flist 
)

uidlist.c311 行で定義されています。

参照先 am_rootfile_list::countfile_list::filesfile_struct::gididlist::idmatch_gid()match_uid()namenext_acl_gid()next_acl_uid()numeric_idsout_of_memory()preserve_aclspreserve_gidpreserve_uidread_byte()read_int()read_sbuf()recv_add_gid()recv_add_uid()file_struct::uid.

参照元 recv_file_list().

00312 {
00313         int id, i;
00314         char *name;
00315 
00316         if ((preserve_uid || preserve_acls) && !numeric_ids) {
00317                 /* read the uid list */
00318                 while ((id = read_int(f)) != 0) {
00319                         int len = read_byte(f);
00320                         name = new_array(char, len+1);
00321                         if (!name)
00322                                 out_of_memory("recv_uid_list");
00323                         read_sbuf(f, name, len);
00324                         recv_add_uid(id, name); /* node keeps name's memory */
00325                 }
00326         }
00327 
00328         if ((preserve_gid || preserve_acls) && !numeric_ids) {
00329                 /* read the gid list */
00330                 while ((id = read_int(f)) != 0) {
00331                         int len = read_byte(f);
00332                         name = new_array(char, len+1);
00333                         if (!name)
00334                                 out_of_memory("recv_uid_list");
00335                         read_sbuf(f, name, len);
00336                         recv_add_gid(id, name); /* node keeps name's memory */
00337                 }
00338         }
00339 
00340 #ifdef SUPPORT_ACLS
00341         if (preserve_acls && !numeric_ids) {
00342                 id_t *id;
00343                 while ((id = next_acl_uid(flist)) != NULL)
00344                         *id = match_uid(*id);
00345                 while ((id = next_acl_gid(flist)) != NULL)
00346                         *id = match_gid(*id);
00347         }
00348 #endif
00349 
00350         /* Now convert all the uids/gids from sender values to our values. */
00351         if (am_root && preserve_uid && !numeric_ids) {
00352                 for (i = 0; i < flist->count; i++)
00353                         flist->files[i]->uid = match_uid(flist->files[i]->uid);
00354         }
00355         if (preserve_gid && (!am_root || !numeric_ids)) {
00356                 for (i = 0; i < flist->count; i++)
00357                         flist->files[i]->gid = match_gid(flist->files[i]->gid);
00358         }
00359 }


変数

int verbose

options.c163 行で定義されています。

int preserve_uid

options.c54 行で定義されています。

int preserve_gid

options.c55 行で定義されています。

int preserve_acls

options.c48 行で定義されています。

int numeric_ids

options.c81 行で定義されています。

int am_root

options.c74 行で定義されています。

struct idlist* uidlist [static]

uidlist.c47 行で定義されています。

参照元 add_uid()match_uid()recv_add_uid()send_uid_list().

struct idlist* gidlist [static]

uidlist.c48 行で定義されています。

参照元 add_gid()match_gid()recv_add_gid()send_uid_list().


rsyncに対してSat Dec 5 19:45:46 2009に生成されました。  doxygen 1.4.7