/* $NetBSD: auth.h,v 1.15 2000/06/02 22:57:55 fvdl Exp $ */12/*-3* SPDX-License-Identifier: BSD-3-Clause4*5* Copyright (c) 2009, Sun Microsystems, Inc.6* All rights reserved.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions are met:10* - Redistributions of source code must retain the above copyright notice,11* this list of conditions and the following disclaimer.12* - Redistributions in binary form must reproduce the above copyright notice,13* this list of conditions and the following disclaimer in the documentation14* and/or other materials provided with the distribution.15* - Neither the name of Sun Microsystems, Inc. nor the names of its16* contributors may be used to endorse or promote products derived17* from this software without specific prior written permission.18*19* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"20* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE23* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR24* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF25* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS26* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN27* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE29* POSSIBILITY OF SUCH DAMAGE.30*/3132/*33* auth.h, Authentication interface.34*35* Copyright (C) 1984, Sun Microsystems, Inc.36*37* The data structures are completely opaque to the client. The client38* is required to pass an AUTH * to routines that create rpc39* "sessions".40*/4142#ifndef _RPC_AUTH_H43#define _RPC_AUTH_H44#include <rpc/xdr.h>45#include <rpc/clnt_stat.h>46#include <sys/cdefs.h>47#include <sys/socket.h>4849#define MAX_AUTH_BYTES 40050#define MAXNETNAMELEN 255 /* maximum length of network user's name */5152/*53* Client side authentication/security data54*/5556typedef struct sec_data {57u_int secmod; /* security mode number e.g. in nfssec.conf */58u_int rpcflavor; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */59int flags; /* AUTH_F_xxx flags */60caddr_t data; /* opaque data per flavor */61} sec_data_t;6263#ifdef _SYSCALL32_IMPL64struct sec_data32 {65uint32_t secmod; /* security mode number e.g. in nfssec.conf */66uint32_t rpcflavor; /* rpc flavors:AUTH_UNIX,AUTH_DES,RPCSEC_GSS */67int32_t flags; /* AUTH_F_xxx flags */68caddr32_t data; /* opaque data per flavor */69};70#endif /* _SYSCALL32_IMPL */7172/*73* AUTH_DES flavor specific data from sec_data opaque data field.74* AUTH_KERB has the same structure.75*/76typedef struct des_clnt_data {77struct netbuf syncaddr; /* time sync addr */78struct knetconfig *knconf; /* knetconfig info that associated */79/* with the syncaddr. */80char *netname; /* server's netname */81int netnamelen; /* server's netname len */82} dh_k4_clntdata_t;8384#ifdef _SYSCALL32_IMPL85struct des_clnt_data32 {86struct netbuf32 syncaddr; /* time sync addr */87caddr32_t knconf; /* knetconfig info that associated */88/* with the syncaddr. */89caddr32_t netname; /* server's netname */90int32_t netnamelen; /* server's netname len */91};92#endif /* _SYSCALL32_IMPL */9394#ifdef KERBEROS95/*96* flavor specific data to hold the data for AUTH_DES/AUTH_KERB(v4)97* in sec_data->data opaque field.98*/99typedef struct krb4_svc_data {100int window; /* window option value */101} krb4_svcdata_t;102103typedef struct krb4_svc_data des_svcdata_t;104#endif /* KERBEROS */105106/*107* authentication/security specific flags108*/109#define AUTH_F_RPCTIMESYNC 0x001 /* use RPC to do time sync */110#define AUTH_F_TRYNONE 0x002 /* allow fall back to AUTH_NONE */111112113/*114* Status returned from authentication check115*/116enum auth_stat {117AUTH_OK=0,118/*119* failed at remote end120*/121AUTH_BADCRED=1, /* bogus credentials (seal broken) */122AUTH_REJECTEDCRED=2, /* client should begin new session */123AUTH_BADVERF=3, /* bogus verifier (seal broken) */124AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */125AUTH_TOOWEAK=5, /* rejected due to security reasons */126/*127* failed locally128*/129AUTH_INVALIDRESP=6, /* bogus response verifier */130AUTH_FAILED=7, /* some unknown reason */131#ifdef KERBEROS132/*133* kerberos errors134*/135AUTH_KERB_GENERIC = 8, /* kerberos generic error */136AUTH_TIMEEXPIRE = 9, /* time of credential expired */137AUTH_TKT_FILE = 10, /* something wrong with ticket file */138AUTH_DECODE = 11, /* can't decode authenticator */139AUTH_NET_ADDR = 12, /* wrong net address in ticket */140#endif /* KERBEROS */141/*142* RPCSEC_GSS errors143*/144RPCSEC_GSS_CREDPROBLEM = 13,145RPCSEC_GSS_CTXPROBLEM = 14,146/* Also used by RPCSEC_TLS for the same purpose */147RPCSEC_GSS_NODISPATCH = 0x8000000148};149150union des_block {151struct {152uint32_t high;153uint32_t low;154} key;155char c[8];156};157typedef union des_block des_block;158__BEGIN_DECLS159extern bool_t xdr_des_block(XDR *, des_block *);160__END_DECLS161162/*163* Authentication info. Opaque to client.164*/165struct opaque_auth {166enum_t oa_flavor; /* flavor of auth */167caddr_t oa_base; /* address of more auth stuff */168u_int oa_length; /* not to exceed MAX_AUTH_BYTES */169};170171172/*173* Auth handle, interface to client side authenticators.174*/175struct rpc_err;176typedef struct __auth {177struct opaque_auth ah_cred;178struct opaque_auth ah_verf;179union des_block ah_key;180const struct auth_ops {181void (*ah_nextverf) (struct __auth *);182/* nextverf & serialize */183int (*ah_marshal) (struct __auth *, uint32_t, XDR *,184struct mbuf *);185/* validate verifier */186int (*ah_validate) (struct __auth *, uint32_t,187struct opaque_auth *, struct mbuf **);188/* refresh credentials */189int (*ah_refresh) (struct __auth *, void *);190/* destroy this structure */191void (*ah_destroy) (struct __auth *);192} *ah_ops;193void *ah_private;194} AUTH;195196197/*198* Authentication ops.199* The ops and the auth handle provide the interface to the authenticators.200*201* AUTH *auth;202* XDR *xdrs;203* struct opaque_auth verf;204*/205#define AUTH_NEXTVERF(auth) \206((*((auth)->ah_ops->ah_nextverf))(auth))207208#define AUTH_MARSHALL(auth, xid, xdrs, args) \209((*((auth)->ah_ops->ah_marshal))(auth, xid, xdrs, args))210211#define AUTH_VALIDATE(auth, xid, verfp, resultsp) \212((*((auth)->ah_ops->ah_validate))((auth), xid, verfp, resultsp))213214#define AUTH_REFRESH(auth, msg) \215((*((auth)->ah_ops->ah_refresh))(auth, msg))216217#define AUTH_DESTROY(auth) \218((*((auth)->ah_ops->ah_destroy))(auth))219220__BEGIN_DECLS221extern struct opaque_auth _null_auth;222__END_DECLS223224/*225* These are the various implementations of client side authenticators.226*/227228/*229* System style authentication230* AUTH *authunix_create(machname, uid, gid, len, aup_gids)231* char *machname;232* u_int uid;233* u_int gid;234* int len;235* u_int *aup_gids;236*/237__BEGIN_DECLS238#ifdef _KERNEL239struct ucred;240extern AUTH *authunix_create(struct ucred *);241#else242extern AUTH *authunix_create(char *, u_int, u_int, int, u_int *);243extern AUTH *authunix_create_default(void); /* takes no parameters */244#endif245extern AUTH *authnone_create(void); /* takes no parameters */246extern AUTH *authtls_create(void); /* takes no parameters */247__END_DECLS248/*249* DES style authentication250* AUTH *authsecdes_create(servername, window, timehost, ckey)251* char *servername; - network name of server252* u_int window; - time to live253* const char *timehost; - optional hostname to sync with254* des_block *ckey; - optional conversation key to use255*/256__BEGIN_DECLS257extern AUTH *authdes_create (char *, u_int, struct sockaddr *, des_block *);258extern AUTH *authdes_seccreate (const char *, const u_int, const char *,259const des_block *);260__END_DECLS261262__BEGIN_DECLS263extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *);264__END_DECLS265266#define authsys_create(c,i1,i2,i3,ip) authunix_create((c),(i1),(i2),(i3),(ip))267#define authsys_create_default() authunix_create_default()268269/*270* Netname manipulation routines.271*/272__BEGIN_DECLS273extern int getnetname(char *);274extern int host2netname(char *, const char *, const char *);275extern int user2netname(char *, const uid_t, const char *);276extern int netname2user(char *, uid_t *, gid_t *, int *, gid_t *);277extern int netname2host(char *, char *, const int);278extern void passwd2des ( char *, char * );279__END_DECLS280281/*282*283* These routines interface to the keyserv daemon284*285*/286__BEGIN_DECLS287extern int key_decryptsession(const char *, des_block *);288extern int key_encryptsession(const char *, des_block *);289extern int key_gendes(des_block *);290extern int key_setsecret(const char *);291extern int key_secretkey_is_set(void);292__END_DECLS293294/*295* Publickey routines.296*/297__BEGIN_DECLS298extern int getpublickey (const char *, char *);299extern int getpublicandprivatekey (const char *, char *);300extern int getsecretkey (char *, char *, char *);301__END_DECLS302303#ifdef KERBEROS304/*305* Kerberos style authentication306* AUTH *authkerb_seccreate(service, srv_inst, realm, window, timehost, status)307* const char *service; - service name308* const char *srv_inst; - server instance309* const char *realm; - server realm310* const u_int window; - time to live311* const char *timehost; - optional hostname to sync with312* int *status; - kerberos status returned313*/314__BEGIN_DECLS315extern AUTH *authkerb_seccreate(const char *, const char *, const char *,316const u_int, const char *, int *);317__END_DECLS318319/*320* Map a kerberos credential into a unix cred.321*322* authkerb_getucred(rqst, uid, gid, grouplen, groups)323* const struct svc_req *rqst; - request pointer324* uid_t *uid;325* gid_t *gid;326* short *grouplen;327* int *groups;328*329*/330__BEGIN_DECLS331extern int authkerb_getucred(/* struct svc_req *, uid_t *, gid_t *,332short *, int * */);333__END_DECLS334#endif /* KERBEROS */335336__BEGIN_DECLS337struct svc_req;338struct rpc_msg;339enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *);340enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *);341enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *);342enum auth_stat _svcauth_rpcsec_tls (struct svc_req *, struct rpc_msg *);343__END_DECLS344345#define AUTH_NONE 0 /* no authentication */346#define AUTH_NULL 0 /* backward compatibility */347#define AUTH_SYS 1 /* unix style (uid, gids) */348#define AUTH_UNIX AUTH_SYS349#define AUTH_SHORT 2 /* short hand unix style */350#define AUTH_DH 3 /* for Diffie-Hellman mechanism */351#define AUTH_DES AUTH_DH /* for backward compatibility */352#define AUTH_KERB 4 /* kerberos style */353#define RPCSEC_GSS 6 /* RPCSEC_GSS */354#define AUTH_TLS 7 /* Initiate RPC-over-TLS */355356/*357* Pseudo auth flavors for RPCSEC_GSS.358*/359#define RPCSEC_GSS_KRB5 390003360#define RPCSEC_GSS_KRB5I 390004361#define RPCSEC_GSS_KRB5P 390005362363#endif /* !_RPC_AUTH_H */364365366