Add a uid/gid to its list of ids. Only called on receiving side. */
| 241 | |
| 242 | /* Add a uid/gid to its list of ids. Only called on receiving side. */ |
| 243 | static struct idlist *recv_add_id(struct idlist **idlist_ptr, struct idlist *idmap, |
| 244 | id_t id, const char *name) |
| 245 | { |
| 246 | struct idlist *node; |
| 247 | union name_or_id noiu; |
| 248 | int flag; |
| 249 | id_t id2; |
| 250 | |
| 251 | noiu.name = name; /* ensure that add_to_list() gets the raw value. */ |
| 252 | if (!name) |
| 253 | name = ""; |
| 254 | |
| 255 | for (node = idmap; node; node = node->next) { |
| 256 | if (node->flags & NFLAGS_WILD_NAME_MATCH) { |
| 257 | if (!wildmatch(node->u.name, name)) |
| 258 | continue; |
| 259 | } else if (node->flags & NFLAGS_NAME_MATCH) { |
| 260 | if (strcmp(node->u.name, name) != 0) |
| 261 | continue; |
| 262 | } else if (node->u.max_id) { |
| 263 | if (id < node->id || id > node->u.max_id) |
| 264 | continue; |
| 265 | } else { |
| 266 | if (node->id != id) |
| 267 | continue; |
| 268 | } |
| 269 | break; |
| 270 | } |
| 271 | if (node) |
| 272 | id2 = node->id2; |
| 273 | else if (*name && id) { |
| 274 | if (idlist_ptr == &uidlist) { |
| 275 | uid_t uid; |
| 276 | id2 = user_to_uid(name, &uid, False) ? (id_t)uid : id; |
| 277 | } else { |
| 278 | gid_t gid; |
| 279 | id2 = group_to_gid(name, &gid, False) ? (id_t)gid : id; |
| 280 | } |
| 281 | } else |
| 282 | id2 = id; |
| 283 | |
| 284 | flag = idlist_ptr == &gidlist && !am_root && !is_in_group(id2) ? FLAG_SKIP_GROUP : 0; |
| 285 | node = add_to_list(idlist_ptr, id, noiu, id2, flag); |
| 286 | |
| 287 | if (DEBUG_GTE(OWN, 2)) { |
| 288 | rprintf(FINFO, "%sid %u(%s) maps to %u\n", |
| 289 | idlist_ptr == &uidlist ? "u" : "g", |
| 290 | (unsigned)id, name, (unsigned)id2); |
| 291 | } |
| 292 | |
| 293 | return node; |
| 294 | } |
| 295 | |
| 296 | /* this function is a definite candidate for a faster algorithm */ |
| 297 | uid_t match_uid(uid_t uid) |
no test coverage detected