move to SAFE_FREE()
[abartlet/samba.git/.git] / source3 / nsswitch / winbindd_nss.h
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 2.0
4
5    Winbind daemon for ntdom nss module
6
7    Copyright (C) Tim Potter 2000
8    
9    This library is free software; you can redistribute it and/or
10    modify it under the terms of the GNU Library General Public
11    License as published by the Free Software Foundation; either
12    version 2 of the License, or (at your option) any later version.
13    
14    This library 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 GNU
17    Library General Public License for more details.
18    
19    You should have received a copy of the GNU Library General Public
20    License along with this library; if not, write to the
21    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22    Boston, MA  02111-1307, USA.   
23 */
24
25 #ifndef SAFE_FREE
26 #define SAFE_FREE(x) do { if(x) {free(x); x=NULL;} } while(0)
27 #endif
28
29 #ifndef _WINBINDD_NTDOM_H
30 #define _WINBINDD_NTDOM_H
31
32 #define WINBINDD_SOCKET_NAME "pipe"            /* Name of PF_UNIX socket */
33 #define WINBINDD_SOCKET_DIR  "/tmp/.winbindd"  /* Name of PF_UNIX dir */
34
35 #define WINBINDD_DOMAIN_ENV  "WINBINDD_DOMAIN" /* Environment variables */
36 #define WINBINDD_DONT_ENV    "_NO_WINBINDD"
37
38 /* Socket commands */
39
40 enum winbindd_cmd {
41
42         /* Get users and groups */
43
44         WINBINDD_GETPWNAM_FROM_USER,
45         WINBINDD_GETPWNAM_FROM_UID,
46         WINBINDD_GETGRNAM_FROM_GROUP,
47         WINBINDD_GETGRNAM_FROM_GID,
48         WINBINDD_GETGROUPS,
49
50         /* Enumerate users and groups */
51
52         WINBINDD_SETPWENT,
53         WINBINDD_ENDPWENT,
54         WINBINDD_GETPWENT,
55         WINBINDD_SETGRENT,
56         WINBINDD_ENDGRENT,
57         WINBINDD_GETGRENT,
58
59         /* PAM authenticate and password change */
60
61         WINBINDD_PAM_AUTH,
62         WINBINDD_PAM_AUTH_CRAP,
63         WINBINDD_PAM_CHAUTHTOK,
64
65         /* List various things */
66
67         WINBINDD_LIST_USERS,         /* List w/o rid->id mapping */
68         WINBINDD_LIST_GROUPS,        /* Ditto */
69         WINBINDD_LIST_TRUSTDOM,
70
71         /* SID conversion */
72
73         WINBINDD_LOOKUPSID,
74         WINBINDD_LOOKUPNAME,
75
76         /* S*RS functions */
77
78         WINBINDD_SID_TO_UID,       
79         WINBINDD_SID_TO_GID,
80         WINBINDD_UID_TO_SID,
81         WINBINDD_GID_TO_SID,
82
83         /* Miscellaneous other stuff */
84
85         WINBINDD_CHECK_MACHACC,     /* Check machine account pw works */
86
87         /* Placeholder for end of cmd list */
88
89         WINBINDD_NUM_CMDS
90 };
91
92 /* Winbind request structure */
93
94 struct winbindd_request {
95         enum winbindd_cmd cmd;   /* Winbindd command to execute */
96         pid_t pid;               /* pid of calling process */
97
98         union {
99                 fstring username;    /* getpwnam */
100                 fstring groupname;   /* getgrnam */
101                 uid_t uid;           /* getpwuid, uid_to_sid */
102                 gid_t gid;           /* getgrgid, gid_to_sid */
103                 struct {
104                         fstring user;
105                         fstring pass;
106                 } auth;              /* pam_winbind auth module */
107                 struct {
108                         unsigned char chal[8];
109                         fstring user;
110                         fstring lm_resp;
111                         uint16 lm_resp_len;
112                         fstring nt_resp;
113                         uint16 nt_resp_len;
114                 } auth_crap;
115                 struct {
116                     fstring user;
117                     fstring oldpass;
118                     fstring newpass;
119                 } chauthtok;         /* pam_winbind passwd module */
120                 fstring sid;         /* lookupsid, sid_to_[ug]id */
121                 fstring name;        /* lookupname */
122                 uint32 num_entries;  /* getpwent, getgrent */
123         } data;
124         fstring domain;      /* {set,get,end}{pw,gr}ent() */
125 };
126
127 /* Response values */
128
129 enum winbindd_result {
130         WINBINDD_ERROR,
131         WINBINDD_OK
132 };
133
134 /* Winbind response structure */
135
136 struct winbindd_response {
137     
138         /* Header information */
139
140         int length;                           /* Length of response */
141         enum winbindd_result result;          /* Result code */
142
143         /* Fixed length return data */
144         
145         union {
146                 
147                 /* getpwnam, getpwuid */
148                 
149                 struct winbindd_pw {
150                         fstring pw_name;
151                         fstring pw_passwd;
152                         uid_t pw_uid;
153                         gid_t pw_gid;
154                         fstring pw_gecos;
155                         fstring pw_dir;
156                         fstring pw_shell;
157                 } pw;
158
159                 /* getgrnam, getgrgid */
160
161                 struct winbindd_gr {
162                         fstring gr_name;
163                         fstring gr_passwd;
164                         gid_t gr_gid;
165                         int num_gr_mem;
166                         int gr_mem_ofs;   /* offset to group membership */
167                 } gr;
168
169                 uint32 num_entries; /* getpwent, getgrent */
170                 struct {
171                         fstring sid;        /* lookupname, [ug]id_to_sid */
172                         int type;
173                 } sid;
174                 struct {
175                         fstring name;       /* lookupsid */
176                         int type;
177                 } name;
178                 uid_t uid;          /* sid_to_uid */
179                 gid_t gid;          /* sid_to_gid */
180         } data;
181
182         /* Variable length return data */
183
184         void *extra_data;               /* getgrnam, getgrgid, getgrent */
185 };
186
187 #endif