summaryrefslogtreecommitdiff
path: root/usr/src/lib/libidmap
diff options
context:
space:
mode:
authorbaban <none@none>2007-09-13 13:50:11 -0700
committerbaban <none@none>2007-09-13 13:50:11 -0700
commitdd5829d1456ba00e6f704e6a88e7eaae608e3c1b (patch)
tree91aeba6f04f7a84dd438b2d2b02251984bf2307a /usr/src/lib/libidmap
parent3b427fad1e8c37a2021700224474a546cc45cc5f (diff)
downloadillumos-joyent-dd5829d1456ba00e6f704e6a88e7eaae608e3c1b.tar.gz
6601949 nfsmapid should handle Windows users and groups in a heterogenous environment
6604089 nfsmapid uses incorrect size when allocating the return buffer
Diffstat (limited to 'usr/src/lib/libidmap')
-rw-r--r--usr/src/lib/libidmap/common/idmap.h17
-rw-r--r--usr/src/lib/libidmap/common/idmap_api.c128
-rw-r--r--usr/src/lib/libidmap/common/mapfile-vers4
3 files changed, 149 insertions, 0 deletions
diff --git a/usr/src/lib/libidmap/common/idmap.h b/usr/src/lib/libidmap/common/idmap.h
index d9d58cd794..7c1507fe49 100644
--- a/usr/src/lib/libidmap/common/idmap.h
+++ b/usr/src/lib/libidmap/common/idmap.h
@@ -103,6 +103,23 @@ extern idmap_stat idmap_get_mappings(idmap_get_handle_t *);
/* Destroy the handle */
extern void idmap_get_destroy(idmap_get_handle_t *);
+
+/*
+ * API to get Windows name by UID/GID and vice-versa
+ */
+/* Given UID, get Windows name */
+extern idmap_stat idmap_getwinnamebyuid(uid_t, char **, char **);
+
+/* Given GID, get Windows name */
+extern idmap_stat idmap_getwinnamebygid(gid_t, char **, char **);
+
+/* Given Windows name, get UID */
+extern idmap_stat idmap_getuidbywinname(const char *, const char *, uid_t *);
+
+/* Given Windows name, get GID */
+extern idmap_stat idmap_getgidbywinname(const char *, const char *, gid_t *);
+
+
#ifdef __cplusplus
}
#endif
diff --git a/usr/src/lib/libidmap/common/idmap_api.c b/usr/src/lib/libidmap/common/idmap_api.c
index 2c6c7edd03..3a90685268 100644
--- a/usr/src/lib/libidmap/common/idmap_api.c
+++ b/usr/src/lib/libidmap/common/idmap_api.c
@@ -1639,3 +1639,131 @@ idmap_stat4prot(idmap_stat status) {
}
return (status);
}
+
+
+/*
+ * Get uid given Windows name
+ */
+idmap_stat
+idmap_getuidbywinname(const char *name, const char *domain, uid_t *uid) {
+ idmap_handle_t *ih;
+ idmap_retcode rc;
+ int is_user;
+
+ if (uid == NULL)
+ return (IDMAP_ERR_ARG);
+
+ /* Get mapping */
+ if ((rc = idmap_init(&ih)) != IDMAP_SUCCESS)
+ return (rc);
+ rc = idmap_get_w2u_mapping(ih, NULL, NULL, name, domain, 0,
+ &is_user, uid, NULL, NULL);
+ (void) idmap_fini(ih);
+
+ /*
+ * XXX Until we have diagonal mapping support, check if
+ * the given name belongs to a user
+ */
+ if (rc == IDMAP_SUCCESS && !is_user)
+ return (IDMAP_ERR_NOTUSER);
+ return (rc);
+}
+
+
+/*
+ * Get gid given Windows name
+ */
+idmap_stat
+idmap_getgidbywinname(const char *name, const char *domain, gid_t *gid) {
+ idmap_handle_t *ih;
+ idmap_retcode rc;
+ int is_user;
+
+ if (gid == NULL)
+ return (IDMAP_ERR_ARG);
+
+ /* Get mapping */
+ if ((rc = idmap_init(&ih)) != IDMAP_SUCCESS)
+ return (rc);
+ rc = idmap_get_w2u_mapping(ih, NULL, NULL, name, domain, 0,
+ &is_user, gid, NULL, NULL);
+ (void) idmap_fini(ih);
+
+ /*
+ * XXX Until we have diagonal mapping support, check if
+ * the given name belongs to a group
+ */
+ if (rc == IDMAP_SUCCESS && is_user)
+ return (IDMAP_ERR_NOTGROUP);
+ return (rc);
+}
+
+
+/*
+ * Get winname given pid
+ */
+static idmap_retcode
+idmap_getwinnamebypid(uid_t pid, int is_user, char **name, char **domain) {
+ idmap_handle_t *ih;
+ idmap_retcode rc;
+ int len;
+ char *winname, *windomain;
+
+ if (name == NULL)
+ return (IDMAP_ERR_ARG);
+
+ /* Get mapping */
+ if ((rc = idmap_init(&ih)) != IDMAP_SUCCESS)
+ return (rc);
+ rc = idmap_get_u2w_mapping(ih, &pid, NULL, 0, is_user, NULL,
+ NULL, &winname, &windomain, NULL);
+ (void) idmap_fini(ih);
+
+ /* Return on error */
+ if (rc != IDMAP_SUCCESS)
+ return (rc);
+
+ /*
+ * The given PID may have been mapped to a locally
+ * generated SID in which case there isn't any
+ * Windows name
+ */
+ if (winname == NULL || windomain == NULL) {
+ idmap_free(winname);
+ idmap_free(windomain);
+ return (IDMAP_ERR_NORESULT);
+ }
+
+ if (domain != NULL) {
+ *name = winname;
+ *domain = windomain;
+ } else {
+ len = strlen(winname) + strlen(windomain) + 2;
+ if ((*name = malloc(len)) != NULL)
+ (void) snprintf(*name, len, "%s@%s", winname,
+ windomain);
+ else
+ rc = IDMAP_ERR_MEMORY;
+ idmap_free(winname);
+ idmap_free(windomain);
+ }
+ return (rc);
+}
+
+
+/*
+ * Get winname given uid
+ */
+idmap_stat
+idmap_getwinnamebyuid(uid_t uid, char **name, char **domain) {
+ return (idmap_getwinnamebypid(uid, 1, name, domain));
+}
+
+
+/*
+ * Get winname given gid
+ */
+idmap_stat
+idmap_getwinnamebygid(gid_t gid, char **name, char **domain) {
+ return (idmap_getwinnamebypid(gid, 0, name, domain));
+}
diff --git a/usr/src/lib/libidmap/common/mapfile-vers b/usr/src/lib/libidmap/common/mapfile-vers
index 00c7647e10..1fe09cf777 100644
--- a/usr/src/lib/libidmap/common/mapfile-vers
+++ b/usr/src/lib/libidmap/common/mapfile-vers
@@ -68,6 +68,10 @@ SUNWprivate {
idmap_udt_commit;
idmap_udt_create;
idmap_udt_flush_namerules;
+ idmap_getwinnamebyuid;
+ idmap_getwinnamebygid;
+ idmap_getuidbywinname;
+ idmap_getgidbywinname;
local:
*;
};