merge from 3.0...LDAP password lockout support
[ira/wip.git] / source3 / include / smbldap.h
1 /* 
2    Unix SMB/CIFS mplementation.
3    LDAP protocol helper functions for SAMBA
4    Copyright (C) Gerald Carter                  2001-2003
5     
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.
10    
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.
15    
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.
19    
20 */
21
22 #ifndef _SMBLDAP_H
23 #define _SMBLDAP_H
24
25 #ifdef HAVE_LDAP
26
27 /* specify schema versions between 2.2. and 3.0 */
28
29 #define SCHEMAVER_SAMBAACCOUNT          1
30 #define SCHEMAVER_SAMBASAMACCOUNT       2
31
32 /* objectclass names */
33
34 #define LDAP_OBJ_SAMBASAMACCOUNT        "sambaSamAccount"
35 #define LDAP_OBJ_SAMBAACCOUNT           "sambaAccount"
36 #define LDAP_OBJ_GROUPMAP               "sambaGroupMapping"
37 #define LDAP_OBJ_DOMINFO                "sambaDomain"
38 #define LDAP_OBJ_IDPOOL                 "sambaUnixIdPool"
39 #define LDAP_OBJ_IDMAP_ENTRY            "sambaIdmapEntry"
40 #define LDAP_OBJ_SID_ENTRY              "sambaSidEntry"
41
42 #define LDAP_OBJ_ACCOUNT                "account"
43 #define LDAP_OBJ_POSIXACCOUNT           "posixAccount"
44 #define LDAP_OBJ_POSIXGROUP             "posixGroup"
45 #define LDAP_OBJ_OU                     "organizationalUnit"
46
47 /* some generic attributes that get reused a lot */
48
49 #define LDAP_ATTRIBUTE_SID              "sambaSID"
50 #define LDAP_ATTRIBUTE_UIDNUMBER        "uidNumber"
51 #define LDAP_ATTRIBUTE_GIDNUMBER        "gidNumber"
52
53 /* attribute map table indexes */
54
55 #define LDAP_ATTR_LIST_END              0
56 #define LDAP_ATTR_UID                   1
57 #define LDAP_ATTR_UIDNUMBER             2
58 #define LDAP_ATTR_GIDNUMBER             3
59 #define LDAP_ATTR_UNIX_HOME             4
60 #define LDAP_ATTR_PWD_LAST_SET          5
61 #define LDAP_ATTR_PWD_CAN_CHANGE        6
62 #define LDAP_ATTR_PWD_MUST_CHANGE       7
63 #define LDAP_ATTR_LOGON_TIME            8
64 #define LDAP_ATTR_LOGOFF_TIME           9
65 #define LDAP_ATTR_KICKOFF_TIME          10
66 #define LDAP_ATTR_CN                    11
67 #define LDAP_ATTR_DISPLAY_NAME          12
68 #define LDAP_ATTR_HOME_PATH             13
69 #define LDAP_ATTR_LOGON_SCRIPT          14
70 #define LDAP_ATTR_PROFILE_PATH          15
71 #define LDAP_ATTR_DESC                  16
72 #define LDAP_ATTR_USER_WKS              17
73 #define LDAP_ATTR_USER_SID              18
74 #define LDAP_ATTR_USER_RID              18
75 #define LDAP_ATTR_PRIMARY_GROUP_SID     19
76 #define LDAP_ATTR_PRIMARY_GROUP_RID     20
77 #define LDAP_ATTR_LMPW                  21
78 #define LDAP_ATTR_NTPW                  22
79 #define LDAP_ATTR_DOMAIN                23
80 #define LDAP_ATTR_OBJCLASS              24
81 #define LDAP_ATTR_ACB_INFO              25
82 #define LDAP_ATTR_NEXT_USERRID          26
83 #define LDAP_ATTR_NEXT_GROUPRID         27
84 #define LDAP_ATTR_DOM_SID               28
85 #define LDAP_ATTR_HOME_DRIVE            29
86 #define LDAP_ATTR_GROUP_SID             30
87 #define LDAP_ATTR_GROUP_TYPE            31
88 #define LDAP_ATTR_SID                   32
89 #define LDAP_ATTR_ALGORITHMIC_RID_BASE  33
90 #define LDAP_ATTR_NEXT_RID              34
91 #define LDAP_ATTR_BAD_PASSWORD_COUNT    35
92 #define LDAP_ATTR_LOGON_COUNT           36
93 #define LDAP_ATTR_MUNGED_DIAL           37
94 #define LDAP_ATTR_BAD_PASSWORD_TIME     38
95 #define LDAP_ATTR_MOD_TIMESTAMP         39
96
97 typedef struct _attrib_map_entry {
98         int             attrib;
99         const char      *name;
100 } ATTRIB_MAP_ENTRY;
101
102
103 /* structures */
104
105 extern ATTRIB_MAP_ENTRY attrib_map_v22[];
106 extern ATTRIB_MAP_ENTRY attrib_map_v30[];
107 extern ATTRIB_MAP_ENTRY dominfo_attr_list[];
108 extern ATTRIB_MAP_ENTRY groupmap_attr_list[];
109 extern ATTRIB_MAP_ENTRY groupmap_attr_list_to_delete[];
110 extern ATTRIB_MAP_ENTRY idpool_attr_list[];
111 extern ATTRIB_MAP_ENTRY sidmap_attr_list[];
112
113 /* Function declarations -- not included in proto.h so we don't
114    have to worry about LDAP structure types */
115
116 const char* get_attr_key2string( ATTRIB_MAP_ENTRY table[], int key );
117 char** get_attr_list( ATTRIB_MAP_ENTRY table[] );
118 void free_attr_list( char **list );
119 void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value);
120 void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
121                       LDAPMod ***mods,
122                       const char *attribute, const char *newval);
123 BOOL smbldap_get_single_attribute (LDAP * ldap_struct, LDAPMessage * entry,
124                                    const char *attribute, char *value,
125                                    int max_len);
126 BOOL smbldap_get_single_pstring (LDAP * ldap_struct, LDAPMessage * entry,
127                                  const char *attribute, pstring value);
128
129 /**
130  * Struct to keep the state for all the ldap stuff 
131  *
132  */
133
134 struct smbldap_state {
135         LDAP *ldap_struct;
136         time_t last_ping;
137         /* retrive-once info */
138         const char *uri;
139         char *bind_dn;
140         char *bind_secret;
141
142         unsigned int num_failures;
143
144         time_t last_use;
145         smb_event_id_t event_id;
146
147         struct timeval last_rebind;
148 };
149
150 #endif  /* HAVE_LDAP */
151
152 struct smbldap_state;
153
154 #endif  /* _SMBLDAP_H */
155