static bool wbinfo_lookupname(const char *full_name) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct wbcDomainSid sid; char *sid_str; enum wbcSidType type; fstring domain_name; fstring account_name; /* Send off request */ parse_wbinfo_domain_user(full_name, domain_name, account_name); wbc_status = wbcLookupName(domain_name, account_name, &sid, &type); if (!WBC_ERROR_IS_OK(wbc_status)) { return false; } wbc_status = wbcSidToString(&sid, &sid_str); if (!WBC_ERROR_IS_OK(wbc_status)) { return false; } /* Display response */ d_printf("%s %s (%d)\n", sid_str, sid_type_lookup(type), type); wbcFreeMemory(sid_str); return true; }
static bool test_wbc_users(struct torture_context *tctx) { const char *domain_name = NULL; uint32_t num_users; const char **users; int i; struct wbcInterfaceDetails *details; torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details), "%s", "wbcInterfaceDetails failed"); domain_name = talloc_strdup(tctx, details->netbios_domain); wbcFreeMemory(details); torture_assert_wbc_ok(tctx, wbcListUsers(domain_name, &num_users, &users), "%s", "wbcListUsers failed"); torture_assert(tctx, !(num_users > 0 && !users), "wbcListUsers returned invalid results"); for (i=0; i < MIN(num_users,100); i++) { struct wbcDomainSid sid, *sids; enum wbcSidType name_type; char *domain; char *name; char *sid_string; uint32_t num_sids; torture_assert_wbc_ok(tctx, wbcLookupName(domain_name, users[i], &sid, &name_type), "wbcLookupName of %s failed", users[i]); torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER, "wbcLookupName expected WBC_SID_NAME_USER"); wbcSidToString(&sid, &sid_string); torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type), "wbcLookupSid of %s failed", sid_string); torture_assert_int_equal(tctx, name_type, WBC_SID_NAME_USER, "wbcLookupSid of expected WBC_SID_NAME_USER"); torture_assert(tctx, name, "wbcLookupSid returned no name"); wbcFreeMemory(domain); wbcFreeMemory(name); torture_assert_wbc_ok(tctx, wbcLookupUserSids(&sid, true, &num_sids, &sids), "wbcLookupUserSids of %s failed", sid_string); torture_assert_wbc_ok( tctx, wbcGetDisplayName(&sid, &domain, &name, &name_type), "wbcGetDisplayName of %s failed", sid_string); wbcFreeMemory(domain); wbcFreeMemory(name); wbcFreeMemory(sids); wbcFreeMemory(sid_string); } wbcFreeMemory(users); return true; }
bool winbind_lookup_name(const char *dom_name, const char *name, struct dom_sid *sid, enum lsa_SidType *name_type) { struct wbcDomainSid dom_sid; wbcErr result; enum wbcSidType type; result = wbcLookupName(dom_name, name, &dom_sid, &type); if (result != WBC_ERR_SUCCESS) return false; memcpy(sid, &dom_sid, sizeof(struct dom_sid)); *name_type = (enum lsa_SidType)type; return true; }
static bool test_wbc_groups(struct torture_context *tctx) { const char *domain_name = NULL; uint32_t num_groups; const char **groups; int i; struct wbcInterfaceDetails *details; torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details), "%s", "wbcInterfaceDetails failed"); domain_name = talloc_strdup(tctx, details->netbios_domain); wbcFreeMemory(details); torture_assert_wbc_ok(tctx, wbcListGroups(domain_name, &num_groups, &groups), "wbcListGroups in %s failed", domain_name); torture_assert(tctx, !(num_groups > 0 && !groups), "wbcListGroups returned invalid results"); for (i=0; i < MIN(num_groups,100); i++) { struct wbcDomainSid sid; enum wbcSidType name_type; char *domain; char *name; char *sid_string; torture_assert_wbc_ok(tctx, wbcLookupName(domain_name, groups[i], &sid, &name_type), "wbcLookupName for %s failed", domain_name); wbcSidToString(&sid, &sid_string); torture_assert_wbc_ok(tctx, wbcLookupSid(&sid, &domain, &name, &name_type), "wbcLookupSid of %s failed", sid_string); wbcFreeMemory(sid_string); torture_assert(tctx, name, "wbcLookupSid returned no name"); } wbcFreeMemory(groups); return true; }
static bool test_wbc_logon_user(struct torture_context *tctx) { struct wbcLogonUserParams params; struct wbcLogonUserInfo *info = NULL; struct wbcAuthErrorInfo *error = NULL; struct wbcUserPasswordPolicyInfo *policy = NULL; struct wbcInterfaceDetails *iface; struct wbcDomainSid sid; enum wbcSidType sidtype; char *sidstr; wbcErr ret; ZERO_STRUCT(params); ret = wbcLogonUser(¶ms, &info, &error, &policy); torture_assert_wbc_equal(tctx, ret, WBC_ERR_INVALID_PARAM, "wbcLogonUser succeeded where it should " "have failed"); params.username = getenv("USERNAME"); params.password = getenv("PASSWORD"); ret = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs, "foo", 0, discard_const_p(uint8_t, "bar"), 4); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcAddNamedBlob failed"); ret = wbcLogonUser(¶ms, &info, &error, &policy); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcLogonUser failed"); wbcFreeMemory(info); info = NULL; wbcFreeMemory(error); error = NULL; wbcFreeMemory(policy); policy = NULL; params.password = "******"; ret = wbcLogonUser(¶ms, &info, &error, &policy); torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR, "wbcLogonUser should have failed with " "WBC_ERR_AUTH_ERROR"); wbcFreeMemory(info); info = NULL; wbcFreeMemory(error); error = NULL; wbcFreeMemory(policy); policy = NULL; ret = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs, "membership_of", 0, discard_const_p(uint8_t, "S-1-2-3-4"), strlen("S-1-2-3-4")+1); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcAddNamedBlob failed"); params.password = getenv("PASSWORD"); ret = wbcLogonUser(¶ms, &info, &error, &policy); torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR, "wbcLogonUser should have failed with " "WBC_ERR_AUTH_ERROR"); wbcFreeMemory(info); info = NULL; wbcFreeMemory(error); error = NULL; wbcFreeMemory(policy); policy = NULL; wbcFreeMemory(params.blobs); params.blobs = NULL; params.num_blobs = 0; ret = wbcInterfaceDetails(&iface); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcInterfaceDetails failed"); ret = wbcLookupName(iface->netbios_domain, getenv("USERNAME"), &sid, &sidtype); wbcFreeMemory(iface); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcLookupName failed"); ret = wbcSidToString(&sid, &sidstr); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcSidToString failed"); ret = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs, "membership_of", 0, (uint8_t *)sidstr, strlen(sidstr)+1); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcAddNamedBlob failed"); wbcFreeMemory(sidstr); params.password = getenv("PASSWORD"); ret = wbcLogonUser(¶ms, &info, &error, &policy); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcLogonUser failed"); wbcFreeMemory(info); info = NULL; wbcFreeMemory(error); error = NULL; wbcFreeMemory(policy); policy = NULL; wbcFreeMemory(params.blobs); params.blobs = NULL; params.num_blobs = 0; return true; }