gdb - Workaround to enable debugging in vkernels.
[dragonfly.git] / include / rpc / auth.h
1 /*      $NetBSD: auth.h,v 1.15 2000/06/02 22:57:55 fvdl Exp $   */
2
3 /*-
4  * Copyright (c) 2009, Sun Microsystems, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * - Redistributions of source code must retain the above copyright notice,
10  *   this list of conditions and the following disclaimer.
11  * - Redistributions in binary form must reproduce the above copyright notice,
12  *   this list of conditions and the following disclaimer in the documentation
13  *   and/or other materials provided with the distribution.
14  * - Neither the name of Sun Microsystems, Inc. nor the names of its
15  *   contributors may be used to endorse or promote products derived
16  *   from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  *      from: @(#)auth.h 1.17 88/02/08 SMI
31  *      from: @(#)auth.h        2.3 88/08/07 4.0 RPCSRC
32  *      from: @(#)auth.h        1.43    98/02/02 SMI
33  * $NetBSD: auth.h,v 1.15 2000/06/02 22:57:55 fvdl Exp $
34  * $FreeBSD: src/include/rpc/auth.h,v 1.21 2006/02/28 16:02:26 deischen Exp $
35  * $DragonFly: src/include/rpc/auth.h,v 1.4 2004/02/26 13:58:26 joerg Exp $
36  */
37
38 /*
39  * auth.h, Authentication interface.
40  *
41  * Copyright (C) 1984, Sun Microsystems, Inc.
42  *
43  * The data structures are completely opaque to the client.  The client
44  * is required to pass an AUTH * to routines that create rpc
45  * "sessions".
46  */
47
48 #ifndef _RPC_AUTH_H
49 #define _RPC_AUTH_H
50 #include <rpc/xdr.h>
51 #include <rpc/clnt_stat.h>
52 #include <sys/cdefs.h>
53 #include <sys/socket.h>
54
55 #define MAX_AUTH_BYTES  400
56 #define MAXNETNAMELEN   255     /* maximum length of network user's name */
57
58 /*
59  *  Client side authentication/security data
60  */
61
62 typedef struct sec_data {
63         u_int   secmod;         /* security mode number e.g. in nfssec.conf */
64         u_int   rpcflavor;      /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
65         int     flags;          /* AUTH_F_xxx flags */
66         caddr_t data;           /* opaque data per flavor */
67 } sec_data_t;
68
69 #ifdef _SYSCALL32_IMPL
70 struct sec_data32 {
71         uint32_t secmod;        /* security mode number e.g. in nfssec.conf */
72         uint32_t rpcflavor;     /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
73         int32_t flags;          /* AUTH_F_xxx flags */
74         caddr32_t data;         /* opaque data per flavor */
75 };
76 #endif /* _SYSCALL32_IMPL */
77
78 /*
79  * AUTH_DES flavor specific data from sec_data opaque data field.
80  * AUTH_KERB has the same structure.
81  */
82 typedef struct des_clnt_data {
83         struct netbuf   syncaddr;       /* time sync addr */
84         struct knetconfig *knconf;      /* knetconfig info that associated */
85                                         /* with the syncaddr. */
86         char            *netname;       /* server's netname */
87         int             netnamelen;     /* server's netname len */
88 } dh_k4_clntdata_t;
89
90 #ifdef _SYSCALL32_IMPL
91 struct des_clnt_data32 {
92         struct netbuf32 syncaddr;       /* time sync addr */
93         caddr32_t knconf;               /* knetconfig info that associated */
94                                         /* with the syncaddr. */
95         caddr32_t netname;              /* server's netname */
96         int32_t netnamelen;             /* server's netname len */
97 };
98 #endif /* _SYSCALL32_IMPL */
99
100 #ifdef KERBEROS
101 /*
102  * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)
103  * in sec_data->data opaque field.
104  */
105 typedef struct krb4_svc_data {
106         int             window;         /* window option value */
107 } krb4_svcdata_t;
108
109 typedef struct krb4_svc_data    des_svcdata_t;
110 #endif /* KERBEROS */
111
112 /*
113  * authentication/security specific flags
114  */
115 #define AUTH_F_RPCTIMESYNC      0x001   /* use RPC to do time sync */
116 #define AUTH_F_TRYNONE          0x002   /* allow fall back to AUTH_NONE */
117
118
119 /*
120  * Status returned from authentication check
121  */
122 enum auth_stat {
123         AUTH_OK=0,
124         /*
125          * failed at remote end
126          */
127         AUTH_BADCRED=1,                 /* bogus credentials (seal broken) */
128         AUTH_REJECTEDCRED=2,            /* client should begin new session */
129         AUTH_BADVERF=3,                 /* bogus verifier (seal broken) */
130         AUTH_REJECTEDVERF=4,            /* verifier expired or was replayed */
131         AUTH_TOOWEAK=5,                 /* rejected due to security reasons */
132         /*
133          * failed locally
134         */
135         AUTH_INVALIDRESP=6,             /* bogus response verifier */
136         AUTH_FAILED=7                   /* some unknown reason */
137 #ifdef KERBEROS
138         /*
139          * kerberos errors
140          */
141         ,
142         AUTH_KERB_GENERIC = 8,          /* kerberos generic error */
143         AUTH_TIMEEXPIRE = 9,            /* time of credential expired */
144         AUTH_TKT_FILE = 10,             /* something wrong with ticket file */
145         AUTH_DECODE = 11,               /* can't decode authenticator */
146         AUTH_NET_ADDR = 12              /* wrong net address in ticket */
147 #endif /* KERBEROS */
148 };
149
150 union des_block {
151         struct {
152                 uint32_t high;
153                 uint32_t low;
154         } key;
155         char c[8];
156 };
157 typedef union des_block des_block;
158 __BEGIN_DECLS
159 bool_t  xdr_des_block(XDR *, des_block *);
160 __END_DECLS
161
162 /*
163  * Authentication info.  Opaque to client.
164  */
165 struct opaque_auth {
166         enum_t  oa_flavor;              /* flavor of auth */
167         caddr_t oa_base;                /* address of more auth stuff */
168         u_int   oa_length;              /* not to exceed MAX_AUTH_BYTES */
169 };
170
171
172 /*
173  * Auth handle, interface to client side authenticators.
174  */
175 typedef struct __auth {
176         struct  opaque_auth     ah_cred;
177         struct  opaque_auth     ah_verf;
178         union   des_block       ah_key;
179         struct auth_ops {
180                 void    (*ah_nextverf) (struct __auth *);
181                 /* nextverf & serialize */
182                 int     (*ah_marshal) (struct __auth *, XDR *);
183                 /* validate verifier */
184                 int     (*ah_validate) (struct __auth *,
185                                 struct opaque_auth *);
186                 /* refresh credentials */
187                 int     (*ah_refresh) (struct __auth *, void *);
188                 /* destroy this structure */
189                 void    (*ah_destroy) (struct __auth *);
190         } *ah_ops;
191         void *ah_private;
192 } AUTH;
193
194
195 /*
196  * Authentication ops.
197  * The ops and the auth handle provide the interface to the authenticators.
198  *
199  * AUTH *auth;
200  * XDR  *xdrs;
201  * struct opaque_auth verf;
202  */
203 #define AUTH_NEXTVERF(auth)             \
204                 ((*((auth)->ah_ops->ah_nextverf))(auth))
205 #define auth_nextverf(auth)             \
206                 ((*((auth)->ah_ops->ah_nextverf))(auth))
207
208 #define AUTH_MARSHALL(auth, xdrs)       \
209                 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
210 #define auth_marshall(auth, xdrs)       \
211                 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
212
213 #define AUTH_VALIDATE(auth, verfp)      \
214                 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
215 #define auth_validate(auth, verfp)      \
216                 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
217
218 #define AUTH_REFRESH(auth, msg)         \
219                 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
220 #define auth_refresh(auth, msg)         \
221                 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
222
223 #define AUTH_DESTROY(auth)              \
224                 ((*((auth)->ah_ops->ah_destroy))(auth))
225 #define auth_destroy(auth)              \
226                 ((*((auth)->ah_ops->ah_destroy))(auth))
227
228
229 __BEGIN_DECLS
230 extern struct opaque_auth _null_auth;
231 __END_DECLS
232
233 /*
234  * These are the various implementations of client side authenticators.
235  */
236
237 /*
238  * System style authentication
239  * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
240  *      char *machname;
241  *      int uid;
242  *      int gid;
243  *      int len;
244  *      int *aup_gids;
245  */
246 __BEGIN_DECLS
247 AUTH    *authunix_create(char *, int, int, int, int *);
248 AUTH    *authunix_create_default(void);
249 AUTH    *authnone_create(void);
250 __END_DECLS
251 /*
252  * DES style authentication
253  * AUTH *authsecdes_create(servername, window, timehost, ckey)
254  *      char *servername;               - network name of server
255  *      u_int window;                   - time to live
256  *      const char *timehost;           - optional hostname to sync with
257  *      des_block *ckey;                - optional conversation key to use
258  */
259 __BEGIN_DECLS
260 AUTH    *authdes_create(char *, u_int, struct sockaddr *, des_block *);
261 AUTH    *authdes_seccreate(const char *, const u_int, const char *,
262                            const des_block *);
263 __END_DECLS
264
265 __BEGIN_DECLS
266 bool_t  xdr_opaque_auth(XDR *, struct opaque_auth *);
267 __END_DECLS
268
269 #define authsys_create(c,i1,i2,i3,ip) authunix_create((c),(i1),(i2),(i3),(ip))
270 #define authsys_create_default() authunix_create_default()
271
272 /*
273  * Netname manipulation routines.
274  */
275 __BEGIN_DECLS
276 int     getnetname(char *);
277 int     host2netname(char *, const char *, const char *);
278 int     user2netname(char *, const uid_t, const char *);
279 int     netname2user(char *, uid_t *, gid_t *, int *, gid_t *);
280 int     netname2host(char *, char *, const int);
281 void    passwd2des(char *, char *);
282 __END_DECLS
283
284 /*
285  *
286  * These routines interface to the keyserv daemon
287  *
288  */
289 __BEGIN_DECLS
290 int     key_decryptsession(const char *, des_block *);
291 int     key_encryptsession(const char *, des_block *);
292 int     key_gendes(des_block *);
293 int     key_setsecret(const char *);
294 int     key_secretkey_is_set(void);
295 __END_DECLS
296
297 /*
298  * Publickey routines.
299  */
300 __BEGIN_DECLS
301 int     getpublickey(const char *, char *);
302 int     getpublicandprivatekey(const char *, char *);
303 int     getsecretkey(char *, char *, char *);
304 __END_DECLS
305
306 #ifdef KERBEROS
307 /*
308  * Kerberos style authentication
309  * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status)
310  *      const char *service;                    - service name
311  *      const char *srv_inst;                   - server instance
312  *      const char *realm;                      - server realm
313  *      const u_int window;                     - time to live
314  *      const char *timehost;                   - optional hostname to sync with
315  *      int *status;                            - kerberos status returned
316  */
317 __BEGIN_DECLS
318 AUTH    *authkerb_seccreate(const char *, const char *, const char *,
319                             const u_int, const char *, int *);
320 __END_DECLS
321
322 /*
323  * Map a kerberos credential into a unix cred.
324  *
325  *      authkerb_getucred(rqst, uid, gid, grouplen, groups)
326  *      const struct svc_req *rqst;             - request pointer
327  *      uid_t *uid;
328  *      gid_t *gid;
329  *      short *grouplen;
330  *      int *groups;
331  *
332  */
333 __BEGIN_DECLS
334 int     authkerb_getucred(/* struct svc_req *, uid_t *, gid_t *,
335                           short *, int * */);
336 __END_DECLS
337 #endif /* KERBEROS */
338
339 __BEGIN_DECLS
340 struct svc_req;
341 struct rpc_msg;
342 enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *);
343 enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *);
344 enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *);
345 __END_DECLS
346
347 #define AUTH_NONE       0               /* no authentication */
348 #define AUTH_NULL       0               /* backward compatibility */
349 #define AUTH_SYS        1               /* unix style (uid, gids) */
350 #define AUTH_UNIX       AUTH_SYS
351 #define AUTH_SHORT      2               /* short hand unix style */
352 #define AUTH_DH         3               /* for Diffie-Hellman mechanism */
353 #define AUTH_DES        AUTH_DH         /* for backward compatibility */
354 #define AUTH_KERB       4               /* kerberos style */
355
356 #endif /* !_RPC_AUTH_H */