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 57typedef 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 65struct 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 */ 77typedef 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 86struct 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 */ 100typedef struct krb4_svc_data { 101 int window; /* window option value */ 102} krb4_svcdata_t; 103 104typedef 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 */ 117enum 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 151union des_block { 152 struct { 153 uint32_t high; 154 uint32_t low; 155 } key; 156 char c[8]; 157}; 158typedef union des_block des_block; 159__BEGIN_DECLS 160extern bool_t xdr_des_block(XDR *, des_block *); 161__END_DECLS 162 163/* 164 * Authentication info. Opaque to client. 165 */ 166struct 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 */ 176struct rpc_err; 177typedef 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 222extern 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 240struct ucred; 241extern AUTH *authunix_create(struct ucred *); 242#else 243extern AUTH *authunix_create(char *, u_int, u_int, int, u_int *); 244extern AUTH *authunix_create_default(void); /* takes no parameters */ 245#endif 246extern AUTH *authnone_create(void); /* takes no parameters */ 247extern AUTH *authtls_create(void); /* takes no parameters */ 248__END_DECLS 249/* 250 * DES style authentication 251 * AUTH *authsecdes_create(servername, window, timehost, ckey) 252 * char *servername; - network name of server 253 * u_int window; - time to live 254 * const char *timehost; - optional hostname to sync with 255 * des_block *ckey; - optional conversation key to use 256 */ 257__BEGIN_DECLS 258extern AUTH *authdes_create (char *, u_int, struct sockaddr *, des_block *); 259extern AUTH *authdes_seccreate (const char *, const u_int, const char *, 260 const des_block *); 261__END_DECLS 262 263__BEGIN_DECLS 264extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *); 265__END_DECLS 266 267#define authsys_create(c,i1,i2,i3,ip) authunix_create((c),(i1),(i2),(i3),(ip)) 268#define authsys_create_default() authunix_create_default() 269 270/* 271 * Netname manipulation routines. 272 */ 273__BEGIN_DECLS 274extern int getnetname(char *); 275extern int host2netname(char *, const char *, const char *); 276extern int user2netname(char *, const uid_t, const char *); 277extern int netname2user(char *, uid_t *, gid_t *, int *, gid_t *); 278extern int netname2host(char *, char *, const int); 279extern void passwd2des ( char *, char * ); 280__END_DECLS 281 282/* 283 * 284 * These routines interface to the keyserv daemon 285 * 286 */ 287__BEGIN_DECLS 288extern int key_decryptsession(const char *, des_block *); 289extern int key_encryptsession(const char *, des_block *); 290extern int key_gendes(des_block *); 291extern int key_setsecret(const char *); 292extern int key_secretkey_is_set(void); 293__END_DECLS 294 295/* 296 * Publickey routines. 297 */ 298__BEGIN_DECLS 299extern int getpublickey (const char *, char *); 300extern int getpublicandprivatekey (const char *, char *); 301extern int getsecretkey (char *, char *, char *); 302__END_DECLS 303 304#ifdef KERBEROS 305/* 306 * Kerberos style authentication 307 * AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status) 308 * const char *service; - service name 309 * const char *srv_inst; - server instance 310 * const char *realm; - server realm 311 * const u_int window; - time to live 312 * const char *timehost; - optional hostname to sync with 313 * int *status; - kerberos status returned 314 */ 315__BEGIN_DECLS 316extern AUTH *authkerb_seccreate(const char *, const char *, const char *, 317 const u_int, const char *, int *); 318__END_DECLS 319 320/* 321 * Map a kerberos credential into a unix cred. 322 * 323 * authkerb_getucred(rqst, uid, gid, grouplen, groups) 324 * const struct svc_req *rqst; - request pointer 325 * uid_t *uid; 326 * gid_t *gid; 327 * short *grouplen; 328 * int *groups; 329 * 330 */ 331__BEGIN_DECLS 332extern int authkerb_getucred(/* struct svc_req *, uid_t *, gid_t *, 333 short *, int * */); 334__END_DECLS 335#endif /* KERBEROS */ 336 337__BEGIN_DECLS 338struct svc_req; 339struct rpc_msg; 340enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *); 341enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *); 342enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *); 343enum auth_stat _svcauth_rpcsec_tls (struct svc_req *, struct rpc_msg *); 344__END_DECLS 345 346#define AUTH_NONE 0 /* no authentication */ 347#define AUTH_NULL 0 /* backward compatibility */ 348#define AUTH_SYS 1 /* unix style (uid, gids) */ 349#define AUTH_UNIX AUTH_SYS 350#define AUTH_SHORT 2 /* short hand unix style */ 351#define AUTH_DH 3 /* for Diffie-Hellman mechanism */ 352#define AUTH_DES AUTH_DH /* for backward compatibility */ 353#define AUTH_KERB 4 /* kerberos style */ 354#define RPCSEC_GSS 6 /* RPCSEC_GSS */ 355#define AUTH_TLS 7 /* Initiate RPC-over-TLS */ 356 357/* 358 * Pseudo auth flavors for RPCSEC_GSS. 359 */ 360#define RPCSEC_GSS_KRB5 390003 361#define RPCSEC_GSS_KRB5I 390004 362#define RPCSEC_GSS_KRB5P 390005 363 364#endif /* !_RPC_AUTH_H */ 365