static bool idmapname2id(char *name, size_t len, uint32_t *id, const uint32_t anon, bool group, gid_t *gid, bool *got_gid, char *at) { #ifdef USE_NFSIDMAP int rc; if (group) rc = nfs4_name_to_gid(name, id); else rc = nfs4_name_to_uid(name, id); if (rc == 0) { return true; } else { LogInfo(COMPONENT_IDMAPPER, "%s %s failed with %d, using anonymous.", (group ? "nfs4_name_to_gid" : "nfs4_name_to_uid"), name, -rc); return false; } #else /* USE_NFSIDMAP */ return false; #endif /* USE_NFSIDMAP */ }
/** * * name2gid: convert a name to a gid * * convert a name to a gid * * @param name [IN] the name of the user * @param pgid [OUT] the resulting gid * * return 1 if successful, 0 otherwise * */ int name2gid(char *name, gid_t * pgid) { #ifndef _USE_NFSIDMAP struct group g; #ifndef _SOLARIS struct group *pg = NULL; #endif static char buff[NFS4_MAX_DOMAIN_LEN]; /* Working area for getgrnam_r */ #endif gid_t gid; int rc; if(gidmap_get(name, (unsigned long *)&gid) == ID_MAPPER_SUCCESS) { LogFullDebug(COMPONENT_IDMAPPER, "name2gid: gidmap_get mapped %s to gid= %d", name, gid); *pgid = gid; } else { #ifdef _USE_NFSIDMAP if(!nfsidmap_set_conf()) { LogCrit(COMPONENT_IDMAPPER, "name2gid: nfsidmap_set_conf failed"); return 0; } rc = nfs4_name_to_gid(name, pgid); if(rc) { LogFullDebug(COMPONENT_IDMAPPER, "name2gid: nfs4_name_to_gid %s failed %d (%s)", name, -rc, strerror(-rc)); return 0; } LogFullDebug(COMPONENT_IDMAPPER, "name2gid: nfs4_name_to_gid %s returned %d", name, *pgid); if(gidmap_add(name, *pgid) != ID_MAPPER_SUCCESS) { LogCrit(COMPONENT_IDMAPPER, "name2gid: gidmap_add %s %d failed", name, *pgid); return 0; } #else #ifdef _SOLARIS if(getgrnam_r(name, &g, buff, NFS4_MAX_DOMAIN_LEN) != 0) #else if(getgrnam_r(name, &g, buff, NFS4_MAX_DOMAIN_LEN, &pg) != 0) #endif { LogFullDebug(COMPONENT_IDMAPPER, "name2gid: getgrnam_r %s failed", name); *pgid = -1; return 0; } else { *pgid = g.gr_gid; if(gidmap_add(name, g.gr_gid) != ID_MAPPER_SUCCESS) { LogCrit(COMPONENT_IDMAPPER, "name2gid: gidmap_add %s %d failed", name, g.gr_gid); return 0; } } #endif /* _USE_NFSIDMAP */ } return 1; } /* name2gid */