static bool test_wbc_lookup_rids(struct torture_context *tctx) { struct wbcDomainSid builtin; uint32_t rids[2] = { 544, 545 }; const char *domain_name, **names; enum wbcSidType *types; wbcErr ret; wbcStringToSid("S-1-5-32", &builtin); ret = wbcLookupRids(&builtin, 2, rids, &domain_name, &names, &types); torture_assert_wbc_ok(tctx, ret, "wbcLookupRids failed"); torture_assert_str_equal( tctx, names[0], "Administrators", "S-1-5-32-544 not mapped to 'Administrators'"); torture_assert_str_equal( tctx, names[1], "Users", "S-1-5-32-545 not mapped to 'Users'"); wbcFreeMemory(discard_const_p(char ,domain_name)); wbcFreeMemory(names); wbcFreeMemory(types); return true; }
static bool test_wbc_pingdc2(struct torture_context *tctx) { struct wbcInterfaceDetails *details; char *name = NULL; torture_assert_wbc_equal(tctx, wbcPingDc2("random_string", NULL, &name), WBC_ERR_DOMAIN_NOT_FOUND, "%s", "wbcPingDc2 failed"); torture_assert_wbc_ok(tctx, wbcPingDc2(NULL, NULL, &name), "%s", "wbcPingDc2 failed"); wbcFreeMemory(name); torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details), "%s", "wbcInterfaceDetails failed"); torture_assert(tctx, details, "wbcInterfaceDetails returned NULL pointer"); torture_assert(tctx, details->netbios_domain, "wbcInterfaceDetails returned NULL netbios_domain"); torture_assert_wbc_ok(tctx, wbcPingDc2(details->netbios_domain, NULL, &name), "wbcPingDc2(%s) failed", details->netbios_domain); wbcFreeMemory(name); torture_assert_wbc_ok(tctx, wbcPingDc2("BUILTIN", NULL, &name), "%s", "wbcPingDc2(BUILTIN) failed"); wbcFreeMemory(name); wbcFreeMemory(details); return true; }
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_userdomgroups(const char *user_sid_str) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; uint32_t num_sids; uint32_t i; struct wbcDomainSid user_sid, *sids = NULL; /* Send request */ wbc_status = wbcStringToSid(user_sid_str, &user_sid); if (!WBC_ERROR_IS_OK(wbc_status)) { return false; } wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids); if (!WBC_ERROR_IS_OK(wbc_status)) { return false; } for (i = 0; i < num_sids; i++) { char *str = NULL; wbc_status = wbcSidToString(&sids[i], &str); if (!WBC_ERROR_IS_OK(wbc_status)) { wbcFreeMemory(sids); return false; } d_printf("%s\n", str); wbcFreeMemory(str); } wbcFreeMemory(sids); return true; }
/* Convert a SID to a domain and name */ wbcErr wbcLookupSid(const struct wbcDomainSid *sid, char **pdomain, char **pname, enum wbcSidType *pname_type) { struct winbindd_request request; struct winbindd_response response; wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; char *domain, *name; if (!sid) { return WBC_ERR_INVALID_PARAM; } /* Initialize request */ ZERO_STRUCT(request); ZERO_STRUCT(response); wbcSidToStringBuf(sid, request.data.sid, sizeof(request.data.sid)); /* Make request */ wbc_status = wbcRequestResponse(WINBINDD_LOOKUPSID, &request, &response); if (!WBC_ERROR_IS_OK(wbc_status)) { return wbc_status; } /* Copy out result */ wbc_status = WBC_ERR_NO_MEMORY; domain = NULL; name = NULL; domain = wbcStrDup(response.data.name.dom_name); if (domain == NULL) { goto done; } name = wbcStrDup(response.data.name.name); if (name == NULL) { goto done; } if (pdomain != NULL) { *pdomain = domain; domain = NULL; } if (pname != NULL) { *pname = name; name = NULL; } if (pname_type != NULL) { *pname_type = (enum wbcSidType)response.data.name.type; } wbc_status = WBC_ERR_SUCCESS; done: wbcFreeMemory(name); wbcFreeMemory(domain); return wbc_status; }
/* Initialize a named blob and add to list of blobs */ wbcErr wbcAddNamedBlob(size_t *num_blobs, struct wbcNamedBlob **pblobs, const char *name, uint32_t flags, uint8_t *data, size_t length) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct wbcNamedBlob *blobs, *blob; if (name == NULL) { return WBC_ERR_INVALID_PARAM; } /* * Overallocate the b->name==NULL terminator for * wbcNamedBlobDestructor */ blobs = (struct wbcNamedBlob *)wbcAllocateMemory( *num_blobs + 2, sizeof(struct wbcNamedBlob), wbcNamedBlobDestructor); if (blobs == NULL) { return WBC_ERR_NO_MEMORY; } if (*pblobs != NULL) { struct wbcNamedBlob *old = *pblobs; memcpy(blobs, old, sizeof(struct wbcNamedBlob) * (*num_blobs)); if (*num_blobs != 0) { /* end indicator for wbcNamedBlobDestructor */ old[0].name = NULL; } wbcFreeMemory(old); } *pblobs = blobs; blob = &blobs[*num_blobs]; blob->name = strdup(name); BAIL_ON_PTR_ERROR(blob->name, wbc_status); blob->flags = flags; blob->blob.length = length; blob->blob.data = (uint8_t *)malloc(length); BAIL_ON_PTR_ERROR(blob->blob.data, wbc_status); memcpy(blob->blob.data, data, length); *num_blobs += 1; *pblobs = blobs; blobs = NULL; wbc_status = WBC_ERR_SUCCESS; done: wbcFreeMemory(blobs); return wbc_status; }
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); }
static void wbcDomainInfosDestructor(void *ptr) { struct wbcDomainInfo *i = (struct wbcDomainInfo *)ptr; while (i->short_name != NULL) { wbcFreeMemory(i->short_name); wbcFreeMemory(i->dns_name); i += 1; } }
static wbcErr wbc_create_error_info(const struct winbindd_response *resp, struct wbcAuthErrorInfo **_e) { wbcErr wbc_status = WBC_ERR_SUCCESS; struct wbcAuthErrorInfo *e; e = (struct wbcAuthErrorInfo *)wbcAllocateMemory( 1, sizeof(struct wbcAuthErrorInfo), wbcAuthErrorInfoDestructor); BAIL_ON_PTR_ERROR(e, wbc_status); e->nt_status = resp->data.auth.nt_status; e->pam_error = resp->data.auth.pam_error; e->authoritative = resp->data.auth.authoritative; e->nt_string = strdup(resp->data.auth.nt_status_string); BAIL_ON_PTR_ERROR(e->nt_string, wbc_status); e->display_string = strdup(resp->data.auth.error_string); BAIL_ON_PTR_ERROR(e->display_string, wbc_status); *_e = e; e = NULL; done: wbcFreeMemory(e); return wbc_status; }
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 print_domain_groups(const char *domain) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; uint32_t i; uint32_t num_groups = 0; const char **groups = NULL; /* Send request to winbind daemon */ /* '.' is the special sign for our own domain */ if (domain && strcmp(domain, ".") == 0) { domain = get_winbind_domain(); } wbc_status = wbcListGroups(domain, &num_groups, &groups); if (!WBC_ERROR_IS_OK(wbc_status)) { return false; } for (i=0; i < num_groups; i++) { d_printf("%s\n", groups[i]); } wbcFreeMemory(groups); return true; }
static bool test_wbc_resolve_winsbyip(struct torture_context *tctx) { const char *ip; const char *host; struct nbt_name nbt_name; char *name; wbcErr ret; NTSTATUS status; host = torture_setting_string(tctx, "host", NULL); torture_comment(tctx, "test-WinsByIp: host='%s'\n", host); make_nbt_name_server(&nbt_name, host); status = resolve_name_ex(lpcfg_resolve_context(tctx->lp_ctx), 0, 0, &nbt_name, tctx, &ip, tctx->ev); torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx,"Failed to resolve %s: %s", nbt_name.name, nt_errstr(status))); torture_comment(tctx, "test-WinsByIp: ip='%s'\n", ip); ret = wbcResolveWinsByIP(ip, &name); torture_assert_wbc_ok(tctx, ret, "wbcResolveWinsByIP for %s failed", ip); wbcFreeMemory(name); return true; }
static bool wbinfo_gid_to_sid(gid_t gid) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct wbcDomainSid sid; char *sid_str = NULL; /* Send request */ wbc_status = wbcGidToSid(gid, &sid); 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\n", sid_str); wbcFreeMemory(sid_str); return true; }
wbcErr wbcSidToGid(const struct wbcDomainSid *sid, gid_t *pgid) { int ret; char *sid_str; uint32_t id; enum sss_id_type type; wbcErr wbc_status; wbc_status = wbcSidToString(sid, &sid_str); if (!WBC_ERROR_IS_OK(wbc_status)) { return wbc_status; } ret = sss_nss_getidbysid(sid_str, &id, &type); wbcFreeMemory(sid_str); if (ret != 0) { return WBC_ERR_UNKNOWN_FAILURE; } if (type != SSS_ID_TYPE_GID && type != SSS_ID_TYPE_BOTH) { return WBC_ERR_UNKNOWN_GROUP; } *pgid = (gid_t) id; return WBC_ERR_SUCCESS; }
/** @brief Remove a group id mapping * * @param gid Gid of the mapping to remove. * @param *sid Pointer to the sid of the mapping to remove. * * @return #wbcErr **/ wbcErr wbcRemoveGidMapping(gid_t gid, const struct wbcDomainSid *sid) { struct winbindd_request request; struct winbindd_response response; wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; char *sid_string = NULL; if (!sid) { return WBC_ERR_INVALID_PARAM; } /* Initialise request */ ZERO_STRUCT(request); ZERO_STRUCT(response); /* Make request */ request.data.dual_idmapset.id = gid; request.data.dual_idmapset.type = _ID_TYPE_GID; wbc_status = wbcSidToString(sid, &sid_string); BAIL_ON_WBC_ERROR(wbc_status); strncpy(request.data.dual_idmapset.sid, sid_string, sizeof(request.data.dual_idmapset.sid)-1); wbcFreeMemory(sid_string); wbc_status = wbcRequestResponse(WINBINDD_REMOVE_MAPPING, &request, &response); BAIL_ON_WBC_ERROR(wbc_status); done: return wbc_status; }
/* Get extended domain controller information */ wbcErr wbcLookupDomainControllerEx(const char *domain, struct wbcGuid *guid, const char *site, uint32_t flags, struct wbcDomainControllerInfoEx **dc_info) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct winbindd_request request; struct winbindd_response response; /* validate input params */ if (!domain || !dc_info) { wbc_status = WBC_ERR_INVALID_PARAM; BAIL_ON_WBC_ERROR(wbc_status); } ZERO_STRUCT(request); ZERO_STRUCT(response); request.data.dsgetdcname.flags = flags; strncpy(request.data.dsgetdcname.domain_name, domain, sizeof(request.data.dsgetdcname.domain_name)-1); if (site) { strncpy(request.data.dsgetdcname.site_name, site, sizeof(request.data.dsgetdcname.site_name)-1); } if (guid) { char *str = NULL; wbc_status = wbcGuidToString(guid, &str); BAIL_ON_WBC_ERROR(wbc_status); strncpy(request.data.dsgetdcname.domain_guid, str, sizeof(request.data.dsgetdcname.domain_guid)-1); wbcFreeMemory(str); } /* Send request */ wbc_status = wbcRequestResponse(WINBINDD_DSGETDCNAME, &request, &response); BAIL_ON_WBC_ERROR(wbc_status); if (dc_info) { wbc_status = wbc_create_domain_controller_info_ex(&response, dc_info); BAIL_ON_WBC_ERROR(wbc_status); } wbc_status = WBC_ERR_SUCCESS; done: return wbc_status; }
static wbcErr wbc_create_domain_controller_info_ex(const struct winbindd_response *resp, struct wbcDomainControllerInfoEx **_i) { wbcErr wbc_status = WBC_ERR_SUCCESS; struct wbcDomainControllerInfoEx *i; struct wbcGuid guid; i = (struct wbcDomainControllerInfoEx *)wbcAllocateMemory( 1, sizeof(struct wbcDomainControllerInfoEx), wbcDomainControllerInfoExDestructor); BAIL_ON_PTR_ERROR(i, wbc_status); i->dc_unc = strdup(resp->data.dsgetdcname.dc_unc); BAIL_ON_PTR_ERROR(i->dc_unc, wbc_status); i->dc_address = strdup(resp->data.dsgetdcname.dc_address); BAIL_ON_PTR_ERROR(i->dc_address, wbc_status); i->dc_address_type = resp->data.dsgetdcname.dc_address_type; wbc_status = wbcStringToGuid(resp->data.dsgetdcname.domain_guid, &guid); if (WBC_ERROR_IS_OK(wbc_status)) { i->domain_guid = (struct wbcGuid *)malloc( sizeof(struct wbcGuid)); BAIL_ON_PTR_ERROR(i->domain_guid, wbc_status); *i->domain_guid = guid; } i->domain_name = strdup(resp->data.dsgetdcname.domain_name); BAIL_ON_PTR_ERROR(i->domain_name, wbc_status); if (resp->data.dsgetdcname.forest_name[0] != '\0') { i->forest_name = strdup(resp->data.dsgetdcname.forest_name); BAIL_ON_PTR_ERROR(i->forest_name, wbc_status); } i->dc_flags = resp->data.dsgetdcname.dc_flags; if (resp->data.dsgetdcname.dc_site_name[0] != '\0') { i->dc_site_name = strdup(resp->data.dsgetdcname.dc_site_name); BAIL_ON_PTR_ERROR(i->dc_site_name, wbc_status); } if (resp->data.dsgetdcname.client_site_name[0] != '\0') { i->client_site_name = strdup( resp->data.dsgetdcname.client_site_name); BAIL_ON_PTR_ERROR(i->client_site_name, wbc_status); } *_i = i; i = NULL; done: if (i != NULL) { wbcFreeMemory(i); } return wbc_status; }
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; }
static void wbcTranslatedNamesDestructor(void *ptr) { struct wbcTranslatedName *n = (struct wbcTranslatedName *)ptr; while (n->name != NULL) { wbcFreeMemory(n->name); n += 1; } }
static bool test_wbc_domain_info(struct torture_context *tctx) { struct wbcDomainInfo *info; struct wbcInterfaceDetails *details; torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details), "wbcInterfaceDetails failed"); torture_assert_wbc_ok( tctx, wbcDomainInfo(details->netbios_domain, &info), "wbcDomainInfo failed"); wbcFreeMemory(details); torture_assert(tctx, info, "wbcDomainInfo returned NULL pointer"); wbcFreeMemory(info); return true; }
static bool test_wbc_lookupdcex(struct torture_context *tctx) { const char *domain_name = NULL; struct wbcInterfaceDetails *details; struct wbcDomainControllerInfoEx *dc_info; torture_assert_wbc_ok(tctx, wbcInterfaceDetails(&details), "wbcInterfaceDetails failed"); domain_name = talloc_strdup(tctx, details->netbios_domain); wbcFreeMemory(details); torture_assert_wbc_ok(tctx, wbcLookupDomainControllerEx(domain_name, NULL, NULL, 0, &dc_info), "wbcLookupDomainControllerEx failed"); wbcFreeMemory(dc_info); return true; }
wbcErr wbcGetDisplayName(const struct wbcDomainSid *sid, char **pdomain, char **pfullname, enum wbcSidType *pname_type) { wbcErr wbc_status; char *domain = NULL; char *name = NULL; enum wbcSidType name_type; wbc_status = wbcLookupSid(sid, &domain, &name, &name_type); BAIL_ON_WBC_ERROR(wbc_status); if (name_type == WBC_SID_NAME_USER) { uid_t uid; struct passwd *pwd; wbc_status = wbcSidToUid(sid, &uid); BAIL_ON_WBC_ERROR(wbc_status); wbc_status = wbcGetpwuid(uid, &pwd); BAIL_ON_WBC_ERROR(wbc_status); wbcFreeMemory(name); name = wbcStrDup(pwd->pw_gecos); wbcFreeMemory(pwd); BAIL_ON_PTR_ERROR(name, wbc_status); } wbc_status = WBC_ERR_SUCCESS; done: if (WBC_ERROR_IS_OK(wbc_status)) { *pdomain = domain; *pfullname = name; *pname_type = name_type; } else { wbcFreeMemory(domain); wbcFreeMemory(name); } return 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; }
static bool wbinfo_domain_info(const char *domain) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct wbcDomainInfo *dinfo = NULL; char *sid_str = NULL; 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)) { return false; } wbc_status = wbcSidToString(&dinfo->sid, &sid_str); if (!WBC_ERROR_IS_OK(wbc_status)) { wbcFreeMemory(dinfo); return false; } /* Display response */ d_printf("Name : %s\n", dinfo->short_name); d_printf("Alt_Name : %s\n", dinfo->dns_name); d_printf("SID : %s\n", sid_str); d_printf("Active Directory : %s\n", (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_AD) ? "Yes" : "No"); d_printf("Native : %s\n", (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_NATIVE) ? "Yes" : "No"); d_printf("Primary : %s\n", (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_PRIMARY) ? "Yes" : "No"); wbcFreeMemory(sid_str); wbcFreeMemory(dinfo); return true; }
wbcErr wbcDomainInfo(const char *domain, struct wbcDomainInfo **dinfo) { struct winbindd_request request; struct winbindd_response response; wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; struct wbcDomainInfo *info = NULL; if (!domain || !dinfo) { wbc_status = WBC_ERR_INVALID_PARAM; BAIL_ON_WBC_ERROR(wbc_status); } /* Initialize request */ ZERO_STRUCT(request); ZERO_STRUCT(response); strncpy(request.domain_name, domain, sizeof(request.domain_name)-1); wbc_status = wbcRequestResponse(WINBINDD_DOMAIN_INFO, &request, &response); BAIL_ON_WBC_ERROR(wbc_status); info = (struct wbcDomainInfo *)wbcAllocateMemory( 1, sizeof(struct wbcDomainInfo), wbcDomainInfoDestructor); BAIL_ON_PTR_ERROR(info, wbc_status); info->short_name = strdup(response.data.domain_info.name); BAIL_ON_PTR_ERROR(info->short_name, wbc_status); info->dns_name = strdup(response.data.domain_info.alt_name); BAIL_ON_PTR_ERROR(info->dns_name, wbc_status); wbc_status = wbcStringToSid(response.data.domain_info.sid, &info->sid); BAIL_ON_WBC_ERROR(wbc_status); if (response.data.domain_info.native_mode) info->domain_flags |= WBC_DOMINFO_DOMAIN_NATIVE; if (response.data.domain_info.active_directory) info->domain_flags |= WBC_DOMINFO_DOMAIN_AD; if (response.data.domain_info.primary) info->domain_flags |= WBC_DOMINFO_DOMAIN_PRIMARY; *dinfo = info; info = NULL; wbc_status = WBC_ERR_SUCCESS; done: wbcFreeMemory(info); return wbc_status; }
static bool test_wbc_getgroups(struct torture_context *tctx) { wbcErr ret; uint32_t num_groups; gid_t *groups; ret = wbcGetGroups(cli_credentials_get_username(cmdline_credentials), &num_groups, &groups); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcGetGroups for %s failed", cli_credentials_get_username(cmdline_credentials)); wbcFreeMemory(groups); return true; }
static bool test_wbc_getgroups(struct torture_context *tctx) { wbcErr ret; uint32_t num_groups; gid_t *groups; ret = wbcGetGroups(getenv("USERNAME"), &num_groups, &groups); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcGetGroups failed"); wbcFreeMemory(groups); 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_authenticate_user_int(struct torture_context *tctx, const char *correct_password) { struct wbcAuthUserParams params; struct wbcAuthUserInfo *info = NULL; struct wbcAuthErrorInfo *error = NULL; wbcErr ret; ret = wbcAuthenticateUser(cli_credentials_get_username(cmdline_credentials), correct_password); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcAuthenticateUser of %s failed", cli_credentials_get_username(cmdline_credentials)); ZERO_STRUCT(params); params.account_name = cli_credentials_get_username(cmdline_credentials); params.level = WBC_AUTH_USER_LEVEL_PLAIN; params.password.plaintext = correct_password; ret = wbcAuthenticateUserEx(¶ms, &info, &error); torture_assert_wbc_equal(tctx, ret, WBC_ERR_SUCCESS, "wbcAuthenticateUserEx of %s failed", params.account_name); wbcFreeMemory(info); info = NULL; wbcFreeMemory(error); error = NULL; params.password.plaintext = "wrong"; ret = wbcAuthenticateUserEx(¶ms, &info, &error); torture_assert_wbc_equal(tctx, ret, WBC_ERR_AUTH_ERROR, "wbcAuthenticateUserEx for %s succeeded where it " "should have failed", params.account_name); wbcFreeMemory(info); info = NULL; wbcFreeMemory(error); error = NULL; return true; }
bool winbind_lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid, const char **domain, const char **name, enum lsa_SidType *name_type) { struct wbcDomainSid dom_sid; wbcErr result; enum wbcSidType type; char *domain_name = NULL; char *account_name = NULL; memcpy(&dom_sid, sid, sizeof(dom_sid)); result = wbcLookupSid(&dom_sid, &domain_name, &account_name, &type); if (result != WBC_ERR_SUCCESS) return false; /* Copy out result */ if (domain) { *domain = talloc_strdup(mem_ctx, domain_name); } if (name) { *name = talloc_strdup(mem_ctx, account_name); } *name_type = (enum lsa_SidType)type; DEBUG(10, ("winbind_lookup_sid: SUCCESS: SID %s -> %s %s\n", sid_string_dbg(sid), domain_name, account_name)); wbcFreeMemory(domain_name); wbcFreeMemory(account_name); if ((domain && !*domain) || (name && !*name)) { DEBUG(0,("winbind_lookup_sid: talloc() failed!\n")); return false; } return true; }