fixed word-order issue in password set and password change.
[Samba.git] / source / lib / sursalgnt5ldap.c
blobc6fe9b11afba4bbf942b4953a778f36609058fa6
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 Groupname handling
5 Copyright (C) Jeremy Allison 1998-2000.
6 Copyright (C) Luke Kenneth Casson Leighton 1996-2000.
7 Copyright (C) Luke Howard 2000.
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.
24 /*
25 * LDAP implementation of a SURS (sid to uid resolution) table.
28 #include "includes.h"
30 #ifdef WITH_NT5LDAP
32 #include "sids.h"
33 #include "ldapdb.h"
35 /******************************************************************
36 converts SID + SID_NAME_USE type to a UNIX id.
37 ********************************************************************/
38 BOOL surs_nt5ldap_sam_sid_to_unixid(LDAPDB *hds, DOM_SID * sid, uint32 type,
39 uint32 * id, BOOL create)
41 if (!ldapdb_lookup_by_sid(hds, sid))
42 return False;
44 switch (type)
46 case RID_TYPE_USER:
47 return ldapdb_get_uint32(hds, "uidNumber", id);
48 case RID_TYPE_GROUP:
49 case RID_TYPE_ALIAS:
50 return ldapdb_get_uint32(hds, "gidNumber", id);
51 default:
52 break;
55 return False;
58 /******************************************************************
59 converts UNIX gid + SID_NAME_USE type to a SID.
60 ********************************************************************/
61 BOOL surs_nt5ldap_unixid_to_sam_sid(LDAPDB *hds, uint32 id, uint32 type,
62 DOM_SID * sid, BOOL create)
64 char *attribute;
65 fstring filter;
66 char *attrs[] = { "objectSid", NULL };
67 BOOL ret;
69 switch (type)
71 case SID_NAME_USER:
73 attribute = "uidNumber";
74 break;
76 case SID_NAME_ALIAS:
77 case SID_NAME_DOM_GRP:
78 case SID_NAME_WKN_GRP:
80 attribute = "gidNumber";
81 break;
83 default:
85 return False;
89 slprintf(filter, sizeof(filter) - 1, "(&(objectSid=*)(%s=%d))",
90 attribute, id);
91 return ldapdb_search(hds, NULL, filter, attrs, 1)
92 && ldapdb_get_sid(hds, "objectSid", sid);
95 #endif /* WITH_NT5LDAP */