06a48f969110079a4b30b8910782af683d9c75cb
[nivanova/samba-autobuild/.git] / source3 / include / ads.h
1 #ifndef _INCLUDE_ADS_H_
2 #define _INCLUDE_ADS_H_
3 /*
4   header for ads (active directory) library routines
5
6   basically this is a wrapper around ldap
7 */
8
9 #define TOK_ID_KRB_AP_REQ       ((const uint8_t *)"\x01\x00")
10 #define TOK_ID_KRB_AP_REP       ((const uint8_t *)"\x02\x00")
11 #define TOK_ID_KRB_ERROR        ((const uint8_t *)"\x03\x00")
12 #define TOK_ID_GSS_GETMIC       ((const uint8_t *)"\x01\x01")
13 #define TOK_ID_GSS_WRAP         ((const uint8_t *)"\x02\x01")
14
15 enum wb_posix_mapping {
16         WB_POSIX_MAP_UNKNOWN    = -1,
17         WB_POSIX_MAP_TEMPLATE   = 0, 
18         WB_POSIX_MAP_SFU        = 1, 
19         WB_POSIX_MAP_SFU20      = 2, 
20         WB_POSIX_MAP_RFC2307    = 3,
21         WB_POSIX_MAP_UNIXINFO   = 4
22 };
23
24 struct ads_struct;
25
26 struct ads_saslwrap_ops {
27         const char *name;
28         ADS_STATUS (*wrap)(struct ads_struct *, uint8 *buf, uint32 len);
29         ADS_STATUS (*unwrap)(struct ads_struct *);
30         void (*disconnect)(struct ads_struct *);
31 };
32
33 enum ads_saslwrap_type {
34         ADS_SASLWRAP_TYPE_PLAIN = 1,
35         ADS_SASLWRAP_TYPE_SIGN = 2,
36         ADS_SASLWRAP_TYPE_SEAL = 4
37 };
38
39 typedef struct ads_struct {
40         int is_mine;    /* do I own this structure's memory? */
41         
42         /* info needed to find the server */
43         struct {
44                 char *realm;
45                 char *workgroup;
46                 char *ldap_server;
47                 int foreign; /* set to 1 if connecting to a foreign
48                               * realm */
49                 bool gc;     /* Is this a global catalog server? */
50         } server;
51
52         /* info needed to authenticate */
53         struct {
54                 char *realm;
55                 char *password;
56                 char *user_name;
57                 char *kdc_server;
58                 unsigned flags;
59                 int time_offset;
60                 time_t tgt_expire;
61                 time_t tgs_expire;
62                 time_t renewable;
63         } auth;
64
65         /* info derived from the servers config */
66         struct {
67                 uint32 flags; /* cldap flags identifying the services. */
68                 char *realm;
69                 char *bind_path;
70                 char *ldap_server_name;
71                 char *server_site_name;
72                 char *client_site_name;
73                 time_t current_time;
74                 char *schema_path;
75                 char *config_path;
76         } config;
77
78         /* info about the current LDAP connection */
79 #ifdef HAVE_LDAP
80         struct {
81                 LDAP *ld;
82                 struct sockaddr_storage ss; /* the ip of the active connection, if any */
83                 time_t last_attempt; /* last attempt to reconnect */
84                 int port;
85
86                 enum ads_saslwrap_type wrap_type;
87
88 #ifdef HAVE_LDAP_SASL_WRAPPING
89                 Sockbuf_IO_Desc *sbiod; /* lowlevel state for LDAP wrapping */
90 #endif /* HAVE_LDAP_SASL_WRAPPING */
91                 TALLOC_CTX *mem_ctx;
92                 const struct ads_saslwrap_ops *wrap_ops;
93                 void *wrap_private_data;
94                 struct {
95                         uint32 ofs;
96                         uint32 needed;
97                         uint32 left;
98 #define        ADS_SASL_WRAPPING_IN_MAX_WRAPPED        0x0FFFFFFF
99                         uint32 max_wrapped;
100                         uint32 min_wrapped;
101                         uint32 size;
102                         uint8 *buf;
103                 } in;
104                 struct {
105                         uint32 ofs;
106                         uint32 left;
107 #define        ADS_SASL_WRAPPING_OUT_MAX_WRAPPED       0x00A00000
108                         uint32 max_unwrapped;
109                         uint32 sig_size;
110                         uint32 size;
111                         uint8 *buf;
112                 } out;
113         } ldap;
114 #endif /* HAVE_LDAP */
115 } ADS_STRUCT;
116
117 /* used to remember the names of the posix attributes in AD */
118 /* see the rfc2307 & sfu nss backends */
119
120 struct posix_schema {
121         char *posix_homedir_attr;
122         char *posix_shell_attr;
123         char *posix_uidnumber_attr;
124         char *posix_gidnumber_attr;
125         char *posix_gecos_attr;
126         char *posix_uid_attr;
127 };
128
129
130
131 #ifdef HAVE_ADS
132 typedef LDAPMod **ADS_MODLIST;
133 #else
134 typedef void **ADS_MODLIST;
135 #endif
136
137 /* time between reconnect attempts */
138 #define ADS_RECONNECT_TIME 5
139
140 /* ldap control oids */
141 #define ADS_PAGE_CTL_OID        "1.2.840.113556.1.4.319"
142 #define ADS_NO_REFERRALS_OID    "1.2.840.113556.1.4.1339"
143 #define ADS_SERVER_SORT_OID     "1.2.840.113556.1.4.473"
144 #define ADS_PERMIT_MODIFY_OID   "1.2.840.113556.1.4.1413"
145 #define ADS_ASQ_OID             "1.2.840.113556.1.4.1504"
146 #define ADS_EXTENDED_DN_OID     "1.2.840.113556.1.4.529"
147 #define ADS_SD_FLAGS_OID        "1.2.840.113556.1.4.801"
148
149 /* ldap attribute oids (Services for Unix 3.0, 3.5) */
150 #define ADS_ATTR_SFU_UIDNUMBER_OID      "1.2.840.113556.1.6.18.1.310"
151 #define ADS_ATTR_SFU_GIDNUMBER_OID      "1.2.840.113556.1.6.18.1.311"
152 #define ADS_ATTR_SFU_HOMEDIR_OID        "1.2.840.113556.1.6.18.1.344"
153 #define ADS_ATTR_SFU_SHELL_OID          "1.2.840.113556.1.6.18.1.312"
154 #define ADS_ATTR_SFU_GECOS_OID          "1.2.840.113556.1.6.18.1.337"
155 #define ADS_ATTR_SFU_UID_OID            "1.2.840.113556.1.6.18.1.309"
156
157 /* ldap attribute oids (Services for Unix 2.0) */
158 #define ADS_ATTR_SFU20_UIDNUMBER_OID    "1.2.840.113556.1.4.7000.187.70"
159 #define ADS_ATTR_SFU20_GIDNUMBER_OID    "1.2.840.113556.1.4.7000.187.71"
160 #define ADS_ATTR_SFU20_HOMEDIR_OID      "1.2.840.113556.1.4.7000.187.106"
161 #define ADS_ATTR_SFU20_SHELL_OID        "1.2.840.113556.1.4.7000.187.72"
162 #define ADS_ATTR_SFU20_GECOS_OID        "1.2.840.113556.1.4.7000.187.97"
163 #define ADS_ATTR_SFU20_UID_OID          "1.2.840.113556.1.4.7000.187.102"
164
165
166 /* ldap attribute oids (RFC2307) */
167 #define ADS_ATTR_RFC2307_UIDNUMBER_OID  "1.3.6.1.1.1.1.0"
168 #define ADS_ATTR_RFC2307_GIDNUMBER_OID  "1.3.6.1.1.1.1.1"
169 #define ADS_ATTR_RFC2307_HOMEDIR_OID    "1.3.6.1.1.1.1.3"
170 #define ADS_ATTR_RFC2307_SHELL_OID      "1.3.6.1.1.1.1.4"
171 #define ADS_ATTR_RFC2307_GECOS_OID      "1.3.6.1.1.1.1.2"
172 #define ADS_ATTR_RFC2307_UID_OID        "0.9.2342.19200300.100.1.1"
173
174 /* ldap bitwise searches */
175 #define ADS_LDAP_MATCHING_RULE_BIT_AND  "1.2.840.113556.1.4.803"
176 #define ADS_LDAP_MATCHING_RULE_BIT_OR   "1.2.840.113556.1.4.804"
177
178 #define ADS_PINGS          0x0000FFFF  /* Ping response */
179
180 /* ads auth control flags */
181 #define ADS_AUTH_DISABLE_KERBEROS 0x0001
182 #define ADS_AUTH_NO_BIND          0x0002
183 #define ADS_AUTH_ANON_BIND        0x0004
184 #define ADS_AUTH_SIMPLE_BIND      0x0008
185 #define ADS_AUTH_ALLOW_NTLMSSP    0x0010
186 #define ADS_AUTH_SASL_SIGN        0x0020
187 #define ADS_AUTH_SASL_SEAL        0x0040
188 #define ADS_AUTH_SASL_FORCE       0x0080
189 #define ADS_AUTH_USER_CREDS       0x0100
190
191 enum ads_extended_dn_flags {
192         ADS_EXTENDED_DN_HEX_STRING      = 0,
193         ADS_EXTENDED_DN_STRING          = 1 /* not supported on win2k */
194 };
195
196 /* this is probably not very well suited to pass other controls generically but
197  * is good enough for the extended dn control where it is only used for atm */
198
199 typedef struct {
200         const char *control;
201         int val;
202         int critical;
203 } ads_control;
204
205 #define ADS_IGNORE_PRINCIPAL "not_defined_in_RFC4178@please_ignore"
206
207 #endif  /* _INCLUDE_ADS_H_ */