2 Unix SMB/CIFS implementation.
4 Winbind ADS backend functions
6 Copyright (C) Andrew Tridgell 2001
7 Copyright (C) Andrew Bartlett 2002
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /* convert a sid to a DN */
29 ADS_STATUS
ads_sid_to_dn(ADS_STRUCT
*ads
,
35 LDAPMessage
*msg
= NULL
;
36 LDAPMessage
*entry
= NULL
;
42 const char *attr
[] = {
47 if (!(sidstr
= sid_binstring(sid
))) {
48 DEBUG(1,("ads_sid_to_dn: sid_binstring failed!\n"));
49 rc
= ADS_ERROR_NT(NT_STATUS_NO_MEMORY
);
53 if(!(ldap_exp
= talloc_asprintf(mem_ctx
, "(objectSid=%s)", sidstr
))) {
54 DEBUG(1,("ads_sid_to_dn: talloc_asprintf failed!\n"));
55 rc
= ADS_ERROR_NT(NT_STATUS_NO_MEMORY
);
59 rc
= ads_search_retry(ads
, (void **)&msg
, ldap_exp
, attr
);
61 if (!ADS_ERR_OK(rc
)) {
62 DEBUG(1,("ads_sid_to_dn ads_search: %s\n", ads_errstr(rc
)));
66 if ((count
= ads_count_replies(ads
, msg
)) != 1) {
68 DEBUG(1,("ads_sid_to_dn (sid=%s): Not found (count=%d)\n",
69 sid_to_string(sid_string
, sid
), count
));
70 rc
= ADS_ERROR_NT(NT_STATUS_UNSUCCESSFUL
);
74 entry
= ads_first_entry(ads
, msg
);
76 dn2
= ads_get_dn(ads
, entry
);
79 rc
= ADS_ERROR_NT(NT_STATUS_NO_MEMORY
);
83 *dn
= talloc_strdup(mem_ctx
, dn2
);
86 ads_memfree(ads
, dn2
);
87 rc
= ADS_ERROR_NT(NT_STATUS_NO_MEMORY
);
91 rc
= ADS_ERROR_NT(NT_STATUS_OK
);
93 DEBUG(3,("ads sid_to_dn mapped %s\n", dn2
));
97 if (msg
) ads_msgfree(ads
, msg
);
98 if (dn2
) ads_memfree(ads
, dn2
);