TALLOC_CTX *mem_ctx;
ADS_STRUCT *ads;
ADS_STATUS status;
- const char *attrs[] = { "userAccountControl", NULL };
- LDAPMessage *res = NULL;
- const char *filter;
- char *dn = NULL;
- struct GROUP_POLICY_OBJECT *gpo_list;
+ const char *dn = NULL;
+ struct GROUP_POLICY_OBJECT *gpo_list = NULL;
uint32 uac = 0;
uint32 flags = 0;
struct GROUP_POLICY_OBJECT *gpo;
return -1;
}
- filter = talloc_asprintf(mem_ctx, "(&(objectclass=user)(sAMAccountName=%s))", argv[0]);
- if (filter == NULL) {
- goto out;
- }
-
status = ads_startup(False, &ads);
if (!ADS_ERR_OK(status)) {
goto out;
}
- status = ads_do_search_all(ads, ads->config.bind_path,
- LDAP_SCOPE_SUBTREE,
- filter, attrs, &res);
-
+ status = ads_find_samaccount(ads, mem_ctx, argv[0], &uac, &dn);
if (!ADS_ERR_OK(status)) {
- goto out;
- }
-
- if (ads_count_replies(ads, res) != 1) {
- printf("no result\n");
- goto out;
- }
-
- dn = ads_get_dn(ads, res);
- if (dn == NULL) {
- goto out;
- }
-
- if (!ads_pull_uint32(ads, res, "userAccountControl", &uac)) {
+ printf("failed to find samaccount for %s\n", argv[0]);
goto out;
}
GPO_VERSION_USER(gpo->version),
GPO_VERSION_MACHINE(gpo->version));
- result = ads_gpo_explode_filesyspath(ads, mem_ctx, gpo->file_sys_path,
- &server, &share, &nt_path, &unix_path);
+ result = gpo_explode_filesyspath(mem_ctx, gpo->file_sys_path,
+ &server, &share, &nt_path, &unix_path);
if (!NT_STATUS_IS_OK(result)) {
printf("got: %s\n", nt_errstr(result));
}
}
out:
- ads_memfree(ads, dn);
- ads_msgfree(ads, res);
-
ads_destroy(&ads);
talloc_destroy(mem_ctx);
return 0;
TALLOC_CTX *mem_ctx;
ADS_STRUCT *ads;
ADS_STATUS status;
- const char *attrs[] = {"distinguishedName", "userAccountControl", NULL};
- LDAPMessage *res = NULL;
- const char *filter;
- char *dn = NULL;
+ const char *dn = NULL;
struct GROUP_POLICY_OBJECT *gpo_list;
uint32 uac = 0;
uint32 flags = 0;
goto out;
}
- filter = talloc_asprintf(mem_ctx, "(&(objectclass=user)(sAMAccountName=%s))", argv[0]);
- if (filter == NULL) {
- goto out;
- }
-
status = ads_startup(False, &ads);
if (!ADS_ERR_OK(status)) {
goto out;
}
- status = ads_do_search_all(ads, ads->config.bind_path,
- LDAP_SCOPE_SUBTREE,
- filter, attrs, &res);
-
+ status = ads_find_samaccount(ads, mem_ctx, argv[0], &uac, &dn);
if (!ADS_ERR_OK(status)) {
goto out;
}
- if (ads_count_replies(ads, res) != 1) {
- printf("no result\n");
- goto out;
- }
-
- dn = ads_get_dn(ads, res);
- if (dn == NULL) {
- goto out;
- }
-
- if (!ads_pull_uint32(ads, res, "userAccountControl", &uac)) {
- goto out;
- }
-
if (uac & UF_WORKSTATION_TRUST_ACCOUNT) {
flags |= GPO_LIST_FLAG_MACHINE;
}
}
/* FIXME: allow to process just a single extension */
- status = gpo_process_gpo_list(ads, mem_ctx, &gpo_list, NULL, flags);
+ status = gpo_process_gpo_list(ads, mem_ctx, gpo_list, NULL, flags);
if (!ADS_ERR_OK(status)) {
goto out;
}
out:
- ads_memfree(ads, dn);
- ads_msgfree(ads, res);
-
ads_destroy(&ads);
talloc_destroy(mem_ctx);
return 0;
if (argc < 2) {
printf("usage: net ads gpo addlink <linkdn> <gpodn> [options]\n");
+ printf("note: DNs must be provided properly escaped.\n See RFC 4514 for details\n");
return -1;
}