1 /* 2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 * unrestricted use provided that this legend is included on all tape 4 * media and as a part of the software program in whole or part. Users 5 * may copy or modify Sun RPC without charge, but are not authorized 6 * to license or distribute it to anyone else except as part of a product or 7 * program developed by the user. 8 * 9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10 * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12 * 13 * Sun RPC is provided with no support and without any obligation on the 14 * part of Sun Microsystems, Inc. to assist in its use, correction, 15 * modification or enhancement. 16 * 17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19 * OR ANY PART THEREOF. 20 * 21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22 * or profits or other special, indirect and consequential damages, even if 23 * Sun has been advised of the possibility of such damages. 24 * 25 * Sun Microsystems, Inc. 26 * 2550 Garcia Avenue 27 * Mountain View, California 94043 28 * 29 * from: @(#)auth.h 1.17 88/02/08 SMI 30 * from: @(#)auth.h 2.3 88/08/07 4.0 RPCSRC 31 * $FreeBSD: src/include/rpc/auth.h,v 1.15 1999/08/27 23:45:02 peter Exp $ 32 * $DragonFly: src/include/rpc/auth.h,v 1.3 2003/11/14 01:01:50 dillon Exp $ 33 */ 34 35 /* 36 * auth.h, Authentication interface. 37 * 38 * Copyright (C) 1984, Sun Microsystems, Inc. 39 * 40 * The data structures are completely opaque to the client. The client 41 * is required to pass a AUTH * to routines that create rpc 42 * "sessions". 43 */ 44 45 #ifndef _RPC_AUTH_H 46 #define _RPC_AUTH_H 47 #include <sys/cdefs.h> 48 #include <sys/socket.h> 49 50 #define MAX_AUTH_BYTES 400 51 #define MAXNETNAMELEN 255 /* maximum length of network user's name */ 52 53 /* 54 * Status returned from authentication check 55 */ 56 enum auth_stat { 57 AUTH_OK=0, 58 /* 59 * failed at remote end 60 */ 61 AUTH_BADCRED=1, /* bogus credentials (seal broken) */ 62 AUTH_REJECTEDCRED=2, /* client should begin new session */ 63 AUTH_BADVERF=3, /* bogus verifier (seal broken) */ 64 AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */ 65 AUTH_TOOWEAK=5, /* rejected due to security reasons */ 66 /* 67 * failed locally 68 */ 69 AUTH_INVALIDRESP=6, /* bogus response verifier */ 70 AUTH_FAILED=7 /* some unknown reason */ 71 }; 72 73 union des_block { 74 struct { 75 u_int32_t high; 76 u_int32_t low; 77 } key; 78 char c[8]; 79 }; 80 typedef union des_block des_block; 81 __BEGIN_DECLS 82 extern bool_t xdr_des_block (XDR *, des_block *); 83 __END_DECLS 84 85 /* 86 * Authentication info. Opaque to client. 87 */ 88 struct opaque_auth { 89 enum_t oa_flavor; /* flavor of auth */ 90 caddr_t oa_base; /* address of more auth stuff */ 91 u_int oa_length; /* not to exceed MAX_AUTH_BYTES */ 92 }; 93 __BEGIN_DECLS 94 bool_t xdr_opaque_auth (XDR *xdrs, struct opaque_auth *ap); 95 __END_DECLS 96 97 98 /* 99 * Auth handle, interface to client side authenticators. 100 */ 101 typedef struct __rpc_auth { 102 struct opaque_auth ah_cred; 103 struct opaque_auth ah_verf; 104 union des_block ah_key; 105 struct auth_ops { 106 void (*ah_nextverf) (struct __rpc_auth *); 107 /* nextverf & serialize */ 108 int (*ah_marshal) (struct __rpc_auth *, XDR *); 109 /* validate verifier */ 110 int (*ah_validate) (struct __rpc_auth *, 111 struct opaque_auth *); 112 /* refresh credentials */ 113 int (*ah_refresh) (struct __rpc_auth *); 114 /* destroy this structure */ 115 void (*ah_destroy) (struct __rpc_auth *); 116 } *ah_ops; 117 caddr_t ah_private; 118 } AUTH; 119 120 121 /* 122 * Authentication ops. 123 * The ops and the auth handle provide the interface to the authenticators. 124 * 125 * AUTH *auth; 126 * XDR *xdrs; 127 * struct opaque_auth verf; 128 */ 129 #define AUTH_NEXTVERF(auth) \ 130 ((*((auth)->ah_ops->ah_nextverf))(auth)) 131 #define auth_nextverf(auth) \ 132 ((*((auth)->ah_ops->ah_nextverf))(auth)) 133 134 #define AUTH_MARSHALL(auth, xdrs) \ 135 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) 136 #define auth_marshall(auth, xdrs) \ 137 ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) 138 139 #define AUTH_VALIDATE(auth, verfp) \ 140 ((*((auth)->ah_ops->ah_validate))((auth), verfp)) 141 #define auth_validate(auth, verfp) \ 142 ((*((auth)->ah_ops->ah_validate))((auth), verfp)) 143 144 #define AUTH_REFRESH(auth) \ 145 ((*((auth)->ah_ops->ah_refresh))(auth)) 146 #define auth_refresh(auth) \ 147 ((*((auth)->ah_ops->ah_refresh))(auth)) 148 149 #define AUTH_DESTROY(auth) \ 150 ((*((auth)->ah_ops->ah_destroy))(auth)) 151 #define auth_destroy(auth) \ 152 ((*((auth)->ah_ops->ah_destroy))(auth)) 153 154 155 extern struct opaque_auth _null_auth; 156 157 /* 158 * These are the various implementations of client side authenticators. 159 */ 160 161 /* 162 * Unix style authentication 163 * AUTH *authunix_create(machname, uid, gid, len, aup_gids) 164 * char *machname; 165 * int uid; 166 * int gid; 167 * int len; 168 * int *aup_gids; 169 */ 170 __BEGIN_DECLS 171 struct sockaddr_in; 172 extern AUTH *authunix_create (char *, int, int, int, int *); 173 extern AUTH *authunix_create_default (void); 174 extern AUTH *authnone_create (void); 175 __END_DECLS 176 177 /* Forward compatibility with TI-RPC */ 178 #define authsys_create authunix_create 179 #define authsys_create_default authunix_create_default 180 181 /* 182 * DES style authentication 183 * AUTH *authdes_create(servername, window, timehost, ckey) 184 * char *servername; - network name of server 185 * u_int window; - time to live 186 * struct sockaddr *timehost; - optional hostname to sync with 187 * des_block *ckey; - optional conversation key to use 188 */ 189 __BEGIN_DECLS 190 extern AUTH *authdes_create ( char *, u_int, struct sockaddr *, des_block * ); 191 #ifdef NOTYET 192 /* 193 * TI-RPC supports this call, but it requires the inclusion of 194 * NIS+-specific headers which would require the inclusion of other 195 * headers which would result in a tangled mess. For now, the NIS+ 196 * code prototypes this routine internally. 197 */ 198 extern AUTH *authdes_pk_create ( char *, netobj *, u_int, 199 struct sockaddr *, des_block *, 200 nis_server * ); 201 #endif 202 __END_DECLS 203 204 /* 205 * Netname manipulation routines. 206 */ 207 __BEGIN_DECLS 208 extern int netname2user ( char *, uid_t *, gid_t *, int *, gid_t *); 209 extern int netname2host ( char *, char *, int ); 210 extern int getnetname ( char * ); 211 extern int user2netname ( char *, uid_t, char * ); 212 extern int host2netname ( char *, char *, char * ); 213 extern void passwd2des ( char *, char * ); 214 __END_DECLS 215 216 /* 217 * Keyserv interface routines. 218 * XXX Should not be here. 219 */ 220 #ifndef HEXKEYBYTES 221 #define HEXKEYBYTES 48 222 #endif 223 typedef char kbuf[HEXKEYBYTES]; 224 typedef char *namestr; 225 226 struct netstarg { 227 kbuf st_priv_key; 228 kbuf st_pub_key; 229 namestr st_netname; 230 }; 231 232 __BEGIN_DECLS 233 extern int key_decryptsession ( const char *, des_block * ); 234 extern int key_decryptsession_pk ( char *, netobj *, des_block * ); 235 extern int key_encryptsession ( const char *, des_block * ); 236 extern int key_encryptsession_pk ( char *, netobj *, des_block * ); 237 extern int key_gendes ( des_block * ); 238 extern int key_setsecret ( const char * ); 239 extern int key_secretkey_is_set ( void ); 240 extern int key_setnet ( struct netstarg * ); 241 extern int key_get_conv ( char *, des_block * ); 242 __END_DECLS 243 244 /* 245 * Publickey routines. 246 */ 247 __BEGIN_DECLS 248 extern int getpublickey ( char *, char * ); 249 extern int getpublicandprivatekey ( char *, char * ); 250 extern int getsecretkey ( char *, char *, char * ); 251 __END_DECLS 252 253 254 #define AUTH_NONE 0 /* no authentication */ 255 #define AUTH_NULL 0 /* backward compatibility */ 256 #define AUTH_UNIX 1 /* unix style (uid, gids) */ 257 #define AUTH_SYS 1 /* forward compatibility */ 258 #define AUTH_SHORT 2 /* short hand unix style */ 259 #define AUTH_DES 3 /* des style (encrypted timestamps) */ 260 261 #endif /* !_RPC_AUTH_H */ 262