1/* 2 * linux/include/linux/sunrpc/auth.h 3 * 4 * Declarations for the RPC client authentication machinery. 5 * 6 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> 7 */ 8 9#ifndef _LINUX_SUNRPC_AUTH_H 10#define _LINUX_SUNRPC_AUTH_H 11 12#ifdef __KERNEL__ 13 14#include <linux/sunrpc/sched.h> 15#include <linux/sunrpc/msg_prot.h> 16#include <linux/sunrpc/xdr.h> 17 18#include <asm/atomic.h> 19 20/* size of the nodename buffer */ 21#define UNX_MAXNODENAME 32 22 23struct auth_cred { 24 uid_t uid; 25 gid_t gid; 26 struct group_info *group_info; 27}; 28 29/* 30 * Client user credentials 31 */ 32struct rpc_cred { 33 struct hlist_node cr_hash; /* hash chain */ 34 struct rpc_credops * cr_ops; 35 unsigned long cr_expire; /* when to gc */ 36 atomic_t cr_count; /* ref count */ 37 unsigned short cr_flags; /* various flags */ 38#ifdef RPC_DEBUG 39 unsigned long cr_magic; /* 0x0f4aa4f0 */ 40#endif 41 42 uid_t cr_uid; 43 44 /* per-flavor data */ 45}; 46#define RPCAUTH_CRED_NEW 0x0001 47#define RPCAUTH_CRED_UPTODATE 0x0002 48 49#define RPCAUTH_CRED_MAGIC 0x0f4aa4f0 50 51/* 52 * Client authentication handle 53 */ 54#define RPC_CREDCACHE_NR 8 55#define RPC_CREDCACHE_MASK (RPC_CREDCACHE_NR - 1) 56struct rpc_cred_cache { 57 struct hlist_head hashtable[RPC_CREDCACHE_NR]; 58 unsigned long nextgc; /* next garbage collection */ 59 unsigned long expire; /* cache expiry interval */ 60}; 61 62struct rpc_auth { 63 unsigned int au_cslack; /* call cred size estimate */ 64 /* guess at number of u32's auth adds before 65 * reply data; normally the verifier size: */ 66 unsigned int au_rslack; 67 /* for gss, used to calculate au_rslack: */ 68 unsigned int au_verfsize; 69 70 unsigned int au_flags; /* various flags */ 71 struct rpc_authops * au_ops; /* operations */ 72 rpc_authflavor_t au_flavor; /* pseudoflavor (note may 73 * differ from the flavor in 74 * au_ops->au_flavor in gss 75 * case) */ 76 atomic_t au_count; /* Reference counter */ 77 78 struct rpc_cred_cache * au_credcache; 79 /* per-flavor data */ 80}; 81 82/* Flags for rpcauth_lookupcred() */ 83#define RPCAUTH_LOOKUP_NEW 0x01 /* Accept an uninitialised cred */ 84#define RPCAUTH_LOOKUP_ROOTCREDS 0x02 /* This really ought to go! */ 85 86/* 87 * Client authentication ops 88 */ 89struct rpc_authops { 90 struct module *owner; 91 rpc_authflavor_t au_flavor; /* flavor (RPC_AUTH_*) */ 92#ifdef RPC_DEBUG 93 char * au_name; 94#endif 95 struct rpc_auth * (*create)(struct rpc_clnt *, rpc_authflavor_t); 96 void (*destroy)(struct rpc_auth *); 97 98 struct rpc_cred * (*lookup_cred)(struct rpc_auth *, struct auth_cred *, int); 99 struct rpc_cred * (*crcreate)(struct rpc_auth*, struct auth_cred *, int); 100}; 101 102struct rpc_credops { 103 const char * cr_name; /* Name of the auth flavour */ 104 int (*cr_init)(struct rpc_auth *, struct rpc_cred *); 105 void (*crdestroy)(struct rpc_cred *); 106 107 int (*crmatch)(struct auth_cred *, struct rpc_cred *, int); 108 __be32 * (*crmarshal)(struct rpc_task *, __be32 *); 109 int (*crrefresh)(struct rpc_task *); 110 __be32 * (*crvalidate)(struct rpc_task *, __be32 *); 111 int (*crwrap_req)(struct rpc_task *, kxdrproc_t, 112 void *, __be32 *, void *); 113 int (*crunwrap_resp)(struct rpc_task *, kxdrproc_t, 114 void *, __be32 *, void *); 115}; 116 117extern struct rpc_authops authunix_ops; 118extern struct rpc_authops authnull_ops; 119#ifdef CONFIG_SUNRPC_SECURE 120extern struct rpc_authops authdes_ops; 121#endif 122 123int rpcauth_register(struct rpc_authops *); 124int rpcauth_unregister(struct rpc_authops *); 125struct rpc_auth * rpcauth_create(rpc_authflavor_t, struct rpc_clnt *); 126void rpcauth_destroy(struct rpc_auth *); 127struct rpc_cred * rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int); 128struct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int); 129struct rpc_cred * rpcauth_bindcred(struct rpc_task *); 130void rpcauth_holdcred(struct rpc_task *); 131void put_rpccred(struct rpc_cred *); 132void rpcauth_unbindcred(struct rpc_task *); 133__be32 * rpcauth_marshcred(struct rpc_task *, __be32 *); 134__be32 * rpcauth_checkverf(struct rpc_task *, __be32 *); 135int rpcauth_wrap_req(struct rpc_task *task, kxdrproc_t encode, void *rqstp, __be32 *data, void *obj); 136int rpcauth_unwrap_resp(struct rpc_task *task, kxdrproc_t decode, void *rqstp, __be32 *data, void *obj); 137int rpcauth_refreshcred(struct rpc_task *); 138void rpcauth_invalcred(struct rpc_task *); 139int rpcauth_uptodatecred(struct rpc_task *); 140int rpcauth_init_credcache(struct rpc_auth *, unsigned long); 141void rpcauth_free_credcache(struct rpc_auth *); 142 143static inline 144struct rpc_cred * get_rpccred(struct rpc_cred *cred) 145{ 146 atomic_inc(&cred->cr_count); 147 return cred; 148} 149 150#endif /* __KERNEL__ */ 151#endif /* _LINUX_SUNRPC_AUTH_H */ 152