bool idmapper_init(void) { #ifdef USE_NFSIDMAP if (!nfs_param.nfsv4_param.use_getpwnam) { if (nfs4_init_name_mapping(nfs_param.nfsv4_param.idmapconf) != 0) { return false; } owner_domain.addr = gsh_malloc(NFS4_MAX_DOMAIN_LEN + 1); if (owner_domain.addr == NULL) return false; if (nfs4_get_default_domain (NULL, owner_domain.addr, NFS4_MAX_DOMAIN_LEN) != 0) { gsh_free(owner_domain.addr); return false; } owner_domain.len = strlen(owner_domain.addr); } #endif /* USE_NFSIDMAP */ if (nfs_param.nfsv4_param.use_getpwnam) { owner_domain.addr = gsh_strdup(nfs_param.nfsv4_param .domainname); if (owner_domain.addr == NULL) return false; owner_domain.len = strlen(nfs_param.nfsv4_param.domainname); } idmapper_cache_init(); return true; }
/* Get list of "local equivalent" realms. Meaning the list of realms * where [email protected] is considered the same user as [email protected] * If not specified, default to upper-case of local domain name */ struct conf_list *get_local_realms(void) { static struct conf_list *local_realms = NULL; if (local_realms) return local_realms; local_realms = conf_get_list("General", "Local-Realms"); if (local_realms == NULL) { struct conf_list_node *node; local_realms = malloc(sizeof *local_realms); if (local_realms == NULL) return NULL; local_realms->cnt = 0; TAILQ_INIT(&local_realms->fields); node = calloc(1, sizeof *node); if (node == NULL) return NULL; node->field = calloc(1, NFS4_MAX_DOMAIN_LEN); if (node->field == NULL) { free(node); return NULL; } nfs4_get_default_domain(NULL, node->field, NFS4_MAX_DOMAIN_LEN); toupper_str(node->field); TAILQ_INSERT_TAIL(&local_realms->fields, node, link); local_realms->cnt++; } return local_realms; }
/* * Find the name@domain string from either a user or group id */ int name_lookup(char *id, key_serial_t key, int type) { char name[IDMAP_NAMESZ]; char domain[NFS4_MAX_DOMAIN_LEN]; uid_t uid; gid_t gid; int rc; rc = nfs4_get_default_domain(NULL, domain, NFS4_MAX_DOMAIN_LEN); if (rc != 0) { xlog_errno(rc, "name_lookup: nfs4_get_default_domain failed: %m"); rc = -1; goto out; } if (type == USER) { uid = atoi(id); rc = nfs4_uid_to_name(uid, domain, name, IDMAP_NAMESZ); } else { gid = atoi(id); rc = nfs4_gid_to_name(gid, domain, name, IDMAP_NAMESZ); } if (rc < 0) xlog_errno(rc, "name_lookup: %s: failed: %m", (type == USER ? "nfs4_uid_to_name" : "nfs4_gid_to_name")); if (rc == 0) { rc = keyctl_instantiate(key, &name, strlen(name), 0); if (rc < 0) xlog_err("name_lookup: keyctl_instantiate failed: %m"); } out: return rc; }
int nfsidmap_set_conf() { if(!nfsidmap_conf_read) { if(nfs4_init_name_mapping(_PATH_IDMAPDCONF)) return 0; if(nfs4_get_default_domain(NULL, idmap_domain, sizeof(idmap_domain))) return 0; nfsidmap_conf_read = TRUE; } return 1; }
static int display_default_domain(void) { char domain[NFS4_MAX_DOMAIN_LEN]; int rc; rc = nfs4_get_default_domain(NULL, domain, NFS4_MAX_DOMAIN_LEN); if (rc) { xlog_errno(rc, "nfs4_get_default_domain failed: %m"); return EXIT_FAILURE; } printf("%s\n", domain); return EXIT_SUCCESS; }