2
Unix SMB/CIFS implementation.
3
ads (active directory) utility library
4
Copyright (C) Andrew Tridgell 2001
5
Copyright (C) Andrew Bartlett 2001
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
/* return a ldap dn path from a string, given separators and field name
27
char *ads_build_path(const char *realm, const char *sep, const char *field, int reverse)
34
r = SMB_STRDUP(realm);
43
len = (numbits+1)*(strlen(field)+1) + strlen(r) + 1;
45
ret = SMB_MALLOC(len);
49
strlcpy(ret,field, len);
54
while ((p=strtok(NULL,sep))) {
57
asprintf(&s, "%s%s,%s", field, p, ret);
59
asprintf(&s, "%s,%s%s", ret, field, p);
69
/* return a dn of the form "dc=AA,dc=BB,dc=CC" from a
70
realm of the form AA.BB.CC
73
char *ads_build_dn(const char *realm)
75
return ads_build_path(realm, ".", "dc=", 0);
84
initialise a ADS_STRUCT, ready for some ads_ ops
86
ADS_STRUCT *ads_init(const char *realm,
87
const char *workgroup,
88
const char *ldap_server)
92
ads = SMB_XMALLOC_P(ADS_STRUCT);
95
ads->server.realm = realm? SMB_STRDUP(realm) : NULL;
96
ads->server.workgroup = workgroup ? SMB_STRDUP(workgroup) : NULL;
97
ads->server.ldap_server = ldap_server? SMB_STRDUP(ldap_server) : NULL;
99
/* we need to know if this is a foreign realm */
100
if (realm && *realm && !strequal(lp_realm(), realm)) {
101
ads->server.foreign = 1;
103
if (workgroup && *workgroup && !strequal(lp_workgroup(), workgroup)) {
104
ads->server.foreign = 1;
107
/* the caller will own the memory by default */
114
free the memory used by the ADS structure initialized with 'ads_init(...)'
116
void ads_destroy(ADS_STRUCT **ads)
121
is_mine = (*ads)->is_mine;
124
ldap_unbind((*ads)->ld);
127
SAFE_FREE((*ads)->server.realm);
128
SAFE_FREE((*ads)->server.workgroup);
129
SAFE_FREE((*ads)->server.ldap_server);
131
SAFE_FREE((*ads)->auth.realm);
132
SAFE_FREE((*ads)->auth.password);
133
SAFE_FREE((*ads)->auth.user_name);
134
SAFE_FREE((*ads)->auth.kdc_server);
136
SAFE_FREE((*ads)->config.realm);
137
SAFE_FREE((*ads)->config.bind_path);
138
SAFE_FREE((*ads)->config.ldap_server_name);
140
SAFE_FREE((*ads)->schema.posix_uidnumber_attr);
141
SAFE_FREE((*ads)->schema.posix_gidnumber_attr);
142
SAFE_FREE((*ads)->schema.posix_shell_attr);
143
SAFE_FREE((*ads)->schema.posix_homedir_attr);
144
SAFE_FREE((*ads)->schema.posix_gecos_attr);