2
Unix SMB/CIFS implementation.
3
ads (active directory) utility library
4
Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 3 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
27
ADS_STATUS ads_find_user_acct(ADS_STRUCT *ads, LDAPMessage **res,
32
const char *attrs[] = {"*", NULL};
33
char *escaped_user = escape_ldap_string_alloc(user);
35
return ADS_ERROR(LDAP_NO_MEMORY);
38
if (asprintf(&ldap_exp, "(samAccountName=%s)", escaped_user) == -1) {
39
SAFE_FREE(escaped_user);
40
return ADS_ERROR(LDAP_NO_MEMORY);
42
status = ads_search(ads, res, ldap_exp, attrs);
44
SAFE_FREE(escaped_user);
48
ADS_STATUS ads_add_user_acct(ADS_STRUCT *ads, const char *user,
49
const char *container, const char *fullname)
54
const char *upn, *new_dn, *name, *controlstr;
55
char *name_escaped = NULL;
56
const char *objectClass[] = {"top", "person", "organizationalPerson",
59
if (fullname && *fullname) name = fullname;
62
if (!(ctx = talloc_init("ads_add_user_acct")))
63
return ADS_ERROR(LDAP_NO_MEMORY);
65
status = ADS_ERROR(LDAP_NO_MEMORY);
67
if (!(upn = talloc_asprintf(ctx, "%s@%s", user, ads->config.realm)))
69
if (!(name_escaped = escape_rdn_val_string_alloc(name)))
71
if (!(new_dn = talloc_asprintf(ctx, "cn=%s,%s,%s", name_escaped, container,
72
ads->config.bind_path)))
74
if (!(controlstr = talloc_asprintf(ctx, "%u", (UF_NORMAL_ACCOUNT | UF_ACCOUNTDISABLE))))
76
if (!(mods = ads_init_mods(ctx)))
79
ads_mod_str(ctx, &mods, "cn", name);
80
ads_mod_strlist(ctx, &mods, "objectClass", objectClass);
81
ads_mod_str(ctx, &mods, "userPrincipalName", upn);
82
ads_mod_str(ctx, &mods, "name", name);
83
ads_mod_str(ctx, &mods, "displayName", name);
84
ads_mod_str(ctx, &mods, "sAMAccountName", user);
85
ads_mod_str(ctx, &mods, "userAccountControl", controlstr);
86
status = ads_gen_add(ads, new_dn, mods);
89
SAFE_FREE(name_escaped);
94
ADS_STATUS ads_add_group_acct(ADS_STRUCT *ads, const char *group,
95
const char *container, const char *comment)
101
char *name_escaped = NULL;
102
const char *objectClass[] = {"top", "group", NULL};
104
if (!(ctx = talloc_init("ads_add_group_acct")))
105
return ADS_ERROR(LDAP_NO_MEMORY);
107
status = ADS_ERROR(LDAP_NO_MEMORY);
109
if (!(name_escaped = escape_rdn_val_string_alloc(group)))
111
if (!(new_dn = talloc_asprintf(ctx, "cn=%s,%s,%s", name_escaped, container,
112
ads->config.bind_path)))
114
if (!(mods = ads_init_mods(ctx)))
117
ads_mod_str(ctx, &mods, "cn", group);
118
ads_mod_strlist(ctx, &mods, "objectClass",objectClass);
119
ads_mod_str(ctx, &mods, "name", group);
120
if (comment && *comment)
121
ads_mod_str(ctx, &mods, "description", comment);
122
ads_mod_str(ctx, &mods, "sAMAccountName", group);
123
status = ads_gen_add(ads, new_dn, mods);
126
SAFE_FREE(name_escaped);