static bool test_wbc_get_sidaliases(struct torture_context *tctx) { struct wbcDomainSid builtin; struct wbcDomainInfo *info; struct wbcInterfaceDetails *details; struct wbcDomainSid sids[2]; uint32_t *rids; uint32_t num_rids; wbcErr ret; torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details), "wbcInterfaceDetails failed"); torture_assert_wbc_ok( tctx, wbcDomainInfo(details->netbios_domain, &info), "wbcDomainInfo failed"); wbcFreeMemory(details); sids[0] = info->sid; sids[0].sub_auths[sids[0].num_auths++] = 500; sids[1] = info->sid; sids[1].sub_auths[sids[1].num_auths++] = 512; wbcFreeMemory(info); torture_assert_wbc_ok( tctx, wbcStringToSid("S-1-5-32", &builtin), "wbcStringToSid failed"); ret = wbcGetSidAliases(&builtin, sids, 2, &rids, &num_rids); torture_assert_wbc_ok(tctx, ret, "wbcGetSidAliases failed"); wbcFreeMemory(rids); 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); }
bool winbind_get_sid_aliases(TALLOC_CTX *mem_ctx, const struct dom_sid *dom_sid, const struct dom_sid *members, size_t num_members, uint32_t **pp_alias_rids, size_t *p_num_alias_rids) { wbcErr ret; struct wbcDomainSid domain_sid; struct wbcDomainSid *sid_list = NULL; size_t i; uint32_t * rids; uint32_t num_rids; memcpy(&domain_sid, dom_sid, sizeof(*dom_sid)); sid_list = talloc_array(mem_ctx, struct wbcDomainSid, num_members); for (i=0; i < num_members; i++) { memcpy(&sid_list[i], &members[i], sizeof(sid_list[i])); } ret = wbcGetSidAliases(&domain_sid, sid_list, num_members, &rids, &num_rids); if (ret != WBC_ERR_SUCCESS) { return false; } *pp_alias_rids = talloc_array(mem_ctx, uint32_t, num_rids); if (*pp_alias_rids == NULL) { wbcFreeMemory(rids); return false; } memcpy(*pp_alias_rids, rids, sizeof(uint32_t) * num_rids); *p_num_alias_rids = num_rids; wbcFreeMemory(rids); return true; }