r11573: Adding Andrew Bartlett's patch to make machine account
[kai/samba.git] / source3 / 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    
8    You are free to use this interface definition in any way you see
9    fit, including without restriction, using this header in your own
10    products. You do not need to give any attribution.  
11 */
12
13
14 #ifndef CONST_DISCARD
15 #define CONST_DISCARD(type, ptr)      ((type) ((void *) (ptr)))
16 #endif
17
18 #ifndef CONST_ADD
19 #define CONST_ADD(type, ptr)          ((type) ((const void *) (ptr)))
20 #endif
21
22 #ifndef SAFE_FREE
23 #define SAFE_FREE(x) do { if(x) {free(x); x=NULL;} } while(0)
24 #endif
25
26 #ifndef _WINBINDD_NTDOM_H
27 #define _WINBINDD_NTDOM_H
28
29 #define WINBINDD_SOCKET_NAME "pipe"            /* Name of PF_UNIX socket */
30 #define WINBINDD_SOCKET_DIR  "/tmp/.winbindd"  /* Name of PF_UNIX dir */
31 #define WINBINDD_PRIV_SOCKET_SUBDIR "winbindd_privileged" /* name of subdirectory of lp_lockdir() to hold the 'privileged' pipe */
32 #define WINBINDD_DOMAIN_ENV  "WINBINDD_DOMAIN" /* Environment variables */
33 #define WINBINDD_DONT_ENV    "_NO_WINBINDD"
34
35 /* Update this when you change the interface.  */
36
37 #define WINBIND_INTERFACE_VERSION 11
38
39 /* Socket commands */
40
41 enum winbindd_cmd {
42
43         WINBINDD_INTERFACE_VERSION,    /* Always a well known value */
44
45         /* Get users and groups */
46
47         WINBINDD_GETPWNAM,
48         WINBINDD_GETPWUID,
49         WINBINDD_GETGRNAM,
50         WINBINDD_GETGRGID,
51         WINBINDD_GETGROUPS,
52
53         /* Enumerate users and groups */
54
55         WINBINDD_SETPWENT,
56         WINBINDD_ENDPWENT,
57         WINBINDD_GETPWENT,
58         WINBINDD_SETGRENT,
59         WINBINDD_ENDGRENT,
60         WINBINDD_GETGRENT,
61
62         /* PAM authenticate and password change */
63
64         WINBINDD_PAM_AUTH,
65         WINBINDD_PAM_AUTH_CRAP,
66         WINBINDD_PAM_CHAUTHTOK,
67
68         /* List various things */
69
70         WINBINDD_LIST_USERS,         /* List w/o rid->id mapping */
71         WINBINDD_LIST_GROUPS,        /* Ditto */
72         WINBINDD_LIST_TRUSTDOM,
73
74         /* SID conversion */
75
76         WINBINDD_LOOKUPSID,
77         WINBINDD_LOOKUPNAME,
78
79         /* Lookup functions */
80
81         WINBINDD_SID_TO_UID,       
82         WINBINDD_SID_TO_GID,
83         WINBINDD_UID_TO_SID,
84         WINBINDD_GID_TO_SID,
85         WINBINDD_ALLOCATE_RID,
86         WINBINDD_ALLOCATE_RID_AND_GID,
87
88         /* Miscellaneous other stuff */
89
90         WINBINDD_CHECK_MACHACC,     /* Check machine account pw works */
91         WINBINDD_PING,              /* Just tell me winbind is running */
92         WINBINDD_INFO,              /* Various bit of info.  Currently just tidbits */
93         WINBINDD_DOMAIN_NAME,       /* The domain this winbind server is a member of (lp_workgroup()) */
94
95         WINBINDD_DOMAIN_INFO,   /* Most of what we know from
96                                    struct winbindd_domain */
97         WINBINDD_GETDCNAME,     /* Issue a GetDCName Request */
98
99         WINBINDD_SHOW_SEQUENCE, /* display sequence numbers of domains */
100
101         /* WINS commands */
102
103         WINBINDD_WINS_BYIP,
104         WINBINDD_WINS_BYNAME,
105
106         /* this is like GETGRENT but gives an empty group list */
107         WINBINDD_GETGRLST,
108
109         WINBINDD_NETBIOS_NAME,       /* The netbios name of the server */
110
111         /* find the location of our privileged pipe */
112         WINBINDD_PRIV_PIPE_DIR,
113
114         /* return a list of group sids for a user sid */
115         WINBINDD_GETUSERSIDS,
116
117         /* Return the domain groups a user is in */
118         WINBINDD_GETUSERDOMGROUPS,
119
120         /* Initialize connection in a child */
121         WINBINDD_INIT_CONNECTION,
122
123         /* Blocking calls that are not allowed on the main winbind pipe, only
124          * between parent and children */
125         WINBINDD_DUAL_SID2UID,
126         WINBINDD_DUAL_SID2GID,
127         WINBINDD_DUAL_IDMAPSET,
128
129         /* Wrapper around possibly blocking unix nss calls */
130         WINBINDD_DUAL_UID2NAME,
131         WINBINDD_DUAL_NAME2UID,
132         WINBINDD_DUAL_GID2NAME,
133         WINBINDD_DUAL_NAME2GID,
134
135         WINBINDD_DUAL_USERINFO,
136         WINBINDD_DUAL_GETSIDALIASES,
137
138         WINBINDD_NUM_CMDS
139 };
140
141 typedef struct winbindd_pw {
142         fstring pw_name;
143         fstring pw_passwd;
144         uid_t pw_uid;
145         gid_t pw_gid;
146         fstring pw_gecos;
147         fstring pw_dir;
148         fstring pw_shell;
149 } WINBINDD_PW;
150
151
152 typedef struct winbindd_gr {
153         fstring gr_name;
154         fstring gr_passwd;
155         gid_t gr_gid;
156         size_t num_gr_mem;
157         size_t gr_mem_ofs;   /* offset to group membership */
158         char **gr_mem;
159 } WINBINDD_GR;
160
161
162 #define WBFLAG_PAM_INFO3_NDR            0x0001
163 #define WBFLAG_PAM_INFO3_TEXT           0x0002
164 #define WBFLAG_PAM_USER_SESSION_KEY     0x0004
165 #define WBFLAG_PAM_LMKEY                0x0008
166 #define WBFLAG_PAM_CONTACT_TRUSTDOM     0x0010
167 #define WBFLAG_QUERY_ONLY               0x0020
168 #define WBFLAG_ALLOCATE_RID             0x0040
169 #define WBFLAG_PAM_UNIX_NAME            0x0080
170 #define WBFLAG_PAM_AFS_TOKEN            0x0100
171 #define WBFLAG_PAM_NT_STATUS_SQUASH     0x0200
172
173 /* This is a flag that can only be sent from parent to child */
174 #define WBFLAG_IS_PRIVILEGED            0x0400
175 /* Flag to say this is a winbindd internal send - don't recurse. */
176 #define WBFLAG_RECURSE                  0x0800
177
178 #define WINBINDD_MAX_EXTRA_DATA (128*1024)
179
180 /* Winbind request structure */
181
182 struct winbindd_request {
183         uint32 length;
184         enum winbindd_cmd cmd;   /* Winbindd command to execute */
185         pid_t pid;               /* pid of calling process */
186         uint32 flags;            /* flags relavant to a given request */
187         fstring domain_name;    /* name of domain for which the request applies */
188
189         union {
190                 fstring winsreq;     /* WINS request */
191                 fstring username;    /* getpwnam */
192                 fstring groupname;   /* getgrnam */
193                 uid_t uid;           /* getpwuid, uid_to_sid */
194                 gid_t gid;           /* getgrgid, gid_to_sid */
195                 struct {
196                         /* We deliberatedly don't split into domain/user to
197                            avoid having the client know what the separator
198                            character is. */     
199                         fstring user;
200                         fstring pass;
201                         fstring require_membership_of_sid;
202                 } auth;              /* pam_winbind auth module */
203                 struct {
204                         unsigned char chal[8];
205                         uint32 logon_parameters;
206                         fstring user;
207                         fstring domain;
208                         fstring lm_resp;
209                         uint16 lm_resp_len;
210                         fstring nt_resp;
211                         uint16 nt_resp_len;
212                         fstring workstation;
213                         fstring require_membership_of_sid;
214                 } auth_crap;
215                 struct {
216                     fstring user;
217                     fstring oldpass;
218                     fstring newpass;
219                 } chauthtok;         /* pam_winbind passwd module */
220                 fstring sid;         /* lookupsid, sid_to_[ug]id */
221                 struct {
222                         fstring dom_name;       /* lookupname */
223                         fstring name;       
224                 } name;
225                 uint32 num_entries;  /* getpwent, getgrent */
226                 struct {
227                         fstring username;
228                         fstring groupname;
229                 } acct_mgt;
230                 struct {
231                         BOOL is_primary;
232                         fstring dcname;
233                 } init_conn;
234                 struct {
235                         fstring sid;
236                         fstring name;
237                         BOOL alloc;
238                 } dual_sid2id;
239                 struct {
240                         int type;
241                         uid_t uid;
242                         gid_t gid;
243                         fstring sid;
244                 } dual_idmapset;
245         } data;
246         char *extra_data;
247         size_t extra_len;
248         char null_term;
249 };
250
251 /* Response values */
252
253 enum winbindd_result {
254         WINBINDD_ERROR,
255         WINBINDD_PENDING,
256         WINBINDD_OK
257 };
258
259 /* Winbind response structure */
260
261 struct winbindd_response {
262     
263         /* Header information */
264
265         uint32 length;                        /* Length of response */
266         enum winbindd_result result;          /* Result code */
267
268         /* Fixed length return data */
269         
270         union {
271                 int interface_version;  /* Try to ensure this is always in the same spot... */
272                 
273                 fstring winsresp;               /* WINS response */
274
275                 /* getpwnam, getpwuid */
276                 
277                 struct winbindd_pw pw;
278
279                 /* getgrnam, getgrgid */
280
281                 struct winbindd_gr gr;
282
283                 uint32 num_entries; /* getpwent, getgrent */
284                 struct winbindd_sid {
285                         fstring sid;        /* lookupname, [ug]id_to_sid */
286                         int type;
287                 } sid;
288                 struct winbindd_name {
289                         fstring dom_name;       /* lookupsid */
290                         fstring name;       
291                         int type;
292                 } name;
293                 uid_t uid;          /* sid_to_uid */
294                 gid_t gid;          /* sid_to_gid */
295                 struct winbindd_info {
296                         char winbind_separator;
297                         fstring samba_version;
298                 } info;
299                 fstring domain_name;
300                 fstring netbios_name;
301                 fstring dc_name;
302
303                 struct auth_reply {
304                         uint32 nt_status;
305                         fstring nt_status_string;
306                         fstring error_string;
307                         int pam_error;
308                         char user_session_key[16];
309                         char first_8_lm_hash[8];
310                 } auth;
311                 uint32 rid;     /* create user or group or allocate rid */
312                 struct {
313                         uint32 rid;
314                         gid_t gid;
315                 } rid_and_gid;
316                 struct {
317                         fstring name;
318                         fstring alt_name;
319                         fstring sid;
320                         BOOL native_mode;
321                         BOOL active_directory;
322                         BOOL primary;
323                         uint32 sequence_number;
324                 } domain_info;
325                 struct {
326                         fstring acct_name;
327                         fstring full_name;
328                         fstring homedir;
329                         fstring shell;
330                         uint32 group_rid;
331                 } user_info;
332         } data;
333
334         /* Variable length return data */
335
336         void *extra_data;               /* getgrnam, getgrgid, getgrent */
337 };
338
339 #endif