diff options
Diffstat (limited to 'nsswitch/wbinfo.c')
-rw-r--r-- | nsswitch/wbinfo.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/nsswitch/wbinfo.c b/nsswitch/wbinfo.c index ce53cadc58..4d935f5239 100644 --- a/nsswitch/wbinfo.c +++ b/nsswitch/wbinfo.c @@ -202,6 +202,31 @@ static bool wbinfo_get_uidinfo(int uid) return true; } +static bool wbinfo_get_user_sidinfo(const char *sid_str) +{ + wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; + struct passwd *pwd = NULL; + struct wbcDomainSid sid; + + wbc_status = wbcStringToSid(sid_str, &sid); + wbc_status = wbcGetpwsid(&sid, &pwd); + if (!WBC_ERROR_IS_OK(wbc_status)) { + return false; + } + + d_printf("%s:%s:%d:%d:%s:%s:%s\n", + pwd->pw_name, + pwd->pw_passwd, + pwd->pw_uid, + pwd->pw_gid, + pwd->pw_gecos, + pwd->pw_dir, + pwd->pw_shell); + + return true; +} + + /* pull grent for a given group */ static bool wbinfo_get_groupinfo(const char *group) { @@ -341,6 +366,64 @@ static bool wbinfo_get_userdomgroups(const char *user_sid_str) return true; } +static bool wbinfo_get_sidaliases(const char *domain, + const char *user_sid_str) +{ + wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; + struct wbcDomainInfo *dinfo = NULL; + uint32_t i; + struct wbcDomainSid user_sid; + uint32_t *alias_rids = NULL; + uint32_t num_alias_rids; + char *domain_sid_str = NULL; + + /* Send request */ + if ((domain == NULL) || (strequal(domain, ".")) || + (domain[0] == '\0')) { + domain = get_winbind_domain(); + } + + /* Send request */ + + wbc_status = wbcDomainInfo(domain, &dinfo); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_printf("wbcDomainInfo(%s) failed: %s\n", domain, + wbcErrorString(wbc_status)); + goto done; + } + wbc_status = wbcStringToSid(user_sid_str, &user_sid); + if (!WBC_ERROR_IS_OK(wbc_status)) { + goto done; + } + + wbc_status = wbcGetSidAliases(&dinfo->sid, &user_sid, 1, + &alias_rids, &num_alias_rids); + if (!WBC_ERROR_IS_OK(wbc_status)) { + goto done; + } + + wbc_status = wbcSidToString(&dinfo->sid, &domain_sid_str); + if (!WBC_ERROR_IS_OK(wbc_status)) { + goto done; + } + + for (i = 0; i < num_alias_rids; i++) { + d_printf("%s-%d\n", domain_sid_str, alias_rids[i]); + } + + wbcFreeMemory(alias_rids); + +done: + if (domain_sid_str) { + wbcFreeMemory(domain_sid_str); + } + if (dinfo) { + wbcFreeMemory(dinfo); + } + return (WBC_ERR_SUCCESS == wbc_status); +} + + /* Convert NetBIOS name to IP */ static bool wbinfo_wins_byname(const char *name) @@ -1553,6 +1636,7 @@ enum { OPT_GETDCNAME, OPT_DSGETDCNAME, OPT_USERDOMGROUPS, + OPT_SIDALIASES, OPT_USERSIDS, OPT_ALLOCATE_UID, OPT_ALLOCATE_GID, @@ -1564,6 +1648,7 @@ enum { OPT_LIST_ALL_DOMAINS, OPT_LIST_OWN_DOMAIN, OPT_UID_INFO, + OPT_USER_SIDINFO, OPT_GROUP_INFO, OPT_GID_INFO, OPT_VERBOSE, @@ -1622,10 +1707,12 @@ int main(int argc, char **argv, char **envp) { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" }, { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" }, { "group-info", 0, POPT_ARG_STRING, &string_arg, OPT_GROUP_INFO, "Get group info", "GROUP" }, + { "user-sidinfo", 0, POPT_ARG_STRING, &string_arg, OPT_USER_SIDINFO, "Get user info from sid", "SID" }, { "gid-info", 0, POPT_ARG_INT, &int_arg, OPT_GID_INFO, "Get group info from gid", "GID" }, { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" }, { "user-domgroups", 0, POPT_ARG_STRING, &string_arg, OPT_USERDOMGROUPS, "Get user domain groups", "SID" }, + { "sid-aliases", 0, POPT_ARG_STRING, &string_arg, OPT_SIDALIASES, "Get sid aliases", "SID" }, { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" }, { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" }, { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" }, @@ -1860,6 +1947,13 @@ int main(int argc, char **argv, char **envp) goto done; } break; + case OPT_USER_SIDINFO: + if ( !wbinfo_get_user_sidinfo(string_arg)) { + d_fprintf(stderr, "Could not get info for user sid %s\n", + string_arg); + goto done; + } + break; case OPT_UID_INFO: if ( !wbinfo_get_uidinfo(int_arg)) { d_fprintf(stderr, "Could not get info for uid " @@ -1902,6 +1996,13 @@ int main(int argc, char **argv, char **envp) goto done; } break; + case OPT_SIDALIASES: + if (!wbinfo_get_sidaliases(opt_domain_name, string_arg)) { + d_fprintf(stderr, "Could not get sid aliases " + "for user SID %s\n", string_arg); + goto done; + } + break; case 'a': { bool got_error = false; |