#ifndef _RPC_AUTH_H
#define _RPC_AUTH_H
#include <rpc/xdr.h>
#include <rpc/clnt_stat.h>
#include <sys/cred.h>
#include <sys/tiuser.h>
#ifdef _KERNEL
#include <sys/zone.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_AUTH_BYTES 400
#define MAXNETNAMELEN 255
#define RQCRED_SIZE 700
typedef struct sec_data {
uint_t secmod;
uint_t rpcflavor;
int flags;
uid_t uid;
caddr_t data;
} sec_data_t;
#ifdef _SYSCALL32_IMPL
struct sec_data32 {
uint32_t secmod;
uint32_t rpcflavor;
int32_t flags;
uid_t uid;
caddr32_t data;
};
#endif
typedef struct des_clnt_data {
struct netbuf syncaddr;
struct knetconfig *knconf;
char *netname;
int netnamelen;
} dh_k4_clntdata_t;
#ifdef _SYSCALL32_IMPL
struct des_clnt_data32 {
struct netbuf32 syncaddr;
caddr32_t knconf;
caddr32_t netname;
int32_t netnamelen;
};
#endif
typedef struct krb4_svc_data {
int window;
} krb4_svcdata_t;
typedef struct krb4_svc_data des_svcdata_t;
#define AUTH_F_RPCTIMESYNC 0x001
#define AUTH_F_TRYNONE 0x002
enum auth_stat {
AUTH_OK = 0,
AUTH_BADCRED = 1,
AUTH_REJECTEDCRED = 2,
AUTH_BADVERF = 3,
AUTH_REJECTEDVERF = 4,
AUTH_TOOWEAK = 5,
AUTH_INVALIDRESP = 6,
AUTH_FAILED = 7,
AUTH_KERB_GENERIC = 8,
AUTH_TIMEEXPIRE = 9,
AUTH_TKT_FILE = 10,
AUTH_DECODE = 11,
AUTH_NET_ADDR = 12,
RPCSEC_GSS_NOCRED = 13,
RPCSEC_GSS_FAILED = 14
};
typedef enum auth_stat AUTH_STAT;
union des_block {
struct {
uint32_t high;
uint32_t low;
} key;
char c[8];
};
typedef union des_block des_block;
#ifdef __STDC__
extern bool_t xdr_des_block(XDR *, des_block *);
#else
extern bool_t xdr_des_block();
#endif
struct opaque_auth {
enum_t oa_flavor;
caddr_t oa_base;
uint_t oa_length;
};
typedef struct __auth {
struct opaque_auth ah_cred;
struct opaque_auth ah_verf;
union des_block ah_key;
struct auth_ops {
#ifdef __STDC__
void (*ah_nextverf)(struct __auth *);
#ifdef _KERNEL
int (*ah_marshal)(struct __auth *, XDR *, struct cred *);
#else
int (*ah_marshal)(struct __auth *, XDR *);
#endif
int (*ah_validate)(struct __auth *,
struct opaque_auth *);
#ifdef _KERNEL
int (*ah_refresh)(struct __auth *, struct rpc_msg *,
cred_t *);
#else
int (*ah_refresh)(struct __auth *, void *);
#endif
void (*ah_destroy)(struct __auth *);
#ifdef _KERNEL
int (*ah_wrap)(struct __auth *, caddr_t, uint_t,
XDR *, xdrproc_t, caddr_t);
int (*ah_unwrap)(struct __auth *, XDR *, xdrproc_t,
caddr_t);
#endif
#else
void (*ah_nextverf)();
int (*ah_marshal)();
int (*ah_validate)();
int (*ah_refresh)();
void (*ah_destroy)();
#ifdef _KERNEL
int (*ah_wrap)();
int (*ah_unwrap)();
#endif
#endif
} *ah_ops;
caddr_t ah_private;
} AUTH;
#define AUTH_NEXTVERF(auth) \
((*((auth)->ah_ops->ah_nextverf))(auth))
#define auth_nextverf(auth) \
((*((auth)->ah_ops->ah_nextverf))(auth))
#ifdef _KERNEL
#define AUTH_MARSHALL(auth, xdrs, cred) \
((*((auth)->ah_ops->ah_marshal))(auth, xdrs, cred))
#define auth_marshall(auth, xdrs, cred) \
((*((auth)->ah_ops->ah_marshal))(auth, xdrs, cred))
#else
#define AUTH_MARSHALL(auth, xdrs) \
((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
#define auth_marshall(auth, xdrs) \
((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
#endif
#define AUTH_VALIDATE(auth, verfp) \
((*((auth)->ah_ops->ah_validate))((auth), verfp))
#define auth_validate(auth, verfp) \
((*((auth)->ah_ops->ah_validate))((auth), verfp))
#ifdef _KERNEL
#define AUTH_REFRESH(auth, msg, cr) \
((*((auth)->ah_ops->ah_refresh))(auth, msg, cr))
#define auth_refresh(auth, msg, cr) \
((*((auth)->ah_ops->ah_refresh))(auth, msg, cr))
#else
#define AUTH_REFRESH(auth, msg) \
((*((auth)->ah_ops->ah_refresh))(auth, msg))
#define auth_refresh(auth, msg) \
((*((auth)->ah_ops->ah_refresh))(auth, msg))
#endif
#define AUTH_DESTROY(auth) \
((*((auth)->ah_ops->ah_destroy))(auth))
#define auth_destroy(auth) \
((*((auth)->ah_ops->ah_destroy))(auth))
#ifdef _KERNEL
#define AUTH_WRAP(auth, buf, buflen, xdrs, xfunc, xwhere) \
((*((auth)->ah_ops->ah_wrap))(auth, buf, buflen, \
xdrs, xfunc, xwhere))
#define auth_wrap(auth, buf, buflen, xdrs, xfunc, xwhere) \
((*((auth)->ah_ops->ah_wrap))(auth, buf, buflen, \
xdrs, xfunc, xwhere))
#define AUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \
((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, xfunc, xwhere))
#define auth_unwrap(auth, xdrs) \
((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, xfunc, xwhere))
#endif
extern struct opaque_auth _null_auth;
#ifdef _KERNEL
extern AUTH *authkern_create(void);
extern int authkern_init(void *, void *, int);
extern struct kmem_cache *authkern_cache;
extern AUTH *authnone_create(void);
extern int authnone_init(void *, void *, int);
extern struct kmem_cache *authnone_cache;
extern AUTH *authloopback_create(void);
extern int authloopback_init(void *, void *, int);
extern struct kmem_cache *authloopback_cache;
#else
#ifdef __STDC__
extern AUTH *authsys_create(const char *, const uid_t, const gid_t, const int,
const gid_t *);
extern AUTH *authsys_create_default(void);
extern AUTH *authnone_create(void);
#else
extern AUTH *authsys_create();
extern AUTH *authsys_create_default();
extern AUTH *authnone_create();
#endif
#define authunix_create authsys_create
#define authunix_create_default authsys_create_default
#endif
#ifdef _KERNEL
extern int authdes_create(char *, uint_t, struct netbuf *, struct knetconfig *,
des_block *, int, AUTH **retauth);
#else
#ifdef __STDC__
extern AUTH *authdes_seccreate(const char *, const uint_t, const char *,
const des_block *);
#else
extern AUTH *authdes_seccreate();
#endif
#endif
#ifdef _KERNEL
extern enum clnt_stat netname2user(char *, uid_t *, gid_t *, int *, gid_t *);
#endif
#ifdef __STDC__
extern int getnetname(char *);
extern int host2netname(char *, const char *, const char *);
extern int user2netname(char *, const uid_t, const char *);
#ifndef _KERNEL
extern int netname2user(const char *, uid_t *, gid_t *, int *, gid_t *);
#endif
extern int netname2host(const char *, char *, const int);
#else
extern int getnetname();
extern int host2netname();
extern int user2netname();
extern int netname2host();
#endif
#ifdef _KERNEL
extern enum clnt_stat key_decryptsession();
extern enum clnt_stat key_encryptsession();
extern enum clnt_stat key_gendes();
extern enum clnt_stat key_getnetname();
#endif
#ifndef _KERNEL
#ifdef __STDC__
extern int key_decryptsession(const char *, des_block *);
extern int key_encryptsession(const char *, des_block *);
extern int key_gendes(des_block *);
extern int key_setsecret(const char *);
extern int key_secretkey_is_set(void);
extern int key_setnet_ruid();
extern int key_setnet_g_ruid();
extern int key_removesecret_g_ruid();
extern int key_secretkey_is_set_g_ruid();
extern AUTH *authsys_create_ruid();
#else
extern int key_decryptsession();
extern int key_encryptsession();
extern int key_gendes();
extern int key_setsecret();
extern int key_secretkey_is_set();
#endif
#endif
#ifdef _KERNEL
extern int authkerb_create(char *, char *, char *, uint_t,
struct netbuf *, int *, struct knetconfig *, int, AUTH **);
#else
#ifdef __STDC__
extern AUTH *authkerb_seccreate(const char *, const char *, const char *,
const uint_t, const char *, int *);
#else
extern AUTH *authkerb_seccreate();
#endif
#endif
#ifdef __STDC__
struct svc_req;
extern int authkerb_getucred(struct svc_req *, uid_t *, gid_t *,
short *, int *);
#else
extern int authkerb_getucred();
#endif
#ifdef _KERNEL
extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
#endif
#ifdef _KERNEL
extern int authany_wrap(AUTH *, caddr_t, uint_t, XDR *, xdrproc_t, caddr_t);
extern int authany_unwrap(AUTH *, XDR *, xdrproc_t, caddr_t);
#endif
#define AUTH_NONE 0
#define AUTH_NULL 0
#define AUTH_SYS 1
#define AUTH_UNIX AUTH_SYS
#define AUTH_SHORT 2
#define AUTH_DH 3
#define AUTH_DES AUTH_DH
#define AUTH_KERB 4
#define RPCSEC_GSS 6
#define AUTH_LOOPBACK 21982
#ifdef _KERNEL
extern char loopback_name[];
extern zone_key_t auth_zone_key;
extern void * auth_zone_init(zoneid_t);
extern void auth_zone_fini(zoneid_t, void *);
#endif
#ifdef __cplusplus
}
#endif
#endif