Imported Upstream version 0.2.2
[platform/upstream/libtirpc.git] / tirpc / 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  * $FreeBSD: src/include/rpc/auth.h,v 1.20 2003/01/01 18:48:42 schweikh Exp $
34  */
35
36 /*
37  * auth.h, Authentication interface.
38  *
39  * Copyright (C) 1984, Sun Microsystems, Inc.
40  *
41  * The data structures are completely opaque to the client.  The client
42  * is required to pass an AUTH * to routines that create rpc
43  * "sessions".
44  */
45
46 #ifndef _TIRPC_AUTH_H
47 #define  _TIRPC_AUTH_H
48
49 #include <rpc/xdr.h>
50 #include <rpc/clnt_stat.h>
51 #include <sys/cdefs.h>
52 #include <sys/socket.h>
53 #include <sys/types.h>
54
55
56 #define MAX_AUTH_BYTES  400
57 #define MAXNETNAMELEN   255     /* maximum length of network user's name */
58
59 /*
60  *  Client side authentication/security data
61  */
62
63 typedef struct sec_data {
64         u_int   secmod;         /* security mode number e.g. in nfssec.conf */
65         u_int   rpcflavor;      /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
66         int     flags;          /* AUTH_F_xxx flags */
67         caddr_t data;           /* opaque data per flavor */
68 } sec_data_t;
69
70 #ifdef _SYSCALL32_IMPL
71 struct sec_data32 {
72         uint32_t secmod;        /* security mode number e.g. in nfssec.conf */
73         uint32_t rpcflavor;     /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */
74         int32_t flags;          /* AUTH_F_xxx flags */
75         caddr32_t data;         /* opaque data per flavor */
76 };
77 #endif /* _SYSCALL32_IMPL */
78
79 /*
80  * AUTH_DES flavor specific data from sec_data opaque data field.
81  * AUTH_KERB has the same structure.
82  */
83 typedef struct des_clnt_data {
84         struct netbuf   syncaddr;       /* time sync addr */
85         struct knetconfig *knconf;      /* knetconfig info that associated */
86                                         /* with the syncaddr. */
87         char            *netname;       /* server's netname */
88         int             netnamelen;     /* server's netname len */
89 } dh_k4_clntdata_t;
90
91 #ifdef _SYSCALL32_IMPL
92 struct des_clnt_data32 {
93         struct netbuf32 syncaddr;       /* time sync addr */
94         caddr32_t knconf;               /* knetconfig info that associated */
95                                         /* with the syncaddr. */
96         caddr32_t netname;              /* server's netname */
97         int32_t netnamelen;             /* server's netname len */
98 };
99 #endif /* _SYSCALL32_IMPL */
100
101 #ifdef KERBEROS
102 /*
103  * flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)
104  * in sec_data->data opaque field.
105  */
106 typedef struct krb4_svc_data {
107         int             window;         /* window option value */
108 } krb4_svcdata_t;
109  
110 typedef struct krb4_svc_data    des_svcdata_t;
111 #endif /* KERBEROS */
112
113 /*
114  * authentication/security specific flags
115  */
116 #define AUTH_F_RPCTIMESYNC      0x001   /* use RPC to do time sync */
117 #define AUTH_F_TRYNONE          0x002   /* allow fall back to AUTH_NONE */
118
119
120 /*
121  * Status returned from authentication check
122  */
123 enum auth_stat {
124         AUTH_OK=0,
125         /*
126          * failed at  remote end
127          */
128         AUTH_BADCRED=1,                 /* bogus credentials (seal broken) */
129         AUTH_REJECTEDCRED=2,            /* client should begin new session */
130         AUTH_BADVERF=3,                 /* bogus verifier (seal broken) */
131         AUTH_REJECTEDVERF=4,            /* verifier expired or was replayed */
132         AUTH_TOOWEAK=5,                 /* rejected due to security reasons */
133         /*
134          * failed locally
135         */
136         AUTH_INVALIDRESP=6,             /* bogus response verifier */
137         AUTH_FAILED=7,                  /* some unknown reason */
138 #ifdef KERBEROS
139         /*
140          * kerberos errors
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          * RPCSEC_GSS errors
151          */
152         RPCSEC_GSS_CREDPROBLEM = 13,
153         RPCSEC_GSS_CTXPROBLEM = 14
154
155 };
156
157 typedef u_int32_t u_int32;      /* 32-bit unsigned integers */
158
159 union des_block {
160         struct {
161                 u_int32_t high;
162                 u_int32_t low;
163         } key;
164         char c[8];
165 };
166 typedef union des_block des_block;
167 __BEGIN_DECLS
168 extern bool_t xdr_des_block(XDR *, des_block *);
169 __END_DECLS
170
171 /*
172  * Authentication info.  Opaque to client.
173  */
174 struct opaque_auth {
175         enum_t  oa_flavor;              /* flavor of auth */
176         caddr_t oa_base;                /* address of more auth stuff */
177         u_int   oa_length;              /* not to exceed MAX_AUTH_BYTES */
178 };
179
180
181 /*
182  * Auth handle, interface to client side authenticators.
183  */
184 typedef struct __auth {
185         struct  opaque_auth     ah_cred;
186         struct  opaque_auth     ah_verf;
187         union   des_block       ah_key;
188         struct auth_ops {
189                 void    (*ah_nextverf) (struct __auth *);
190                 /* nextverf & serialize */
191                 int     (*ah_marshal) (struct __auth *, XDR *);
192                 /* validate verifier */
193                 int     (*ah_validate) (struct __auth *,
194                             struct opaque_auth *);
195                 /* refresh credentials */
196                 int     (*ah_refresh) (struct __auth *, void *);
197                 /* destroy this structure */
198                 void    (*ah_destroy) (struct __auth *);
199                 /* encode data for wire */
200                 int     (*ah_wrap) (struct __auth *, XDR *, xdrproc_t, caddr_t);
201                 /* decode data for wire */
202                 int     (*ah_unwrap) (struct __auth *, XDR *, xdrproc_t, caddr_t);
203
204         } *ah_ops;
205         void *ah_private;
206 } AUTH;
207
208
209 /*
210  * Authentication ops.
211  * The ops and the auth handle provide the interface to the authenticators.
212  *
213  * AUTH *auth;
214  * XDR  *xdrs;
215  * struct opaque_auth verf;
216  */
217 #define AUTH_NEXTVERF(auth)             \
218                 ((*((auth)->ah_ops->ah_nextverf))(auth))
219 #define auth_nextverf(auth)             \
220                 ((*((auth)->ah_ops->ah_nextverf))(auth))
221
222 #define AUTH_MARSHALL(auth, xdrs)       \
223                 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
224 #define auth_marshall(auth, xdrs)       \
225                 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
226
227 #define AUTH_VALIDATE(auth, verfp)      \
228                 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
229 #define auth_validate(auth, verfp)      \
230                 ((*((auth)->ah_ops->ah_validate))((auth), verfp))
231
232 #define AUTH_REFRESH(auth, msg)         \
233                 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
234 #define auth_refresh(auth, msg)         \
235                 ((*((auth)->ah_ops->ah_refresh))(auth, msg))
236
237 #define AUTH_DESTROY(auth)              \
238                 ((*((auth)->ah_ops->ah_destroy))(auth))
239 #define auth_destroy(auth)              \
240                 ((*((auth)->ah_ops->ah_destroy))(auth))
241
242 #define AUTH_WRAP(auth, xdrs, xfunc, xwhere)            \
243                 ((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \
244                 xfunc, xwhere))
245 #define auth_wrap(auth, xdrs, xfunc, xwhere)            \
246                 ((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \
247                 xfunc, xwhere))
248
249 #define AUTH_UNWRAP(auth, xdrs, xfunc, xwhere)          \
250                 ((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \
251                 xfunc, xwhere))
252 #define auth_unwrap(auth, xdrs, xfunc, xwhere)          \
253                 ((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \
254                 xfunc, xwhere))
255
256
257 __BEGIN_DECLS
258 extern struct opaque_auth _null_auth;
259 __END_DECLS
260
261 /*
262  * Any style authentication.  These routines can be used by any
263  * authentication style that does not use the wrap/unwrap functions.
264  */
265 int authany_wrap(void), authany_unwrap(void);
266
267 /*
268  * These are the various implementations of client side authenticators.
269  */
270
271 /*
272  * System style authentication
273  * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
274  *      char *machname;
275  *      int uid;
276  *      int gid;
277  *      int len;
278  *      int *aup_gids;
279  */
280 __BEGIN_DECLS
281 extern AUTH *authunix_create(char *, uid_t, uid_t, int, uid_t *);
282 extern AUTH *authunix_create_default(void);     /* takes no parameters */
283 extern AUTH *authnone_create(void);             /* takes no parameters */
284 __END_DECLS
285 /*
286  * DES style authentication
287  * AUTH *authsecdes_create(servername, window, timehost, ckey)
288  *      char *servername;               - network name of server
289  *      u_int window;                   - time to live
290  *      const char *timehost;                   - optional hostname to sync with
291  *      des_block *ckey;                - optional conversation key to use
292  */
293 __BEGIN_DECLS
294 extern AUTH *authdes_create (char *, u_int, struct sockaddr *, des_block *);
295 extern AUTH *authdes_seccreate (const char *, const u_int, const  char *,
296     const  des_block *);
297 __END_DECLS
298
299 __BEGIN_DECLS
300 extern bool_t xdr_opaque_auth           (XDR *, struct opaque_auth *);
301 __END_DECLS
302
303 #define authsys_create(c,i1,i2,i3,ip) authunix_create((c),(i1),(i2),(i3),(ip))
304 #define authsys_create_default() authunix_create_default()
305
306 /*
307  * Netname manipulation routines.
308  */
309 __BEGIN_DECLS
310 extern int getnetname(char *);
311 extern int host2netname(char *, const char *, const char *);
312 extern int user2netname(char *, const uid_t, const char *);
313 extern int netname2user(char *, uid_t *, gid_t *, int *, gid_t *);
314 extern int netname2host(char *, char *, const int);
315 extern void passwd2des ( char *, char * );
316 __END_DECLS
317
318 /*
319  *
320  * These routines interface to the keyserv daemon
321  *
322  */
323 __BEGIN_DECLS
324 extern int key_decryptsession(const char *, des_block *);
325 extern int key_encryptsession(const char *, des_block *);
326 extern int key_gendes(des_block *);
327 extern int key_setsecret(const char *);
328 extern int key_secretkey_is_set(void);
329 __END_DECLS
330
331 /*
332  * Publickey routines.
333  */
334 __BEGIN_DECLS
335 extern int getpublickey (const char *, char *);
336 extern int getpublicandprivatekey (char *, char *);
337 extern int getsecretkey (char *, char *, char *);
338 __END_DECLS
339
340 #ifdef KERBEROS
341 /*
342  * Kerberos style authentication
343  * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status)
344  *      const char *service;                    - service name
345  *      const char *srv_inst;                   - server instance
346  *      const char *realm;                      - server realm
347  *      const u_int window;                     - time to live
348  *      const char *timehost;                   - optional hostname to sync with
349  *      int *status;                            - kerberos status returned
350  */
351 __BEGIN_DECLS
352 extern AUTH     *authkerb_seccreate(const char *, const char *, const  char *,
353                     const u_int, const char *, int *);
354 __END_DECLS
355
356 /*
357  * Map a kerberos credential into a unix cred.
358  *
359  *      authkerb_getucred(rqst, uid, gid, grouplen, groups)
360  *      const struct svc_req *rqst;             - request pointer
361  *      uid_t *uid;
362  *      gid_t *gid;
363  *      short *grouplen;
364  *      int *groups;
365  *
366  */
367 __BEGIN_DECLS
368 extern int      authkerb_getucred(/* struct svc_req *, uid_t *, gid_t *,
369                     short *, int * */);
370 __END_DECLS
371 #endif /* KERBEROS */
372
373 __BEGIN_DECLS
374 struct svc_req;
375 struct rpc_msg;
376 enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *);
377 enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *);
378 enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *);
379 __END_DECLS
380
381 #define AUTH_NONE       0               /* no authentication */
382 #define AUTH_NULL       0               /* backward compatibility */
383 #define AUTH_SYS        1               /* unix style (uid, gids) */
384 #define AUTH_UNIX       AUTH_SYS
385 #define AUTH_SHORT      2               /* short hand unix style */
386 #define AUTH_DH         3               /* for Diffie-Hellman mechanism */
387 #define AUTH_DES        AUTH_DH         /* for backward compatibility */
388 #define AUTH_KERB       4               /* kerberos style */
389 #define RPCSEC_GSS      6               /* RPCSEC_GSS */
390
391 #endif /* !_TIRPC_AUTH_H */