#ifndef _NFS_NFS_GSS_H_
#define _NFS_NFS_GSS_H_
#include <gssd/gssd_mach.h>
#include <libkern/crypto/md5.h>
#include <crypto/des/des_locl.h>
#include <sys/param.h>
#define RPCSEC_GSS 6
#define RPCSEC_GSS_VERS_1 1
enum rpcsec_gss_proc {
RPCSEC_GSS_DATA = 0,
RPCSEC_GSS_INIT = 1,
RPCSEC_GSS_CONTINUE_INIT = 2,
RPCSEC_GSS_DESTROY = 3
};
enum rpcsec_gss_service {
RPCSEC_GSS_SVC_NONE = 1, RPCSEC_GSS_SVC_INTEGRITY = 2, RPCSEC_GSS_SVC_PRIVACY = 3, RPCSEC_GSS_SVC_SYS = 4 };
#define GSS_S_COMPLETE 0
#define GSS_S_CONTINUE_NEEDED 1
#define GSS_MAXSEQ 0x80000000 // The biggest sequence number
#define GSS_SVC_MAXCONTEXTS 500000 // Max contexts supported
#define GSS_SVC_SEQWINDOW 256 // Server's sequence window
#define GSS_CLNT_SEQLISTMAX 32 // Max length of req seq num list
#define GSS_CLNT_SYS_VALID 300 // Valid time (sec) for failover ctx
#define SKEYLEN 8 // length of DES key
struct nfs_gss_clnt_ctx {
lck_mtx_t *gss_clnt_mtx;
thread_t gss_clnt_thread; TAILQ_ENTRY(nfs_gss_clnt_ctx) gss_clnt_entries;
uint32_t gss_clnt_flags; uint32_t gss_clnt_refcnt; uid_t gss_clnt_uid; uint32_t gss_clnt_proc; uint32_t gss_clnt_seqnum; uint32_t gss_clnt_service; u_char *gss_clnt_handle; uint32_t gss_clnt_handle_len; time_t gss_clnt_ctime; uint32_t gss_clnt_seqwin; uint32_t *gss_clnt_seqbits; mach_port_t gss_clnt_mport; u_char *gss_clnt_verf; uint64_t gss_clnt_gssd_verf; char *gss_clnt_svcname; uint32_t gss_clnt_cred_handle; uint32_t gss_clnt_context; u_char *gss_clnt_token; uint32_t gss_clnt_tokenlen; u_char gss_clnt_skey[SKEYLEN]; des_key_schedule gss_clnt_sched; uint32_t gss_clnt_major; uint32_t gss_clnt_minor; };
#define GSS_CTX_COMPLETE 0x00000001 // Context is complete
#define GSS_CTX_INVAL 0x00000002 // Context is invalid
#define GSS_NEEDSEQ 0x00000004 // Need a sequence number
#define GSS_NEEDCTX 0x00000008 // Need the context
struct nfs_gss_svc_ctx {
lck_mtx_t *gss_svc_mtx;
LIST_ENTRY(nfs_gss_svc_ctx) gss_svc_entries;
uint32_t gss_svc_handle; uint32_t gss_svc_proc; uid_t gss_svc_uid; gid_t gss_svc_gids[NGROUPS]; uint32_t gss_svc_ngroups; uint64_t gss_svc_expiretime; uint32_t gss_svc_seqmax; uint32_t gss_svc_seqwin; uint32_t *gss_svc_seqbits; uint64_t gss_svc_gssd_verf; uint32_t gss_svc_cred_handle; uint32_t gss_svc_context; u_char *gss_svc_token; uint32_t gss_svc_tokenlen; u_char gss_svc_skey[SKEYLEN]; des_key_schedule gss_svc_sched; uint32_t gss_svc_major; uint32_t gss_svc_minor; };
#define SVC_CTX_HASHSZ 64
#define SVC_CTX_HASH(handle) ((handle) % SVC_CTX_HASHSZ)
LIST_HEAD(nfs_gss_svc_ctx_hashhead, nfs_gss_svc_ctx);
#define win_getbit(bits, bit) ((bits[(bit) / 32] & (1 << (bit) % 32)) != 0)
#define win_setbit(bits, bit) do { bits[(bit) / 32] |= (1 << (bit) % 32); } while (0)
#define win_resetbit(bits, bit) do { bits[(bit) / 32] &= ~(1 << (bit) % 32); } while (0)
#define GSS_CTX_PEND 5 // seconds
#define GSS_CTX_EXPIRE (8 * 3600) // seconds
#define GSS_TIMER_PERIOD 300 // seconds
#define MSECS_PER_SEC 1000
__BEGIN_DECLS
void nfs_gss_init(void);
int nfs_gss_clnt_cred_put(struct nfsreq *, struct nfsm_chain *, mbuf_t);
int nfs_gss_clnt_verf_get(struct nfsreq *, struct nfsm_chain *,
uint32_t, uint32_t, uint32_t *);
void nfs_gss_clnt_rpcdone(struct nfsreq *);
int nfs_gss_clnt_args_restore(struct nfsreq *);
int nfs_gss_clnt_ctx_renew(struct nfsreq *);
void nfs_gss_clnt_ctx_ref(struct nfsreq *, struct nfs_gss_clnt_ctx *);
void nfs_gss_clnt_ctx_unref(struct nfsreq *);
void nfs_gss_clnt_ctx_unmount(struct nfsmount *, int);
int nfs_gss_svc_cred_get(struct nfsrv_descript *, struct nfsm_chain *);
int nfs_gss_svc_verf_put(struct nfsrv_descript *, struct nfsm_chain *);
int nfs_gss_svc_ctx_init(struct nfsrv_descript *, struct nfsrv_sock *, mbuf_t *);
int nfs_gss_svc_prepare_reply(struct nfsrv_descript *, struct nfsm_chain *);
int nfs_gss_svc_protect_reply(struct nfsrv_descript *, mbuf_t);
void nfs_gss_svc_cleanup(void);
__END_DECLS
#endif