X-Git-Url: http://git.samba.org/samba.git/?p=nivanova%2Fsamba-autobuild%2F.git;a=blobdiff_plain;f=nsswitch%2Fwbinfo.c;h=30e23b6a8fb5287dc1831a2dbba0a60c5c733052;hp=a4b2a3c998e3d015f0f3b5ca43651cff0bbd5c4e;hb=c51795c747198f9e002505ffa39ad710beff0358;hpb=48ad64aa78568c4ce743345448c9d39305752d73 diff --git a/nsswitch/wbinfo.c b/nsswitch/wbinfo.c index a4b2a3c998e..30e23b6a8fb 100644 --- a/nsswitch/wbinfo.c +++ b/nsswitch/wbinfo.c @@ -134,7 +134,6 @@ static bool parse_wbinfo_domain_user(const char *domuser, fstring domain, fstrcpy(user, p+1); fstrcpy(domain, domuser); domain[PTR_DIFF(p, domuser)] = 0; - strupper_m(domain); return true; } @@ -187,6 +186,8 @@ static bool wbinfo_get_userinfo(char *user) pwd->pw_dir, pwd->pw_shell); + wbcFreeMemory(pwd); + return true; } @@ -212,6 +213,8 @@ static bool wbinfo_get_uidinfo(int uid) pwd->pw_dir, pwd->pw_shell); + wbcFreeMemory(pwd); + return true; } @@ -357,16 +360,9 @@ static bool wbinfo_get_usersids(const char *user_sid_str) } for (i = 0; i < num_sids; i++) { - char *str = NULL; - wbc_status = wbcSidToString(&sids[i], &str); - if (!WBC_ERROR_IS_OK(wbc_status)) { - d_fprintf(stderr, "failed to call wbcSidToString: " - "%s\n", wbcErrorString(wbc_status)); - wbcFreeMemory(sids); - return false; - } + char str[WBC_SID_STRING_BUFLEN]; + wbcSidToStringBuf(&sids[i], str, sizeof(str)); d_printf("%s\n", str); - wbcFreeMemory(str); } wbcFreeMemory(sids); @@ -385,7 +381,7 @@ static bool wbinfo_get_userdomgroups(const char *user_sid_str) wbc_status = wbcStringToSid(user_sid_str, &user_sid); if (!WBC_ERROR_IS_OK(wbc_status)) { - d_fprintf(stderr, "failed to call wbcSidToString: %s\n", + d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", wbcErrorString(wbc_status)); return false; } @@ -398,16 +394,9 @@ static bool wbinfo_get_userdomgroups(const char *user_sid_str) } for (i = 0; i < num_sids; i++) { - char *str = NULL; - wbc_status = wbcSidToString(&sids[i], &str); - if (!WBC_ERROR_IS_OK(wbc_status)) { - d_fprintf(stderr, "failed to call wbcSidToString: " - "%s\n", wbcErrorString(wbc_status)); - wbcFreeMemory(sids); - return false; - } + char str[WBC_SID_STRING_BUFLEN]; + wbcSidToStringBuf(&sids[i], str, sizeof(str)); d_printf("%s\n", str); - wbcFreeMemory(str); } wbcFreeMemory(sids); @@ -424,7 +413,7 @@ static bool wbinfo_get_sidaliases(const char *domain, struct wbcDomainSid user_sid; uint32_t *alias_rids = NULL; uint32_t num_alias_rids; - char *domain_sid_str = NULL; + char domain_sid_str[WBC_SID_STRING_BUFLEN]; /* Send request */ if ((domain == NULL) || (strequal(domain, ".")) || @@ -451,10 +440,7 @@ static bool wbinfo_get_sidaliases(const char *domain, goto done; } - wbc_status = wbcSidToString(&dinfo->sid, &domain_sid_str); - if (!WBC_ERROR_IS_OK(wbc_status)) { - goto done; - } + wbcSidToStringBuf(&dinfo->sid, domain_sid_str, sizeof(domain_sid_str)); for (i = 0; i < num_alias_rids; i++) { d_printf("%s-%d\n", domain_sid_str, alias_rids[i]); @@ -463,12 +449,7 @@ static bool wbinfo_get_sidaliases(const char *domain, wbcFreeMemory(alias_rids); done: - if (domain_sid_str) { - wbcFreeMemory(domain_sid_str); - } - if (dinfo) { - wbcFreeMemory(dinfo); - } + wbcFreeMemory(dinfo); return (WBC_ERR_SUCCESS == wbc_status); } @@ -589,6 +570,8 @@ static bool wbinfo_list_domains(bool list_all_domains, bool verbose) d_printf("\n"); } + wbcFreeMemory(domain_list); + return true; } @@ -641,6 +624,8 @@ static bool wbinfo_show_onlinestatus(const char *domain) is_offline ? "offline" : "online" ); } + wbcFreeMemory(domain_list); + return true; } @@ -651,7 +636,7 @@ static bool wbinfo_domain_info(const char *domain) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct wbcDomainInfo *dinfo = NULL; - char *sid_str = NULL; + char sid_str[WBC_SID_STRING_BUFLEN]; if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){ domain = get_winbind_domain(); @@ -666,13 +651,7 @@ static bool wbinfo_domain_info(const char *domain) return false; } - wbc_status = wbcSidToString(&dinfo->sid, &sid_str); - if (!WBC_ERROR_IS_OK(wbc_status)) { - d_fprintf(stderr, "failed to call wbcSidToString: %s\n", - wbcErrorString(wbc_status)); - wbcFreeMemory(dinfo); - return false; - } + wbcSidToStringBuf(&dinfo->sid, sid_str, sizeof(sid_str)); /* Display response */ @@ -691,7 +670,6 @@ static bool wbinfo_domain_info(const char *domain) (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_PRIMARY) ? "Yes" : "No"); - wbcFreeMemory(sid_str); wbcFreeMemory(dinfo); return true; @@ -878,7 +856,7 @@ static bool wbinfo_uid_to_sid(uid_t uid) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct wbcDomainSid sid; - char *sid_str = NULL; + char sid_str[WBC_SID_STRING_BUFLEN]; /* Send request */ @@ -889,19 +867,12 @@ static bool wbinfo_uid_to_sid(uid_t uid) return false; } - wbc_status = wbcSidToString(&sid, &sid_str); - if (!WBC_ERROR_IS_OK(wbc_status)) { - d_fprintf(stderr, "failed to call wbcSidToString: %s\n", - wbcErrorString(wbc_status)); - return false; - } + wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str)); /* Display response */ d_printf("%s\n", sid_str); - wbcFreeMemory(sid_str); - return true; } @@ -911,7 +882,7 @@ static bool wbinfo_gid_to_sid(gid_t gid) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct wbcDomainSid sid; - char *sid_str = NULL; + char sid_str[WBC_SID_STRING_BUFLEN]; /* Send request */ @@ -922,19 +893,12 @@ static bool wbinfo_gid_to_sid(gid_t gid) return false; } - wbc_status = wbcSidToString(&sid, &sid_str); - if (!WBC_ERROR_IS_OK(wbc_status)) { - d_fprintf(stderr, "failed to call wbcSidToString: %s\n", - wbcErrorString(wbc_status)); - return false; - } + wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str)); /* Display response */ d_printf("%s\n", sid_str); - wbcFreeMemory(sid_str); - return true; } @@ -998,6 +962,74 @@ static bool wbinfo_sid_to_gid(const char *sid_str) return true; } +static bool wbinfo_sids_to_unix_ids(const char *arg) +{ + char sidstr[WBC_SID_STRING_BUFLEN]; + struct wbcDomainSid *sids; + struct wbcUnixId *unix_ids; + int i, num_sids; + const char *p; + wbcErr wbc_status; + + + num_sids = 0; + sids = NULL; + p = arg; + + while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) { + sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid, + num_sids+1); + if (sids == NULL) { + d_fprintf(stderr, "talloc failed\n"); + return false; + } + wbc_status = wbcStringToSid(sidstr, &sids[num_sids]); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n", + sidstr, wbcErrorString(wbc_status)); + TALLOC_FREE(sids); + return false; + } + num_sids += 1; + } + + unix_ids = talloc_array(talloc_tos(), struct wbcUnixId, num_sids); + if (unix_ids == NULL) { + TALLOC_FREE(sids); + return false; + } + + wbc_status = wbcSidsToUnixIds(sids, num_sids, unix_ids); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "wbcSidsToUnixIds failed: %s\n", + wbcErrorString(wbc_status)); + TALLOC_FREE(sids); + return false; + } + + for (i=0; i uid %d\n", sidstr, unix_ids[i].id.uid); + break; + case WBC_ID_TYPE_GID: + d_printf("%s -> gid %d\n", sidstr, unix_ids[i].id.gid); + break; + default: + d_printf("%s -> unmapped\n", sidstr); + break; + } + } + + TALLOC_FREE(sids); + TALLOC_FREE(unix_ids); + + return true; +} + static bool wbinfo_allocate_uid(void) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; @@ -1040,6 +1072,122 @@ static bool wbinfo_allocate_gid(void) return true; } +static bool wbinfo_set_uid_mapping(uid_t uid, const char *sid_str) +{ + wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; + struct wbcDomainSid sid; + + /* Send request */ + + wbc_status = wbcStringToSid(sid_str, &sid); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", + wbcErrorString(wbc_status)); + return false; + } + + wbc_status = wbcSetUidMapping(uid, &sid); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "failed to call wbcSetUidMapping: %s\n", + wbcErrorString(wbc_status)); + return false; + } + + /* Display response */ + + d_printf("uid %u now mapped to sid %s\n", + (unsigned int)uid, sid_str); + + return true; +} + +static bool wbinfo_set_gid_mapping(gid_t gid, const char *sid_str) +{ + wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; + struct wbcDomainSid sid; + + /* Send request */ + + wbc_status = wbcStringToSid(sid_str, &sid); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", + wbcErrorString(wbc_status)); + return false; + } + + wbc_status = wbcSetGidMapping(gid, &sid); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "failed to call wbcSetGidMapping: %s\n", + wbcErrorString(wbc_status)); + return false; + } + + /* Display response */ + + d_printf("gid %u now mapped to sid %s\n", + (unsigned int)gid, sid_str); + + return true; +} + +static bool wbinfo_remove_uid_mapping(uid_t uid, const char *sid_str) +{ + wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; + struct wbcDomainSid sid; + + /* Send request */ + + wbc_status = wbcStringToSid(sid_str, &sid); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", + wbcErrorString(wbc_status)); + return false; + } + + wbc_status = wbcRemoveUidMapping(uid, &sid); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "failed to call wbcRemoveUidMapping: %s\n", + wbcErrorString(wbc_status)); + return false; + } + + /* Display response */ + + d_printf("Removed uid %u to sid %s mapping\n", + (unsigned int)uid, sid_str); + + return true; +} + +static bool wbinfo_remove_gid_mapping(gid_t gid, const char *sid_str) +{ + wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; + struct wbcDomainSid sid; + + /* Send request */ + + wbc_status = wbcStringToSid(sid_str, &sid); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "failed to call wbcStringToSid: %s\n", + wbcErrorString(wbc_status)); + return false; + } + + wbc_status = wbcRemoveGidMapping(gid, &sid); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "failed to call wbcRemoveGidMapping: %s\n", + wbcErrorString(wbc_status)); + return false; + } + + /* Display response */ + + d_printf("Removed gid %u to sid %s mapping\n", + (unsigned int)gid, sid_str); + + return true; +} + /* Convert sid to string */ static bool wbinfo_lookupsid(const char *sid_str) @@ -1180,20 +1328,64 @@ static bool wbinfo_lookuprids(const char *domain, const char *arg) ret = true; done: - if (dinfo) { - wbcFreeMemory(dinfo); - } - if (domain_name) { - wbcFreeMemory(domain_name); + wbcFreeMemory(dinfo); + wbcFreeMemory(domain_name); + wbcFreeMemory(names); + wbcFreeMemory(types); + TALLOC_FREE(mem_ctx); + return ret; +} + +static bool wbinfo_lookup_sids(const char *arg) +{ + char sidstr[WBC_SID_STRING_BUFLEN]; + struct wbcDomainSid *sids; + struct wbcDomainInfo *domains; + struct wbcTranslatedName *names; + int num_domains; + int i, num_sids; + const char *p; + wbcErr wbc_status; + + + num_sids = 0; + sids = NULL; + p = arg; + + while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) { + sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid, + num_sids+1); + if (sids == NULL) { + d_fprintf(stderr, "talloc failed\n"); + return false; + } + wbc_status = wbcStringToSid(sidstr, &sids[num_sids]); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n", + sidstr, wbcErrorString(wbc_status)); + TALLOC_FREE(sids); + return false; + } + num_sids += 1; } - if (names) { - wbcFreeMemory(names); + + wbc_status = wbcLookupSids(sids, num_sids, &domains, &num_domains, + &names); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "wbcLookupSids failed: %s\n", + wbcErrorString(wbc_status)); + TALLOC_FREE(sids); + return false; } - if (types) { - wbcFreeMemory(types); + + for (i=0; i %s\\%s %d\n", sidstr, + domains[names[i].domain_index].short_name, + names[i].name, names[i].type); } - TALLOC_FREE(mem_ctx); - return ret; + return true; } /* Convert string to sid */ @@ -1202,7 +1394,7 @@ static bool wbinfo_lookupname(const char *full_name) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct wbcDomainSid sid; - char *sid_str; + char sid_str[WBC_SID_STRING_BUFLEN]; enum wbcSidType type; fstring domain_name; fstring account_name; @@ -1220,19 +1412,12 @@ static bool wbinfo_lookupname(const char *full_name) return false; } - wbc_status = wbcSidToString(&sid, &sid_str); - if (!WBC_ERROR_IS_OK(wbc_status)) { - d_fprintf(stderr, "failed to call wbcSidToString: %s\n", - wbcErrorString(wbc_status)); - return false; - } + wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str)); /* Display response */ d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type); - wbcFreeMemory(sid_str); - return true; } @@ -1834,8 +2019,14 @@ enum { OPT_USERDOMGROUPS, OPT_SIDALIASES, OPT_USERSIDS, + OPT_LOOKUP_SIDS, OPT_ALLOCATE_UID, OPT_ALLOCATE_GID, + OPT_SET_UID_MAPPING, + OPT_SET_GID_MAPPING, + OPT_REMOVE_UID_MAPPING, + OPT_REMOVE_GID_MAPPING, + OPT_SIDS_TO_XIDS, OPT_SEPARATOR, OPT_LIST_ALL_DOMAINS, OPT_LIST_OWN_DOMAIN, @@ -1888,6 +2079,9 @@ int main(int argc, char **argv, char **envp) { "sid-to-fullname", 0, POPT_ARG_STRING, &string_arg, OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" }, { "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" }, + { "lookup-sids", 0, POPT_ARG_STRING, &string_arg, + OPT_LOOKUP_SIDS, "Converts SIDs to types and names", + "Sid-List"}, { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" }, { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" }, { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" }, @@ -1896,6 +2090,12 @@ int main(int argc, char **argv, char **envp) "Get a new UID out of idmap" }, { "allocate-gid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_GID, "Get a new GID out of idmap" }, + { "set-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_SET_UID_MAPPING, "Create or modify uid to sid mapping in idmap", "UID,SID" }, + { "set-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_SET_GID_MAPPING, "Create or modify gid to sid mapping in idmap", "GID,SID" }, + { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" }, + { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" }, + { "sids-to-unix-ids", 0, POPT_ARG_STRING, &string_arg, + OPT_SIDS_TO_XIDS, "Translate SIDs to Unix IDs", "Sid-List" }, { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" }, { "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" }, { "ping-dc", 'P', POPT_ARG_NONE, 0, 'P', @@ -2028,6 +2228,13 @@ int main(int argc, char **argv, char **envp) goto done; } break; + case OPT_LOOKUP_SIDS: + if (!wbinfo_lookup_sids(string_arg)) { + d_fprintf(stderr, "Could not lookup SIDs %s\n", + string_arg); + goto done; + } + break; case 'n': if (!wbinfo_lookupname(string_arg)) { d_fprintf(stderr, "Could not lookup name %s\n", @@ -2095,6 +2302,55 @@ int main(int argc, char **argv, char **envp) goto done; } break; + case OPT_SET_UID_MAPPING: + if (!parse_mapping_arg(string_arg, &int_subarg, + &string_subarg) || + !wbinfo_set_uid_mapping(int_subarg, string_subarg)) + { + d_fprintf(stderr, "Could not create or modify " + "uid to sid mapping\n"); + goto done; + } + break; + case OPT_SET_GID_MAPPING: + if (!parse_mapping_arg(string_arg, &int_subarg, + &string_subarg) || + !wbinfo_set_gid_mapping(int_subarg, string_subarg)) + { + d_fprintf(stderr, "Could not create or modify " + "gid to sid mapping\n"); + goto done; + } + break; + case OPT_REMOVE_UID_MAPPING: + if (!parse_mapping_arg(string_arg, &int_subarg, + &string_subarg) || + !wbinfo_remove_uid_mapping(int_subarg, + string_subarg)) + { + d_fprintf(stderr, "Could not remove uid to sid " + "mapping\n"); + goto done; + } + break; + case OPT_REMOVE_GID_MAPPING: + if (!parse_mapping_arg(string_arg, &int_subarg, + &string_subarg) || + !wbinfo_remove_gid_mapping(int_subarg, + string_subarg)) + { + d_fprintf(stderr, "Could not remove gid to sid " + "mapping\n"); + goto done; + } + break; + case OPT_SIDS_TO_XIDS: + if (!wbinfo_sids_to_unix_ids(string_arg)) { + d_fprintf(stderr, "wbinfo_sids_to_unix_ids " + "failed\n"); + goto done; + } + break; case 't': if (!wbinfo_check_secret(opt_domain_name)) { d_fprintf(stderr, "Could not check secret\n");