r17837: Split out the storing of memory cached credentials
[sfrench/samba-autobuild/.git] / source / nsswitch / winbindd_nss.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Winbind daemon for ntdom nss module
5
6    Copyright (C) Tim Potter 2000
7    Copyright (C) Gerald Carter 2006
8    
9    You are free to use this interface definition in any way you see
10    fit, including without restriction, using this header in your own
11    products. You do not need to give any attribution.  
12 */
13
14
15 #ifndef CONST_DISCARD
16 #define CONST_DISCARD(type, ptr)      ((type) ((void *) (ptr)))
17 #endif
18
19 #ifndef CONST_ADD
20 #define CONST_ADD(type, ptr)          ((type) ((const void *) (ptr)))
21 #endif
22
23 #ifndef SAFE_FREE
24 #define SAFE_FREE(x) do { if(x) {free(x); x=NULL;} } while(0)
25 #endif
26
27 #ifndef _WINBINDD_NTDOM_H
28 #define _WINBINDD_NTDOM_H
29
30 #define WINBINDD_SOCKET_NAME "pipe"            /* Name of PF_UNIX socket */
31 #define WINBINDD_SOCKET_DIR  "/tmp/.winbindd"  /* Name of PF_UNIX dir */
32 #define WINBINDD_PRIV_SOCKET_SUBDIR "winbindd_privileged" /* name of subdirectory of lp_lockdir() to hold the 'privileged' pipe */
33 #define WINBINDD_DOMAIN_ENV  "WINBINDD_DOMAIN" /* Environment variables */
34 #define WINBINDD_DONT_ENV    "_NO_WINBINDD"
35
36 /* Update this when you change the interface.  */
37
38 #define WINBIND_INTERFACE_VERSION 17
39
40 /* Have to deal with time_t being 4 or 8 bytes due to structure alignment.
41    On a 64bit Linux box, we have to support a constant structure size
42    between /lib/libnss_winbind.so.2 and /li64/libnss_winbind.so.2.
43    The easiest way to do this is to always use 8byte values for time_t. */
44
45 #if defined(int64)
46 #  define SMB_TIME_T int64
47 #else
48 #  define SMB_TIME_T time_t
49 #endif
50
51 /* Socket commands */
52
53 enum winbindd_cmd {
54
55         WINBINDD_INTERFACE_VERSION,    /* Always a well known value */
56
57         /* Get users and groups */
58
59         WINBINDD_GETPWNAM,
60         WINBINDD_GETPWUID,
61         WINBINDD_GETGRNAM,
62         WINBINDD_GETGRGID,
63         WINBINDD_GETGROUPS,
64
65         /* Enumerate users and groups */
66
67         WINBINDD_SETPWENT,
68         WINBINDD_ENDPWENT,
69         WINBINDD_GETPWENT,
70         WINBINDD_SETGRENT,
71         WINBINDD_ENDGRENT,
72         WINBINDD_GETGRENT,
73
74         /* PAM authenticate and password change */
75
76         WINBINDD_PAM_AUTH,
77         WINBINDD_PAM_AUTH_CRAP,
78         WINBINDD_PAM_CHAUTHTOK,
79         WINBINDD_PAM_LOGOFF,
80         WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP,
81
82         /* List various things */
83
84         WINBINDD_LIST_USERS,         /* List w/o rid->id mapping */
85         WINBINDD_LIST_GROUPS,        /* Ditto */
86         WINBINDD_LIST_TRUSTDOM,
87
88         /* SID conversion */
89
90         WINBINDD_LOOKUPSID,
91         WINBINDD_LOOKUPNAME,
92         WINBINDD_LOOKUPRIDS,
93
94         /* Lookup functions */
95
96         WINBINDD_SID_TO_UID,       
97         WINBINDD_SID_TO_GID,
98         WINBINDD_UID_TO_SID,
99         WINBINDD_GID_TO_SID,
100
101         WINBINDD_ALLOCATE_UID,
102         WINBINDD_ALLOCATE_GID,
103
104         /* Miscellaneous other stuff */
105
106         WINBINDD_CHECK_MACHACC,     /* Check machine account pw works */
107         WINBINDD_PING,              /* Just tell me winbind is running */
108         WINBINDD_INFO,              /* Various bit of info.  Currently just tidbits */
109         WINBINDD_DOMAIN_NAME,       /* The domain this winbind server is a member of (lp_workgroup()) */
110
111         WINBINDD_DOMAIN_INFO,   /* Most of what we know from
112                                    struct winbindd_domain */
113         WINBINDD_GETDCNAME,     /* Issue a GetDCName Request */
114
115         WINBINDD_SHOW_SEQUENCE, /* display sequence numbers of domains */
116
117         /* WINS commands */
118
119         WINBINDD_WINS_BYIP,
120         WINBINDD_WINS_BYNAME,
121
122         /* this is like GETGRENT but gives an empty group list */
123         WINBINDD_GETGRLST,
124
125         WINBINDD_NETBIOS_NAME,       /* The netbios name of the server */
126
127         /* find the location of our privileged pipe */
128         WINBINDD_PRIV_PIPE_DIR,
129
130         /* return a list of group sids for a user sid */
131         WINBINDD_GETUSERSIDS,
132
133         /* Various group queries */
134         WINBINDD_GETUSERDOMGROUPS,
135
136         /* Initialize connection in a child */
137         WINBINDD_INIT_CONNECTION,
138
139         /* Blocking calls that are not allowed on the main winbind pipe, only
140          * between parent and children */
141         WINBINDD_DUAL_SID2UID,
142         WINBINDD_DUAL_SID2GID,
143         WINBINDD_DUAL_UID2SID,
144         WINBINDD_DUAL_GID2SID,
145         WINBINDD_DUAL_IDMAPSET,
146
147         /* Wrapper around possibly blocking unix nss calls */
148         WINBINDD_DUAL_UID2NAME,
149         WINBINDD_DUAL_NAME2UID,
150         WINBINDD_DUAL_GID2NAME,
151         WINBINDD_DUAL_NAME2GID,
152
153         WINBINDD_DUAL_USERINFO,
154         WINBINDD_DUAL_GETSIDALIASES,
155
156         /* Complete the challenge phase of the NTLM authentication
157            protocol using cached password. */
158         WINBINDD_CCACHE_NTLMAUTH,
159
160         WINBINDD_NUM_CMDS
161 };
162
163 typedef struct winbindd_pw {
164         fstring pw_name;
165         fstring pw_passwd;
166         uid_t pw_uid;
167         gid_t pw_gid;
168         fstring pw_gecos;
169         fstring pw_dir;
170         fstring pw_shell;
171 } WINBINDD_PW;
172
173
174 typedef struct winbindd_gr {
175         fstring gr_name;
176         fstring gr_passwd;
177         gid_t gr_gid;
178         uint32 num_gr_mem;
179         uint32 gr_mem_ofs;   /* offset to group membership */
180 } WINBINDD_GR;
181
182
183 #define WBFLAG_PAM_INFO3_NDR            0x0001
184 #define WBFLAG_PAM_INFO3_TEXT           0x0002
185 #define WBFLAG_PAM_USER_SESSION_KEY     0x0004
186 #define WBFLAG_PAM_LMKEY                0x0008
187 #define WBFLAG_PAM_CONTACT_TRUSTDOM     0x0010
188 #define WBFLAG_QUERY_ONLY               0x0020
189 #define WBFLAG_PAM_UNIX_NAME            0x0080
190 #define WBFLAG_PAM_AFS_TOKEN            0x0100
191 #define WBFLAG_PAM_NT_STATUS_SQUASH     0x0200
192
193 /* This is a flag that can only be sent from parent to child */
194 #define WBFLAG_IS_PRIVILEGED            0x0400
195 /* Flag to say this is a winbindd internal send - don't recurse. */
196 #define WBFLAG_RECURSE                  0x0800
197
198 #define WBFLAG_PAM_KRB5                 0x1000
199 #define WBFLAG_PAM_FALLBACK_AFTER_KRB5  0x2000
200 #define WBFLAG_PAM_CACHED_LOGIN         0x4000
201 #define WBFLAG_PAM_GET_PWD_POLICY       0x8000  /* not used */
202
203 #define WINBINDD_MAX_EXTRA_DATA (128*1024)
204
205 /* Winbind request structure */
206
207 /*******************************************************************************
208  * This structure MUST be the same size in the 32bit and 64bit builds
209  * for compatibility between /lib64/libnss_winbind.so and /lib/libnss_winbind.so
210  * 
211  * DO NOT CHANGE THIS STRUCTURE WITHOUT TESTING THE 32BIT NSS LIB AGAINST
212  * A 64BIT WINBINDD    --jerry
213  ******************************************************************************/
214
215 struct winbindd_request {
216         uint32 length;
217         enum winbindd_cmd cmd;   /* Winbindd command to execute */
218         pid_t pid;               /* pid of calling process */
219         uint32 flags;            /* flags relavant to a given request */
220         fstring domain_name;    /* name of domain for which the request applies */
221
222         union {
223                 fstring winsreq;     /* WINS request */
224                 fstring username;    /* getpwnam */
225                 fstring groupname;   /* getgrnam */
226                 uid_t uid;           /* getpwuid, uid_to_sid */
227                 gid_t gid;           /* getgrgid, gid_to_sid */
228                 struct {
229                         /* We deliberatedly don't split into domain/user to
230                            avoid having the client know what the separator
231                            character is. */     
232                         fstring user;
233                         fstring pass;
234                         fstring require_membership_of_sid;
235                         fstring krb5_cc_type;
236                         uid_t uid;
237                 } auth;              /* pam_winbind auth module */
238                 struct {
239                         unsigned char chal[8];
240                         uint32 logon_parameters;
241                         fstring user;
242                         fstring domain;
243                         fstring lm_resp;
244                         uint32 lm_resp_len;
245                         fstring nt_resp;
246                         uint32 nt_resp_len;
247                         fstring workstation;
248                         fstring require_membership_of_sid;
249                 } auth_crap;
250                 struct {
251                     fstring user;
252                     fstring oldpass;
253                     fstring newpass;
254                 } chauthtok;         /* pam_winbind passwd module */
255                 struct {
256                         fstring user;
257                         fstring domain;
258                         unsigned char new_nt_pswd[516];
259                         uint16  new_nt_pswd_len;
260                         unsigned char old_nt_hash_enc[16];
261                         uint16  old_nt_hash_enc_len;
262                         unsigned char new_lm_pswd[516];
263                         uint16  new_lm_pswd_len;
264                         unsigned char old_lm_hash_enc[16];
265                         uint16  old_lm_hash_enc_len;
266                 } chng_pswd_auth_crap;/* pam_winbind passwd module */
267                 struct {
268                         fstring user;
269                         fstring krb5ccname;
270                         uid_t uid;
271                 } logoff;              /* pam_winbind session module */
272                 fstring sid;         /* lookupsid, sid_to_[ug]id */
273                 struct {
274                         fstring dom_name;       /* lookupname */
275                         fstring name;       
276                 } name;
277                 uint32 num_entries;  /* getpwent, getgrent */
278                 struct {
279                         fstring username;
280                         fstring groupname;
281                 } acct_mgt;
282                 struct {
283                         BOOL is_primary;
284                         fstring dcname;
285                 } init_conn;
286                 struct {
287                         fstring sid;
288                         fstring name;
289                         BOOL alloc;
290                 } dual_sid2id;
291                 struct {
292                         int type;
293                         uid_t uid;
294                         gid_t gid;
295                         fstring sid;
296                 } dual_idmapset;
297                 BOOL list_all_domains;
298
299                 struct {
300                         uid_t uid;
301                         fstring user;
302                         /* the effective uid of the client, must be the uid for 'user'.
303                            This is checked by the main daemon, trusted by children. */
304                         /* if the blobs are length zero, then this doesn't
305                            produce an actual challenge response. It merely
306                            succeeds if there are cached credentials available
307                            that could be used. */
308                         uint32 initial_blob_len; /* blobs in extra_data */
309                         uint32 challenge_blob_len;
310                 } ccache_ntlm_auth;
311
312                 /* padding -- needed to fix alignment between 32bit and 64bit libs.
313                    The size is the sizeof the union without the padding aligned on 
314                    an 8 byte boundary.   --jerry */
315
316                 char padding[1560];
317         } data;
318         union {
319                 SMB_TIME_T padding;
320                 char *data;
321         } extra_data;
322         uint32 extra_len;
323         char null_term;
324 };
325
326 /* Response values */
327
328 enum winbindd_result {
329         WINBINDD_ERROR,
330         WINBINDD_PENDING,
331         WINBINDD_OK
332 };
333
334 /* Winbind response structure */
335
336 /*******************************************************************************
337  * This structure MUST be the same size in the 32bit and 64bit builds
338  * for compatibility between /lib64/libnss_winbind.so and /lib/libnss_winbind.so
339  * 
340  * DO NOT CHANGE THIS STRUCTURE WITHOUT TESTING THE 32BIT NSS LIB AGAINST
341  * A 64BIT WINBINDD    --jerry
342  ******************************************************************************/
343
344 struct winbindd_response {
345     
346         /* Header information */
347
348         uint32 length;                        /* Length of response */
349         enum winbindd_result result;          /* Result code */
350
351         /* Fixed length return data */
352         
353         union {
354                 int interface_version;  /* Try to ensure this is always in the same spot... */
355                 
356                 fstring winsresp;               /* WINS response */
357
358                 /* getpwnam, getpwuid */
359                 
360                 struct winbindd_pw pw;
361
362                 /* getgrnam, getgrgid */
363
364                 struct winbindd_gr gr;
365
366                 uint32 num_entries; /* getpwent, getgrent */
367                 struct winbindd_sid {
368                         fstring sid;        /* lookupname, [ug]id_to_sid */
369                         int type;
370                 } sid;
371                 struct winbindd_name {
372                         fstring dom_name;       /* lookupsid */
373                         fstring name;       
374                         int type;
375                 } name;
376                 uid_t uid;          /* sid_to_uid */
377                 gid_t gid;          /* sid_to_gid */
378                 struct winbindd_info {
379                         char winbind_separator;
380                         fstring samba_version;
381                 } info;
382                 fstring domain_name;
383                 fstring netbios_name;
384                 fstring dc_name;
385
386                 struct auth_reply {
387                         uint32 nt_status;
388                         fstring nt_status_string;
389                         fstring error_string;
390                         int pam_error;
391                         char user_session_key[16];
392                         char first_8_lm_hash[8];
393                         fstring krb5ccname;
394                         uint32 reject_reason;
395                         uint32 padding;
396                         struct policy_settings {
397                                 uint32 min_length_password;
398                                 uint32 password_history;
399                                 uint32 password_properties;
400                                 uint32 padding;
401                                 SMB_TIME_T expire;
402                                 SMB_TIME_T min_passwordage;
403                         } policy;
404                         struct info3_text {
405                                 SMB_TIME_T logon_time;
406                                 SMB_TIME_T logoff_time;
407                                 SMB_TIME_T kickoff_time;
408                                 SMB_TIME_T pass_last_set_time;
409                                 SMB_TIME_T pass_can_change_time;
410                                 SMB_TIME_T pass_must_change_time;
411                                 uint32 logon_count;
412                                 uint32 bad_pw_count;
413                                 uint32 user_rid;
414                                 uint32 group_rid;
415                                 uint32 num_groups;
416                                 uint32 user_flgs;
417                                 uint32 acct_flags;
418                                 uint32 num_other_sids;
419                                 fstring dom_sid;
420                                 fstring user_name;
421                                 fstring full_name;
422                                 fstring logon_script;
423                                 fstring profile_path;
424                                 fstring home_dir;
425                                 fstring dir_drive;
426                                 fstring logon_srv;
427                                 fstring logon_dom;
428                         } info3;
429                 } auth;
430                 struct {
431                         fstring name;
432                         fstring alt_name;
433                         fstring sid;
434                         BOOL native_mode;
435                         BOOL active_directory;
436                         BOOL primary;
437                         uint32 sequence_number;
438                 } domain_info;
439                 struct {
440                         fstring acct_name;
441                         fstring full_name;
442                         fstring homedir;
443                         fstring shell;
444                         uint32 group_rid;
445                 } user_info;
446                 struct {
447                         uint32 auth_blob_len; /* blob in extra_data */
448                 } ccache_ntlm_auth;
449         } data;
450
451         /* Variable length return data */
452
453         union {
454                 SMB_TIME_T padding;
455                 void *data;
456         } extra_data;
457 };
458
459 struct WINBINDD_MEMORY_CREDS {
460         struct WINBINDD_MEMORY_CREDS *next, *prev;
461         const char *username; /* lookup key. */
462         int ref_count;
463         size_t len;
464         unsigned char *nt_hash; /* Base pointer for the following 2 */
465         unsigned char *lm_hash;
466         char *pass;
467 };
468
469 struct WINBINDD_CCACHE_ENTRY {
470         struct WINBINDD_CCACHE_ENTRY *next, *prev;
471         const char *principal_name;
472         const char *ccname;
473         const char *service;
474         const char *username;
475         const char *sid_string;
476         struct WINBINDD_MEMORY_CREDS *cred_ptr;
477         int ref_count;
478         uid_t uid;
479         time_t create_time;
480         time_t renew_until;
481         BOOL refresh_tgt;
482         time_t refresh_time;
483         struct timed_event *event;
484 };
485
486 #endif