diff --git a/src/responder/nss/nss_cmd.c b/src/responder/nss/nss_cmd.c index 956ee53..6f6a766 100644 --- a/src/responder/nss/nss_cmd.c +++ b/src/responder/nss/nss_cmd.c @@ -1131,6 +1131,22 @@ static errno_t nss_cmd_getsidbyid(struct cli_ctx *cli_ctx) SSS_MC_NONE, nss_protocol_fill_sid); } +static errno_t nss_cmd_getsidbyuid(struct cli_ctx *cli_ctx) +{ + const char *attrs[] = { SYSDB_SID_STR, NULL }; + + return nss_getby_id(cli_ctx, false, CACHE_REQ_OBJECT_BY_ID, attrs, + SSS_MC_PASSWD, nss_protocol_fill_sid); +} + +static errno_t nss_cmd_getsidbygid(struct cli_ctx *cli_ctx) +{ + const char *attrs[] = { SYSDB_SID_STR, NULL }; + + return nss_getby_id(cli_ctx, false, CACHE_REQ_OBJECT_BY_ID, attrs, + SSS_MC_GROUP, nss_protocol_fill_sid); +} + static errno_t nss_cmd_getnamebysid(struct cli_ctx *cli_ctx) { return nss_getby_sid(cli_ctx, CACHE_REQ_OBJECT_BY_SID, @@ -1222,6 +1238,8 @@ struct sss_cmd_table *get_nss_cmds(void) { SSS_NSS_ENDSERVENT, nss_cmd_endservent }, { SSS_NSS_GETSIDBYNAME, nss_cmd_getsidbyname }, { SSS_NSS_GETSIDBYID, nss_cmd_getsidbyid }, + { SSS_NSS_GETSIDBYUID, nss_cmd_getsidbyuid }, + { SSS_NSS_GETSIDBYGID, nss_cmd_getsidbygid }, { SSS_NSS_GETNAMEBYSID, nss_cmd_getnamebysid }, { SSS_NSS_GETIDBYSID, nss_cmd_getidbysid }, { SSS_NSS_GETORIGBYNAME, nss_cmd_getorigbyname }, diff --git a/src/sss_client/idmap/sss_nss_idmap.c b/src/sss_client/idmap/sss_nss_idmap.c index cbf8c11..e643011 100644 --- a/src/sss_client/idmap/sss_nss_idmap.c +++ b/src/sss_client/idmap/sss_nss_idmap.c @@ -246,6 +246,8 @@ static int sss_nss_getyyybyxxx(union input inp, enum sss_cli_command cmd, break; case SSS_NSS_GETSIDBYID: + case SSS_NSS_GETSIDBYUID: + case SSS_NSS_GETSIDBYGID: rd.len = sizeof(uint32_t); rd.data = &inp.id; @@ -292,6 +294,8 @@ static int sss_nss_getyyybyxxx(union input inp, enum sss_cli_command cmd, switch(cmd) { case SSS_NSS_GETSIDBYID: + case SSS_NSS_GETSIDBYUID: + case SSS_NSS_GETSIDBYGID: case SSS_NSS_GETSIDBYNAME: case SSS_NSS_GETNAMEBYSID: case SSS_NSS_GETNAMEBYCERT: @@ -414,6 +418,60 @@ int sss_nss_getsidbyid(uint32_t id, char **sid, enum sss_id_type *type) return sss_nss_getsidbyid_timeout(id, NO_TIMEOUT, sid, type); } +int sss_nss_getsidbyuid_timeout(uint32_t uid, unsigned int timeout, + char **sid, enum sss_id_type *type) +{ + int ret; + union input inp; + struct output out; + + if (sid == NULL) { + return EINVAL; + } + + inp.id = uid; + + ret = sss_nss_getyyybyxxx(inp, SSS_NSS_GETSIDBYUID, timeout, &out); + if (ret == EOK) { + *sid = out.d.str; + *type = out.type; + } + + return ret; +} + +int sss_nss_getsidbyuid(uint32_t uid, char **sid, enum sss_id_type *type) +{ + return sss_nss_getsidbyuid_timeout(uid, NO_TIMEOUT, sid, type); +} + +int sss_nss_getsidbygid_timeout(uint32_t gid, unsigned int timeout, + char **sid, enum sss_id_type *type) +{ + int ret; + union input inp; + struct output out; + + if (sid == NULL) { + return EINVAL; + } + + inp.id = gid; + + ret = sss_nss_getyyybyxxx(inp, SSS_NSS_GETSIDBYGID, timeout, &out); + if (ret == EOK) { + *sid = out.d.str; + *type = out.type; + } + + return ret; +} + +int sss_nss_getsidbygid(uint32_t gid, char **sid, enum sss_id_type *type) +{ + return sss_nss_getsidbygid_timeout(gid, NO_TIMEOUT, sid, type); +} + int sss_nss_getnamebysid_timeout(const char *sid, unsigned int timeout, char **fq_name, enum sss_id_type *type) { diff --git a/src/sss_client/idmap/sss_nss_idmap.h b/src/sss_client/idmap/sss_nss_idmap.h index 125e72a..92d6672 100644 --- a/src/sss_client/idmap/sss_nss_idmap.h +++ b/src/sss_client/idmap/sss_nss_idmap.h @@ -79,6 +79,32 @@ int sss_nss_getsidbyname(const char *fq_name, char **sid, int sss_nss_getsidbyid(uint32_t id, char **sid, enum sss_id_type *type); /** + * @brief Find SID by a POSIX UID + * + * @param[in] id GID + * @param[out] sid String representation of the SID of the requested user + * or group, must be freed by the caller + * @param[out] type Type of the object related to the given ID + * + * @return + * - see #sss_nss_getsidbyname + */ +int sss_nss_getsidbyuid(uint32_t id, char **sid, enum sss_id_type *type); + +/** + * @brief Find SID by a POSIX GID + * + * @param[in] id GID + * @param[out] sid String representation of the SID of the requested user + * or group, must be freed by the caller + * @param[out] type Type of the object related to the given ID + * + * @return + * - see #sss_nss_getsidbyname + */ +int sss_nss_getsidbygid(uint32_t id, char **sid, enum sss_id_type *type); + +/** * @brief Return the fully qualified name for the given SID * * @param[in] sid String representation of the SID diff --git a/src/sss_client/sss_cli.h b/src/sss_client/sss_cli.h index 34eee58..b10cc03 100644 --- a/src/sss_client/sss_cli.h +++ b/src/sss_client/sss_cli.h @@ -272,6 +272,14 @@ SSS_NSS_GETLISTBYCERT = 0x0117, /**< Takes the zero terminated string of a X509 certificate and returns a list of zero terminated fully qualified names of the related objects. */ +SSS_NSS_GETSIDBYUID = 0x0118, /**< Takes an unsigned 32bit integer (POSIX UID) + and reurn the zero terminated string + representation of the SID of the object + with the given UID. */ +SSS_NSS_GETSIDBYGID = 0x0119, /**< Takes an unsigned 32bit integer (POSIX GID) + and reurn the zero terminated string + representation of the SID of the object + with the given UID. */ }; /**