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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 ADS_STATUS
ads_find_user_acct(ADS_STRUCT
*ads
, LDAPMessage
**res
,
33 const char *attrs
[] = {"*", NULL
};
34 char *escaped_user
= escape_ldap_string_alloc(user
);
36 return ADS_ERROR(LDAP_NO_MEMORY
);
39 asprintf(&ldap_exp
, "(samAccountName=%s)", escaped_user
);
40 status
= ads_search(ads
, res
, ldap_exp
, attrs
);
42 SAFE_FREE(escaped_user
);
46 ADS_STATUS
ads_add_user_acct(ADS_STRUCT
*ads
, const char *user
,
47 const char *container
, const char *fullname
)
52 const char *upn
, *new_dn
, *name
, *controlstr
;
53 const char *objectClass
[] = {"top", "person", "organizationalPerson",
56 if (fullname
&& *fullname
) name
= fullname
;
59 if (!(ctx
= talloc_init("ads_add_user_acct")))
60 return ADS_ERROR(LDAP_NO_MEMORY
);
62 status
= ADS_ERROR(LDAP_NO_MEMORY
);
64 if (!(upn
= talloc_asprintf(ctx
, "%s@%s", user
, ads
->config
.realm
)))
66 if (!(new_dn
= talloc_asprintf(ctx
, "cn=%s,%s,%s", name
, container
,
67 ads
->config
.bind_path
)))
69 if (!(controlstr
= talloc_asprintf(ctx
, "%u", (UF_NORMAL_ACCOUNT
| UF_ACCOUNTDISABLE
))))
71 if (!(mods
= ads_init_mods(ctx
)))
74 ads_mod_str(ctx
, &mods
, "cn", name
);
75 ads_mod_strlist(ctx
, &mods
, "objectClass", objectClass
);
76 ads_mod_str(ctx
, &mods
, "userPrincipalName", upn
);
77 ads_mod_str(ctx
, &mods
, "name", name
);
78 ads_mod_str(ctx
, &mods
, "displayName", name
);
79 ads_mod_str(ctx
, &mods
, "sAMAccountName", user
);
80 ads_mod_str(ctx
, &mods
, "userAccountControl", controlstr
);
81 status
= ads_gen_add(ads
, new_dn
, mods
);
88 ADS_STATUS
ads_add_group_acct(ADS_STRUCT
*ads
, const char *group
,
89 const char *container
, const char *comment
)
95 const char *objectClass
[] = {"top", "group", NULL
};
97 if (!(ctx
= talloc_init("ads_add_group_acct")))
98 return ADS_ERROR(LDAP_NO_MEMORY
);
100 status
= ADS_ERROR(LDAP_NO_MEMORY
);
102 if (!(new_dn
= talloc_asprintf(ctx
, "cn=%s,%s,%s", group
, container
,
103 ads
->config
.bind_path
)))
105 if (!(mods
= ads_init_mods(ctx
)))
108 ads_mod_str(ctx
, &mods
, "cn", group
);
109 ads_mod_strlist(ctx
, &mods
, "objectClass",objectClass
);
110 ads_mod_str(ctx
, &mods
, "name", group
);
111 if (comment
&& *comment
)
112 ads_mod_str(ctx
, &mods
, "description", comment
);
113 ads_mod_str(ctx
, &mods
, "sAMAccountName", group
);
114 status
= ads_gen_add(ads
, new_dn
, mods
);