14 /* gcc nfsidmap.c -o nfsidmap -l nfsidmap -l keyutils */
17 #define IDMAP_NAMESZ 128
23 * Find either a user or group id based on the name@domain string
25 int id_lookup(char *name_at_domain, key_serial_t key, int type)
33 rc = nfs4_owner_to_uid(name_at_domain, &uid);
34 sprintf(id, "%u", uid);
36 rc = nfs4_group_owner_to_gid(name_at_domain, &gid);
37 sprintf(id, "%u", gid);
41 rc = keyctl_instantiate(key, id, strlen(id) + 1, 0);
47 * Find the name@domain string from either a user or group id
49 int name_lookup(char *id, key_serial_t key, int type)
51 char name[IDMAP_NAMESZ];
52 char domain[NFS4_MAX_DOMAIN_LEN];
57 rc = nfs4_get_default_domain(NULL, domain, NFS4_MAX_DOMAIN_LEN);
65 rc = nfs4_uid_to_name(uid, domain, name, IDMAP_NAMESZ);
68 rc = nfs4_gid_to_name(gid, domain, name, IDMAP_NAMESZ);
72 rc = keyctl_instantiate(key, &name, strlen(name), 0);
78 int main(int argc, char **argv)
90 arg = malloc(sizeof(char) * strlen(argv[2]) + 1);
92 type = strtok(arg, ":");
93 value = strtok(NULL, ":");
96 timeout = atoi(argv[3]);
101 key = strtol(argv[1], NULL, 10);
103 if (strcmp(type, "uid") == 0)
104 rc = id_lookup(value, key, USER);
105 else if (strcmp(type, "gid") == 0)
106 rc = id_lookup(value, key, GROUP);
107 else if (strcmp(type, "user") == 0)
108 rc = name_lookup(value, key, USER);
109 else if (strcmp(type, "group") == 0)
110 rc = name_lookup(value, key, GROUP);
112 /* Set timeout to 5 (600 seconds) minutes */
114 keyctl_set_timeout(key, timeout);