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