lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* @(#)auth.h 2.3 88/08/07 4.0 RPCSRC; from 1.17 88/02/08 SMI */ |
| 2 | /* |
| 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for |
| 4 | * unrestricted use provided that this legend is included on all tape |
| 5 | * media and as a part of the software program in whole or part. Users |
| 6 | * may copy or modify Sun RPC without charge, but are not authorized |
| 7 | * to license or distribute it to anyone else except as part of a product or |
| 8 | * program developed by the user. |
| 9 | * |
| 10 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE |
| 11 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR |
| 12 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. |
| 13 | * |
| 14 | * Sun RPC is provided with no support and without any obligation on the |
| 15 | * part of Sun Microsystems, Inc. to assist in its use, correction, |
| 16 | * modification or enhancement. |
| 17 | * |
| 18 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE |
| 19 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC |
| 20 | * OR ANY PART THEREOF. |
| 21 | * |
| 22 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue |
| 23 | * or profits or other special, indirect and consequential damages, even if |
| 24 | * Sun has been advised of the possibility of such damages. |
| 25 | * |
| 26 | * Sun Microsystems, Inc. |
| 27 | * 2550 Garcia Avenue |
| 28 | * Mountain View, California 94043 |
| 29 | */ |
| 30 | |
| 31 | /* |
| 32 | * auth.h, Authentication interface. |
| 33 | * |
| 34 | * Copyright (C) 1984, Sun Microsystems, Inc. |
| 35 | * |
| 36 | * The data structures are completely opaque to the client. The client |
| 37 | * is required to pass a AUTH * to routines that create rpc |
| 38 | * "sessions". |
| 39 | */ |
| 40 | |
| 41 | #ifndef _RPC_AUTH_H |
| 42 | |
| 43 | #define _RPC_AUTH_H 1 |
| 44 | #ifdef _LIBC |
| 45 | /* Some adjustments to make the libc source from glibc |
| 46 | * compile more easily with uClibc... */ |
| 47 | #ifndef __FORCE_GLIBC |
| 48 | #define __FORCE_GLIBC |
| 49 | #endif |
| 50 | #ifndef _GNU_SOURCE |
| 51 | #define _GNU_SOURCE |
| 52 | #endif |
| 53 | #define _(X) X |
| 54 | #endif |
| 55 | #include <features.h> |
| 56 | #include <rpc/xdr.h> |
| 57 | |
| 58 | __BEGIN_DECLS |
| 59 | |
| 60 | #define MAX_AUTH_BYTES 400 |
| 61 | #define MAXNETNAMELEN 255 /* maximum length of network user's name */ |
| 62 | |
| 63 | /* |
| 64 | * Status returned from authentication check |
| 65 | */ |
| 66 | enum auth_stat { |
| 67 | AUTH_OK=0, |
| 68 | /* |
| 69 | * failed at remote end |
| 70 | */ |
| 71 | AUTH_BADCRED=1, /* bogus credentials (seal broken) */ |
| 72 | AUTH_REJECTEDCRED=2, /* client should begin new session */ |
| 73 | AUTH_BADVERF=3, /* bogus verifier (seal broken) */ |
| 74 | AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */ |
| 75 | AUTH_TOOWEAK=5, /* rejected due to security reasons */ |
| 76 | /* |
| 77 | * failed locally |
| 78 | */ |
| 79 | AUTH_INVALIDRESP=6, /* bogus response verifier */ |
| 80 | AUTH_FAILED=7 /* some unknown reason */ |
| 81 | }; |
| 82 | |
| 83 | union des_block { |
| 84 | struct { |
| 85 | u_int32_t high; |
| 86 | u_int32_t low; |
| 87 | } key; |
| 88 | char c[8]; |
| 89 | }; |
| 90 | typedef union des_block des_block; |
| 91 | extern bool_t xdr_des_block (XDR *__xdrs, des_block *__blkp) __THROW; |
| 92 | |
| 93 | /* |
| 94 | * Authentication info. Opaque to client. |
| 95 | */ |
| 96 | struct opaque_auth { |
| 97 | enum_t oa_flavor; /* flavor of auth */ |
| 98 | caddr_t oa_base; /* address of more auth stuff */ |
| 99 | u_int oa_length; /* not to exceed MAX_AUTH_BYTES */ |
| 100 | }; |
| 101 | |
| 102 | /* |
| 103 | * Auth handle, interface to client side authenticators. |
| 104 | */ |
| 105 | typedef struct AUTH AUTH; |
| 106 | struct AUTH { |
| 107 | struct opaque_auth ah_cred; |
| 108 | struct opaque_auth ah_verf; |
| 109 | union des_block ah_key; |
| 110 | struct auth_ops { |
| 111 | void (*ah_nextverf) (AUTH *); |
| 112 | int (*ah_marshal) (AUTH *, XDR *); /* nextverf & serialize */ |
| 113 | int (*ah_validate) (AUTH *, struct opaque_auth *); |
| 114 | /* validate verifier */ |
| 115 | int (*ah_refresh) (AUTH *); /* refresh credentials */ |
| 116 | void (*ah_destroy) (AUTH *); /* destroy this structure */ |
| 117 | } *ah_ops; |
| 118 | caddr_t ah_private; |
| 119 | }; |
| 120 | |
| 121 | |
| 122 | /* |
| 123 | * Authentication ops. |
| 124 | * The ops and the auth handle provide the interface to the authenticators. |
| 125 | * |
| 126 | * AUTH *auth; |
| 127 | * XDR *xdrs; |
| 128 | * struct opaque_auth verf; |
| 129 | */ |
| 130 | #define AUTH_NEXTVERF(auth) \ |
| 131 | ((*((auth)->ah_ops->ah_nextverf))(auth)) |
| 132 | #define auth_nextverf(auth) \ |
| 133 | ((*((auth)->ah_ops->ah_nextverf))(auth)) |
| 134 | |
| 135 | #define AUTH_MARSHALL(auth, xdrs) \ |
| 136 | ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) |
| 137 | #define auth_marshall(auth, xdrs) \ |
| 138 | ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) |
| 139 | |
| 140 | #define AUTH_VALIDATE(auth, verfp) \ |
| 141 | ((*((auth)->ah_ops->ah_validate))((auth), verfp)) |
| 142 | #define auth_validate(auth, verfp) \ |
| 143 | ((*((auth)->ah_ops->ah_validate))((auth), verfp)) |
| 144 | |
| 145 | #define AUTH_REFRESH(auth) \ |
| 146 | ((*((auth)->ah_ops->ah_refresh))(auth)) |
| 147 | #define auth_refresh(auth) \ |
| 148 | ((*((auth)->ah_ops->ah_refresh))(auth)) |
| 149 | |
| 150 | #define AUTH_DESTROY(auth) \ |
| 151 | ((*((auth)->ah_ops->ah_destroy))(auth)) |
| 152 | #define auth_destroy(auth) \ |
| 153 | ((*((auth)->ah_ops->ah_destroy))(auth)) |
| 154 | |
| 155 | |
| 156 | extern struct opaque_auth _null_auth; |
| 157 | |
| 158 | |
| 159 | /* |
| 160 | * These are the various implementations of client side authenticators. |
| 161 | */ |
| 162 | |
| 163 | /* |
| 164 | * Unix style authentication |
| 165 | * AUTH *authunix_create(machname, uid, gid, len, aup_gids) |
| 166 | * char *machname; |
| 167 | * int uid; |
| 168 | * int gid; |
| 169 | * int len; |
| 170 | * int *aup_gids; |
| 171 | */ |
| 172 | extern AUTH *authunix_create (char *__machname, __uid_t __uid, __gid_t __gid, |
| 173 | int __len, __gid_t *__aup_gids); |
| 174 | libc_hidden_proto(authunix_create) |
| 175 | extern AUTH *authunix_create_default (void); |
| 176 | libc_hidden_proto(authunix_create_default) |
| 177 | extern AUTH *authnone_create (void) __THROW; |
| 178 | libc_hidden_proto(authnone_create) |
| 179 | #if 0 |
| 180 | extern AUTH *authdes_create (const char *__servername, u_int __window, |
| 181 | struct sockaddr *__syncaddr, des_block *__ckey) |
| 182 | __THROW; |
| 183 | extern AUTH *authdes_pk_create (const char *, netobj *, u_int, |
| 184 | struct sockaddr *, des_block *) __THROW; |
| 185 | #endif |
| 186 | |
| 187 | |
| 188 | #define AUTH_NONE 0 /* no authentication */ |
| 189 | #define AUTH_NULL 0 /* backward compatibility */ |
| 190 | #define AUTH_SYS 1 /* unix style (uid, gids) */ |
| 191 | #define AUTH_UNIX AUTH_SYS |
| 192 | #define AUTH_SHORT 2 /* short hand unix style */ |
| 193 | #define AUTH_DES 3 /* des style (encrypted timestamps) */ |
| 194 | #define AUTH_DH AUTH_DES /* Diffie-Hellman (this is DES) */ |
| 195 | #define AUTH_KERB 4 /* kerberos style */ |
| 196 | |
| 197 | #if 0 |
| 198 | /* |
| 199 | * Netname manipulating functions |
| 200 | * |
| 201 | */ |
| 202 | extern int getnetname (char *) __THROW; |
| 203 | extern int host2netname (char *, __const char *, __const char *) __THROW; |
| 204 | extern int user2netname (char *, __const uid_t, __const char *) __THROW; |
| 205 | extern int netname2user (__const char *, uid_t *, gid_t *, int *, gid_t *) |
| 206 | __THROW; |
| 207 | extern int netname2host (__const char *, char *, __const int) __THROW; |
| 208 | |
| 209 | /* |
| 210 | * |
| 211 | * These routines interface to the keyserv daemon |
| 212 | * |
| 213 | */ |
| 214 | extern int key_decryptsession (char *, des_block *); |
| 215 | extern int key_decryptsession_pk (char *, netobj *, des_block *); |
| 216 | extern int key_encryptsession (char *, des_block *); |
| 217 | extern int key_encryptsession_pk (char *, netobj *, des_block *); |
| 218 | extern int key_gendes (des_block *); |
| 219 | extern int key_setsecret (char *); |
| 220 | extern int key_secretkey_is_set (void); |
| 221 | extern int key_get_conv (char *, des_block *); |
| 222 | #endif |
| 223 | |
| 224 | /* |
| 225 | * XDR an opaque authentication struct. |
| 226 | */ |
| 227 | extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *) __THROW; |
| 228 | libc_hidden_proto(xdr_opaque_auth) |
| 229 | |
| 230 | __END_DECLS |
| 231 | |
| 232 | #endif /* rpc/auth.h */ |