Implement support for RPCSEC_GSS authentication to both the NFS client
and server. This replaces the RPC implementation of the NFS client and server with the newer RPC implementation originally developed (actually ported from the userland sunrpc code) to support the NFS Lock Manager. I have tested this code extensively and I believe it is stable and that performance is at least equal to the legacy RPC implementation. The NFS code currently contains support for both the new RPC implementation and the older legacy implementation inherited from the original NFS codebase. The default is to use the new implementation - add the NFS_LEGACYRPC option to fall back to the old code. When I merge this support back to RELENG_7, I will probably change this so that users have to 'opt in' to get the new code. To use RPCSEC_GSS on either client or server, you must build a kernel which includes the KGSSAPI option and the crypto device. On the userland side, you must build at least a new libc, mountd, mount_nfs and gssd. You must install new versions of /etc/rc.d/gssd and /etc/rc.d/nfsd and add 'gssd_enable=YES' to /etc/rc.conf. As long as gssd is running, you should be able to mount an NFS filesystem from a server that requires RPCSEC_GSS authentication. The mount itself can happen without any kerberos credentials but all access to the filesystem will be denied unless the accessing user has a valid ticket file in the standard place (/tmp/krb5cc_<uid>). There is currently no support for situations where the ticket file is in a different place, such as when the user logged in via SSH and has delegated credentials from that login. This restriction is also present in Solaris and Linux. In theory, we could improve this in future, possibly using Brooks Davis' implementation of variant symlinks. Supporting RPCSEC_GSS on a server is nearly as simple. You must create service creds for the server in the form 'nfs/<fqdn>@<REALM>' and install them in /etc/krb5.keytab. The standard heimdal utility ktutil makes this fairly easy. After the service creds have been created, you can add a '-sec=krb5' option to /etc/exports and restart both mountd and nfsd. The only other difference an administrator should notice is that nfsd doesn't fork to create service threads any more. In normal operation, there will be two nfsd processes, one in userland waiting for TCP connections and one in the kernel handling requests. The latter process will create as many kthreads as required - these should be visible via 'top -H'. The code has some support for varying the number of service threads according to load but initially at least, nfsd uses a fixed number of threads according to the value supplied to its '-n' option. Sponsored by: Isilon Systems MFC after: 1 month
This commit is contained in:
parent
4a723bd20c
commit
a9148abd9d
@ -1,6 +1,6 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
# Name OID Library name Kernel module
|
||||
kerberosv5 1.2.840.113554.1.2.2 /usr/lib/libgssapi_krb5.so.10 -
|
||||
kerberosv5 1.2.840.113554.1.2.2 /usr/lib/libgssapi_krb5.so.10 kgssapi_krb5
|
||||
spnego 1.3.6.1.5.5.2 /usr/lib/libgssapi_spnego.so.10 -
|
||||
#ntlm 1.3.6.1.4.1.311.2.2.10 /usr/lib/libgssapi_ntlm.so.10 -
|
||||
|
@ -11,7 +11,7 @@ FILES= DAEMON FILESYSTEMS LOGIN NETWORKING SERVERS \
|
||||
dmesg dumpon \
|
||||
early.sh encswap \
|
||||
fsck ftp-proxy ftpd \
|
||||
gbde geli geli2 \
|
||||
gbde geli geli2 gssd \
|
||||
hcsecd \
|
||||
hostapd hostid hostname \
|
||||
idmapd inetd initrandom \
|
||||
|
18
etc/rc.d/gssd
Executable file
18
etc/rc.d/gssd
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
|
||||
# PROVIDE: gssd
|
||||
# REQUIRE: root
|
||||
# KEYWORD: nojail shutdown
|
||||
|
||||
. /etc/rc.subr
|
||||
|
||||
name="gssd"
|
||||
|
||||
load_rc_config $name
|
||||
rcvar="gssd_enable"
|
||||
command="${gssd:-/usr/sbin/${name}}"
|
||||
eval ${name}_flags=\"${gssd_flags}\"
|
||||
run_rc_command "$1"
|
@ -4,7 +4,7 @@
|
||||
#
|
||||
|
||||
# PROVIDE: nfsd
|
||||
# REQUIRE: mountd
|
||||
# REQUIRE: mountd hostname gssd
|
||||
# KEYWORD: nojail shutdown
|
||||
|
||||
. /etc/rc.subr
|
||||
|
@ -294,10 +294,13 @@ extern bool_t xdr_short(XDR *, short *);
|
||||
extern bool_t xdr_u_short(XDR *, u_short *);
|
||||
extern bool_t xdr_int16_t(XDR *, int16_t *);
|
||||
extern bool_t xdr_u_int16_t(XDR *, u_int16_t *);
|
||||
extern bool_t xdr_uint16_t(XDR *, u_int16_t *);
|
||||
extern bool_t xdr_int32_t(XDR *, int32_t *);
|
||||
extern bool_t xdr_u_int32_t(XDR *, u_int32_t *);
|
||||
extern bool_t xdr_uint32_t(XDR *, u_int32_t *);
|
||||
extern bool_t xdr_int64_t(XDR *, int64_t *);
|
||||
extern bool_t xdr_u_int64_t(XDR *, u_int64_t *);
|
||||
extern bool_t xdr_uint64_t(XDR *, u_int64_t *);
|
||||
extern bool_t xdr_bool(XDR *, bool_t *);
|
||||
extern bool_t xdr_enum(XDR *, enum_t *);
|
||||
extern bool_t xdr_array(XDR *, char **, u_int *, u_int, u_int, xdrproc_t);
|
||||
|
@ -982,4 +982,5 @@ FBSDprivate_1.0 {
|
||||
__sys_writev;
|
||||
__error_unthreaded;
|
||||
nlm_syscall;
|
||||
gssd_syscall;
|
||||
};
|
||||
|
@ -45,3 +45,9 @@ FBSD_1.0 {
|
||||
/* xdr_sizeof; */ /* Why is xdr_sizeof.c not included in Makefileinc? */
|
||||
xdrstdio_create;
|
||||
};
|
||||
|
||||
FBSD_1.1 {
|
||||
xdr_uint16_t;
|
||||
xdr_uint32_t;
|
||||
xdr_uint64_t;
|
||||
};
|
||||
|
@ -263,6 +263,36 @@ xdr_u_int32_t(xdrs, u_int32_p)
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* XDR unsigned 32-bit integers
|
||||
* same as xdr_int32_t - open coded to save a proc call!
|
||||
*/
|
||||
bool_t
|
||||
xdr_uint32_t(xdrs, u_int32_p)
|
||||
XDR *xdrs;
|
||||
uint32_t *u_int32_p;
|
||||
{
|
||||
u_long l;
|
||||
|
||||
switch (xdrs->x_op) {
|
||||
|
||||
case XDR_ENCODE:
|
||||
l = (u_long) *u_int32_p;
|
||||
return (XDR_PUTLONG(xdrs, (long *)&l));
|
||||
|
||||
case XDR_DECODE:
|
||||
if (!XDR_GETLONG(xdrs, (long *)&l)) {
|
||||
return (FALSE);
|
||||
}
|
||||
*u_int32_p = (u_int32_t) l;
|
||||
return (TRUE);
|
||||
|
||||
case XDR_FREE:
|
||||
return (TRUE);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* XDR short integers
|
||||
@ -385,6 +415,36 @@ xdr_u_int16_t(xdrs, u_int16_p)
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* XDR unsigned 16-bit integers
|
||||
*/
|
||||
bool_t
|
||||
xdr_uint16_t(xdrs, u_int16_p)
|
||||
XDR *xdrs;
|
||||
uint16_t *u_int16_p;
|
||||
{
|
||||
u_long l;
|
||||
|
||||
switch (xdrs->x_op) {
|
||||
|
||||
case XDR_ENCODE:
|
||||
l = (u_long) *u_int16_p;
|
||||
return (XDR_PUTLONG(xdrs, (long *)&l));
|
||||
|
||||
case XDR_DECODE:
|
||||
if (!XDR_GETLONG(xdrs, (long *)&l)) {
|
||||
return (FALSE);
|
||||
}
|
||||
*u_int16_p = (u_int16_t) l;
|
||||
return (TRUE);
|
||||
|
||||
case XDR_FREE:
|
||||
return (TRUE);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* XDR a char
|
||||
@ -806,6 +866,38 @@ xdr_u_int64_t(xdrs, ullp)
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* XDR unsigned 64-bit integers
|
||||
*/
|
||||
bool_t
|
||||
xdr_uint64_t(xdrs, ullp)
|
||||
XDR *xdrs;
|
||||
uint64_t *ullp;
|
||||
{
|
||||
u_long ul[2];
|
||||
|
||||
switch (xdrs->x_op) {
|
||||
case XDR_ENCODE:
|
||||
ul[0] = (u_long)(*ullp >> 32) & 0xffffffff;
|
||||
ul[1] = (u_long)(*ullp) & 0xffffffff;
|
||||
if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE)
|
||||
return (FALSE);
|
||||
return (XDR_PUTLONG(xdrs, (long *)&ul[1]));
|
||||
case XDR_DECODE:
|
||||
if (XDR_GETLONG(xdrs, (long *)&ul[0]) == FALSE)
|
||||
return (FALSE);
|
||||
if (XDR_GETLONG(xdrs, (long *)&ul[1]) == FALSE)
|
||||
return (FALSE);
|
||||
*ullp = (u_int64_t)
|
||||
(((u_int64_t)ul[0] << 32) | ((u_int64_t)ul[1]));
|
||||
return (TRUE);
|
||||
case XDR_FREE:
|
||||
return (TRUE);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* XDR hypers
|
||||
|
@ -168,7 +168,7 @@ rpc_gss_set_callback(rpc_gss_callback_t *cb)
|
||||
{
|
||||
struct svc_rpc_gss_callback *scb;
|
||||
|
||||
scb = malloc(sizeof(struct svc_rpc_gss_callback));
|
||||
scb = mem_alloc(sizeof(struct svc_rpc_gss_callback));
|
||||
if (!scb) {
|
||||
_rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOMEM);
|
||||
return (FALSE);
|
||||
@ -255,7 +255,7 @@ rpc_gss_get_principal_name(rpc_gss_principal_t *principal,
|
||||
namelen += strlen(domain) + 1;
|
||||
}
|
||||
|
||||
buf.value = malloc(namelen);
|
||||
buf.value = mem_alloc(namelen);
|
||||
buf.length = namelen;
|
||||
strcpy((char *) buf.value, name);
|
||||
if (node) {
|
||||
@ -273,7 +273,7 @@ rpc_gss_get_principal_name(rpc_gss_principal_t *principal,
|
||||
*/
|
||||
maj_stat = gss_import_name(&min_stat, &buf,
|
||||
GSS_C_NT_USER_NAME, &gss_name);
|
||||
free(buf.value);
|
||||
mem_free(buf.value, buf.length);
|
||||
if (maj_stat != GSS_S_COMPLETE) {
|
||||
log_status("gss_import_name", mech_oid, maj_stat, min_stat);
|
||||
return (FALSE);
|
||||
@ -300,7 +300,7 @@ rpc_gss_get_principal_name(rpc_gss_principal_t *principal,
|
||||
}
|
||||
gss_release_name(&min_stat, &gss_mech_name);
|
||||
|
||||
result = malloc(sizeof(int) + buf.length);
|
||||
result = mem_alloc(sizeof(int) + buf.length);
|
||||
if (!result) {
|
||||
gss_release_buffer(&min_stat, &buf);
|
||||
return (FALSE);
|
||||
@ -443,7 +443,9 @@ svc_rpc_gss_destroy_client(struct svc_rpc_gss_client *client)
|
||||
gss_release_name(&min_stat, &client->cl_cname);
|
||||
|
||||
if (client->cl_rawcred.client_principal)
|
||||
free(client->cl_rawcred.client_principal);
|
||||
mem_free(client->cl_rawcred.client_principal,
|
||||
sizeof(*client->cl_rawcred.client_principal)
|
||||
+ client->cl_rawcred.client_principal->len);
|
||||
|
||||
if (client->cl_verf.value)
|
||||
gss_release_buffer(&min_stat, &client->cl_verf);
|
||||
@ -527,7 +529,7 @@ gss_oid_to_str(OM_uint32 *minor_status, gss_OID oid, gss_buffer_t oid_str)
|
||||
* here for "{ " and "}\0".
|
||||
*/
|
||||
string_length += 4;
|
||||
if ((bp = (char *) malloc(string_length))) {
|
||||
if ((bp = (char *) mem_alloc(string_length))) {
|
||||
strcpy(bp, "{ ");
|
||||
number = (unsigned long) cp[0];
|
||||
sprintf(numstr, "%ld ", number/40);
|
||||
@ -634,8 +636,15 @@ svc_rpc_gss_accept_sec_context(struct svc_rpc_gss_client *client,
|
||||
client->cl_sname = sname;
|
||||
break;
|
||||
}
|
||||
client->cl_sname = sname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!sname) {
|
||||
xdr_free((xdrproc_t) xdr_gss_buffer_desc,
|
||||
(char *) &recv_tok);
|
||||
return (FALSE);
|
||||
}
|
||||
} else {
|
||||
gr->gr_major = gss_accept_sec_context(
|
||||
&gr->gr_minor,
|
||||
@ -663,11 +672,11 @@ svc_rpc_gss_accept_sec_context(struct svc_rpc_gss_client *client,
|
||||
log_status("accept_sec_context", client->cl_mech,
|
||||
gr->gr_major, gr->gr_minor);
|
||||
client->cl_state = CLIENT_STALE;
|
||||
return (FALSE);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
gr->gr_handle.value = &client->cl_id;
|
||||
gr->gr_handle.length = sizeof(uint32_t);
|
||||
gr->gr_handle.length = sizeof(client->cl_id);
|
||||
gr->gr_win = SVC_RPC_GSS_SEQWINDOW;
|
||||
|
||||
/* Save client info. */
|
||||
@ -703,7 +712,7 @@ svc_rpc_gss_accept_sec_context(struct svc_rpc_gss_client *client,
|
||||
return (FALSE);
|
||||
}
|
||||
client->cl_rawcred.client_principal =
|
||||
malloc(sizeof(*client->cl_rawcred.client_principal)
|
||||
mem_alloc(sizeof(*client->cl_rawcred.client_principal)
|
||||
+ export_name.length);
|
||||
client->cl_rawcred.client_principal->len = export_name.length;
|
||||
memcpy(client->cl_rawcred.client_principal->name,
|
||||
@ -718,6 +727,7 @@ svc_rpc_gss_accept_sec_context(struct svc_rpc_gss_client *client,
|
||||
* kerberos5, this uses krb5_aname_to_localname.
|
||||
*/
|
||||
svc_rpc_gss_build_ucred(client, client->cl_cname);
|
||||
gss_release_name(&min_stat, &client->cl_cname);
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
@ -892,13 +902,12 @@ svc_rpc_gss_check_replay(struct svc_rpc_gss_client *client, uint32_t seq)
|
||||
* discard it.
|
||||
*/
|
||||
offset = client->cl_seqlast - seq;
|
||||
if (offset >= client->cl_win)
|
||||
if (offset >= SVC_RPC_GSS_SEQWINDOW)
|
||||
return (FALSE);
|
||||
word = offset / 32;
|
||||
bit = offset % 32;
|
||||
if (client->cl_seqmask[word] & (1 << bit))
|
||||
return (FALSE);
|
||||
client->cl_seqmask[word] |= (1 << bit);
|
||||
}
|
||||
|
||||
return (TRUE);
|
||||
@ -907,7 +916,7 @@ svc_rpc_gss_check_replay(struct svc_rpc_gss_client *client, uint32_t seq)
|
||||
static void
|
||||
svc_rpc_gss_update_seq(struct svc_rpc_gss_client *client, uint32_t seq)
|
||||
{
|
||||
int offset, i;
|
||||
int offset, i, word, bit;
|
||||
uint32_t carry, newcarry;
|
||||
|
||||
if (seq > client->cl_seqlast) {
|
||||
@ -936,7 +945,13 @@ svc_rpc_gss_update_seq(struct svc_rpc_gss_client *client, uint32_t seq)
|
||||
}
|
||||
client->cl_seqmask[0] |= 1;
|
||||
client->cl_seqlast = seq;
|
||||
} else {
|
||||
offset = client->cl_seqlast - seq;
|
||||
word = offset / 32;
|
||||
bit = offset % 32;
|
||||
client->cl_seqmask[word] |= (1 << bit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum auth_stat
|
||||
@ -983,6 +998,10 @@ svc_rpc_gss(struct svc_req *rqst, struct rpc_msg *msg)
|
||||
|
||||
/* Check the proc and find the client (or create it) */
|
||||
if (gc.gc_proc == RPCSEC_GSS_INIT) {
|
||||
if (gc.gc_handle.length != 0) {
|
||||
result = AUTH_BADCRED;
|
||||
goto out;
|
||||
}
|
||||
client = svc_rpc_gss_create_client();
|
||||
} else {
|
||||
if (gc.gc_handle.length != sizeof(uint32_t)) {
|
||||
|
@ -134,6 +134,7 @@ struct sockaddr *addr;
|
||||
int addrlen = 0;
|
||||
u_char *fh = NULL;
|
||||
int fhsize = 0;
|
||||
int secflavor = -1;
|
||||
|
||||
enum mountmode {
|
||||
ANY,
|
||||
@ -151,6 +152,8 @@ enum tryret {
|
||||
};
|
||||
|
||||
int fallback_mount(struct iovec *iov, int iovlen, int mntflags);
|
||||
int sec_name_to_num(char *sec);
|
||||
char *sec_num_to_name(int num);
|
||||
int getnfsargs(char *, struct iovec **iov, int *iovlen);
|
||||
int getnfs4args(char *, struct iovec **iov, int *iovlen);
|
||||
/* void set_rpc_maxgrouplist(int); */
|
||||
@ -308,6 +311,21 @@ main(int argc, char *argv[])
|
||||
atoi(val));
|
||||
if (portspec == NULL)
|
||||
err(1, "asprintf");
|
||||
} else if (strcmp(opt, "sec") == 0) {
|
||||
/*
|
||||
* Don't add this option to
|
||||
* the iovec yet - we will
|
||||
* negotiate which sec flavor
|
||||
* to use with the remote
|
||||
* mountd.
|
||||
*/
|
||||
pass_flag_to_nmount=0;
|
||||
secflavor = sec_name_to_num(val);
|
||||
if (secflavor < 0) {
|
||||
errx(1,
|
||||
"illegal sec value -- %s",
|
||||
val);
|
||||
}
|
||||
} else if (strcmp(opt, "retrycnt") == 0) {
|
||||
pass_flag_to_nmount=0;
|
||||
num = strtol(val, &p, 10);
|
||||
@ -634,6 +652,36 @@ fallback_mount(struct iovec *iov, int iovlen, int mntflags)
|
||||
return nmount(newiov, newiovlen, mntflags);
|
||||
}
|
||||
|
||||
int
|
||||
sec_name_to_num(char *sec)
|
||||
{
|
||||
if (!strcmp(sec, "krb5"))
|
||||
return (RPCSEC_GSS_KRB5);
|
||||
if (!strcmp(sec, "krb5i"))
|
||||
return (RPCSEC_GSS_KRB5I);
|
||||
if (!strcmp(sec, "krb5p"))
|
||||
return (RPCSEC_GSS_KRB5P);
|
||||
if (!strcmp(sec, "sys"))
|
||||
return (AUTH_SYS);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
char *
|
||||
sec_num_to_name(int flavor)
|
||||
{
|
||||
switch (flavor) {
|
||||
case RPCSEC_GSS_KRB5:
|
||||
return ("krb5");
|
||||
case RPCSEC_GSS_KRB5I:
|
||||
return ("krb5i");
|
||||
case RPCSEC_GSS_KRB5P:
|
||||
return ("krb5p");
|
||||
case AUTH_SYS:
|
||||
return ("sys");
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
getnfsargs(char *spec, struct iovec **iov, int *iovlen)
|
||||
{
|
||||
@ -904,6 +952,7 @@ nfs_tryproto(struct addrinfo *ai, char *hostp, char *spec, char **errstr,
|
||||
CLIENT *clp;
|
||||
struct netconfig *nconf, *nconf_mnt;
|
||||
const char *netid, *netid_mnt;
|
||||
char *secname;
|
||||
int doconnect, nfsvers, mntvers, sotype;
|
||||
enum clnt_stat stat;
|
||||
enum mountmode trymntmode;
|
||||
@ -1033,7 +1082,7 @@ nfs_tryproto(struct addrinfo *ai, char *hostp, char *spec, char **errstr,
|
||||
&rpc_createerr.cf_error));
|
||||
}
|
||||
clp->cl_auth = authsys_create_default();
|
||||
nfhret.auth = -1;
|
||||
nfhret.auth = secflavor;
|
||||
nfhret.vers = mntvers;
|
||||
stat = clnt_call(clp, RPCMNT_MOUNT, (xdrproc_t)xdr_dir, spec,
|
||||
(xdrproc_t)xdr_fh, &nfhret,
|
||||
@ -1074,6 +1123,9 @@ nfs_tryproto(struct addrinfo *ai, char *hostp, char *spec, char **errstr,
|
||||
|
||||
build_iovec(iov, iovlen, "addr", addr, addrlen);
|
||||
build_iovec(iov, iovlen, "fh", fh, fhsize);
|
||||
secname = sec_num_to_name(nfhret.auth);
|
||||
if (secname)
|
||||
build_iovec(iov, iovlen, "sec", secname, (size_t)-1);
|
||||
if (nfsvers == 3)
|
||||
build_iovec(iov, iovlen, "nfsv3", NULL, 0);
|
||||
|
||||
|
@ -854,3 +854,5 @@
|
||||
503 AUE_UNLINKAT NOPROTO { int unlinkat(int fd, char *path, \
|
||||
int flag); }
|
||||
504 AUE_POSIX_OPENPT NOPROTO { int posix_openpt(int flags); }
|
||||
; 505 is initialised by the kgssapi code, if present.
|
||||
505 AUE_NULL UNIMPL gssd_syscall
|
||||
|
123
sys/conf/files
123
sys/conf/files
@ -339,7 +339,7 @@ crypto/camellia/camellia.c optional crypto | ipsec
|
||||
crypto/camellia/camellia-api.c optional crypto | ipsec
|
||||
crypto/des/des_ecb.c optional crypto | ipsec | netsmb
|
||||
crypto/des/des_setkey.c optional crypto | ipsec | netsmb
|
||||
crypto/rc4/rc4.c optional netgraph_mppc_encryption
|
||||
crypto/rc4/rc4.c optional netgraph_mppc_encryption | kgssapi
|
||||
crypto/rijndael/rijndael-alg-fst.c optional crypto | geom_bde | \
|
||||
ipsec | random | wlan_ccmp
|
||||
crypto/rijndael/rijndael-api-fst.c optional geom_bde | random
|
||||
@ -1746,6 +1746,56 @@ kern/vfs_subr.c standard
|
||||
kern/vfs_syscalls.c standard
|
||||
kern/vfs_vnops.c standard
|
||||
#
|
||||
# Kernel GSS-API
|
||||
#
|
||||
gssd.h optional kgssapi \
|
||||
dependency "$S/kgssapi/gssd.x" \
|
||||
compile-with "rpcgen -hM $S/kgssapi/gssd.x | grep -v pthread.h > gssd.h" \
|
||||
no-obj no-implicit-rule before-depend local \
|
||||
clean "gssd.h"
|
||||
gssd_xdr.c optional kgssapi \
|
||||
dependency "$S/kgssapi/gssd.x gssd.h" \
|
||||
compile-with "rpcgen -c $S/kgssapi/gssd.x -o gssd_xdr.c" \
|
||||
no-implicit-rule before-depend local \
|
||||
clean "gssd_xdr.c"
|
||||
gssd_clnt.c optional kgssapi \
|
||||
dependency "$S/kgssapi/gssd.x gssd.h" \
|
||||
compile-with "rpcgen -lM $S/kgssapi/gssd.x | grep -v string.h > gssd_clnt.c" \
|
||||
no-implicit-rule before-depend local \
|
||||
clean "gssd_clnt.c"
|
||||
kgssapi/gss_accept_sec_context.c optional kgssapi
|
||||
kgssapi/gss_add_oid_set_member.c optional kgssapi
|
||||
kgssapi/gss_acquire_cred.c optional kgssapi
|
||||
kgssapi/gss_canonicalize_name.c optional kgssapi
|
||||
kgssapi/gss_create_empty_oid_set.c optional kgssapi
|
||||
kgssapi/gss_delete_sec_context.c optional kgssapi
|
||||
kgssapi/gss_display_status.c optional kgssapi
|
||||
kgssapi/gss_export_name.c optional kgssapi
|
||||
kgssapi/gss_get_mic.c optional kgssapi
|
||||
kgssapi/gss_init_sec_context.c optional kgssapi
|
||||
kgssapi/gss_impl.c optional kgssapi
|
||||
kgssapi/gss_import_name.c optional kgssapi
|
||||
kgssapi/gss_names.c optional kgssapi
|
||||
kgssapi/gss_pname_to_uid.c optional kgssapi
|
||||
kgssapi/gss_release_buffer.c optional kgssapi
|
||||
kgssapi/gss_release_cred.c optional kgssapi
|
||||
kgssapi/gss_release_name.c optional kgssapi
|
||||
kgssapi/gss_release_oid_set.c optional kgssapi
|
||||
kgssapi/gss_set_cred_option.c optional kgssapi
|
||||
kgssapi/gss_test_oid_set_member.c optional kgssapi
|
||||
kgssapi/gss_unwrap.c optional kgssapi
|
||||
kgssapi/gss_verify_mic.c optional kgssapi
|
||||
kgssapi/gss_wrap.c optional kgssapi
|
||||
kgssapi/gss_wrap_size_limit.c optional kgssapi
|
||||
kgssapi/gssd_prot.c optional kgssapi
|
||||
kgssapi/krb5/krb5_mech.c optional kgssapi
|
||||
kgssapi/krb5/kcrypto.c optional kgssapi
|
||||
kgssapi/krb5/kcrypto_aes.c optional kgssapi
|
||||
kgssapi/krb5/kcrypto_arcfour.c optional kgssapi
|
||||
kgssapi/krb5/kcrypto_des.c optional kgssapi
|
||||
kgssapi/krb5/kcrypto_des3.c optional kgssapi
|
||||
kgssapi/kgss_if.m optional kgssapi
|
||||
kgssapi/gsstest.c optional kgssapi_debug
|
||||
# These files in libkern/ are those needed by all architectures. Some
|
||||
# of the files in libkern/ are only needed on some architectures, e.g.,
|
||||
# libkern/divdi3.c is needed by i386 but not alpha. Also, some of these
|
||||
@ -2106,18 +2156,21 @@ nfsclient/krpc_subr.c optional bootp nfsclient
|
||||
nfsclient/nfs_bio.c optional nfsclient
|
||||
nfsclient/nfs_diskless.c optional nfsclient nfs_root
|
||||
nfsclient/nfs_node.c optional nfsclient
|
||||
nfsclient/nfs_socket.c optional nfsclient
|
||||
nfsclient/nfs_socket.c optional nfsclient nfs_legacyrpc
|
||||
nfsclient/nfs_krpc.c optional nfsclient
|
||||
nfsclient/nfs_subs.c optional nfsclient
|
||||
nfsclient/nfs_nfsiod.c optional nfsclient
|
||||
nfsclient/nfs_vfsops.c optional nfsclient
|
||||
nfsclient/nfs_vnops.c optional nfsclient
|
||||
nfsclient/nfs_lock.c optional nfsclient
|
||||
nfsserver/nfs_fha.c optional nfsserver
|
||||
nfsserver/nfs_serv.c optional nfsserver
|
||||
nfsserver/nfs_srvsock.c optional nfsserver
|
||||
nfsserver/nfs_srvcache.c optional nfsserver
|
||||
nfsserver/nfs_srvkrpc.c optional nfsserver
|
||||
nfsserver/nfs_srvsock.c optional nfsserver nfs_legacyrpc
|
||||
nfsserver/nfs_srvcache.c optional nfsserver nfs_legacyrpc
|
||||
nfsserver/nfs_srvsubs.c optional nfsserver
|
||||
nfsserver/nfs_syscalls.c optional nfsserver
|
||||
nlm/nlm_advlock.c optional nfslockd
|
||||
nfsserver/nfs_syscalls.c optional nfsserver nfs_legacyrpc
|
||||
nlm/nlm_advlock.c optional nfslockd nfsclient
|
||||
nlm/nlm_prot_clnt.c optional nfslockd
|
||||
nlm/nlm_prot_impl.c optional nfslockd
|
||||
nlm/nlm_prot_server.c optional nfslockd
|
||||
@ -2143,27 +2196,33 @@ pci/intpm.c optional intpm pci
|
||||
pci/ncr.c optional ncr pci
|
||||
pci/nfsmb.c optional nfsmb pci
|
||||
pci/viapm.c optional viapm pci
|
||||
rpc/auth_none.c optional krpc | nfslockd
|
||||
rpc/auth_unix.c optional krpc | nfslockd
|
||||
rpc/authunix_prot.c optional krpc | nfslockd
|
||||
rpc/clnt_dg.c optional krpc | nfslockd
|
||||
rpc/clnt_rc.c optional krpc | nfslockd
|
||||
rpc/clnt_vc.c optional krpc | nfslockd
|
||||
rpc/getnetconfig.c optional krpc | nfslockd
|
||||
rpc/inet_ntop.c optional krpc | nfslockd
|
||||
rpc/inet_pton.c optional krpc | nfslockd
|
||||
rpc/rpc_callmsg.c optional krpc | nfslockd
|
||||
rpc/rpc_generic.c optional krpc | nfslockd
|
||||
rpc/rpc_prot.c optional krpc | nfslockd
|
||||
rpc/rpcb_clnt.c optional krpc | nfslockd
|
||||
rpc/rpcb_prot.c optional krpc | nfslockd
|
||||
rpc/auth_none.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
rpc/auth_unix.c optional krpc | nfslockd | nfsclient
|
||||
rpc/authunix_prot.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
rpc/clnt_dg.c optional krpc | nfslockd | nfsclient
|
||||
rpc/clnt_rc.c optional krpc | nfslockd | nfsclient
|
||||
rpc/clnt_vc.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
rpc/getnetconfig.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
rpc/inet_ntop.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
rpc/inet_pton.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
rpc/replay.c optional krpc | nfslockd | nfsserver
|
||||
rpc/rpc_callmsg.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
rpc/rpc_generic.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
rpc/rpc_prot.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
rpc/rpcb_clnt.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
rpc/rpcb_prot.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
rpc/rpcclnt.c optional nfsclient
|
||||
rpc/svc.c optional krpc | nfslockd
|
||||
rpc/svc_auth.c optional krpc | nfslockd
|
||||
rpc/svc_auth_unix.c optional krpc | nfslockd
|
||||
rpc/svc_dg.c optional krpc | nfslockd
|
||||
rpc/svc_generic.c optional krpc | nfslockd
|
||||
rpc/svc_vc.c optional krpc | nfslockd
|
||||
rpc/svc.c optional krpc | nfslockd | nfsserver
|
||||
rpc/svc_auth.c optional krpc | nfslockd | nfsserver
|
||||
rpc/svc_auth_unix.c optional krpc | nfslockd | nfsserver
|
||||
rpc/svc_dg.c optional krpc | nfslockd | nfsserver
|
||||
rpc/svc_generic.c optional krpc | nfslockd | nfsserver
|
||||
rpc/svc_vc.c optional krpc | nfslockd | nfsserver
|
||||
rpc/rpcsec_gss/rpcsec_gss.c optional krpc kgssapi | nfslockd kgssapi
|
||||
rpc/rpcsec_gss/rpcsec_gss_conf.c optional krpc kgssapi | nfslockd kgssapi
|
||||
rpc/rpcsec_gss/rpcsec_gss_misc.c optional krpc kgssapi | nfslockd kgssapi
|
||||
rpc/rpcsec_gss/rpcsec_gss_prot.c optional krpc kgssapi | nfslockd kgssapi
|
||||
rpc/rpcsec_gss/svc_rpcsec_gss.c optional krpc kgssapi | nfslockd kgssapi
|
||||
security/audit/audit.c optional audit
|
||||
security/audit/audit_arg.c optional audit
|
||||
security/audit/audit_bsm.c optional audit
|
||||
@ -2251,12 +2310,12 @@ vm/vm_reserv.c standard
|
||||
vm/vm_unix.c standard
|
||||
vm/vm_zeroidle.c standard
|
||||
vm/vnode_pager.c standard
|
||||
xdr/xdr.c optional krpc | nfslockd
|
||||
xdr/xdr_array.c optional krpc | nfslockd
|
||||
xdr/xdr_mbuf.c optional krpc | nfslockd
|
||||
xdr/xdr_mem.c optional krpc | nfslockd
|
||||
xdr/xdr_reference.c optional krpc | nfslockd
|
||||
xdr/xdr_sizeof.c optional krpc | nfslockd
|
||||
xdr/xdr.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
xdr/xdr_array.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
xdr/xdr_mbuf.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
xdr/xdr_mem.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
xdr/xdr_reference.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
xdr/xdr_sizeof.c optional krpc | nfslockd | nfsclient | nfsserver
|
||||
#
|
||||
gnu/fs/xfs/xfs_alloc.c optional xfs \
|
||||
compile-with "${NORMAL_C} -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs" \
|
||||
|
@ -214,6 +214,10 @@ PSEUDOFS_TRACE opt_pseudofs.h
|
||||
# Broken - ffs_snapshot() dependency from ufs_lookup() :-(
|
||||
FFS opt_ffs_broken_fixme.h
|
||||
|
||||
# In-kernel GSS-API
|
||||
KGSSAPI opt_kgssapi.h
|
||||
KGSSAPI_DEBUG opt_kgssapi.h
|
||||
|
||||
# These static filesystems have one slightly bogus static dependency in
|
||||
# sys/i386/i386/autoconf.c. If any of these filesystems are
|
||||
# statically compiled into the kernel, code for mounting them as root
|
||||
@ -222,6 +226,11 @@ NFSCLIENT opt_nfs.h
|
||||
NFSSERVER opt_nfs.h
|
||||
NFS4CLIENT opt_nfs.h
|
||||
|
||||
# Use this option to compile both NFS client and server using the
|
||||
# legacy RPC implementation instead of the newer KRPC system (which
|
||||
# supports modern features such as RPCSEC_GSS
|
||||
NFS_LEGACYRPC opt_nfs.h
|
||||
|
||||
# filesystems and libiconv bridge
|
||||
CD9660_ICONV opt_dontuse.h
|
||||
MSDOSFS_ICONV opt_dontuse.h
|
||||
|
@ -521,7 +521,7 @@ unionfs_fhtovp(struct mount *mp, struct fid *fidp, struct vnode **vpp)
|
||||
|
||||
static int
|
||||
unionfs_checkexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
|
||||
struct ucred **credanonp)
|
||||
struct ucred **credanonp, int *numsecflavors, int **secflavors)
|
||||
{
|
||||
return (EOPNOTSUPP);
|
||||
}
|
||||
|
@ -895,5 +895,7 @@
|
||||
char *path2); }
|
||||
503 AUE_UNLINKAT STD { int unlinkat(int fd, char *path, int flag); }
|
||||
504 AUE_POSIX_OPENPT STD { int posix_openpt(int flags); }
|
||||
; 505 is initialised by the kgssapi code, if present.
|
||||
505 AUE_NULL NOSTD { int gssd_syscall(char *path); }
|
||||
; Please copy any additions and changes to the following compatability tables:
|
||||
; sys/compat/freebsd32/syscalls.master
|
||||
|
@ -68,6 +68,8 @@ struct netcred {
|
||||
struct radix_node netc_rnodes[2];
|
||||
int netc_exflags;
|
||||
struct ucred netc_anon;
|
||||
int netc_numsecflavors;
|
||||
int netc_secflavors[MAXSECFLAVORS];
|
||||
};
|
||||
|
||||
/*
|
||||
@ -120,6 +122,9 @@ vfs_hang_addrlist(struct mount *mp, struct netexport *nep,
|
||||
np->netc_anon.cr_ngroups = argp->ex_anon.cr_ngroups;
|
||||
bcopy(argp->ex_anon.cr_groups, np->netc_anon.cr_groups,
|
||||
sizeof(np->netc_anon.cr_groups));
|
||||
np->netc_numsecflavors = argp->ex_numsecflavors;
|
||||
bcopy(argp->ex_secflavors, np->netc_secflavors,
|
||||
sizeof(np->netc_secflavors));
|
||||
refcount_init(&np->netc_anon.cr_ref, 1);
|
||||
MNT_ILOCK(mp);
|
||||
mp->mnt_flag |= MNT_DEFEXPORTED;
|
||||
@ -203,6 +208,9 @@ vfs_hang_addrlist(struct mount *mp, struct netexport *nep,
|
||||
np->netc_anon.cr_ngroups = argp->ex_anon.cr_ngroups;
|
||||
bcopy(argp->ex_anon.cr_groups, np->netc_anon.cr_groups,
|
||||
sizeof(np->netc_anon.cr_groups));
|
||||
np->netc_numsecflavors = argp->ex_numsecflavors;
|
||||
bcopy(argp->ex_secflavors, np->netc_secflavors,
|
||||
sizeof(np->netc_secflavors));
|
||||
refcount_init(&np->netc_anon.cr_ref, 1);
|
||||
return (0);
|
||||
out:
|
||||
@ -253,6 +261,10 @@ vfs_export(struct mount *mp, struct export_args *argp)
|
||||
struct netexport *nep;
|
||||
int error;
|
||||
|
||||
if (argp->ex_numsecflavors < 0
|
||||
|| argp->ex_numsecflavors >= MAXSECFLAVORS)
|
||||
return (EINVAL);
|
||||
|
||||
nep = mp->mnt_export;
|
||||
error = 0;
|
||||
lockmgr(&mp->mnt_explock, LK_EXCLUSIVE, NULL);
|
||||
@ -441,7 +453,7 @@ vfs_export_lookup(struct mount *mp, struct sockaddr *nam)
|
||||
|
||||
int
|
||||
vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
|
||||
struct ucred **credanonp)
|
||||
struct ucred **credanonp, int *numsecflavors, int **secflavors)
|
||||
{
|
||||
struct netcred *np;
|
||||
|
||||
@ -452,6 +464,10 @@ vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
|
||||
return (EACCES);
|
||||
*extflagsp = np->netc_exflags;
|
||||
*credanonp = &np->netc_anon;
|
||||
if (numsecflavors)
|
||||
*numsecflavors = np->netc_numsecflavors;
|
||||
if (secflavors)
|
||||
*secflavors = np->netc_secflavors;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -827,6 +827,7 @@ vfs_domount(
|
||||
struct vnode *vp;
|
||||
struct mount *mp;
|
||||
struct vfsconf *vfsp;
|
||||
struct oexport_args oexport;
|
||||
struct export_args export;
|
||||
int error, flag = 0;
|
||||
struct vattr va;
|
||||
@ -1010,6 +1011,19 @@ vfs_domount(
|
||||
if (vfs_copyopt(mp->mnt_optnew, "export", &export,
|
||||
sizeof(export)) == 0)
|
||||
error = vfs_export(mp, &export);
|
||||
else if (vfs_copyopt(mp->mnt_optnew, "export", &oexport,
|
||||
sizeof(oexport)) == 0) {
|
||||
export.ex_flags = oexport.ex_flags;
|
||||
export.ex_root = oexport.ex_root;
|
||||
export.ex_anon = oexport.ex_anon;
|
||||
export.ex_addr = oexport.ex_addr;
|
||||
export.ex_addrlen = oexport.ex_addrlen;
|
||||
export.ex_mask = oexport.ex_mask;
|
||||
export.ex_masklen = oexport.ex_masklen;
|
||||
export.ex_indexfile = oexport.ex_indexfile;
|
||||
export.ex_numsecflavors = 0;
|
||||
error = vfs_export(mp, &export);
|
||||
}
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
|
138
sys/kgssapi/gss_accept_sec_context.c
Normal file
138
sys/kgssapi/gss_accept_sec_context.c
Normal file
@ -0,0 +1,138 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
#include "gssd.h"
|
||||
#include "kgss_if.h"
|
||||
|
||||
OM_uint32 gss_accept_sec_context(OM_uint32 *minor_status,
|
||||
gss_ctx_id_t *context_handle,
|
||||
const gss_cred_id_t acceptor_cred_handle,
|
||||
const gss_buffer_t input_token,
|
||||
const gss_channel_bindings_t input_chan_bindings,
|
||||
gss_name_t *src_name,
|
||||
gss_OID *mech_type,
|
||||
gss_buffer_t output_token,
|
||||
OM_uint32 *ret_flags,
|
||||
OM_uint32 *time_rec,
|
||||
gss_cred_id_t *delegated_cred_handle)
|
||||
{
|
||||
struct accept_sec_context_res res;
|
||||
struct accept_sec_context_args args;
|
||||
enum clnt_stat stat;
|
||||
gss_ctx_id_t ctx = *context_handle;
|
||||
gss_name_t name;
|
||||
gss_cred_id_t cred;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
if (ctx)
|
||||
args.ctx = ctx->handle;
|
||||
else
|
||||
args.ctx = 0;
|
||||
if (acceptor_cred_handle)
|
||||
args.cred = acceptor_cred_handle->handle;
|
||||
else
|
||||
args.cred = 0;
|
||||
args.input_token = *input_token;
|
||||
args.input_chan_bindings = input_chan_bindings;
|
||||
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_accept_sec_context_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
if (res.major_status != GSS_S_COMPLETE
|
||||
&& res.major_status != GSS_S_CONTINUE_NEEDED) {
|
||||
*minor_status = res.minor_status;
|
||||
xdr_free((xdrproc_t) xdr_accept_sec_context_res, &res);
|
||||
return (res.major_status);
|
||||
}
|
||||
|
||||
*minor_status = res.minor_status;
|
||||
|
||||
if (!ctx) {
|
||||
ctx = kgss_create_context(res.mech_type);
|
||||
if (!ctx) {
|
||||
xdr_free((xdrproc_t) xdr_accept_sec_context_res, &res);
|
||||
*minor_status = 0;
|
||||
return (GSS_S_BAD_MECH);
|
||||
}
|
||||
}
|
||||
*context_handle = ctx;
|
||||
|
||||
ctx->handle = res.ctx;
|
||||
name = malloc(sizeof(struct _gss_name_t), M_GSSAPI, M_WAITOK);
|
||||
name->handle = res.src_name;
|
||||
if (src_name) {
|
||||
*src_name = name;
|
||||
} else {
|
||||
OM_uint32 junk;
|
||||
gss_release_name(&junk, &name);
|
||||
}
|
||||
if (mech_type)
|
||||
*mech_type = KGSS_MECH_TYPE(ctx);
|
||||
kgss_copy_buffer(&res.output_token, output_token);
|
||||
if (ret_flags)
|
||||
*ret_flags = res.ret_flags;
|
||||
if (time_rec)
|
||||
*time_rec = res.time_rec;
|
||||
cred = malloc(sizeof(struct _gss_cred_id_t), M_GSSAPI, M_WAITOK);
|
||||
cred->handle = res.delegated_cred_handle;
|
||||
if (delegated_cred_handle) {
|
||||
*delegated_cred_handle = cred;
|
||||
} else {
|
||||
OM_uint32 junk;
|
||||
gss_release_cred(&junk, &cred);
|
||||
}
|
||||
|
||||
xdr_free((xdrproc_t) xdr_accept_sec_context_res, &res);
|
||||
|
||||
/*
|
||||
* If the context establishment is complete, export it from
|
||||
* userland and hand the result (which includes key material
|
||||
* etc.) to the kernel implementation.
|
||||
*/
|
||||
if (res.major_status == GSS_S_COMPLETE)
|
||||
res.major_status = kgss_transfer_context(ctx);
|
||||
|
||||
return (res.major_status);
|
||||
}
|
105
sys/kgssapi/gss_acquire_cred.c
Normal file
105
sys/kgssapi/gss_acquire_cred.c
Normal file
@ -0,0 +1,105 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "gssd.h"
|
||||
|
||||
OM_uint32
|
||||
gss_acquire_cred(OM_uint32 *minor_status,
|
||||
const gss_name_t desired_name,
|
||||
OM_uint32 time_req,
|
||||
const gss_OID_set desired_mechs,
|
||||
gss_cred_usage_t cred_usage,
|
||||
gss_cred_id_t *output_cred_handle,
|
||||
gss_OID_set *actual_mechs,
|
||||
OM_uint32 *time_rec)
|
||||
{
|
||||
OM_uint32 major_status;
|
||||
struct acquire_cred_res res;
|
||||
struct acquire_cred_args args;
|
||||
enum clnt_stat stat;
|
||||
gss_cred_id_t cred;
|
||||
int i;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
args.uid = curthread->td_ucred->cr_uid;
|
||||
if (desired_name)
|
||||
args.desired_name = desired_name->handle;
|
||||
else
|
||||
args.desired_name = 0;
|
||||
args.time_req = time_req;
|
||||
args.desired_mechs = desired_mechs;
|
||||
args.cred_usage = cred_usage;
|
||||
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_acquire_cred_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
if (res.major_status != GSS_S_COMPLETE) {
|
||||
*minor_status = res.minor_status;
|
||||
return (res.major_status);
|
||||
}
|
||||
|
||||
*minor_status = 0;
|
||||
cred = malloc(sizeof(struct _gss_cred_id_t), M_GSSAPI, M_WAITOK);
|
||||
cred->handle = res.output_cred;
|
||||
*output_cred_handle = cred;
|
||||
if (actual_mechs) {
|
||||
major_status = gss_create_empty_oid_set(minor_status,
|
||||
actual_mechs);
|
||||
if (major_status)
|
||||
return (major_status);
|
||||
for (i = 0; i < res.actual_mechs->count; i++) {
|
||||
major_status = gss_add_oid_set_member(minor_status,
|
||||
&res.actual_mechs->elements[i], actual_mechs);
|
||||
if (major_status)
|
||||
return (major_status);
|
||||
}
|
||||
}
|
||||
if (time_rec)
|
||||
*time_rec = res.time_rec;
|
||||
|
||||
xdr_free((xdrproc_t) xdr_acquire_cred_res, &res);
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
76
sys/kgssapi/gss_add_oid_set_member.c
Normal file
76
sys/kgssapi/gss_add_oid_set_member.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
OM_uint32
|
||||
gss_add_oid_set_member(OM_uint32 *minor_status,
|
||||
const gss_OID member_oid,
|
||||
gss_OID_set *oid_set)
|
||||
{
|
||||
OM_uint32 major_status;
|
||||
gss_OID_set set = *oid_set;
|
||||
gss_OID new_elements;
|
||||
gss_OID new_oid;
|
||||
int t;
|
||||
|
||||
*minor_status = 0;
|
||||
|
||||
major_status = gss_test_oid_set_member(minor_status,
|
||||
member_oid, *oid_set, &t);
|
||||
if (major_status)
|
||||
return (major_status);
|
||||
if (t)
|
||||
return (GSS_S_COMPLETE);
|
||||
|
||||
new_elements = malloc((set->count + 1) * sizeof(gss_OID_desc),
|
||||
M_GSSAPI, M_WAITOK);
|
||||
|
||||
new_oid = &new_elements[set->count];
|
||||
new_oid->elements = malloc(member_oid->length, M_GSSAPI, M_WAITOK);
|
||||
new_oid->length = member_oid->length;
|
||||
memcpy(new_oid->elements, member_oid->elements, member_oid->length);
|
||||
|
||||
if (set->elements) {
|
||||
memcpy(new_elements, set->elements,
|
||||
set->count * sizeof(gss_OID_desc));
|
||||
free(set->elements, M_GSSAPI);
|
||||
}
|
||||
set->elements = new_elements;
|
||||
set->count++;
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
76
sys/kgssapi/gss_canonicalize_name.c
Normal file
76
sys/kgssapi/gss_canonicalize_name.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "gssd.h"
|
||||
|
||||
OM_uint32
|
||||
gss_canonicalize_name(OM_uint32 *minor_status,
|
||||
gss_name_t input_name,
|
||||
const gss_OID mech_type,
|
||||
gss_name_t *output_name)
|
||||
{
|
||||
struct canonicalize_name_res res;
|
||||
struct canonicalize_name_args args;
|
||||
enum clnt_stat stat;
|
||||
gss_name_t name;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
args.input_name = input_name->handle;
|
||||
args.mech_type = mech_type;
|
||||
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_canonicalize_name_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
if (res.major_status != GSS_S_COMPLETE) {
|
||||
*minor_status = res.minor_status;
|
||||
return (res.major_status);
|
||||
}
|
||||
|
||||
name = malloc(sizeof(struct _gss_name_t), M_GSSAPI, M_WAITOK);
|
||||
name->handle = res.output_name;
|
||||
*minor_status = 0;
|
||||
*output_name = name;
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
55
sys/kgssapi/gss_create_empty_oid_set.c
Normal file
55
sys/kgssapi/gss_create_empty_oid_set.c
Normal file
@ -0,0 +1,55 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
OM_uint32
|
||||
gss_create_empty_oid_set(OM_uint32 *minor_status,
|
||||
gss_OID_set *oid_set)
|
||||
{
|
||||
gss_OID_set set;
|
||||
|
||||
*minor_status = 0;
|
||||
*oid_set = GSS_C_NO_OID_SET;
|
||||
|
||||
set = malloc(sizeof(gss_OID_set_desc), M_GSSAPI, M_WAITOK);
|
||||
|
||||
set->count = 0;
|
||||
set->elements = 0;
|
||||
*oid_set = set;
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
91
sys/kgssapi/gss_delete_sec_context.c
Normal file
91
sys/kgssapi/gss_delete_sec_context.c
Normal file
@ -0,0 +1,91 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "gssd.h"
|
||||
|
||||
OM_uint32
|
||||
gss_delete_sec_context(OM_uint32 *minor_status, gss_ctx_id_t *context_handle,
|
||||
gss_buffer_t output_token)
|
||||
{
|
||||
struct delete_sec_context_res res;
|
||||
struct delete_sec_context_args args;
|
||||
enum clnt_stat stat;
|
||||
gss_ctx_id_t ctx;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
if (*context_handle) {
|
||||
ctx = *context_handle;
|
||||
|
||||
/*
|
||||
* If we are past the context establishment phase, let
|
||||
* the in-kernel code do the delete, otherwise
|
||||
* userland needs to deal with it.
|
||||
*/
|
||||
if (ctx->handle) {
|
||||
args.ctx = ctx->handle;
|
||||
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_delete_sec_context_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
if (output_token)
|
||||
kgss_copy_buffer(&res.output_token,
|
||||
output_token);
|
||||
xdr_free((xdrproc_t) xdr_delete_sec_context_res, &res);
|
||||
|
||||
kgss_delete_context(ctx, NULL);
|
||||
} else {
|
||||
kgss_delete_context(ctx, output_token);
|
||||
}
|
||||
*context_handle = NULL;
|
||||
} else {
|
||||
if (output_token) {
|
||||
output_token->length = 0;
|
||||
output_token->value = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
*minor_status = 0;
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
79
sys/kgssapi/gss_display_status.c
Normal file
79
sys/kgssapi/gss_display_status.c
Normal file
@ -0,0 +1,79 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "gssd.h"
|
||||
|
||||
OM_uint32
|
||||
gss_display_status(OM_uint32 *minor_status,
|
||||
OM_uint32 status_value,
|
||||
int status_type,
|
||||
const gss_OID mech_type,
|
||||
OM_uint32 *message_context,
|
||||
gss_buffer_t status_string) /* status_string */
|
||||
{
|
||||
struct display_status_res res;
|
||||
struct display_status_args args;
|
||||
enum clnt_stat stat;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
args.status_value = status_value;
|
||||
args.status_type = status_type;
|
||||
args.mech_type = mech_type;
|
||||
args.message_context = *message_context;
|
||||
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_display_status_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
if (res.major_status != GSS_S_COMPLETE) {
|
||||
*minor_status = res.minor_status;
|
||||
return (res.major_status);
|
||||
}
|
||||
|
||||
*minor_status = 0;
|
||||
*message_context = res.message_context;
|
||||
kgss_copy_buffer(&res.status_string, status_string);
|
||||
xdr_free((xdrproc_t) xdr_display_status_res, &res);
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
71
sys/kgssapi/gss_export_name.c
Normal file
71
sys/kgssapi/gss_export_name.c
Normal file
@ -0,0 +1,71 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "gssd.h"
|
||||
|
||||
OM_uint32
|
||||
gss_export_name(OM_uint32 *minor_status, gss_name_t input_name,
|
||||
gss_buffer_t exported_name)
|
||||
{
|
||||
struct export_name_res res;
|
||||
struct export_name_args args;
|
||||
enum clnt_stat stat;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
args.input_name = input_name->handle;
|
||||
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_export_name_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
if (res.major_status != GSS_S_COMPLETE) {
|
||||
*minor_status = res.minor_status;
|
||||
return (res.major_status);
|
||||
}
|
||||
|
||||
*minor_status = 0;
|
||||
kgss_copy_buffer(&res.exported_name, exported_name);
|
||||
xdr_free((xdrproc_t) xdr_export_name_res, &res);
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
89
sys/kgssapi/gss_get_mic.c
Normal file
89
sys/kgssapi/gss_get_mic.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "kgss_if.h"
|
||||
|
||||
OM_uint32
|
||||
gss_get_mic(OM_uint32 *minor_status,
|
||||
const gss_ctx_id_t ctx,
|
||||
gss_qop_t qop_req,
|
||||
const gss_buffer_t message_buffer,
|
||||
gss_buffer_t message_token)
|
||||
{
|
||||
OM_uint32 maj_stat;
|
||||
struct mbuf *m, *mic;
|
||||
|
||||
if (!ctx) {
|
||||
*minor_status = 0;
|
||||
return (GSS_S_NO_CONTEXT);
|
||||
}
|
||||
|
||||
MGET(m, M_WAITOK, MT_DATA);
|
||||
if (message_buffer->length > MLEN)
|
||||
MCLGET(m, M_WAITOK);
|
||||
m_append(m, message_buffer->length, message_buffer->value);
|
||||
|
||||
maj_stat = KGSS_GET_MIC(ctx, minor_status, qop_req, m, &mic);
|
||||
|
||||
m_freem(m);
|
||||
if (maj_stat == GSS_S_COMPLETE) {
|
||||
message_token->length = m_length(mic, NULL);
|
||||
message_token->value = malloc(message_token->length,
|
||||
M_GSSAPI, M_WAITOK);
|
||||
m_copydata(mic, 0, message_token->length,
|
||||
message_token->value);
|
||||
m_freem(mic);
|
||||
}
|
||||
|
||||
return (maj_stat);
|
||||
}
|
||||
|
||||
OM_uint32
|
||||
gss_get_mic_mbuf(OM_uint32 *minor_status, const gss_ctx_id_t ctx,
|
||||
gss_qop_t qop_req, struct mbuf *m, struct mbuf **micp)
|
||||
{
|
||||
|
||||
if (!ctx) {
|
||||
*minor_status = 0;
|
||||
return (GSS_S_NO_CONTEXT);
|
||||
}
|
||||
|
||||
return (KGSS_GET_MIC(ctx, minor_status, qop_req, m, micp));
|
||||
}
|
||||
|
266
sys/kgssapi/gss_impl.c
Normal file
266
sys/kgssapi/gss_impl.c
Normal file
@ -0,0 +1,266 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/priv.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/sysent.h>
|
||||
#include <sys/sysproto.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpc_com.h>
|
||||
|
||||
#include "gssd.h"
|
||||
#include "kgss_if.h"
|
||||
|
||||
MALLOC_DEFINE(M_GSSAPI, "GSS-API", "GSS-API");
|
||||
|
||||
/*
|
||||
* Syscall hooks
|
||||
*/
|
||||
static int gssd_syscall_offset = SYS_gssd_syscall;
|
||||
static struct sysent gssd_syscall_prev_sysent;
|
||||
MAKE_SYSENT(gssd_syscall);
|
||||
static bool_t gssd_syscall_registered = FALSE;
|
||||
|
||||
struct kgss_mech_list kgss_mechs;
|
||||
CLIENT *kgss_gssd_handle;
|
||||
|
||||
static void
|
||||
kgss_init(void *dummy)
|
||||
{
|
||||
int error;
|
||||
|
||||
LIST_INIT(&kgss_mechs);
|
||||
error = syscall_register(&gssd_syscall_offset, &gssd_syscall_sysent,
|
||||
&gssd_syscall_prev_sysent);
|
||||
if (error)
|
||||
printf("Can't register GSSD syscall\n");
|
||||
else
|
||||
gssd_syscall_registered = TRUE;
|
||||
}
|
||||
SYSINIT(kgss_init, SI_SUB_LOCK, SI_ORDER_FIRST, kgss_init, NULL);
|
||||
|
||||
static void
|
||||
kgss_uninit(void *dummy)
|
||||
{
|
||||
|
||||
if (gssd_syscall_registered)
|
||||
syscall_deregister(&gssd_syscall_offset,
|
||||
&gssd_syscall_prev_sysent);
|
||||
}
|
||||
SYSUNINIT(kgss_uninit, SI_SUB_LOCK, SI_ORDER_FIRST, kgss_uninit, NULL);
|
||||
|
||||
int
|
||||
gssd_syscall(struct thread *td, struct gssd_syscall_args *uap)
|
||||
{
|
||||
struct sockaddr_un sun;
|
||||
struct netconfig *nconf;
|
||||
char path[MAXPATHLEN];
|
||||
int error;
|
||||
|
||||
error = priv_check(td, PRIV_NFS_DAEMON);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
if (kgss_gssd_handle)
|
||||
CLNT_DESTROY(kgss_gssd_handle);
|
||||
|
||||
error = copyinstr(uap->path, path, sizeof(path), NULL);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
sun.sun_family = AF_LOCAL;
|
||||
strcpy(sun.sun_path, path);
|
||||
sun.sun_len = SUN_LEN(&sun);
|
||||
|
||||
nconf = getnetconfigent("local");
|
||||
kgss_gssd_handle = clnt_reconnect_create(nconf,
|
||||
(struct sockaddr *) &sun, GSSD, GSSDVERS,
|
||||
RPC_MAXDATASIZE, RPC_MAXDATASIZE);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
kgss_oid_equal(const gss_OID oid1, const gss_OID oid2)
|
||||
{
|
||||
|
||||
if (oid1 == oid2)
|
||||
return (1);
|
||||
if (!oid1 || !oid2)
|
||||
return (0);
|
||||
if (oid1->length != oid2->length)
|
||||
return (0);
|
||||
if (memcmp(oid1->elements, oid2->elements, oid1->length))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
kgss_install_mech(gss_OID mech_type, const char *name, struct kobj_class *cls)
|
||||
{
|
||||
struct kgss_mech *km;
|
||||
|
||||
km = malloc(sizeof(struct kgss_mech), M_GSSAPI, M_WAITOK);
|
||||
km->km_mech_type = mech_type;
|
||||
km->km_mech_name = name;
|
||||
km->km_class = cls;
|
||||
LIST_INSERT_HEAD(&kgss_mechs, km, km_link);
|
||||
}
|
||||
|
||||
void
|
||||
kgss_uninstall_mech(gss_OID mech_type)
|
||||
{
|
||||
struct kgss_mech *km;
|
||||
|
||||
LIST_FOREACH(km, &kgss_mechs, km_link) {
|
||||
if (kgss_oid_equal(km->km_mech_type, mech_type)) {
|
||||
LIST_REMOVE(km, km_link);
|
||||
free(km, M_GSSAPI);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gss_OID
|
||||
kgss_find_mech_by_name(const char *name)
|
||||
{
|
||||
struct kgss_mech *km;
|
||||
|
||||
LIST_FOREACH(km, &kgss_mechs, km_link) {
|
||||
if (!strcmp(km->km_mech_name, name)) {
|
||||
return (km->km_mech_type);
|
||||
}
|
||||
}
|
||||
return (GSS_C_NO_OID);
|
||||
}
|
||||
|
||||
const char *
|
||||
kgss_find_mech_by_oid(const gss_OID oid)
|
||||
{
|
||||
struct kgss_mech *km;
|
||||
|
||||
LIST_FOREACH(km, &kgss_mechs, km_link) {
|
||||
if (kgss_oid_equal(km->km_mech_type, oid)) {
|
||||
return (km->km_mech_name);
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
gss_ctx_id_t
|
||||
kgss_create_context(gss_OID mech_type)
|
||||
{
|
||||
struct kgss_mech *km;
|
||||
gss_ctx_id_t ctx;
|
||||
|
||||
LIST_FOREACH(km, &kgss_mechs, km_link) {
|
||||
if (kgss_oid_equal(km->km_mech_type, mech_type))
|
||||
break;
|
||||
}
|
||||
if (!km)
|
||||
return (NULL);
|
||||
|
||||
ctx = (gss_ctx_id_t) kobj_create(km->km_class, M_GSSAPI, M_WAITOK);
|
||||
KGSS_INIT(ctx);
|
||||
|
||||
return (ctx);
|
||||
}
|
||||
|
||||
void
|
||||
kgss_delete_context(gss_ctx_id_t ctx, gss_buffer_t output_token)
|
||||
{
|
||||
|
||||
KGSS_DELETE(ctx, output_token);
|
||||
kobj_delete((kobj_t) ctx, M_GSSAPI);
|
||||
}
|
||||
|
||||
OM_uint32
|
||||
kgss_transfer_context(gss_ctx_id_t ctx)
|
||||
{
|
||||
struct export_sec_context_res res;
|
||||
struct export_sec_context_args args;
|
||||
enum clnt_stat stat;
|
||||
OM_uint32 maj_stat;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
args.ctx = ctx->handle;
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_export_sec_context_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
maj_stat = KGSS_IMPORT(ctx, res.format, &res.interprocess_token);
|
||||
ctx->handle = 0;
|
||||
|
||||
xdr_free((xdrproc_t) xdr_export_sec_context_res, &res);
|
||||
|
||||
return (maj_stat);
|
||||
}
|
||||
|
||||
void
|
||||
kgss_copy_buffer(const gss_buffer_t from, gss_buffer_t to)
|
||||
{
|
||||
to->length = from->length;
|
||||
if (from->length) {
|
||||
to->value = malloc(from->length, M_GSSAPI, M_WAITOK);
|
||||
bcopy(from->value, to->value, from->length);
|
||||
} else {
|
||||
to->value = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Kernel module glue
|
||||
*/
|
||||
static int
|
||||
kgssapi_modevent(module_t mod, int type, void *data)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
static moduledata_t kgssapi_mod = {
|
||||
"kgssapi",
|
||||
kgssapi_modevent,
|
||||
NULL,
|
||||
};
|
||||
DECLARE_MODULE(kgssapi, kgssapi_mod, SI_SUB_VFS, SI_ORDER_ANY);
|
||||
MODULE_DEPEND(kgssapi, krpc, 1, 1, 1);
|
||||
MODULE_VERSION(kgssapi, 1);
|
79
sys/kgssapi/gss_import_name.c
Normal file
79
sys/kgssapi/gss_import_name.c
Normal file
@ -0,0 +1,79 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "gssd.h"
|
||||
|
||||
OM_uint32
|
||||
gss_import_name(OM_uint32 *minor_status,
|
||||
const gss_buffer_t input_name_buffer,
|
||||
const gss_OID input_name_type,
|
||||
gss_name_t *output_name)
|
||||
{
|
||||
struct import_name_res res;
|
||||
struct import_name_args args;
|
||||
enum clnt_stat stat;
|
||||
gss_name_t name;
|
||||
|
||||
*minor_status = 0;
|
||||
*output_name = GSS_C_NO_NAME;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
args.input_name_buffer = *input_name_buffer;
|
||||
args.input_name_type = input_name_type;
|
||||
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_import_name_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
if (res.major_status != GSS_S_COMPLETE) {
|
||||
*minor_status = res.minor_status;
|
||||
return (res.major_status);
|
||||
}
|
||||
|
||||
name = malloc(sizeof(struct _gss_name_t), M_GSSAPI, M_WAITOK);
|
||||
name->handle = res.output_name;
|
||||
*minor_status = 0;
|
||||
*output_name = name;
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
135
sys/kgssapi/gss_init_sec_context.c
Normal file
135
sys/kgssapi/gss_init_sec_context.c
Normal file
@ -0,0 +1,135 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/proc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
#include "gssd.h"
|
||||
#include "kgss_if.h"
|
||||
|
||||
OM_uint32
|
||||
gss_init_sec_context(OM_uint32 * minor_status,
|
||||
const gss_cred_id_t initiator_cred_handle,
|
||||
gss_ctx_id_t * context_handle,
|
||||
const gss_name_t target_name,
|
||||
const gss_OID input_mech_type,
|
||||
OM_uint32 req_flags,
|
||||
OM_uint32 time_req,
|
||||
const gss_channel_bindings_t input_chan_bindings,
|
||||
const gss_buffer_t input_token,
|
||||
gss_OID * actual_mech_type,
|
||||
gss_buffer_t output_token,
|
||||
OM_uint32 * ret_flags,
|
||||
OM_uint32 * time_rec)
|
||||
{
|
||||
struct init_sec_context_res res;
|
||||
struct init_sec_context_args args;
|
||||
enum clnt_stat stat;
|
||||
gss_ctx_id_t ctx = *context_handle;
|
||||
|
||||
*minor_status = 0;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
args.uid = curthread->td_ucred->cr_uid;
|
||||
if (initiator_cred_handle)
|
||||
args.cred = initiator_cred_handle->handle;
|
||||
else
|
||||
args.cred = 0;
|
||||
if (ctx)
|
||||
args.ctx = ctx->handle;
|
||||
else
|
||||
args.ctx = 0;
|
||||
args.name = target_name->handle;
|
||||
args.mech_type = input_mech_type;
|
||||
args.req_flags = req_flags;
|
||||
args.time_req = time_req;
|
||||
args.input_chan_bindings = input_chan_bindings;
|
||||
if (input_token)
|
||||
args.input_token = *input_token;
|
||||
else {
|
||||
args.input_token.length = 0;
|
||||
args.input_token.value = NULL;
|
||||
}
|
||||
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_init_sec_context_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
if (res.major_status != GSS_S_COMPLETE
|
||||
&& res.major_status != GSS_S_CONTINUE_NEEDED) {
|
||||
*minor_status = res.minor_status;
|
||||
xdr_free((xdrproc_t) xdr_init_sec_context_res, &res);
|
||||
return (res.major_status);
|
||||
}
|
||||
|
||||
*minor_status = res.minor_status;
|
||||
|
||||
if (!ctx) {
|
||||
ctx = kgss_create_context(res.actual_mech_type);
|
||||
if (!ctx) {
|
||||
xdr_free((xdrproc_t) xdr_init_sec_context_res, &res);
|
||||
*minor_status = 0;
|
||||
return (GSS_S_BAD_MECH);
|
||||
}
|
||||
}
|
||||
*context_handle = ctx;
|
||||
ctx->handle = res.ctx;
|
||||
if (actual_mech_type)
|
||||
*actual_mech_type = KGSS_MECH_TYPE(ctx);
|
||||
kgss_copy_buffer(&res.output_token, output_token);
|
||||
if (ret_flags)
|
||||
*ret_flags = res.ret_flags;
|
||||
if (time_rec)
|
||||
*time_rec = res.time_rec;
|
||||
|
||||
xdr_free((xdrproc_t) xdr_init_sec_context_res, &res);
|
||||
|
||||
/*
|
||||
* If the context establishment is complete, export it from
|
||||
* userland and hand the result (which includes key material
|
||||
* etc.) to the kernel implementation.
|
||||
*/
|
||||
if (res.major_status == GSS_S_COMPLETE)
|
||||
res.major_status = kgss_transfer_context(ctx);
|
||||
|
||||
return (res.major_status);
|
||||
}
|
176
sys/kgssapi/gss_names.c
Normal file
176
sys/kgssapi/gss_names.c
Normal file
@ -0,0 +1,176 @@
|
||||
/*-
|
||||
* Copyright (c) 2005 Doug Rabson
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <kgssapi/gssapi.h>
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x01"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) member-body(2) United States(840) mit(113554)
|
||||
* infosys(1) gssapi(2) generic(1) user_name(1)}. The constant
|
||||
* GSS_C_NT_USER_NAME should be initialized to point
|
||||
* to that gss_OID_desc.
|
||||
*/
|
||||
static gss_OID_desc GSS_C_NT_USER_NAME_storage =
|
||||
{10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01"};
|
||||
gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_storage;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x02"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) member-body(2) United States(840) mit(113554)
|
||||
* infosys(1) gssapi(2) generic(1) machine_uid_name(2)}.
|
||||
* The constant GSS_C_NT_MACHINE_UID_NAME should be
|
||||
* initialized to point to that gss_OID_desc.
|
||||
*/
|
||||
static gss_OID_desc GSS_C_NT_MACHINE_UID_NAME_storage =
|
||||
{10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"};
|
||||
gss_OID GSS_C_NT_MACHINE_UID_NAME = &GSS_C_NT_MACHINE_UID_NAME_storage;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x03"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) member-body(2) United States(840) mit(113554)
|
||||
* infosys(1) gssapi(2) generic(1) string_uid_name(3)}.
|
||||
* The constant GSS_C_NT_STRING_UID_NAME should be
|
||||
* initialized to point to that gss_OID_desc.
|
||||
*/
|
||||
static gss_OID_desc GSS_C_NT_STRING_UID_NAME_storage =
|
||||
{10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x03"};
|
||||
gss_OID GSS_C_NT_STRING_UID_NAME = &GSS_C_NT_STRING_UID_NAME_storage;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {6, (void *)"\x2b\x06\x01\x05\x06\x02"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) org(3) dod(6) internet(1) security(5)
|
||||
* nametypes(6) gss-host-based-services(2)). The constant
|
||||
* GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point
|
||||
* to that gss_OID_desc. This is a deprecated OID value, and
|
||||
* implementations wishing to support hostbased-service names
|
||||
* should instead use the GSS_C_NT_HOSTBASED_SERVICE OID,
|
||||
* defined below, to identify such names;
|
||||
* GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym
|
||||
* for GSS_C_NT_HOSTBASED_SERVICE when presented as an input
|
||||
* parameter, but should not be emitted by GSS-API
|
||||
* implementations
|
||||
*/
|
||||
static gss_OID_desc GSS_C_NT_HOSTBASED_SERVICE_X_storage =
|
||||
{6, (void *)(uintptr_t)"\x2b\x06\x01\x05\x06\x02"};
|
||||
gss_OID GSS_C_NT_HOSTBASED_SERVICE_X = &GSS_C_NT_HOSTBASED_SERVICE_X_storage;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x04"}, corresponding to an
|
||||
* object-identifier value of {iso(1) member-body(2)
|
||||
* Unites States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) service_name(4)}. The constant
|
||||
* GSS_C_NT_HOSTBASED_SERVICE should be initialized
|
||||
* to point to that gss_OID_desc.
|
||||
*/
|
||||
static gss_OID_desc GSS_C_NT_HOSTBASED_SERVICE_storage =
|
||||
{10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04"};
|
||||
gss_OID GSS_C_NT_HOSTBASED_SERVICE = &GSS_C_NT_HOSTBASED_SERVICE_storage;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {6, (void *)"\x2b\x06\01\x05\x06\x03"},
|
||||
* corresponding to an object identifier value of
|
||||
* {1(iso), 3(org), 6(dod), 1(internet), 5(security),
|
||||
* 6(nametypes), 3(gss-anonymous-name)}. The constant
|
||||
* and GSS_C_NT_ANONYMOUS should be initialized to point
|
||||
* to that gss_OID_desc.
|
||||
*/
|
||||
static gss_OID_desc GSS_C_NT_ANONYMOUS_storage =
|
||||
{6, (void *)(uintptr_t)"\x2b\x06\01\x05\x06\x03"};
|
||||
gss_OID GSS_C_NT_ANONYMOUS = &GSS_C_NT_ANONYMOUS_storage;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {6, (void *)"\x2b\x06\x01\x05\x06\x04"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {1(iso), 3(org), 6(dod), 1(internet), 5(security),
|
||||
* 6(nametypes), 4(gss-api-exported-name)}. The constant
|
||||
* GSS_C_NT_EXPORT_NAME should be initialized to point
|
||||
* to that gss_OID_desc.
|
||||
*/
|
||||
static gss_OID_desc GSS_C_NT_EXPORT_NAME_storage =
|
||||
{6, (void *)(uintptr_t)"\x2b\x06\x01\x05\x06\x04"};
|
||||
gss_OID GSS_C_NT_EXPORT_NAME = &GSS_C_NT_EXPORT_NAME_storage;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* krb5(2) krb5_name(1)}. The recommended symbolic name for this type
|
||||
* is "GSS_KRB5_NT_PRINCIPAL_NAME".
|
||||
*/
|
||||
static gss_OID_desc GSS_KRB5_NT_PRINCIPAL_NAME_storage =
|
||||
{10, (void *)(uintptr_t)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02\x01"};
|
||||
gss_OID GSS_KRB5_NT_PRINCIPAL_NAME = &GSS_KRB5_NT_PRINCIPAL_NAME_storage;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) user_name(1)}. The recommended symbolic name for this
|
||||
* type is "GSS_KRB5_NT_USER_NAME".
|
||||
*/
|
||||
gss_OID GSS_KRB5_NT_USER_NAME = &GSS_C_NT_USER_NAME_storage;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) machine_uid_name(2)}. The recommended symbolic name for
|
||||
* this type is "GSS_KRB5_NT_MACHINE_UID_NAME".
|
||||
*/
|
||||
gss_OID GSS_KRB5_NT_MACHINE_UID_NAME = &GSS_C_NT_MACHINE_UID_NAME_storage;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) string_uid_name(3)}. The recommended symbolic name for
|
||||
* this type is "GSS_KRB5_NT_STRING_UID_NAME".
|
||||
*/
|
||||
gss_OID GSS_KRB5_NT_STRING_UID_NAME = &GSS_C_NT_STRING_UID_NAME_storage;
|
||||
|
||||
|
122
sys/kgssapi/gss_pname_to_uid.c
Normal file
122
sys/kgssapi/gss_pname_to_uid.c
Normal file
@ -0,0 +1,122 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "kgss_if.h"
|
||||
|
||||
OM_uint32
|
||||
gss_pname_to_uid(OM_uint32 *minor_status, const gss_name_t pname,
|
||||
const gss_OID mech, uid_t *uidp)
|
||||
{
|
||||
struct pname_to_uid_res res;
|
||||
struct pname_to_uid_args args;
|
||||
enum clnt_stat stat;
|
||||
|
||||
*minor_status = 0;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
if (pname == GSS_C_NO_NAME)
|
||||
return (GSS_S_BAD_NAME);
|
||||
|
||||
args.pname = pname->handle;
|
||||
args.mech = mech;
|
||||
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_pname_to_uid_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
if (res.major_status != GSS_S_COMPLETE) {
|
||||
*minor_status = res.minor_status;
|
||||
return (res.major_status);
|
||||
}
|
||||
|
||||
*uidp = res.uid;
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
||||
|
||||
OM_uint32
|
||||
gss_pname_to_unix_cred(OM_uint32 *minor_status, const gss_name_t pname,
|
||||
const gss_OID mech, uid_t *uidp, gid_t *gidp,
|
||||
int *numgroups, gid_t *groups)
|
||||
|
||||
{
|
||||
struct pname_to_uid_res res;
|
||||
struct pname_to_uid_args args;
|
||||
enum clnt_stat stat;
|
||||
int i, n;
|
||||
|
||||
*minor_status = 0;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
if (pname == GSS_C_NO_NAME)
|
||||
return (GSS_S_BAD_NAME);
|
||||
|
||||
args.pname = pname->handle;
|
||||
args.mech = mech;
|
||||
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_pname_to_uid_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
if (res.major_status != GSS_S_COMPLETE) {
|
||||
*minor_status = res.minor_status;
|
||||
return (res.major_status);
|
||||
}
|
||||
|
||||
*uidp = res.uid;
|
||||
*gidp = res.gid;
|
||||
n = res.gidlist.gidlist_len;
|
||||
if (n > *numgroups)
|
||||
n = *numgroups;
|
||||
for (i = 0; i < n; i++)
|
||||
groups[i] = res.gidlist.gidlist_val[i];
|
||||
*numgroups = n;
|
||||
|
||||
xdr_free((xdrproc_t) xdr_pname_to_uid_res, &res);
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
52
sys/kgssapi/gss_release_buffer.c
Normal file
52
sys/kgssapi/gss_release_buffer.c
Normal file
@ -0,0 +1,52 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
OM_uint32
|
||||
gss_release_buffer(OM_uint32 *minor_status, gss_buffer_t buffer)
|
||||
{
|
||||
|
||||
*minor_status = 0;
|
||||
if (buffer->value) {
|
||||
free(buffer->value, M_GSSAPI);
|
||||
}
|
||||
buffer->length = 0;
|
||||
buffer->value = NULL;
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
||||
|
69
sys/kgssapi/gss_release_cred.c
Normal file
69
sys/kgssapi/gss_release_cred.c
Normal file
@ -0,0 +1,69 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "gssd.h"
|
||||
|
||||
OM_uint32
|
||||
gss_release_cred(OM_uint32 *minor_status, gss_cred_id_t *cred_handle)
|
||||
{
|
||||
struct release_cred_res res;
|
||||
struct release_cred_args args;
|
||||
enum clnt_stat stat;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
if (*cred_handle) {
|
||||
args.cred = (*cred_handle)->handle;
|
||||
stat = gssd_release_cred_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
free((*cred_handle), M_GSSAPI);
|
||||
*cred_handle = NULL;
|
||||
|
||||
*minor_status = res.minor_status;
|
||||
return (res.major_status);
|
||||
}
|
||||
|
||||
*minor_status = 0;
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
74
sys/kgssapi/gss_release_name.c
Normal file
74
sys/kgssapi/gss_release_name.c
Normal file
@ -0,0 +1,74 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "gssd.h"
|
||||
|
||||
OM_uint32
|
||||
gss_release_name(OM_uint32 *minor_status, gss_name_t *input_name)
|
||||
{
|
||||
struct release_name_res res;
|
||||
struct release_name_args args;
|
||||
enum clnt_stat stat;
|
||||
gss_name_t name;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
if (*input_name) {
|
||||
name = *input_name;
|
||||
args.input_name = name->handle;
|
||||
|
||||
stat = gssd_release_name_1(&args, &res, kgss_gssd_handle);
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
free(name, M_GSSAPI);
|
||||
*input_name = NULL;
|
||||
|
||||
if (res.major_status != GSS_S_COMPLETE) {
|
||||
*minor_status = res.minor_status;
|
||||
return (res.major_status);
|
||||
}
|
||||
}
|
||||
|
||||
*minor_status = 0;
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
52
sys/kgssapi/gss_release_oid_set.c
Normal file
52
sys/kgssapi/gss_release_oid_set.c
Normal file
@ -0,0 +1,52 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
OM_uint32
|
||||
gss_release_oid_set(OM_uint32 *minor_status,
|
||||
gss_OID_set *set)
|
||||
{
|
||||
|
||||
*minor_status = 0;
|
||||
if (set && *set) {
|
||||
if ((*set)->elements)
|
||||
free((*set)->elements, M_GSSAPI);
|
||||
free(*set, M_GSSAPI);
|
||||
*set = GSS_C_NO_OID_SET;
|
||||
}
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
77
sys/kgssapi/gss_set_cred_option.c
Normal file
77
sys/kgssapi/gss_set_cred_option.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "gssd.h"
|
||||
|
||||
OM_uint32
|
||||
gss_set_cred_option(OM_uint32 *minor_status,
|
||||
gss_cred_id_t *cred,
|
||||
const gss_OID option_name,
|
||||
const gss_buffer_t option_value)
|
||||
{
|
||||
struct set_cred_option_res res;
|
||||
struct set_cred_option_args args;
|
||||
enum clnt_stat stat;
|
||||
|
||||
*minor_status = 0;
|
||||
|
||||
if (!kgss_gssd_handle)
|
||||
return (GSS_S_FAILURE);
|
||||
|
||||
if (cred)
|
||||
args.cred = (*cred)->handle;
|
||||
else
|
||||
args.cred = 0;
|
||||
args.option_name = option_name;
|
||||
args.option_value = *option_value;
|
||||
|
||||
bzero(&res, sizeof(res));
|
||||
stat = gssd_set_cred_option_1(&args, &res, kgss_gssd_handle);
|
||||
|
||||
if (stat != RPC_SUCCESS) {
|
||||
*minor_status = stat;
|
||||
return (GSS_S_FAILURE);
|
||||
}
|
||||
|
||||
if (res.major_status != GSS_S_COMPLETE) {
|
||||
*minor_status = res.minor_status;
|
||||
return (res.major_status);
|
||||
}
|
||||
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
54
sys/kgssapi/gss_test_oid_set_member.c
Normal file
54
sys/kgssapi/gss_test_oid_set_member.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
OM_uint32
|
||||
gss_test_oid_set_member(OM_uint32 *minor_status,
|
||||
const gss_OID member,
|
||||
const gss_OID_set set,
|
||||
int *present)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
*present = 0;
|
||||
for (i = 0; i < set->count; i++)
|
||||
if (kgss_oid_equal(member, &set->elements[i]))
|
||||
*present = 1;
|
||||
|
||||
*minor_status = 0;
|
||||
return (GSS_S_COMPLETE);
|
||||
}
|
97
sys/kgssapi/gss_unwrap.c
Normal file
97
sys/kgssapi/gss_unwrap.c
Normal file
@ -0,0 +1,97 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "kgss_if.h"
|
||||
|
||||
OM_uint32
|
||||
gss_unwrap(OM_uint32 *minor_status,
|
||||
const gss_ctx_id_t ctx,
|
||||
const gss_buffer_t input_message_buffer,
|
||||
gss_buffer_t output_message_buffer,
|
||||
int *conf_state,
|
||||
gss_qop_t *qop_state)
|
||||
{
|
||||
OM_uint32 maj_stat;
|
||||
struct mbuf *m;
|
||||
|
||||
if (!ctx) {
|
||||
*minor_status = 0;
|
||||
return (GSS_S_NO_CONTEXT);
|
||||
}
|
||||
|
||||
MGET(m, M_WAITOK, MT_DATA);
|
||||
if (input_message_buffer->length > MLEN)
|
||||
MCLGET(m, M_WAITOK);
|
||||
m_append(m, input_message_buffer->length, input_message_buffer->value);
|
||||
|
||||
maj_stat = KGSS_UNWRAP(ctx, minor_status, &m, conf_state, qop_state);
|
||||
|
||||
/*
|
||||
* On success, m is the wrapped message, on failure, m is
|
||||
* freed.
|
||||
*/
|
||||
if (maj_stat == GSS_S_COMPLETE) {
|
||||
output_message_buffer->length = m_length(m, NULL);
|
||||
output_message_buffer->value =
|
||||
malloc(output_message_buffer->length,
|
||||
M_GSSAPI, M_WAITOK);
|
||||
m_copydata(m, 0, output_message_buffer->length,
|
||||
output_message_buffer->value);
|
||||
m_freem(m);
|
||||
}
|
||||
|
||||
return (maj_stat);
|
||||
}
|
||||
|
||||
OM_uint32
|
||||
gss_unwrap_mbuf(OM_uint32 *minor_status,
|
||||
const gss_ctx_id_t ctx,
|
||||
struct mbuf **mp,
|
||||
int *conf_state,
|
||||
gss_qop_t *qop_state)
|
||||
{
|
||||
|
||||
if (!ctx) {
|
||||
*minor_status = 0;
|
||||
return (GSS_S_NO_CONTEXT);
|
||||
}
|
||||
|
||||
return (KGSS_UNWRAP(ctx, minor_status, mp, conf_state, qop_state));
|
||||
}
|
||||
|
87
sys/kgssapi/gss_verify_mic.c
Normal file
87
sys/kgssapi/gss_verify_mic.c
Normal file
@ -0,0 +1,87 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "kgss_if.h"
|
||||
|
||||
OM_uint32
|
||||
gss_verify_mic(OM_uint32 *minor_status,
|
||||
const gss_ctx_id_t ctx,
|
||||
const gss_buffer_t message_buffer,
|
||||
const gss_buffer_t token_buffer,
|
||||
gss_qop_t *qop_state)
|
||||
{
|
||||
OM_uint32 maj_stat;
|
||||
struct mbuf *m, *mic;
|
||||
|
||||
if (!ctx) {
|
||||
*minor_status = 0;
|
||||
return (GSS_S_NO_CONTEXT);
|
||||
}
|
||||
|
||||
MGET(m, M_WAITOK, MT_DATA);
|
||||
if (message_buffer->length > MLEN)
|
||||
MCLGET(m, M_WAITOK);
|
||||
m_append(m, message_buffer->length, message_buffer->value);
|
||||
|
||||
MGET(mic, M_WAITOK, MT_DATA);
|
||||
if (token_buffer->length > MLEN)
|
||||
MCLGET(mic, M_WAITOK);
|
||||
m_append(mic, token_buffer->length, token_buffer->value);
|
||||
|
||||
maj_stat = KGSS_VERIFY_MIC(ctx, minor_status, m, mic, qop_state);
|
||||
|
||||
m_freem(m);
|
||||
m_freem(mic);
|
||||
|
||||
return (maj_stat);
|
||||
}
|
||||
|
||||
OM_uint32
|
||||
gss_verify_mic_mbuf(OM_uint32 *minor_status, const gss_ctx_id_t ctx,
|
||||
struct mbuf *m, struct mbuf *mic, gss_qop_t *qop_state)
|
||||
{
|
||||
|
||||
if (!ctx) {
|
||||
*minor_status = 0;
|
||||
return (GSS_S_NO_CONTEXT);
|
||||
}
|
||||
|
||||
return (KGSS_VERIFY_MIC(ctx, minor_status, m, mic, qop_state));
|
||||
}
|
||||
|
96
sys/kgssapi/gss_wrap.c
Normal file
96
sys/kgssapi/gss_wrap.c
Normal file
@ -0,0 +1,96 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "kgss_if.h"
|
||||
|
||||
OM_uint32
|
||||
gss_wrap(OM_uint32 *minor_status,
|
||||
const gss_ctx_id_t ctx,
|
||||
int conf_req_flag,
|
||||
gss_qop_t qop_req,
|
||||
const gss_buffer_t input_message_buffer,
|
||||
int *conf_state,
|
||||
gss_buffer_t output_message_buffer)
|
||||
{
|
||||
OM_uint32 maj_stat;
|
||||
struct mbuf *m;
|
||||
|
||||
if (!ctx) {
|
||||
*minor_status = 0;
|
||||
return (GSS_S_NO_CONTEXT);
|
||||
}
|
||||
|
||||
MGET(m, M_WAITOK, MT_DATA);
|
||||
if (input_message_buffer->length > MLEN)
|
||||
MCLGET(m, M_WAITOK);
|
||||
m_append(m, input_message_buffer->length, input_message_buffer->value);
|
||||
|
||||
maj_stat = KGSS_WRAP(ctx, minor_status, conf_req_flag, qop_req,
|
||||
&m, conf_state);
|
||||
|
||||
/*
|
||||
* On success, m is the wrapped message, on failure, m is
|
||||
* freed.
|
||||
*/
|
||||
if (maj_stat == GSS_S_COMPLETE) {
|
||||
output_message_buffer->length = m_length(m, NULL);
|
||||
output_message_buffer->value =
|
||||
malloc(output_message_buffer->length,
|
||||
M_GSSAPI, M_WAITOK);
|
||||
m_copydata(m, 0, output_message_buffer->length,
|
||||
output_message_buffer->value);
|
||||
m_freem(m);
|
||||
}
|
||||
|
||||
return (maj_stat);
|
||||
}
|
||||
|
||||
OM_uint32
|
||||
gss_wrap_mbuf(OM_uint32 *minor_status, const gss_ctx_id_t ctx,
|
||||
int conf_req_flag, gss_qop_t qop_req, struct mbuf **mp, int *conf_state)
|
||||
{
|
||||
|
||||
if (!ctx) {
|
||||
*minor_status = 0;
|
||||
return (GSS_S_NO_CONTEXT);
|
||||
}
|
||||
|
||||
return (KGSS_WRAP(ctx, minor_status, conf_req_flag, qop_req,
|
||||
mp, conf_state));
|
||||
}
|
56
sys/kgssapi/gss_wrap_size_limit.c
Normal file
56
sys/kgssapi/gss_wrap_size_limit.c
Normal file
@ -0,0 +1,56 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "kgss_if.h"
|
||||
|
||||
OM_uint32
|
||||
gss_wrap_size_limit(OM_uint32 *minor_status,
|
||||
const gss_ctx_id_t ctx,
|
||||
int conf_req_flag,
|
||||
gss_qop_t qop_req,
|
||||
OM_uint32 req_output_size,
|
||||
OM_uint32 *max_input_size)
|
||||
{
|
||||
if (!ctx) {
|
||||
*minor_status = 0;
|
||||
return (GSS_S_NO_CONTEXT);
|
||||
}
|
||||
|
||||
return (KGSS_WRAP_SIZE_LIMIT(ctx, minor_status, conf_req_flag,
|
||||
qop_req, req_output_size, max_input_size));
|
||||
}
|
620
sys/kgssapi/gssapi.h
Normal file
620
sys/kgssapi/gssapi.h
Normal file
@ -0,0 +1,620 @@
|
||||
/*
|
||||
* Copyright (C) The Internet Society (2000). All Rights Reserved.
|
||||
*
|
||||
* This document and translations of it may be copied and furnished to
|
||||
* others, and derivative works that comment on or otherwise explain it
|
||||
* or assist in its implementation may be prepared, copied, published
|
||||
* and distributed, in whole or in part, without restriction of any
|
||||
* kind, provided that the above copyright notice and this paragraph are
|
||||
* included on all such copies and derivative works. However, this
|
||||
* document itself may not be modified in any way, such as by removing
|
||||
* the copyright notice or references to the Internet Society or other
|
||||
* Internet organizations, except as needed for the purpose of
|
||||
* developing Internet standards in which case the procedures for
|
||||
* copyrights defined in the Internet Standards process must be
|
||||
* followed, or as required to translate it into languages other than
|
||||
* English.
|
||||
*
|
||||
* The limited permissions granted above are perpetual and will not be
|
||||
* revoked by the Internet Society or its successors or assigns.
|
||||
*
|
||||
* This document and the information contained herein is provided on an
|
||||
* "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
|
||||
* TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
|
||||
* HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _KGSSAPI_GSSAPI_H_
|
||||
#define _KGSSAPI_GSSAPI_H_
|
||||
|
||||
/*
|
||||
* A cut-down version of the GSS-API for in-kernel use
|
||||
*/
|
||||
|
||||
/*
|
||||
* Now define the three implementation-dependent types.
|
||||
*/
|
||||
typedef struct _gss_ctx_id_t *gss_ctx_id_t;
|
||||
typedef struct _gss_cred_id_t *gss_cred_id_t;
|
||||
typedef struct _gss_name_t *gss_name_t;
|
||||
|
||||
/*
|
||||
* We can't use X/Open definitions, so roll our own.
|
||||
*/
|
||||
typedef uint32_t OM_uint32;
|
||||
typedef uint64_t OM_uint64;
|
||||
|
||||
typedef struct gss_OID_desc_struct {
|
||||
OM_uint32 length;
|
||||
void *elements;
|
||||
} gss_OID_desc, *gss_OID;
|
||||
|
||||
typedef struct gss_OID_set_desc_struct {
|
||||
size_t count;
|
||||
gss_OID elements;
|
||||
} gss_OID_set_desc, *gss_OID_set;
|
||||
|
||||
typedef struct gss_buffer_desc_struct {
|
||||
size_t length;
|
||||
void *value;
|
||||
} gss_buffer_desc, *gss_buffer_t;
|
||||
|
||||
typedef struct gss_channel_bindings_struct {
|
||||
OM_uint32 initiator_addrtype;
|
||||
gss_buffer_desc initiator_address;
|
||||
OM_uint32 acceptor_addrtype;
|
||||
gss_buffer_desc acceptor_address;
|
||||
gss_buffer_desc application_data;
|
||||
} *gss_channel_bindings_t;
|
||||
|
||||
/*
|
||||
* For now, define a QOP-type as an OM_uint32
|
||||
*/
|
||||
typedef OM_uint32 gss_qop_t;
|
||||
|
||||
typedef int gss_cred_usage_t;
|
||||
|
||||
/*
|
||||
* Flag bits for context-level services.
|
||||
*/
|
||||
#define GSS_C_DELEG_FLAG 1
|
||||
#define GSS_C_MUTUAL_FLAG 2
|
||||
#define GSS_C_REPLAY_FLAG 4
|
||||
#define GSS_C_SEQUENCE_FLAG 8
|
||||
#define GSS_C_CONF_FLAG 16
|
||||
#define GSS_C_INTEG_FLAG 32
|
||||
#define GSS_C_ANON_FLAG 64
|
||||
#define GSS_C_PROT_READY_FLAG 128
|
||||
#define GSS_C_TRANS_FLAG 256
|
||||
|
||||
/*
|
||||
* Credential usage options
|
||||
*/
|
||||
#define GSS_C_BOTH 0
|
||||
#define GSS_C_INITIATE 1
|
||||
#define GSS_C_ACCEPT 2
|
||||
|
||||
/*
|
||||
* Status code types for gss_display_status
|
||||
*/
|
||||
#define GSS_C_GSS_CODE 1
|
||||
#define GSS_C_MECH_CODE 2
|
||||
|
||||
/*
|
||||
* The constant definitions for channel-bindings address families
|
||||
*/
|
||||
#define GSS_C_AF_UNSPEC 0
|
||||
#define GSS_C_AF_LOCAL 1
|
||||
#define GSS_C_AF_INET 2
|
||||
#define GSS_C_AF_IMPLINK 3
|
||||
#define GSS_C_AF_PUP 4
|
||||
#define GSS_C_AF_CHAOS 5
|
||||
#define GSS_C_AF_NS 6
|
||||
#define GSS_C_AF_NBS 7
|
||||
#define GSS_C_AF_ECMA 8
|
||||
#define GSS_C_AF_DATAKIT 9
|
||||
#define GSS_C_AF_CCITT 10
|
||||
#define GSS_C_AF_SNA 11
|
||||
#define GSS_C_AF_DECnet 12
|
||||
#define GSS_C_AF_DLI 13
|
||||
#define GSS_C_AF_LAT 14
|
||||
#define GSS_C_AF_HYLINK 15
|
||||
#define GSS_C_AF_APPLETALK 16
|
||||
#define GSS_C_AF_BSC 17
|
||||
#define GSS_C_AF_DSS 18
|
||||
#define GSS_C_AF_OSI 19
|
||||
#define GSS_C_AF_X25 21
|
||||
#define GSS_C_AF_NULLADDR 255
|
||||
|
||||
/*
|
||||
* Various Null values
|
||||
*/
|
||||
#define GSS_C_NO_NAME ((gss_name_t) 0)
|
||||
#define GSS_C_NO_BUFFER ((gss_buffer_t) 0)
|
||||
#define GSS_C_NO_OID ((gss_OID) 0)
|
||||
#define GSS_C_NO_OID_SET ((gss_OID_set) 0)
|
||||
#define GSS_C_NO_CONTEXT ((gss_ctx_id_t) 0)
|
||||
#define GSS_C_NO_CREDENTIAL ((gss_cred_id_t) 0)
|
||||
#define GSS_C_NO_CHANNEL_BINDINGS ((gss_channel_bindings_t) 0)
|
||||
#define GSS_C_EMPTY_BUFFER {0, NULL}
|
||||
|
||||
/*
|
||||
* Some alternate names for a couple of the above
|
||||
* values. These are defined for V1 compatibility.
|
||||
*/
|
||||
#define GSS_C_NULL_OID GSS_C_NO_OID
|
||||
#define GSS_C_NULL_OID_SET GSS_C_NO_OID_SET
|
||||
|
||||
/*
|
||||
* Define the default Quality of Protection for per-message
|
||||
* services. Note that an implementation that offers multiple
|
||||
* levels of QOP may define GSS_C_QOP_DEFAULT to be either zero
|
||||
* (as done here) to mean "default protection", or to a specific
|
||||
* explicit QOP value. However, a value of 0 should always be
|
||||
* interpreted by a GSS-API implementation as a request for the
|
||||
* default protection level.
|
||||
*/
|
||||
#define GSS_C_QOP_DEFAULT 0
|
||||
|
||||
/*
|
||||
* Expiration time of 2^32-1 seconds means infinite lifetime for a
|
||||
* credential or security context
|
||||
*/
|
||||
#define GSS_C_INDEFINITE 0xfffffffful
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x01"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) member-body(2) United States(840) mit(113554)
|
||||
* infosys(1) gssapi(2) generic(1) user_name(1)}. The constant
|
||||
* GSS_C_NT_USER_NAME should be initialized to point
|
||||
* to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_USER_NAME;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x02"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) member-body(2) United States(840) mit(113554)
|
||||
* infosys(1) gssapi(2) generic(1) machine_uid_name(2)}.
|
||||
* The constant GSS_C_NT_MACHINE_UID_NAME should be
|
||||
* initialized to point to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_MACHINE_UID_NAME;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x03"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) member-body(2) United States(840) mit(113554)
|
||||
* infosys(1) gssapi(2) generic(1) string_uid_name(3)}.
|
||||
* The constant GSS_C_NT_STRING_UID_NAME should be
|
||||
* initialized to point to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_STRING_UID_NAME;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {6, (void *)"\x2b\x06\x01\x05\x06\x02"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {iso(1) org(3) dod(6) internet(1) security(5)
|
||||
* nametypes(6) gss-host-based-services(2)). The constant
|
||||
* GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point
|
||||
* to that gss_OID_desc. This is a deprecated OID value, and
|
||||
* implementations wishing to support hostbased-service names
|
||||
* should instead use the GSS_C_NT_HOSTBASED_SERVICE OID,
|
||||
* defined below, to identify such names;
|
||||
* GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym
|
||||
* for GSS_C_NT_HOSTBASED_SERVICE when presented as an input
|
||||
* parameter, but should not be emitted by GSS-API
|
||||
* implementations
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_HOSTBASED_SERVICE_X;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {10, (void *)"\x2a\x86\x48\x86\xf7\x12"
|
||||
* "\x01\x02\x01\x04"}, corresponding to an
|
||||
* object-identifier value of {iso(1) member-body(2)
|
||||
* Unites States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) service_name(4)}. The constant
|
||||
* GSS_C_NT_HOSTBASED_SERVICE should be initialized
|
||||
* to point to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_HOSTBASED_SERVICE;
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {6, (void *)"\x2b\x06\01\x05\x06\x03"},
|
||||
* corresponding to an object identifier value of
|
||||
* {1(iso), 3(org), 6(dod), 1(internet), 5(security),
|
||||
* 6(nametypes), 3(gss-anonymous-name)}. The constant
|
||||
* and GSS_C_NT_ANONYMOUS should be initialized to point
|
||||
* to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_ANONYMOUS;
|
||||
|
||||
|
||||
/*
|
||||
* The implementation must reserve static storage for a
|
||||
* gss_OID_desc object containing the value
|
||||
* {6, (void *)"\x2b\x06\x01\x05\x06\x04"},
|
||||
* corresponding to an object-identifier value of
|
||||
* {1(iso), 3(org), 6(dod), 1(internet), 5(security),
|
||||
* 6(nametypes), 4(gss-api-exported-name)}. The constant
|
||||
* GSS_C_NT_EXPORT_NAME should be initialized to point
|
||||
* to that gss_OID_desc.
|
||||
*/
|
||||
extern gss_OID GSS_C_NT_EXPORT_NAME;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* krb5(2) krb5_name(1)}. The recommended symbolic name for this type
|
||||
* is "GSS_KRB5_NT_PRINCIPAL_NAME".
|
||||
*/
|
||||
extern gss_OID GSS_KRB5_NT_PRINCIPAL_NAME;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) user_name(1)}. The recommended symbolic name for this
|
||||
* type is "GSS_KRB5_NT_USER_NAME".
|
||||
*/
|
||||
extern gss_OID GSS_KRB5_NT_USER_NAME;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) machine_uid_name(2)}. The recommended symbolic name for
|
||||
* this type is "GSS_KRB5_NT_MACHINE_UID_NAME".
|
||||
*/
|
||||
extern gss_OID GSS_KRB5_NT_MACHINE_UID_NAME;
|
||||
|
||||
/*
|
||||
* This name form shall be represented by the Object Identifier {iso(1)
|
||||
* member-body(2) United States(840) mit(113554) infosys(1) gssapi(2)
|
||||
* generic(1) string_uid_name(3)}. The recommended symbolic name for
|
||||
* this type is "GSS_KRB5_NT_STRING_UID_NAME".
|
||||
*/
|
||||
extern gss_OID GSS_KRB5_NT_STRING_UID_NAME;
|
||||
|
||||
/* Major status codes */
|
||||
|
||||
#define GSS_S_COMPLETE 0
|
||||
|
||||
/*
|
||||
* Some "helper" definitions to make the status code macros obvious.
|
||||
*/
|
||||
#define GSS_C_CALLING_ERROR_OFFSET 24
|
||||
#define GSS_C_ROUTINE_ERROR_OFFSET 16
|
||||
#define GSS_C_SUPPLEMENTARY_OFFSET 0
|
||||
#define GSS_C_CALLING_ERROR_MASK 0377ul
|
||||
#define GSS_C_ROUTINE_ERROR_MASK 0377ul
|
||||
#define GSS_C_SUPPLEMENTARY_MASK 0177777ul
|
||||
|
||||
/*
|
||||
* The macros that test status codes for error conditions.
|
||||
* Note that the GSS_ERROR() macro has changed slightly from
|
||||
* the V1 GSS-API so that it now evaluates its argument
|
||||
* only once.
|
||||
*/
|
||||
#define GSS_CALLING_ERROR(x) \
|
||||
(x & (GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET))
|
||||
#define GSS_ROUTINE_ERROR(x) \
|
||||
(x & (GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET))
|
||||
#define GSS_SUPPLEMENTARY_INFO(x) \
|
||||
(x & (GSS_C_SUPPLEMENTARY_MASK << GSS_C_SUPPLEMENTARY_OFFSET))
|
||||
#define GSS_ERROR(x) \
|
||||
(x & ((GSS_C_CALLING_ERROR_MASK << GSS_C_CALLING_ERROR_OFFSET) | \
|
||||
(GSS_C_ROUTINE_ERROR_MASK << GSS_C_ROUTINE_ERROR_OFFSET)))
|
||||
|
||||
/*
|
||||
* Now the actual status code definitions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Calling errors:
|
||||
*/
|
||||
#define GSS_S_CALL_INACCESSIBLE_READ \
|
||||
(1ul << GSS_C_CALLING_ERROR_OFFSET)
|
||||
#define GSS_S_CALL_INACCESSIBLE_WRITE \
|
||||
(2ul << GSS_C_CALLING_ERROR_OFFSET)
|
||||
#define GSS_S_CALL_BAD_STRUCTURE \
|
||||
(3ul << GSS_C_CALLING_ERROR_OFFSET)
|
||||
|
||||
/*
|
||||
* Routine errors:
|
||||
*/
|
||||
#define GSS_S_BAD_MECH (1ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_NAME (2ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_NAMETYPE (3ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_BINDINGS (4ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_STATUS (5ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_SIG (6ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_MIC GSS_S_BAD_SIG
|
||||
#define GSS_S_NO_CRED (7ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_NO_CONTEXT (8ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_DEFECTIVE_TOKEN (9ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_DEFECTIVE_CREDENTIAL (10ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_CREDENTIALS_EXPIRED (11ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_CONTEXT_EXPIRED (12ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_FAILURE (13ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_BAD_QOP (14ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_UNAUTHORIZED (15ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_UNAVAILABLE (16ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_DUPLICATE_ELEMENT (17ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
#define GSS_S_NAME_NOT_MN (18ul << GSS_C_ROUTINE_ERROR_OFFSET)
|
||||
|
||||
/*
|
||||
* Supplementary info bits:
|
||||
*/
|
||||
#define GSS_S_CONTINUE_NEEDED \
|
||||
(1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 0))
|
||||
#define GSS_S_DUPLICATE_TOKEN \
|
||||
(1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 1))
|
||||
#define GSS_S_OLD_TOKEN \
|
||||
(1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 2))
|
||||
#define GSS_S_UNSEQ_TOKEN \
|
||||
(1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 3))
|
||||
#define GSS_S_GAP_TOKEN \
|
||||
(1ul << (GSS_C_SUPPLEMENTARY_OFFSET + 4))
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* Finally, function prototypes for the GSS-API routines.
|
||||
*/
|
||||
OM_uint32 gss_acquire_cred
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_name_t, /* desired_name */
|
||||
OM_uint32, /* time_req */
|
||||
const gss_OID_set, /* desired_mechs */
|
||||
gss_cred_usage_t, /* cred_usage */
|
||||
gss_cred_id_t *, /* output_cred_handle */
|
||||
gss_OID_set *, /* actual_mechs */
|
||||
OM_uint32 * /* time_rec */
|
||||
);
|
||||
|
||||
OM_uint32 gss_release_cred
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_cred_id_t * /* cred_handle */
|
||||
);
|
||||
|
||||
OM_uint32 gss_init_sec_context
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_cred_id_t, /* initiator_cred_handle */
|
||||
gss_ctx_id_t *, /* context_handle */
|
||||
const gss_name_t, /* target_name */
|
||||
const gss_OID, /* mech_type */
|
||||
OM_uint32, /* req_flags */
|
||||
OM_uint32, /* time_req */
|
||||
const gss_channel_bindings_t,
|
||||
/* input_chan_bindings */
|
||||
const gss_buffer_t, /* input_token */
|
||||
gss_OID *, /* actual_mech_type */
|
||||
gss_buffer_t, /* output_token */
|
||||
OM_uint32 *, /* ret_flags */
|
||||
OM_uint32 * /* time_rec */
|
||||
);
|
||||
|
||||
OM_uint32 gss_accept_sec_context
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_ctx_id_t *, /* context_handle */
|
||||
const gss_cred_id_t, /* acceptor_cred_handle */
|
||||
const gss_buffer_t, /* input_token_buffer */
|
||||
const gss_channel_bindings_t,
|
||||
/* input_chan_bindings */
|
||||
gss_name_t *, /* src_name */
|
||||
gss_OID *, /* mech_type */
|
||||
gss_buffer_t, /* output_token */
|
||||
OM_uint32 *, /* ret_flags */
|
||||
OM_uint32 *, /* time_rec */
|
||||
gss_cred_id_t * /* delegated_cred_handle */
|
||||
);
|
||||
|
||||
OM_uint32 gss_delete_sec_context
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_ctx_id_t *, /* context_handle */
|
||||
gss_buffer_t /* output_token */
|
||||
);
|
||||
|
||||
OM_uint32 gss_get_mic
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
gss_qop_t, /* qop_req */
|
||||
const gss_buffer_t, /* message_buffer */
|
||||
gss_buffer_t /* message_token */
|
||||
);
|
||||
|
||||
OM_uint32 gss_verify_mic
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
const gss_buffer_t, /* message_buffer */
|
||||
const gss_buffer_t, /* token_buffer */
|
||||
gss_qop_t * /* qop_state */
|
||||
);
|
||||
|
||||
OM_uint32 gss_wrap
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
int, /* conf_req_flag */
|
||||
gss_qop_t, /* qop_req */
|
||||
const gss_buffer_t, /* input_message_buffer */
|
||||
int *, /* conf_state */
|
||||
gss_buffer_t /* output_message_buffer */
|
||||
);
|
||||
|
||||
OM_uint32 gss_unwrap
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
const gss_buffer_t, /* input_message_buffer */
|
||||
gss_buffer_t, /* output_message_buffer */
|
||||
int *, /* conf_state */
|
||||
gss_qop_t * /* qop_state */
|
||||
);
|
||||
|
||||
OM_uint32 gss_display_status
|
||||
(OM_uint32 *, /* minor_status */
|
||||
OM_uint32, /* status_value */
|
||||
int, /* status_type */
|
||||
const gss_OID, /* mech_type */
|
||||
OM_uint32 *, /* message_context */
|
||||
gss_buffer_t /* status_string */
|
||||
);
|
||||
|
||||
OM_uint32 gss_import_name
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_buffer_t, /* input_name_buffer */
|
||||
const gss_OID, /* input_name_type */
|
||||
gss_name_t * /* output_name */
|
||||
);
|
||||
|
||||
OM_uint32 gss_export_name
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_name_t, /* input_name */
|
||||
gss_buffer_t /* exported_name */
|
||||
);
|
||||
|
||||
OM_uint32 gss_release_name
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_name_t * /* input_name */
|
||||
);
|
||||
|
||||
OM_uint32 gss_release_buffer
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_buffer_t /* buffer */
|
||||
);
|
||||
|
||||
OM_uint32 gss_release_oid_set
|
||||
(OM_uint32 *, /* minor_status */
|
||||
gss_OID_set * /* set */
|
||||
);
|
||||
|
||||
OM_uint32 gss_wrap_size_limit (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
int, /* conf_req_flag */
|
||||
gss_qop_t, /* qop_req */
|
||||
OM_uint32, /* req_output_size */
|
||||
OM_uint32 * /* max_input_size */
|
||||
);
|
||||
|
||||
OM_uint32 gss_create_empty_oid_set (
|
||||
OM_uint32 *, /* minor_status */
|
||||
gss_OID_set * /* oid_set */
|
||||
);
|
||||
|
||||
OM_uint32 gss_add_oid_set_member (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_OID, /* member_oid */
|
||||
gss_OID_set * /* oid_set */
|
||||
);
|
||||
|
||||
OM_uint32 gss_test_oid_set_member (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_OID, /* member */
|
||||
const gss_OID_set, /* set */
|
||||
int * /* present */
|
||||
);
|
||||
|
||||
OM_uint32 gss_canonicalize_name (
|
||||
OM_uint32 *, /* minor_status */
|
||||
const gss_name_t, /* input_name */
|
||||
const gss_OID, /* mech_type */
|
||||
gss_name_t * /* output_name */
|
||||
);
|
||||
|
||||
/*
|
||||
* Other extensions and helper functions.
|
||||
*/
|
||||
|
||||
OM_uint32 gss_set_cred_option
|
||||
(OM_uint32 *, /* minor status */
|
||||
gss_cred_id_t *, /* cred */
|
||||
const gss_OID, /* option to set */
|
||||
const gss_buffer_t /* option value */
|
||||
);
|
||||
|
||||
OM_uint32 gss_pname_to_uid
|
||||
(OM_uint32 *, /* minor status */
|
||||
const gss_name_t pname, /* principal name */
|
||||
const gss_OID mech, /* mechanism to query */
|
||||
uid_t *uidp /* pointer to UID for result */
|
||||
);
|
||||
|
||||
/*
|
||||
* On entry, *numgroups is set to the maximum number of groups to return. On exit, *numgroups is set to the actual number of groups returned.
|
||||
*/
|
||||
OM_uint32 gss_pname_to_unix_cred
|
||||
(OM_uint32 *, /* minor status */
|
||||
const gss_name_t pname, /* principal name */
|
||||
const gss_OID mech, /* mechanism to query */
|
||||
uid_t *uidp, /* pointer to UID for result */
|
||||
gid_t *gidp, /* pointer to GID for result */
|
||||
int *numgroups, /* number of groups */
|
||||
gid_t *groups /* pointer to group list */
|
||||
);
|
||||
|
||||
/*
|
||||
* Mbuf oriented message signing and encryption.
|
||||
*
|
||||
* Get_mic allocates an mbuf to hold the message checksum. Verify_mic
|
||||
* may modify the passed-in mic but will not free it.
|
||||
*
|
||||
* Wrap and unwrap
|
||||
* consume the message and generate a new mbuf chain with the
|
||||
* result. The original message is freed on error.
|
||||
*/
|
||||
struct mbuf;
|
||||
OM_uint32 gss_get_mic_mbuf
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
gss_qop_t, /* qop_req */
|
||||
struct mbuf *, /* message_buffer */
|
||||
struct mbuf ** /* message_token */
|
||||
);
|
||||
|
||||
OM_uint32 gss_verify_mic_mbuf
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
struct mbuf *, /* message_buffer */
|
||||
struct mbuf *, /* token_buffer */
|
||||
gss_qop_t * /* qop_state */
|
||||
);
|
||||
|
||||
OM_uint32 gss_wrap_mbuf
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
int, /* conf_req_flag */
|
||||
gss_qop_t, /* qop_req */
|
||||
struct mbuf **, /* message_buffer */
|
||||
int * /* conf_state */
|
||||
);
|
||||
|
||||
OM_uint32 gss_unwrap_mbuf
|
||||
(OM_uint32 *, /* minor_status */
|
||||
const gss_ctx_id_t, /* context_handle */
|
||||
struct mbuf **, /* message_buffer */
|
||||
int *, /* conf_state */
|
||||
gss_qop_t * /* qop_state */
|
||||
);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _KGSSAPI_GSSAPI_H_ */
|
67
sys/kgssapi/gssapi_impl.h
Normal file
67
sys/kgssapi/gssapi_impl.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include "gssd.h"
|
||||
|
||||
MALLOC_DECLARE(M_GSSAPI);
|
||||
|
||||
struct _gss_ctx_id_t {
|
||||
KOBJ_FIELDS;
|
||||
gssd_ctx_id_t handle;
|
||||
};
|
||||
|
||||
struct _gss_cred_id_t {
|
||||
gssd_cred_id_t handle;
|
||||
};
|
||||
|
||||
struct _gss_name_t {
|
||||
gssd_name_t handle;
|
||||
};
|
||||
|
||||
struct kgss_mech {
|
||||
LIST_ENTRY(kgss_mech) km_link;
|
||||
gss_OID km_mech_type;
|
||||
const char *km_mech_name;
|
||||
struct kobj_class *km_class;
|
||||
};
|
||||
LIST_HEAD(kgss_mech_list, kgss_mech);
|
||||
|
||||
extern CLIENT *kgss_gssd_handle;
|
||||
extern struct kgss_mech_list kgss_mechs;
|
||||
|
||||
int kgss_oid_equal(const gss_OID oid1, const gss_OID oid2);
|
||||
extern void kgss_install_mech(gss_OID mech_type, const char *name,
|
||||
struct kobj_class *cls);
|
||||
extern void kgss_uninstall_mech(gss_OID mech_type);
|
||||
extern gss_OID kgss_find_mech_by_name(const char *name);
|
||||
extern const char *kgss_find_mech_by_oid(const gss_OID oid);
|
||||
extern gss_ctx_id_t kgss_create_context(gss_OID mech_type);
|
||||
extern void kgss_delete_context(gss_ctx_id_t ctx, gss_buffer_t output_token);
|
||||
extern OM_uint32 kgss_transfer_context(gss_ctx_id_t ctx);
|
||||
extern void kgss_copy_buffer(const gss_buffer_t from, gss_buffer_t to);
|
265
sys/kgssapi/gssd.x
Normal file
265
sys/kgssapi/gssd.x
Normal file
@ -0,0 +1,265 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* $FreeBSD$ */
|
||||
|
||||
#ifdef RPC_HDR
|
||||
|
||||
%#ifdef _KERNEL
|
||||
%#include <kgssapi/gssapi.h>
|
||||
%#else
|
||||
%#include <gssapi/gssapi.h>
|
||||
%#endif
|
||||
|
||||
%extern bool_t xdr_gss_buffer_desc(XDR *xdrs, gss_buffer_desc *buf);
|
||||
%extern bool_t xdr_gss_OID_desc(XDR *xdrs, gss_OID_desc *oid);
|
||||
%extern bool_t xdr_gss_OID(XDR *xdrs, gss_OID *oidp);
|
||||
%extern bool_t xdr_gss_OID_set_desc(XDR *xdrs, gss_OID_set_desc *set);
|
||||
%extern bool_t xdr_gss_OID_set(XDR *xdrs, gss_OID_set *setp);
|
||||
%extern bool_t xdr_gss_channel_bindings_t(XDR *xdrs, gss_channel_bindings_t *chp);
|
||||
|
||||
#endif
|
||||
|
||||
typedef uint64_t gssd_ctx_id_t;
|
||||
typedef uint64_t gssd_cred_id_t;
|
||||
typedef uint64_t gssd_name_t;
|
||||
|
||||
struct init_sec_context_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
gssd_ctx_id_t ctx;
|
||||
gss_OID actual_mech_type;
|
||||
gss_buffer_desc output_token;
|
||||
uint32_t ret_flags;
|
||||
uint32_t time_rec;
|
||||
};
|
||||
|
||||
struct init_sec_context_args {
|
||||
uint32_t uid;
|
||||
gssd_cred_id_t cred;
|
||||
gssd_ctx_id_t ctx;
|
||||
gssd_name_t name;
|
||||
gss_OID mech_type;
|
||||
uint32_t req_flags;
|
||||
uint32_t time_req;
|
||||
gss_channel_bindings_t input_chan_bindings;
|
||||
gss_buffer_desc input_token;
|
||||
};
|
||||
|
||||
struct accept_sec_context_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
gssd_ctx_id_t ctx;
|
||||
gssd_name_t src_name;
|
||||
gss_OID mech_type;
|
||||
gss_buffer_desc output_token;
|
||||
uint32_t ret_flags;
|
||||
uint32_t time_rec;
|
||||
gssd_cred_id_t delegated_cred_handle;
|
||||
};
|
||||
|
||||
struct accept_sec_context_args {
|
||||
gssd_ctx_id_t ctx;
|
||||
gssd_cred_id_t cred;
|
||||
gss_buffer_desc input_token;
|
||||
gss_channel_bindings_t input_chan_bindings;
|
||||
};
|
||||
|
||||
struct delete_sec_context_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
gss_buffer_desc output_token;
|
||||
};
|
||||
|
||||
struct delete_sec_context_args {
|
||||
gssd_ctx_id_t ctx;
|
||||
};
|
||||
|
||||
enum sec_context_format {
|
||||
KGSS_HEIMDAL_0_6,
|
||||
KGSS_HEIMDAL_1_1
|
||||
};
|
||||
|
||||
struct export_sec_context_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
enum sec_context_format format;
|
||||
gss_buffer_desc interprocess_token;
|
||||
};
|
||||
|
||||
struct export_sec_context_args {
|
||||
gssd_ctx_id_t ctx;
|
||||
};
|
||||
|
||||
struct import_name_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
gssd_name_t output_name;
|
||||
};
|
||||
|
||||
struct import_name_args {
|
||||
gss_buffer_desc input_name_buffer;
|
||||
gss_OID input_name_type;
|
||||
};
|
||||
|
||||
struct canonicalize_name_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
gssd_name_t output_name;
|
||||
};
|
||||
|
||||
struct canonicalize_name_args {
|
||||
gssd_name_t input_name;
|
||||
gss_OID mech_type;
|
||||
};
|
||||
|
||||
struct export_name_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
gss_buffer_desc exported_name;
|
||||
};
|
||||
|
||||
struct export_name_args {
|
||||
gssd_name_t input_name;
|
||||
};
|
||||
|
||||
struct release_name_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
};
|
||||
|
||||
struct release_name_args {
|
||||
gssd_name_t input_name;
|
||||
};
|
||||
|
||||
struct pname_to_uid_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
uint32_t uid;
|
||||
uint32_t gid;
|
||||
uint32_t gidlist<>;
|
||||
};
|
||||
|
||||
struct pname_to_uid_args {
|
||||
gssd_name_t pname;
|
||||
gss_OID mech;
|
||||
};
|
||||
|
||||
struct acquire_cred_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
gssd_cred_id_t output_cred;
|
||||
gss_OID_set actual_mechs;
|
||||
uint32_t time_rec;
|
||||
};
|
||||
|
||||
struct acquire_cred_args {
|
||||
uint32_t uid;
|
||||
gssd_name_t desired_name;
|
||||
uint32_t time_req;
|
||||
gss_OID_set desired_mechs;
|
||||
int cred_usage;
|
||||
};
|
||||
|
||||
struct set_cred_option_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
};
|
||||
|
||||
struct set_cred_option_args {
|
||||
gssd_cred_id_t cred;
|
||||
gss_OID option_name;
|
||||
gss_buffer_desc option_value;
|
||||
};
|
||||
|
||||
struct release_cred_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
};
|
||||
|
||||
struct release_cred_args {
|
||||
gssd_cred_id_t cred;
|
||||
};
|
||||
|
||||
struct display_status_res {
|
||||
uint32_t major_status;
|
||||
uint32_t minor_status;
|
||||
uint32_t message_context;
|
||||
gss_buffer_desc status_string;
|
||||
};
|
||||
|
||||
struct display_status_args {
|
||||
uint32_t status_value;
|
||||
int status_type;
|
||||
gss_OID mech_type;
|
||||
uint32_t message_context;
|
||||
};
|
||||
|
||||
program GSSD {
|
||||
version GSSDVERS {
|
||||
void GSSD_NULL(void) = 0;
|
||||
|
||||
init_sec_context_res
|
||||
GSSD_INIT_SEC_CONTEXT(init_sec_context_args) = 1;
|
||||
|
||||
accept_sec_context_res
|
||||
GSSD_ACCEPT_SEC_CONTEXT(accept_sec_context_args) = 2;
|
||||
|
||||
delete_sec_context_res
|
||||
GSSD_DELETE_SEC_CONTEXT(delete_sec_context_args) = 3;
|
||||
|
||||
export_sec_context_res
|
||||
GSSD_EXPORT_SEC_CONTEXT(export_sec_context_args) = 4;
|
||||
|
||||
import_name_res
|
||||
GSSD_IMPORT_NAME(import_name_args) = 5;
|
||||
|
||||
canonicalize_name_res
|
||||
GSSD_CANONICALIZE_NAME(canonicalize_name_args) = 6;
|
||||
|
||||
export_name_res
|
||||
GSSD_EXPORT_NAME(export_name_args) = 7;
|
||||
|
||||
release_name_res
|
||||
GSSD_RELEASE_NAME(release_name_args) = 8;
|
||||
|
||||
pname_to_uid_res
|
||||
GSSD_PNAME_TO_UID(pname_to_uid_args) = 9;
|
||||
|
||||
acquire_cred_res
|
||||
GSSD_ACQUIRE_CRED(acquire_cred_args) = 10;
|
||||
|
||||
set_cred_option_res
|
||||
GSSD_SET_CRED_OPTION(set_cred_option_args) = 11;
|
||||
|
||||
release_cred_res
|
||||
GSSD_RELEASE_CRED(release_cred_args) = 12;
|
||||
|
||||
display_status_res
|
||||
GSSD_DISPLAY_STATUS(display_status_args) = 13;
|
||||
} = 1;
|
||||
} = 0x40677373;
|
244
sys/kgssapi/gssd_prot.c
Normal file
244
sys/kgssapi/gssd_prot.c
Normal file
@ -0,0 +1,244 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#ifdef _KERNEL
|
||||
#include <sys/malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpc_com.h>
|
||||
|
||||
#include "gssd.h"
|
||||
|
||||
bool_t
|
||||
xdr_gss_buffer_desc(XDR *xdrs, gss_buffer_desc *buf)
|
||||
{
|
||||
char *val;
|
||||
u_int len;
|
||||
|
||||
len = buf->length;
|
||||
val = buf->value;
|
||||
if (!xdr_bytes(xdrs, &val, &len, ~0))
|
||||
return (FALSE);
|
||||
buf->length = len;
|
||||
buf->value = val;
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_gss_OID_desc(XDR *xdrs, gss_OID_desc *oid)
|
||||
{
|
||||
char *val;
|
||||
u_int len;
|
||||
|
||||
len = oid->length;
|
||||
val = oid->elements;
|
||||
if (!xdr_bytes(xdrs, &val, &len, ~0))
|
||||
return (FALSE);
|
||||
oid->length = len;
|
||||
oid->elements = val;
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_gss_OID(XDR *xdrs, gss_OID *oidp)
|
||||
{
|
||||
gss_OID oid;
|
||||
bool_t is_null;
|
||||
|
||||
switch (xdrs->x_op) {
|
||||
case XDR_ENCODE:
|
||||
oid = *oidp;
|
||||
if (oid) {
|
||||
is_null = FALSE;
|
||||
if (!xdr_bool(xdrs, &is_null)
|
||||
|| !xdr_gss_OID_desc(xdrs, oid))
|
||||
return (FALSE);
|
||||
} else {
|
||||
is_null = TRUE;
|
||||
if (!xdr_bool(xdrs, &is_null))
|
||||
return (FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case XDR_DECODE:
|
||||
if (!xdr_bool(xdrs, &is_null))
|
||||
return (FALSE);
|
||||
if (is_null) {
|
||||
*oidp = GSS_C_NO_OID;
|
||||
} else {
|
||||
oid = mem_alloc(sizeof(gss_OID_desc));
|
||||
memset(oid, 0, sizeof(*oid));
|
||||
if (!xdr_gss_OID_desc(xdrs, oid))
|
||||
return (FALSE);
|
||||
*oidp = oid;
|
||||
}
|
||||
break;
|
||||
|
||||
case XDR_FREE:
|
||||
oid = *oidp;
|
||||
if (oid) {
|
||||
xdr_gss_OID_desc(xdrs, oid);
|
||||
mem_free(oid, sizeof(gss_OID_desc));
|
||||
}
|
||||
}
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_gss_OID_set_desc(XDR *xdrs, gss_OID_set_desc *set)
|
||||
{
|
||||
caddr_t addr;
|
||||
u_int len;
|
||||
|
||||
len = set->count;
|
||||
addr = (caddr_t) set->elements;
|
||||
if (!xdr_array(xdrs, &addr, &len, ~0, sizeof(gss_OID_desc),
|
||||
(xdrproc_t) xdr_gss_OID_desc))
|
||||
return (FALSE);
|
||||
set->count = len;
|
||||
set->elements = (gss_OID) addr;
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_gss_OID_set(XDR *xdrs, gss_OID_set *setp)
|
||||
{
|
||||
gss_OID_set set;
|
||||
bool_t is_null;
|
||||
|
||||
switch (xdrs->x_op) {
|
||||
case XDR_ENCODE:
|
||||
set = *setp;
|
||||
if (set) {
|
||||
is_null = FALSE;
|
||||
if (!xdr_bool(xdrs, &is_null)
|
||||
|| !xdr_gss_OID_set_desc(xdrs, set))
|
||||
return (FALSE);
|
||||
} else {
|
||||
is_null = TRUE;
|
||||
if (!xdr_bool(xdrs, &is_null))
|
||||
return (FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case XDR_DECODE:
|
||||
if (!xdr_bool(xdrs, &is_null))
|
||||
return (FALSE);
|
||||
if (is_null) {
|
||||
*setp = GSS_C_NO_OID_SET;
|
||||
} else {
|
||||
set = mem_alloc(sizeof(gss_OID_set_desc));
|
||||
memset(set, 0, sizeof(*set));
|
||||
if (!xdr_gss_OID_set_desc(xdrs, set))
|
||||
return (FALSE);
|
||||
*setp = set;
|
||||
}
|
||||
break;
|
||||
|
||||
case XDR_FREE:
|
||||
set = *setp;
|
||||
if (set) {
|
||||
xdr_gss_OID_set_desc(xdrs, set);
|
||||
mem_free(set, sizeof(gss_OID_set_desc));
|
||||
}
|
||||
}
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_gss_channel_bindings_t(XDR *xdrs, gss_channel_bindings_t *chp)
|
||||
{
|
||||
gss_channel_bindings_t ch;
|
||||
bool_t is_null;
|
||||
|
||||
switch (xdrs->x_op) {
|
||||
case XDR_ENCODE:
|
||||
ch = *chp;
|
||||
if (ch) {
|
||||
is_null = FALSE;
|
||||
if (!xdr_bool(xdrs, &is_null)
|
||||
|| !xdr_uint32_t(xdrs, &ch->initiator_addrtype)
|
||||
|| !xdr_gss_buffer_desc(xdrs,
|
||||
&ch->initiator_address)
|
||||
|| !xdr_uint32_t(xdrs, &ch->acceptor_addrtype)
|
||||
|| !xdr_gss_buffer_desc(xdrs,
|
||||
&ch->acceptor_address)
|
||||
|| !xdr_gss_buffer_desc(xdrs,
|
||||
&ch->application_data))
|
||||
return (FALSE);
|
||||
} else {
|
||||
is_null = TRUE;
|
||||
if (!xdr_bool(xdrs, &is_null))
|
||||
return (FALSE);
|
||||
}
|
||||
break;
|
||||
|
||||
case XDR_DECODE:
|
||||
if (!xdr_bool(xdrs, &is_null))
|
||||
return (FALSE);
|
||||
if (is_null) {
|
||||
*chp = GSS_C_NO_CHANNEL_BINDINGS;
|
||||
} else {
|
||||
ch = mem_alloc(sizeof(*ch));
|
||||
memset(ch, 0, sizeof(*ch));
|
||||
if (!xdr_uint32_t(xdrs, &ch->initiator_addrtype)
|
||||
|| !xdr_gss_buffer_desc(xdrs,
|
||||
&ch->initiator_address)
|
||||
|| !xdr_uint32_t(xdrs, &ch->acceptor_addrtype)
|
||||
|| !xdr_gss_buffer_desc(xdrs,
|
||||
&ch->acceptor_address)
|
||||
|| !xdr_gss_buffer_desc(xdrs,
|
||||
&ch->application_data))
|
||||
return (FALSE);
|
||||
*chp = ch;
|
||||
}
|
||||
break;
|
||||
|
||||
case XDR_FREE:
|
||||
ch = *chp;
|
||||
if (ch) {
|
||||
xdr_gss_buffer_desc(xdrs, &ch->initiator_address);
|
||||
xdr_gss_buffer_desc(xdrs, &ch->acceptor_address);
|
||||
xdr_gss_buffer_desc(xdrs, &ch->application_data);
|
||||
mem_free(ch, sizeof(*ch));
|
||||
}
|
||||
}
|
||||
|
||||
return (TRUE);
|
||||
}
|
1141
sys/kgssapi/gsstest.c
Normal file
1141
sys/kgssapi/gsstest.c
Normal file
File diff suppressed because it is too large
Load Diff
95
sys/kgssapi/kgss_if.m
Normal file
95
sys/kgssapi/kgss_if.m
Normal file
@ -0,0 +1,95 @@
|
||||
#-
|
||||
# Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
# Authors: Doug Rabson <dfr@rabson.org>
|
||||
# Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
#
|
||||
# $FreeBSD$
|
||||
|
||||
# Interface for the in-kernel part of a GSS-API mechanism
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include "gssd.h"
|
||||
|
||||
INTERFACE kgss;
|
||||
|
||||
METHOD void init {
|
||||
gss_ctx_id_t ctx;
|
||||
};
|
||||
|
||||
METHOD OM_uint32 import {
|
||||
gss_ctx_id_t ctx;
|
||||
enum sec_context_format format;
|
||||
const gss_buffer_t context_token;
|
||||
};
|
||||
|
||||
METHOD void delete {
|
||||
gss_ctx_id_t ctx;
|
||||
gss_buffer_t output_token;
|
||||
};
|
||||
|
||||
METHOD gss_OID mech_type {
|
||||
gss_ctx_id_t ctx;
|
||||
};
|
||||
|
||||
METHOD OM_uint32 get_mic {
|
||||
gss_ctx_id_t ctx;
|
||||
OM_uint32 *minor_status;
|
||||
gss_qop_t qop_req;
|
||||
struct mbuf *message_buffer;
|
||||
struct mbuf **message_token;
|
||||
};
|
||||
|
||||
METHOD OM_uint32 verify_mic {
|
||||
gss_ctx_id_t ctx;
|
||||
OM_uint32 *minor_status;
|
||||
struct mbuf *message_buffer;
|
||||
struct mbuf *token_buffer;
|
||||
gss_qop_t *qop_state;
|
||||
};
|
||||
|
||||
METHOD OM_uint32 wrap {
|
||||
gss_ctx_id_t ctx;
|
||||
OM_uint32 *minor_status;
|
||||
int conf_req_flag;
|
||||
gss_qop_t qop_req;
|
||||
struct mbuf **message_buffer;
|
||||
int *conf_state;
|
||||
};
|
||||
|
||||
METHOD OM_uint32 unwrap {
|
||||
gss_ctx_id_t ctx;
|
||||
OM_uint32 *minor_status;
|
||||
struct mbuf **message_buffer;
|
||||
int *conf_state;
|
||||
gss_qop_t *qop_state;
|
||||
};
|
||||
|
||||
METHOD OM_uint32 wrap_size_limit {
|
||||
gss_ctx_id_t ctx;
|
||||
OM_uint32 *minor_status;
|
||||
int conf_req_flag;
|
||||
gss_qop_t qop_req;
|
||||
OM_uint32 req_ouput_size;
|
||||
OM_uint32 *max_input_size;
|
||||
}
|
266
sys/kgssapi/krb5/kcrypto.c
Normal file
266
sys/kgssapi/krb5/kcrypto.c
Normal file
@ -0,0 +1,266 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "kcrypto.h"
|
||||
|
||||
static struct krb5_encryption_class *krb5_encryption_classes[] = {
|
||||
&krb5_des_encryption_class,
|
||||
&krb5_des3_encryption_class,
|
||||
&krb5_aes128_encryption_class,
|
||||
&krb5_aes256_encryption_class,
|
||||
&krb5_arcfour_encryption_class,
|
||||
&krb5_arcfour_56_encryption_class,
|
||||
NULL
|
||||
};
|
||||
|
||||
struct krb5_encryption_class *
|
||||
krb5_find_encryption_class(int etype)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; krb5_encryption_classes[i]; i++) {
|
||||
if (krb5_encryption_classes[i]->ec_type == etype)
|
||||
return (krb5_encryption_classes[i]);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
struct krb5_key_state *
|
||||
krb5_create_key(const struct krb5_encryption_class *ec)
|
||||
{
|
||||
struct krb5_key_state *ks;
|
||||
|
||||
ks = malloc(sizeof(struct krb5_key_state), M_GSSAPI, M_WAITOK);
|
||||
ks->ks_class = ec;
|
||||
refcount_init(&ks->ks_refs, 1);
|
||||
ks->ks_key = malloc(ec->ec_keylen, M_GSSAPI, M_WAITOK);
|
||||
ec->ec_init(ks);
|
||||
|
||||
return (ks);
|
||||
}
|
||||
|
||||
void
|
||||
krb5_free_key(struct krb5_key_state *ks)
|
||||
{
|
||||
|
||||
if (refcount_release(&ks->ks_refs)) {
|
||||
ks->ks_class->ec_destroy(ks);
|
||||
bzero(ks->ks_key, ks->ks_class->ec_keylen);
|
||||
free(ks->ks_key, M_GSSAPI);
|
||||
free(ks, M_GSSAPI);
|
||||
}
|
||||
}
|
||||
|
||||
static size_t
|
||||
gcd(size_t a, size_t b)
|
||||
{
|
||||
|
||||
if (b == 0)
|
||||
return (a);
|
||||
return gcd(b, a % b);
|
||||
}
|
||||
|
||||
static size_t
|
||||
lcm(size_t a, size_t b)
|
||||
{
|
||||
return ((a * b) / gcd(a, b));
|
||||
}
|
||||
|
||||
/*
|
||||
* Rotate right 13 of a variable precision number in 'in', storing the
|
||||
* result in 'out'. The number is assumed to be big-endian in memory
|
||||
* representation.
|
||||
*/
|
||||
static void
|
||||
krb5_rotate_right_13(uint8_t *out, uint8_t *in, size_t numlen)
|
||||
{
|
||||
uint32_t carry;
|
||||
size_t i;
|
||||
|
||||
/*
|
||||
* Special case when numlen == 1. A rotate right 13 of a
|
||||
* single byte number changes to a rotate right 5.
|
||||
*/
|
||||
if (numlen == 1) {
|
||||
carry = in[0] >> 5;
|
||||
out[0] = (in[0] << 3) | carry;
|
||||
return;
|
||||
}
|
||||
|
||||
carry = ((in[numlen - 2] & 31) << 8) | in[numlen - 1];
|
||||
for (i = 2; i < numlen; i++) {
|
||||
out[i] = ((in[i - 2] & 31) << 3) | (in[i - 1] >> 5);
|
||||
}
|
||||
out[1] = ((carry & 31) << 3) | (in[0] >> 5);
|
||||
out[0] = carry >> 5;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add two variable precision numbers in big-endian representation
|
||||
* using ones-complement arithmetic.
|
||||
*/
|
||||
static void
|
||||
krb5_ones_complement_add(uint8_t *out, const uint8_t *in, size_t len)
|
||||
{
|
||||
int n, i;
|
||||
|
||||
/*
|
||||
* First calculate the 2s complement sum, remembering the
|
||||
* carry.
|
||||
*/
|
||||
n = 0;
|
||||
for (i = len - 1; i >= 0; i--) {
|
||||
n = out[i] + in[i] + n;
|
||||
out[i] = n;
|
||||
n >>= 8;
|
||||
}
|
||||
/*
|
||||
* Then add back the carry.
|
||||
*/
|
||||
for (i = len - 1; n && i >= 0; i--) {
|
||||
n = out[i] + n;
|
||||
out[i] = n;
|
||||
n >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
krb5_n_fold(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen)
|
||||
{
|
||||
size_t tmplen;
|
||||
uint8_t *tmp;
|
||||
size_t i;
|
||||
uint8_t *p;
|
||||
|
||||
tmplen = lcm(inlen, outlen);
|
||||
tmp = malloc(tmplen, M_GSSAPI, M_WAITOK);
|
||||
|
||||
bcopy(in, tmp, inlen);
|
||||
for (i = inlen, p = tmp; i < tmplen; i += inlen, p += inlen) {
|
||||
krb5_rotate_right_13(p + inlen, p, inlen);
|
||||
}
|
||||
bzero(out, outlen);
|
||||
for (i = 0, p = tmp; i < tmplen; i += outlen, p += outlen) {
|
||||
krb5_ones_complement_add(out, p, outlen);
|
||||
}
|
||||
free(tmp, M_GSSAPI);
|
||||
}
|
||||
|
||||
struct krb5_key_state *
|
||||
krb5_derive_key(struct krb5_key_state *inkey,
|
||||
void *constant, size_t constantlen)
|
||||
{
|
||||
struct krb5_key_state *dk;
|
||||
const struct krb5_encryption_class *ec = inkey->ks_class;
|
||||
uint8_t *folded;
|
||||
uint8_t *bytes, *p, *q;
|
||||
struct mbuf *m;
|
||||
int randomlen, i;
|
||||
|
||||
/*
|
||||
* Expand the constant to blocklen bytes.
|
||||
*/
|
||||
folded = malloc(ec->ec_blocklen, M_GSSAPI, M_WAITOK);
|
||||
krb5_n_fold(folded, ec->ec_blocklen, constant, constantlen);
|
||||
|
||||
/*
|
||||
* Generate enough bytes for keybits rounded up to a multiple
|
||||
* of blocklen.
|
||||
*/
|
||||
randomlen = ((ec->ec_keybits/8 + ec->ec_blocklen - 1) / ec->ec_blocklen)
|
||||
* ec->ec_blocklen;
|
||||
bytes = malloc(randomlen, M_GSSAPI, M_WAITOK);
|
||||
MGET(m, M_WAITOK, MT_DATA);
|
||||
m->m_len = ec->ec_blocklen;
|
||||
for (i = 0, p = bytes, q = folded; i < randomlen;
|
||||
q = p, i += ec->ec_blocklen, p += ec->ec_blocklen) {
|
||||
bcopy(q, m->m_data, ec->ec_blocklen);
|
||||
krb5_encrypt(inkey, m, 0, ec->ec_blocklen, NULL, 0);
|
||||
bcopy(m->m_data, p, ec->ec_blocklen);
|
||||
}
|
||||
m_free(m);
|
||||
|
||||
dk = krb5_create_key(ec);
|
||||
krb5_random_to_key(dk, bytes);
|
||||
|
||||
free(folded, M_GSSAPI);
|
||||
free(bytes, M_GSSAPI);
|
||||
|
||||
return (dk);
|
||||
}
|
||||
|
||||
static struct krb5_key_state *
|
||||
krb5_get_usage_key(struct krb5_key_state *basekey, int usage, int which)
|
||||
{
|
||||
const struct krb5_encryption_class *ec = basekey->ks_class;
|
||||
|
||||
if (ec->ec_flags & EC_DERIVED_KEYS) {
|
||||
uint8_t constant[5];
|
||||
|
||||
constant[0] = usage >> 24;
|
||||
constant[1] = usage >> 16;
|
||||
constant[2] = usage >> 8;
|
||||
constant[3] = usage;
|
||||
constant[4] = which;
|
||||
return (krb5_derive_key(basekey, constant, 5));
|
||||
} else {
|
||||
refcount_acquire(&basekey->ks_refs);
|
||||
return (basekey);
|
||||
}
|
||||
}
|
||||
|
||||
struct krb5_key_state *
|
||||
krb5_get_encryption_key(struct krb5_key_state *basekey, int usage)
|
||||
{
|
||||
|
||||
return (krb5_get_usage_key(basekey, usage, 0xaa));
|
||||
}
|
||||
|
||||
struct krb5_key_state *
|
||||
krb5_get_integrity_key(struct krb5_key_state *basekey, int usage)
|
||||
{
|
||||
|
||||
return (krb5_get_usage_key(basekey, usage, 0x55));
|
||||
}
|
||||
|
||||
struct krb5_key_state *
|
||||
krb5_get_checksum_key(struct krb5_key_state *basekey, int usage)
|
||||
{
|
||||
|
||||
return (krb5_get_usage_key(basekey, usage, 0x99));
|
||||
}
|
154
sys/kgssapi/krb5/kcrypto.h
Normal file
154
sys/kgssapi/krb5/kcrypto.h
Normal file
@ -0,0 +1,154 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/_iovec.h>
|
||||
|
||||
#define ETYPE_NULL 0
|
||||
#define ETYPE_DES_CBC_CRC 1
|
||||
#define ETYPE_DES_CBC_MD4 2
|
||||
#define ETYPE_DES_CBC_MD5 3
|
||||
#define ETYPE_DES3_CBC_MD5 5
|
||||
#define ETYPE_OLD_DES3_CBC_SHA1 7
|
||||
#define ETYPE_DES3_CBC_SHA1 16
|
||||
#define ETYPE_AES128_CTS_HMAC_SHA1_96 17
|
||||
#define ETYPE_AES256_CTS_HMAC_SHA1_96 18
|
||||
#define ETYPE_ARCFOUR_HMAC_MD5 23
|
||||
#define ETYPE_ARCFOUR_HMAC_MD5_56 24
|
||||
|
||||
/*
|
||||
* Key usages for des3-cbc-sha1 tokens
|
||||
*/
|
||||
#define KG_USAGE_SEAL 22
|
||||
#define KG_USAGE_SIGN 23
|
||||
#define KG_USAGE_SEQ 24
|
||||
|
||||
/*
|
||||
* Key usages for RFC4121 tokens
|
||||
*/
|
||||
#define KG_USAGE_ACCEPTOR_SEAL 22
|
||||
#define KG_USAGE_ACCEPTOR_SIGN 23
|
||||
#define KG_USAGE_INITIATOR_SEAL 24
|
||||
#define KG_USAGE_INITIATOR_SIGN 25
|
||||
|
||||
struct krb5_key_state;
|
||||
|
||||
typedef void init_func(struct krb5_key_state *ks);
|
||||
typedef void destroy_func(struct krb5_key_state *ks);
|
||||
typedef void set_key_func(struct krb5_key_state *ks, const void *in);
|
||||
typedef void random_to_key_func(struct krb5_key_state *ks, const void *in);
|
||||
typedef void encrypt_func(const struct krb5_key_state *ks,
|
||||
struct mbuf *inout, size_t skip, size_t len, void *ivec, size_t ivlen);
|
||||
typedef void checksum_func(const struct krb5_key_state *ks, int usage,
|
||||
struct mbuf *inout, size_t skip, size_t inlen, size_t outlen);
|
||||
|
||||
struct krb5_encryption_class {
|
||||
const char *ec_name;
|
||||
int ec_type;
|
||||
int ec_flags;
|
||||
#define EC_DERIVED_KEYS 1
|
||||
size_t ec_blocklen;
|
||||
size_t ec_msgblocklen;
|
||||
size_t ec_checksumlen;
|
||||
size_t ec_keybits; /* key length in bits */
|
||||
size_t ec_keylen; /* size of key in memory */
|
||||
init_func *ec_init;
|
||||
destroy_func *ec_destroy;
|
||||
set_key_func *ec_set_key;
|
||||
random_to_key_func *ec_random_to_key;
|
||||
encrypt_func *ec_encrypt;
|
||||
encrypt_func *ec_decrypt;
|
||||
checksum_func *ec_checksum;
|
||||
};
|
||||
|
||||
struct krb5_key_state {
|
||||
const struct krb5_encryption_class *ks_class;
|
||||
volatile u_int ks_refs;
|
||||
void *ks_key;
|
||||
void *ks_priv;
|
||||
};
|
||||
|
||||
extern struct krb5_encryption_class krb5_des_encryption_class;
|
||||
extern struct krb5_encryption_class krb5_des3_encryption_class;
|
||||
extern struct krb5_encryption_class krb5_aes128_encryption_class;
|
||||
extern struct krb5_encryption_class krb5_aes256_encryption_class;
|
||||
extern struct krb5_encryption_class krb5_arcfour_encryption_class;
|
||||
extern struct krb5_encryption_class krb5_arcfour_56_encryption_class;
|
||||
|
||||
static __inline void
|
||||
krb5_set_key(struct krb5_key_state *ks, const void *keydata)
|
||||
{
|
||||
|
||||
ks->ks_class->ec_set_key(ks, keydata);
|
||||
}
|
||||
|
||||
static __inline void
|
||||
krb5_random_to_key(struct krb5_key_state *ks, const void *keydata)
|
||||
{
|
||||
|
||||
ks->ks_class->ec_random_to_key(ks, keydata);
|
||||
}
|
||||
|
||||
static __inline void
|
||||
krb5_encrypt(const struct krb5_key_state *ks, struct mbuf *inout,
|
||||
size_t skip, size_t len, void *ivec, size_t ivlen)
|
||||
{
|
||||
|
||||
ks->ks_class->ec_encrypt(ks, inout, skip, len, ivec, ivlen);
|
||||
}
|
||||
|
||||
static __inline void
|
||||
krb5_decrypt(const struct krb5_key_state *ks, struct mbuf *inout,
|
||||
size_t skip, size_t len, void *ivec, size_t ivlen)
|
||||
{
|
||||
|
||||
ks->ks_class->ec_decrypt(ks, inout, skip, len, ivec, ivlen);
|
||||
}
|
||||
|
||||
static __inline void
|
||||
krb5_checksum(const struct krb5_key_state *ks, int usage,
|
||||
struct mbuf *inout, size_t skip, size_t inlen, size_t outlen)
|
||||
{
|
||||
|
||||
ks->ks_class->ec_checksum(ks, usage, inout, skip, inlen, outlen);
|
||||
}
|
||||
|
||||
extern struct krb5_encryption_class *
|
||||
krb5_find_encryption_class(int etype);
|
||||
extern struct krb5_key_state *
|
||||
krb5_create_key(const struct krb5_encryption_class *ec);
|
||||
extern void krb5_free_key(struct krb5_key_state *ks);
|
||||
extern struct krb5_key_state *
|
||||
krb5_derive_key(struct krb5_key_state *inkey,
|
||||
void *constant, size_t constantlen);
|
||||
extern struct krb5_key_state *
|
||||
krb5_get_encryption_key(struct krb5_key_state *basekey, int usage);
|
||||
extern struct krb5_key_state *
|
||||
krb5_get_integrity_key(struct krb5_key_state *basekey, int usage);
|
||||
extern struct krb5_key_state *
|
||||
krb5_get_checksum_key(struct krb5_key_state *basekey, int usage);
|
384
sys/kgssapi/krb5/kcrypto_aes.c
Normal file
384
sys/kgssapi/krb5/kcrypto_aes.c
Normal file
@ -0,0 +1,384 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <opencrypto/cryptodev.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "kcrypto.h"
|
||||
|
||||
struct aes_state {
|
||||
struct mtx as_lock;
|
||||
uint64_t as_session;
|
||||
};
|
||||
|
||||
static void
|
||||
aes_init(struct krb5_key_state *ks)
|
||||
{
|
||||
struct aes_state *as;
|
||||
|
||||
as = malloc(sizeof(struct aes_state), M_GSSAPI, M_WAITOK|M_ZERO);
|
||||
mtx_init(&as->as_lock, "gss aes lock", NULL, MTX_DEF);
|
||||
ks->ks_priv = as;
|
||||
}
|
||||
|
||||
static void
|
||||
aes_destroy(struct krb5_key_state *ks)
|
||||
{
|
||||
struct aes_state *as = ks->ks_priv;
|
||||
|
||||
if (as->as_session)
|
||||
crypto_freesession(as->as_session);
|
||||
mtx_destroy(&as->as_lock);
|
||||
free(ks->ks_priv, M_GSSAPI);
|
||||
}
|
||||
|
||||
static void
|
||||
aes_set_key(struct krb5_key_state *ks, const void *in)
|
||||
{
|
||||
void *kp = ks->ks_key;
|
||||
struct aes_state *as = ks->ks_priv;
|
||||
struct cryptoini cri[2];
|
||||
|
||||
if (kp != in)
|
||||
bcopy(in, kp, ks->ks_class->ec_keylen);
|
||||
|
||||
if (as->as_session)
|
||||
crypto_freesession(as->as_session);
|
||||
|
||||
bzero(cri, sizeof(cri));
|
||||
|
||||
/*
|
||||
* We only want the first 96 bits of the HMAC.
|
||||
*/
|
||||
cri[0].cri_alg = CRYPTO_SHA1_HMAC;
|
||||
cri[0].cri_klen = ks->ks_class->ec_keybits;
|
||||
cri[0].cri_mlen = 12;
|
||||
cri[0].cri_key = ks->ks_key;
|
||||
cri[0].cri_next = &cri[1];
|
||||
|
||||
cri[1].cri_alg = CRYPTO_AES_CBC;
|
||||
cri[1].cri_klen = ks->ks_class->ec_keybits;
|
||||
cri[1].cri_mlen = 0;
|
||||
cri[1].cri_key = ks->ks_key;
|
||||
cri[1].cri_next = NULL;
|
||||
|
||||
crypto_newsession(&as->as_session, cri,
|
||||
CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE);
|
||||
}
|
||||
|
||||
static void
|
||||
aes_random_to_key(struct krb5_key_state *ks, const void *in)
|
||||
{
|
||||
|
||||
aes_set_key(ks, in);
|
||||
}
|
||||
|
||||
static int
|
||||
aes_crypto_cb(struct cryptop *crp)
|
||||
{
|
||||
int error;
|
||||
struct aes_state *as = (struct aes_state *) crp->crp_opaque;
|
||||
|
||||
if (CRYPTO_SESID2CAPS(as->as_session) & CRYPTOCAP_F_SYNC)
|
||||
return (0);
|
||||
|
||||
error = crp->crp_etype;
|
||||
if (error == EAGAIN)
|
||||
error = crypto_dispatch(crp);
|
||||
mtx_lock(&as->as_lock);
|
||||
if (error || (crp->crp_flags & CRYPTO_F_DONE))
|
||||
wakeup(crp);
|
||||
mtx_unlock(&as->as_lock);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
aes_encrypt_1(const struct krb5_key_state *ks, int buftype, void *buf,
|
||||
size_t skip, size_t len, void *ivec, int encdec)
|
||||
{
|
||||
struct aes_state *as = ks->ks_priv;
|
||||
struct cryptop *crp;
|
||||
struct cryptodesc *crd;
|
||||
int error;
|
||||
|
||||
crp = crypto_getreq(1);
|
||||
crd = crp->crp_desc;
|
||||
|
||||
crd->crd_skip = skip;
|
||||
crd->crd_len = len;
|
||||
crd->crd_flags = CRD_F_IV_EXPLICIT | CRD_F_IV_PRESENT | encdec;
|
||||
if (ivec) {
|
||||
bcopy(ivec, crd->crd_iv, 16);
|
||||
} else {
|
||||
bzero(crd->crd_iv, 16);
|
||||
}
|
||||
crd->crd_next = NULL;
|
||||
crd->crd_alg = CRYPTO_AES_CBC;
|
||||
|
||||
crp->crp_sid = as->as_session;
|
||||
crp->crp_flags = buftype | CRYPTO_F_CBIFSYNC;
|
||||
crp->crp_buf = buf;
|
||||
crp->crp_opaque = (void *) as;
|
||||
crp->crp_callback = aes_crypto_cb;
|
||||
|
||||
error = crypto_dispatch(crp);
|
||||
|
||||
if ((CRYPTO_SESID2CAPS(as->as_session) & CRYPTOCAP_F_SYNC) == 0) {
|
||||
mtx_lock(&as->as_lock);
|
||||
if (!error && !(crp->crp_flags & CRYPTO_F_DONE))
|
||||
error = msleep(crp, &as->as_lock, 0, "gssaes", 0);
|
||||
mtx_unlock(&as->as_lock);
|
||||
}
|
||||
|
||||
crypto_freereq(crp);
|
||||
}
|
||||
|
||||
static void
|
||||
aes_encrypt(const struct krb5_key_state *ks, struct mbuf *inout,
|
||||
size_t skip, size_t len, void *ivec, size_t ivlen)
|
||||
{
|
||||
size_t blocklen = 16, plen;
|
||||
struct {
|
||||
uint8_t cn_1[16], cn[16];
|
||||
} last2;
|
||||
int i, off;
|
||||
|
||||
/*
|
||||
* AES encryption with cyphertext stealing:
|
||||
*
|
||||
* CTSencrypt(P[0], ..., P[n], IV, K):
|
||||
* len = length(P[n])
|
||||
* (C[0], ..., C[n-2], E[n-1]) =
|
||||
* CBCencrypt(P[0], ..., P[n-1], IV, K)
|
||||
* P = pad(P[n], 0, blocksize)
|
||||
* E[n] = CBCencrypt(P, E[n-1], K);
|
||||
* C[n-1] = E[n]
|
||||
* C[n] = E[n-1]{0..len-1}
|
||||
*/
|
||||
plen = len % blocklen;
|
||||
if (len == blocklen) {
|
||||
/*
|
||||
* Note: caller will ensure len >= blocklen.
|
||||
*/
|
||||
aes_encrypt_1(ks, CRYPTO_F_IMBUF, inout, skip, len, ivec,
|
||||
CRD_F_ENCRYPT);
|
||||
} else if (plen == 0) {
|
||||
/*
|
||||
* This is equivalent to CBC mode followed by swapping
|
||||
* the last two blocks. We assume that neither of the
|
||||
* last two blocks cross iov boundaries.
|
||||
*/
|
||||
aes_encrypt_1(ks, CRYPTO_F_IMBUF, inout, skip, len, ivec,
|
||||
CRD_F_ENCRYPT);
|
||||
off = skip + len - 2 * blocklen;
|
||||
m_copydata(inout, off, 2 * blocklen, (void*) &last2);
|
||||
m_copyback(inout, off, blocklen, last2.cn);
|
||||
m_copyback(inout, off + blocklen, blocklen, last2.cn_1);
|
||||
} else {
|
||||
/*
|
||||
* This is the difficult case. We encrypt all but the
|
||||
* last partial block first. We then create a padded
|
||||
* copy of the last block and encrypt that using the
|
||||
* second to last encrypted block as IV. Once we have
|
||||
* the encrypted versions of the last two blocks, we
|
||||
* reshuffle to create the final result.
|
||||
*/
|
||||
aes_encrypt_1(ks, CRYPTO_F_IMBUF, inout, skip, len - plen,
|
||||
ivec, CRD_F_ENCRYPT);
|
||||
|
||||
/*
|
||||
* Copy out the last two blocks, pad the last block
|
||||
* and encrypt it. Rearrange to get the final
|
||||
* result. The cyphertext for cn_1 is in cn. The
|
||||
* cyphertext for cn is the first plen bytes of what
|
||||
* is in cn_1 now.
|
||||
*/
|
||||
off = skip + len - blocklen - plen;
|
||||
m_copydata(inout, off, blocklen + plen, (void*) &last2);
|
||||
for (i = plen; i < blocklen; i++)
|
||||
last2.cn[i] = 0;
|
||||
aes_encrypt_1(ks, 0, last2.cn, 0, blocklen, last2.cn_1,
|
||||
CRD_F_ENCRYPT);
|
||||
m_copyback(inout, off, blocklen, last2.cn);
|
||||
m_copyback(inout, off + blocklen, plen, last2.cn_1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
aes_decrypt(const struct krb5_key_state *ks, struct mbuf *inout,
|
||||
size_t skip, size_t len, void *ivec, size_t ivlen)
|
||||
{
|
||||
size_t blocklen = 16, plen;
|
||||
struct {
|
||||
uint8_t cn_1[16], cn[16];
|
||||
} last2;
|
||||
int i, off, t;
|
||||
|
||||
/*
|
||||
* AES decryption with cyphertext stealing:
|
||||
*
|
||||
* CTSencrypt(C[0], ..., C[n], IV, K):
|
||||
* len = length(C[n])
|
||||
* E[n] = C[n-1]
|
||||
* X = decrypt(E[n], K)
|
||||
* P[n] = (X ^ C[n]){0..len-1}
|
||||
* E[n-1] = {C[n,0],...,C[n,len-1],X[len],...,X[blocksize-1]}
|
||||
* (P[0],...,P[n-1]) = CBCdecrypt(C[0],...,C[n-2],E[n-1], IV, K)
|
||||
*/
|
||||
plen = len % blocklen;
|
||||
if (len == blocklen) {
|
||||
/*
|
||||
* Note: caller will ensure len >= blocklen.
|
||||
*/
|
||||
aes_encrypt_1(ks, CRYPTO_F_IMBUF, inout, skip, len, ivec, 0);
|
||||
} else if (plen == 0) {
|
||||
/*
|
||||
* This is equivalent to CBC mode followed by swapping
|
||||
* the last two blocks.
|
||||
*/
|
||||
off = skip + len - 2 * blocklen;
|
||||
m_copydata(inout, off, 2 * blocklen, (void*) &last2);
|
||||
m_copyback(inout, off, blocklen, last2.cn);
|
||||
m_copyback(inout, off + blocklen, blocklen, last2.cn_1);
|
||||
aes_encrypt_1(ks, CRYPTO_F_IMBUF, inout, skip, len, ivec, 0);
|
||||
} else {
|
||||
/*
|
||||
* This is the difficult case. We first decrypt the
|
||||
* second to last block with a zero IV to make X. The
|
||||
* plaintext for the last block is the XOR of X and
|
||||
* the last cyphertext block.
|
||||
*
|
||||
* We derive a new cypher text for the second to last
|
||||
* block by mixing the unused bytes of X with the last
|
||||
* cyphertext block. The result of that can be
|
||||
* decrypted with the rest in CBC mode.
|
||||
*/
|
||||
off = skip + len - plen - blocklen;
|
||||
aes_encrypt_1(ks, CRYPTO_F_IMBUF, inout, off, blocklen,
|
||||
NULL, 0);
|
||||
m_copydata(inout, off, blocklen + plen, (void*) &last2);
|
||||
|
||||
for (i = 0; i < plen; i++) {
|
||||
t = last2.cn[i];
|
||||
last2.cn[i] ^= last2.cn_1[i];
|
||||
last2.cn_1[i] = t;
|
||||
}
|
||||
|
||||
m_copyback(inout, off, blocklen + plen, (void*) &last2);
|
||||
aes_encrypt_1(ks, CRYPTO_F_IMBUF, inout, skip, len - plen,
|
||||
ivec, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
aes_checksum(const struct krb5_key_state *ks, int usage,
|
||||
struct mbuf *inout, size_t skip, size_t inlen, size_t outlen)
|
||||
{
|
||||
struct aes_state *as = ks->ks_priv;
|
||||
struct cryptop *crp;
|
||||
struct cryptodesc *crd;
|
||||
int error;
|
||||
|
||||
crp = crypto_getreq(1);
|
||||
crd = crp->crp_desc;
|
||||
|
||||
crd->crd_skip = skip;
|
||||
crd->crd_len = inlen;
|
||||
crd->crd_inject = skip + inlen;
|
||||
crd->crd_flags = 0;
|
||||
crd->crd_next = NULL;
|
||||
crd->crd_alg = CRYPTO_SHA1_HMAC;
|
||||
|
||||
crp->crp_sid = as->as_session;
|
||||
crp->crp_ilen = inlen;
|
||||
crp->crp_olen = 12;
|
||||
crp->crp_etype = 0;
|
||||
crp->crp_flags = CRYPTO_F_IMBUF | CRYPTO_F_CBIFSYNC;
|
||||
crp->crp_buf = (void *) inout;
|
||||
crp->crp_opaque = (void *) as;
|
||||
crp->crp_callback = aes_crypto_cb;
|
||||
|
||||
error = crypto_dispatch(crp);
|
||||
|
||||
if ((CRYPTO_SESID2CAPS(as->as_session) & CRYPTOCAP_F_SYNC) == 0) {
|
||||
mtx_lock(&as->as_lock);
|
||||
if (!error && !(crp->crp_flags & CRYPTO_F_DONE))
|
||||
error = msleep(crp, &as->as_lock, 0, "gssaes", 0);
|
||||
mtx_unlock(&as->as_lock);
|
||||
}
|
||||
|
||||
crypto_freereq(crp);
|
||||
}
|
||||
|
||||
struct krb5_encryption_class krb5_aes128_encryption_class = {
|
||||
"aes128-cts-hmac-sha1-96", /* name */
|
||||
ETYPE_AES128_CTS_HMAC_SHA1_96, /* etype */
|
||||
EC_DERIVED_KEYS, /* flags */
|
||||
16, /* blocklen */
|
||||
1, /* msgblocklen */
|
||||
12, /* checksumlen */
|
||||
128, /* keybits */
|
||||
16, /* keylen */
|
||||
aes_init,
|
||||
aes_destroy,
|
||||
aes_set_key,
|
||||
aes_random_to_key,
|
||||
aes_encrypt,
|
||||
aes_decrypt,
|
||||
aes_checksum
|
||||
};
|
||||
|
||||
struct krb5_encryption_class krb5_aes256_encryption_class = {
|
||||
"aes256-cts-hmac-sha1-96", /* name */
|
||||
ETYPE_AES256_CTS_HMAC_SHA1_96, /* etype */
|
||||
EC_DERIVED_KEYS, /* flags */
|
||||
16, /* blocklen */
|
||||
1, /* msgblocklen */
|
||||
12, /* checksumlen */
|
||||
256, /* keybits */
|
||||
32, /* keylen */
|
||||
aes_init,
|
||||
aes_destroy,
|
||||
aes_set_key,
|
||||
aes_random_to_key,
|
||||
aes_encrypt,
|
||||
aes_decrypt,
|
||||
aes_checksum
|
||||
};
|
220
sys/kgssapi/krb5/kcrypto_arcfour.c
Normal file
220
sys/kgssapi/krb5/kcrypto_arcfour.c
Normal file
@ -0,0 +1,220 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/md5.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <crypto/rc4/rc4.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "kcrypto.h"
|
||||
|
||||
static void
|
||||
arcfour_init(struct krb5_key_state *ks)
|
||||
{
|
||||
|
||||
ks->ks_priv = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
arcfour_destroy(struct krb5_key_state *ks)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
arcfour_set_key(struct krb5_key_state *ks, const void *in)
|
||||
{
|
||||
void *kp = ks->ks_key;
|
||||
|
||||
if (kp != in)
|
||||
bcopy(in, kp, 16);
|
||||
}
|
||||
|
||||
static void
|
||||
arcfour_random_to_key(struct krb5_key_state *ks, const void *in)
|
||||
{
|
||||
|
||||
arcfour_set_key(ks, in);
|
||||
}
|
||||
|
||||
static void
|
||||
arcfour_hmac(uint8_t *key, uint8_t *data, size_t datalen,
|
||||
uint8_t *result)
|
||||
{
|
||||
uint8_t buf[64];
|
||||
MD5_CTX md5;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
buf[i] = key[i] ^ 0x36;
|
||||
for (; i < 64; i++)
|
||||
buf[i] = 0x36;
|
||||
|
||||
MD5Init(&md5);
|
||||
MD5Update(&md5, buf, 64);
|
||||
MD5Update(&md5, data, datalen);
|
||||
MD5Final(result, &md5);
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
buf[i] = key[i] ^ 0x5c;
|
||||
for (; i < 64; i++)
|
||||
buf[i] = 0x5c;
|
||||
|
||||
MD5Init(&md5);
|
||||
MD5Update(&md5, buf, 64);
|
||||
MD5Update(&md5, result, 16);
|
||||
MD5Final(result, &md5);
|
||||
}
|
||||
|
||||
static void
|
||||
arcfour_derive_key(const struct krb5_key_state *ks, uint32_t usage,
|
||||
uint8_t *newkey)
|
||||
{
|
||||
uint8_t t[4];
|
||||
|
||||
t[0] = (usage >> 24);
|
||||
t[1] = (usage >> 16);
|
||||
t[2] = (usage >> 8);
|
||||
t[3] = (usage >> 0);
|
||||
if (ks->ks_class->ec_type == ETYPE_ARCFOUR_HMAC_MD5_56) {
|
||||
uint8_t L40[14] = "fortybits";
|
||||
bcopy(t, L40 + 10, 4);
|
||||
arcfour_hmac(ks->ks_key, L40, 14, newkey);
|
||||
memset(newkey + 7, 0xab, 9);
|
||||
} else {
|
||||
arcfour_hmac(ks->ks_key, t, 4, newkey);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
rc4_crypt_int(void *rs, void *buf, u_int len)
|
||||
{
|
||||
|
||||
rc4_crypt(rs, buf, buf, len);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
arcfour_encrypt(const struct krb5_key_state *ks, struct mbuf *inout,
|
||||
size_t skip, size_t len, void *ivec, size_t ivlen)
|
||||
{
|
||||
struct rc4_state rs;
|
||||
uint8_t newkey[16];
|
||||
|
||||
arcfour_derive_key(ks, 0, newkey);
|
||||
|
||||
/*
|
||||
* If we have an IV, then generate a new key from it using HMAC.
|
||||
*/
|
||||
if (ivec) {
|
||||
uint8_t kk[16];
|
||||
arcfour_hmac(newkey, ivec, ivlen, kk);
|
||||
rc4_init(&rs, kk, 16);
|
||||
} else {
|
||||
rc4_init(&rs, newkey, 16);
|
||||
}
|
||||
|
||||
m_apply(inout, skip, len, rc4_crypt_int, &rs);
|
||||
}
|
||||
|
||||
static int
|
||||
MD5Update_int(void *ctx, void *buf, u_int len)
|
||||
{
|
||||
|
||||
MD5Update(ctx, buf, len);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
arcfour_checksum(const struct krb5_key_state *ks, int usage,
|
||||
struct mbuf *inout, size_t skip, size_t inlen, size_t outlen)
|
||||
{
|
||||
MD5_CTX md5;
|
||||
uint8_t Ksign[16];
|
||||
uint8_t t[4];
|
||||
uint8_t sgn_cksum[16];
|
||||
|
||||
arcfour_hmac(ks->ks_key, "signaturekey", 13, Ksign);
|
||||
|
||||
t[0] = usage >> 0;
|
||||
t[1] = usage >> 8;
|
||||
t[2] = usage >> 16;
|
||||
t[3] = usage >> 24;
|
||||
|
||||
MD5Init(&md5);
|
||||
MD5Update(&md5, t, 4);
|
||||
m_apply(inout, skip, inlen, MD5Update_int, &md5);
|
||||
MD5Final(sgn_cksum, &md5);
|
||||
|
||||
arcfour_hmac(Ksign, sgn_cksum, 16, sgn_cksum);
|
||||
m_copyback(inout, skip + inlen, outlen, sgn_cksum);
|
||||
}
|
||||
|
||||
struct krb5_encryption_class krb5_arcfour_encryption_class = {
|
||||
"arcfour-hmac-md5", /* name */
|
||||
ETYPE_ARCFOUR_HMAC_MD5, /* etype */
|
||||
0, /* flags */
|
||||
1, /* blocklen */
|
||||
1, /* msgblocklen */
|
||||
8, /* checksumlen */
|
||||
128, /* keybits */
|
||||
16, /* keylen */
|
||||
arcfour_init,
|
||||
arcfour_destroy,
|
||||
arcfour_set_key,
|
||||
arcfour_random_to_key,
|
||||
arcfour_encrypt,
|
||||
arcfour_encrypt,
|
||||
arcfour_checksum
|
||||
};
|
||||
|
||||
struct krb5_encryption_class krb5_arcfour_56_encryption_class = {
|
||||
"arcfour-hmac-md5-56", /* name */
|
||||
ETYPE_ARCFOUR_HMAC_MD5_56, /* etype */
|
||||
0, /* flags */
|
||||
1, /* blocklen */
|
||||
1, /* msgblocklen */
|
||||
8, /* checksumlen */
|
||||
128, /* keybits */
|
||||
16, /* keylen */
|
||||
arcfour_init,
|
||||
arcfour_destroy,
|
||||
arcfour_set_key,
|
||||
arcfour_random_to_key,
|
||||
arcfour_encrypt,
|
||||
arcfour_encrypt,
|
||||
arcfour_checksum
|
||||
};
|
262
sys/kgssapi/krb5/kcrypto_des.c
Normal file
262
sys/kgssapi/krb5/kcrypto_des.c
Normal file
@ -0,0 +1,262 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/md5.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <crypto/des/des.h>
|
||||
#include <opencrypto/cryptodev.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "kcrypto.h"
|
||||
|
||||
struct des1_state {
|
||||
struct mtx ds_lock;
|
||||
uint64_t ds_session;
|
||||
};
|
||||
|
||||
static void
|
||||
des1_init(struct krb5_key_state *ks)
|
||||
{
|
||||
struct des1_state *ds;
|
||||
|
||||
ds = malloc(sizeof(struct des1_state), M_GSSAPI, M_WAITOK|M_ZERO);
|
||||
mtx_init(&ds->ds_lock, "gss des lock", NULL, MTX_DEF);
|
||||
ks->ks_priv = ds;
|
||||
}
|
||||
|
||||
static void
|
||||
des1_destroy(struct krb5_key_state *ks)
|
||||
{
|
||||
struct des1_state *ds = ks->ks_priv;
|
||||
|
||||
if (ds->ds_session)
|
||||
crypto_freesession(ds->ds_session);
|
||||
mtx_destroy(&ds->ds_lock);
|
||||
free(ks->ks_priv, M_GSSAPI);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
des1_set_key(struct krb5_key_state *ks, const void *in)
|
||||
{
|
||||
void *kp = ks->ks_key;
|
||||
struct des1_state *ds = ks->ks_priv;
|
||||
struct cryptoini cri[1];
|
||||
|
||||
if (kp != in)
|
||||
bcopy(in, kp, ks->ks_class->ec_keylen);
|
||||
|
||||
if (ds->ds_session)
|
||||
crypto_freesession(ds->ds_session);
|
||||
|
||||
bzero(cri, sizeof(cri));
|
||||
|
||||
cri[0].cri_alg = CRYPTO_DES_CBC;
|
||||
cri[0].cri_klen = 64;
|
||||
cri[0].cri_mlen = 0;
|
||||
cri[0].cri_key = ks->ks_key;
|
||||
cri[0].cri_next = NULL;
|
||||
|
||||
crypto_newsession(&ds->ds_session, cri,
|
||||
CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE);
|
||||
}
|
||||
|
||||
static void
|
||||
des1_random_to_key(struct krb5_key_state *ks, const void *in)
|
||||
{
|
||||
uint8_t *outkey = ks->ks_key;
|
||||
const uint8_t *inkey = in;
|
||||
|
||||
/*
|
||||
* Expand 56 bits of random data to 64 bits as follows
|
||||
* (in the example, bit number 1 is the MSB of the 56
|
||||
* bits of random data):
|
||||
*
|
||||
* expanded =
|
||||
* 1 2 3 4 5 6 7 p
|
||||
* 9 10 11 12 13 14 15 p
|
||||
* 17 18 19 20 21 22 23 p
|
||||
* 25 26 27 28 29 30 31 p
|
||||
* 33 34 35 36 37 38 39 p
|
||||
* 41 42 43 44 45 46 47 p
|
||||
* 49 50 51 52 53 54 55 p
|
||||
* 56 48 40 32 24 16 8 p
|
||||
*/
|
||||
outkey[0] = inkey[0];
|
||||
outkey[1] = inkey[1];
|
||||
outkey[2] = inkey[2];
|
||||
outkey[3] = inkey[3];
|
||||
outkey[4] = inkey[4];
|
||||
outkey[5] = inkey[5];
|
||||
outkey[6] = inkey[6];
|
||||
outkey[7] = (((inkey[0] & 1) << 1)
|
||||
| ((inkey[1] & 1) << 2)
|
||||
| ((inkey[2] & 1) << 3)
|
||||
| ((inkey[3] & 1) << 4)
|
||||
| ((inkey[4] & 1) << 5)
|
||||
| ((inkey[5] & 1) << 6)
|
||||
| ((inkey[6] & 1) << 7));
|
||||
des_set_odd_parity((des_cblock *) outkey);
|
||||
if (des_is_weak_key((des_cblock *) outkey))
|
||||
outkey[7] ^= 0xf0;
|
||||
|
||||
des1_set_key(ks, ks->ks_key);
|
||||
}
|
||||
|
||||
static int
|
||||
des1_crypto_cb(struct cryptop *crp)
|
||||
{
|
||||
int error;
|
||||
struct des1_state *ds = (struct des1_state *) crp->crp_opaque;
|
||||
|
||||
if (CRYPTO_SESID2CAPS(ds->ds_session) & CRYPTOCAP_F_SYNC)
|
||||
return (0);
|
||||
|
||||
error = crp->crp_etype;
|
||||
if (error == EAGAIN)
|
||||
error = crypto_dispatch(crp);
|
||||
mtx_lock(&ds->ds_lock);
|
||||
if (error || (crp->crp_flags & CRYPTO_F_DONE))
|
||||
wakeup(crp);
|
||||
mtx_unlock(&ds->ds_lock);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
des1_encrypt_1(const struct krb5_key_state *ks, int buftype, void *buf,
|
||||
size_t skip, size_t len, void *ivec, int encdec)
|
||||
{
|
||||
struct des1_state *ds = ks->ks_priv;
|
||||
struct cryptop *crp;
|
||||
struct cryptodesc *crd;
|
||||
int error;
|
||||
|
||||
crp = crypto_getreq(1);
|
||||
crd = crp->crp_desc;
|
||||
|
||||
crd->crd_skip = skip;
|
||||
crd->crd_len = len;
|
||||
crd->crd_flags = CRD_F_IV_EXPLICIT | CRD_F_IV_PRESENT | encdec;
|
||||
if (ivec) {
|
||||
bcopy(ivec, crd->crd_iv, 8);
|
||||
} else {
|
||||
bzero(crd->crd_iv, 8);
|
||||
}
|
||||
crd->crd_next = NULL;
|
||||
crd->crd_alg = CRYPTO_DES_CBC;
|
||||
|
||||
crp->crp_sid = ds->ds_session;
|
||||
crp->crp_flags = buftype | CRYPTO_F_CBIFSYNC;
|
||||
crp->crp_buf = buf;
|
||||
crp->crp_opaque = (void *) ds;
|
||||
crp->crp_callback = des1_crypto_cb;
|
||||
|
||||
error = crypto_dispatch(crp);
|
||||
|
||||
if ((CRYPTO_SESID2CAPS(ds->ds_session) & CRYPTOCAP_F_SYNC) == 0) {
|
||||
mtx_lock(&ds->ds_lock);
|
||||
if (!error && !(crp->crp_flags & CRYPTO_F_DONE))
|
||||
error = msleep(crp, &ds->ds_lock, 0, "gssdes", 0);
|
||||
mtx_unlock(&ds->ds_lock);
|
||||
}
|
||||
|
||||
crypto_freereq(crp);
|
||||
}
|
||||
|
||||
static void
|
||||
des1_encrypt(const struct krb5_key_state *ks, struct mbuf *inout,
|
||||
size_t skip, size_t len, void *ivec, size_t ivlen)
|
||||
{
|
||||
|
||||
des1_encrypt_1(ks, CRYPTO_F_IMBUF, inout, skip, len, ivec,
|
||||
CRD_F_ENCRYPT);
|
||||
}
|
||||
|
||||
static void
|
||||
des1_decrypt(const struct krb5_key_state *ks, struct mbuf *inout,
|
||||
size_t skip, size_t len, void *ivec, size_t ivlen)
|
||||
{
|
||||
|
||||
des1_encrypt_1(ks, CRYPTO_F_IMBUF, inout, skip, len, ivec, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
MD5Update_int(void *ctx, void *buf, u_int len)
|
||||
{
|
||||
|
||||
MD5Update(ctx, buf, len);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
des1_checksum(const struct krb5_key_state *ks, int usage,
|
||||
struct mbuf *inout, size_t skip, size_t inlen, size_t outlen)
|
||||
{
|
||||
char hash[16];
|
||||
MD5_CTX md5;
|
||||
|
||||
/*
|
||||
* This checksum is specifically for GSS-API. First take the
|
||||
* MD5 checksum of the message, then calculate the CBC mode
|
||||
* checksum of that MD5 checksum using a zero IV.
|
||||
*/
|
||||
MD5Init(&md5);
|
||||
m_apply(inout, skip, inlen, MD5Update_int, &md5);
|
||||
MD5Final(hash, &md5);
|
||||
|
||||
des1_encrypt_1(ks, 0, hash, 0, 16, NULL, CRD_F_ENCRYPT);
|
||||
m_copyback(inout, skip + inlen, outlen, hash + 8);
|
||||
}
|
||||
|
||||
struct krb5_encryption_class krb5_des_encryption_class = {
|
||||
"des-cbc-md5", /* name */
|
||||
ETYPE_DES_CBC_CRC, /* etype */
|
||||
0, /* flags */
|
||||
8, /* blocklen */
|
||||
8, /* msgblocklen */
|
||||
8, /* checksumlen */
|
||||
56, /* keybits */
|
||||
8, /* keylen */
|
||||
des1_init,
|
||||
des1_destroy,
|
||||
des1_set_key,
|
||||
des1_random_to_key,
|
||||
des1_encrypt,
|
||||
des1_decrypt,
|
||||
des1_checksum
|
||||
};
|
402
sys/kgssapi/krb5/kcrypto_des3.c
Normal file
402
sys/kgssapi/krb5/kcrypto_des3.c
Normal file
@ -0,0 +1,402 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <crypto/des/des.h>
|
||||
#include <opencrypto/cryptodev.h>
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
#include "kcrypto.h"
|
||||
|
||||
#define DES3_FLAGS (CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE)
|
||||
|
||||
struct des3_state {
|
||||
struct mtx ds_lock;
|
||||
uint64_t ds_session;
|
||||
};
|
||||
|
||||
static void
|
||||
des3_init(struct krb5_key_state *ks)
|
||||
{
|
||||
struct des3_state *ds;
|
||||
|
||||
ds = malloc(sizeof(struct des3_state), M_GSSAPI, M_WAITOK|M_ZERO);
|
||||
mtx_init(&ds->ds_lock, "gss des3 lock", NULL, MTX_DEF);
|
||||
ks->ks_priv = ds;
|
||||
}
|
||||
|
||||
static void
|
||||
des3_destroy(struct krb5_key_state *ks)
|
||||
{
|
||||
struct des3_state *ds = ks->ks_priv;
|
||||
|
||||
if (ds->ds_session)
|
||||
crypto_freesession(ds->ds_session);
|
||||
mtx_destroy(&ds->ds_lock);
|
||||
free(ks->ks_priv, M_GSSAPI);
|
||||
}
|
||||
|
||||
static void
|
||||
des3_set_key(struct krb5_key_state *ks, const void *in)
|
||||
{
|
||||
void *kp = ks->ks_key;
|
||||
struct des3_state *ds = ks->ks_priv;
|
||||
struct cryptoini cri[2];
|
||||
|
||||
if (kp != in)
|
||||
bcopy(in, kp, ks->ks_class->ec_keylen);
|
||||
|
||||
if (ds->ds_session)
|
||||
crypto_freesession(ds->ds_session);
|
||||
|
||||
bzero(cri, sizeof(cri));
|
||||
|
||||
cri[0].cri_alg = CRYPTO_SHA1_HMAC;
|
||||
cri[0].cri_klen = 192;
|
||||
cri[0].cri_mlen = 0;
|
||||
cri[0].cri_key = ks->ks_key;
|
||||
cri[0].cri_next = &cri[1];
|
||||
|
||||
cri[1].cri_alg = CRYPTO_3DES_CBC;
|
||||
cri[1].cri_klen = 192;
|
||||
cri[1].cri_mlen = 0;
|
||||
cri[1].cri_key = ks->ks_key;
|
||||
cri[1].cri_next = NULL;
|
||||
|
||||
crypto_newsession(&ds->ds_session, cri,
|
||||
CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE);
|
||||
}
|
||||
|
||||
static void
|
||||
des3_random_to_key(struct krb5_key_state *ks, const void *in)
|
||||
{
|
||||
uint8_t *outkey;
|
||||
const uint8_t *inkey;
|
||||
int subkey;
|
||||
|
||||
for (subkey = 0, outkey = ks->ks_key, inkey = in; subkey < 3;
|
||||
subkey++, outkey += 8, inkey += 7) {
|
||||
/*
|
||||
* Expand 56 bits of random data to 64 bits as follows
|
||||
* (in the example, bit number 1 is the MSB of the 56
|
||||
* bits of random data):
|
||||
*
|
||||
* expanded =
|
||||
* 1 2 3 4 5 6 7 p
|
||||
* 9 10 11 12 13 14 15 p
|
||||
* 17 18 19 20 21 22 23 p
|
||||
* 25 26 27 28 29 30 31 p
|
||||
* 33 34 35 36 37 38 39 p
|
||||
* 41 42 43 44 45 46 47 p
|
||||
* 49 50 51 52 53 54 55 p
|
||||
* 56 48 40 32 24 16 8 p
|
||||
*/
|
||||
outkey[0] = inkey[0];
|
||||
outkey[1] = inkey[1];
|
||||
outkey[2] = inkey[2];
|
||||
outkey[3] = inkey[3];
|
||||
outkey[4] = inkey[4];
|
||||
outkey[5] = inkey[5];
|
||||
outkey[6] = inkey[6];
|
||||
outkey[7] = (((inkey[0] & 1) << 1)
|
||||
| ((inkey[1] & 1) << 2)
|
||||
| ((inkey[2] & 1) << 3)
|
||||
| ((inkey[3] & 1) << 4)
|
||||
| ((inkey[4] & 1) << 5)
|
||||
| ((inkey[5] & 1) << 6)
|
||||
| ((inkey[6] & 1) << 7));
|
||||
des_set_odd_parity((des_cblock *) outkey);
|
||||
if (des_is_weak_key((des_cblock *) outkey))
|
||||
outkey[7] ^= 0xf0;
|
||||
}
|
||||
|
||||
des3_set_key(ks, ks->ks_key);
|
||||
}
|
||||
|
||||
static int
|
||||
des3_crypto_cb(struct cryptop *crp)
|
||||
{
|
||||
int error;
|
||||
struct des3_state *ds = (struct des3_state *) crp->crp_opaque;
|
||||
|
||||
if (CRYPTO_SESID2CAPS(ds->ds_session) & CRYPTOCAP_F_SYNC)
|
||||
return (0);
|
||||
|
||||
error = crp->crp_etype;
|
||||
if (error == EAGAIN)
|
||||
error = crypto_dispatch(crp);
|
||||
mtx_lock(&ds->ds_lock);
|
||||
if (error || (crp->crp_flags & CRYPTO_F_DONE))
|
||||
wakeup(crp);
|
||||
mtx_unlock(&ds->ds_lock);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
des3_encrypt_1(const struct krb5_key_state *ks, struct mbuf *inout,
|
||||
size_t skip, size_t len, void *ivec, int encdec)
|
||||
{
|
||||
struct des3_state *ds = ks->ks_priv;
|
||||
struct cryptop *crp;
|
||||
struct cryptodesc *crd;
|
||||
int error;
|
||||
|
||||
crp = crypto_getreq(1);
|
||||
crd = crp->crp_desc;
|
||||
|
||||
crd->crd_skip = skip;
|
||||
crd->crd_len = len;
|
||||
crd->crd_flags = CRD_F_IV_EXPLICIT | CRD_F_IV_PRESENT | encdec;
|
||||
if (ivec) {
|
||||
bcopy(ivec, crd->crd_iv, 8);
|
||||
} else {
|
||||
bzero(crd->crd_iv, 8);
|
||||
}
|
||||
crd->crd_next = NULL;
|
||||
crd->crd_alg = CRYPTO_3DES_CBC;
|
||||
|
||||
crp->crp_sid = ds->ds_session;
|
||||
crp->crp_flags = CRYPTO_F_IMBUF | CRYPTO_F_CBIFSYNC;
|
||||
crp->crp_buf = (void *) inout;
|
||||
crp->crp_opaque = (void *) ds;
|
||||
crp->crp_callback = des3_crypto_cb;
|
||||
|
||||
error = crypto_dispatch(crp);
|
||||
|
||||
if ((CRYPTO_SESID2CAPS(ds->ds_session) & CRYPTOCAP_F_SYNC) == 0) {
|
||||
mtx_lock(&ds->ds_lock);
|
||||
if (!error && !(crp->crp_flags & CRYPTO_F_DONE))
|
||||
error = msleep(crp, &ds->ds_lock, 0, "gssdes3", 0);
|
||||
mtx_unlock(&ds->ds_lock);
|
||||
}
|
||||
|
||||
crypto_freereq(crp);
|
||||
}
|
||||
|
||||
static void
|
||||
des3_encrypt(const struct krb5_key_state *ks, struct mbuf *inout,
|
||||
size_t skip, size_t len, void *ivec, size_t ivlen)
|
||||
{
|
||||
|
||||
des3_encrypt_1(ks, inout, skip, len, ivec, CRD_F_ENCRYPT);
|
||||
}
|
||||
|
||||
static void
|
||||
des3_decrypt(const struct krb5_key_state *ks, struct mbuf *inout,
|
||||
size_t skip, size_t len, void *ivec, size_t ivlen)
|
||||
{
|
||||
|
||||
des3_encrypt_1(ks, inout, skip, len, ivec, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
des3_checksum(const struct krb5_key_state *ks, int usage,
|
||||
struct mbuf *inout, size_t skip, size_t inlen, size_t outlen)
|
||||
{
|
||||
struct des3_state *ds = ks->ks_priv;
|
||||
struct cryptop *crp;
|
||||
struct cryptodesc *crd;
|
||||
int error;
|
||||
|
||||
crp = crypto_getreq(1);
|
||||
crd = crp->crp_desc;
|
||||
|
||||
crd->crd_skip = skip;
|
||||
crd->crd_len = inlen;
|
||||
crd->crd_inject = skip + inlen;
|
||||
crd->crd_flags = 0;
|
||||
crd->crd_next = NULL;
|
||||
crd->crd_alg = CRYPTO_SHA1_HMAC;
|
||||
|
||||
crp->crp_sid = ds->ds_session;
|
||||
crp->crp_ilen = inlen;
|
||||
crp->crp_olen = 20;
|
||||
crp->crp_etype = 0;
|
||||
crp->crp_flags = CRYPTO_F_IMBUF | CRYPTO_F_CBIFSYNC;
|
||||
crp->crp_buf = (void *) inout;
|
||||
crp->crp_opaque = (void *) ds;
|
||||
crp->crp_callback = des3_crypto_cb;
|
||||
|
||||
error = crypto_dispatch(crp);
|
||||
|
||||
if ((CRYPTO_SESID2CAPS(ds->ds_session) & CRYPTOCAP_F_SYNC) == 0) {
|
||||
mtx_lock(&ds->ds_lock);
|
||||
if (!error && !(crp->crp_flags & CRYPTO_F_DONE))
|
||||
error = msleep(crp, &ds->ds_lock, 0, "gssdes3", 0);
|
||||
mtx_unlock(&ds->ds_lock);
|
||||
}
|
||||
|
||||
crypto_freereq(crp);
|
||||
}
|
||||
|
||||
struct krb5_encryption_class krb5_des3_encryption_class = {
|
||||
"des3-cbc-sha1", /* name */
|
||||
ETYPE_DES3_CBC_SHA1, /* etype */
|
||||
EC_DERIVED_KEYS, /* flags */
|
||||
8, /* blocklen */
|
||||
8, /* msgblocklen */
|
||||
20, /* checksumlen */
|
||||
168, /* keybits */
|
||||
24, /* keylen */
|
||||
des3_init,
|
||||
des3_destroy,
|
||||
des3_set_key,
|
||||
des3_random_to_key,
|
||||
des3_encrypt,
|
||||
des3_decrypt,
|
||||
des3_checksum
|
||||
};
|
||||
|
||||
#if 0
|
||||
struct des3_dk_test {
|
||||
uint8_t key[24];
|
||||
uint8_t usage[8];
|
||||
size_t usagelen;
|
||||
uint8_t dk[24];
|
||||
};
|
||||
struct des3_dk_test tests[] = {
|
||||
{{0xdc, 0xe0, 0x6b, 0x1f, 0x64, 0xc8, 0x57, 0xa1, 0x1c, 0x3d, 0xb5,
|
||||
0x7c, 0x51, 0x89, 0x9b, 0x2c, 0xc1, 0x79, 0x10, 0x08, 0xce, 0x97,
|
||||
0x3b, 0x92},
|
||||
{0x00, 0x00, 0x00, 0x01, 0x55}, 5,
|
||||
{0x92, 0x51, 0x79, 0xd0, 0x45, 0x91, 0xa7, 0x9b, 0x5d, 0x31, 0x92,
|
||||
0xc4, 0xa7, 0xe9, 0xc2, 0x89, 0xb0, 0x49, 0xc7, 0x1f, 0x6e, 0xe6,
|
||||
0x04, 0xcd}},
|
||||
|
||||
{{0x5e, 0x13, 0xd3, 0x1c, 0x70, 0xef, 0x76, 0x57, 0x46, 0x57, 0x85,
|
||||
0x31, 0xcb, 0x51, 0xc1, 0x5b, 0xf1, 0x1c, 0xa8, 0x2c, 0x97, 0xce,
|
||||
0xe9, 0xf2},
|
||||
{0x00, 0x00, 0x00, 0x01, 0xaa}, 5,
|
||||
{0x9e, 0x58, 0xe5, 0xa1, 0x46, 0xd9, 0x94, 0x2a, 0x10, 0x1c, 0x46,
|
||||
0x98, 0x45, 0xd6, 0x7a, 0x20, 0xe3, 0xc4, 0x25, 0x9e, 0xd9, 0x13,
|
||||
0xf2, 0x07}},
|
||||
|
||||
{{0x98, 0xe6, 0xfd, 0x8a, 0x04, 0xa4, 0xb6, 0x85, 0x9b, 0x75, 0xa1,
|
||||
0x76, 0x54, 0x0b, 0x97, 0x52, 0xba, 0xd3, 0xec, 0xd6, 0x10, 0xa2,
|
||||
0x52, 0xbc},
|
||||
{0x00, 0x00, 0x00, 0x01, 0x55}, 5,
|
||||
{0x13, 0xfe, 0xf8, 0x0d, 0x76, 0x3e, 0x94, 0xec, 0x6d, 0x13, 0xfd,
|
||||
0x2c, 0xa1, 0xd0, 0x85, 0x07, 0x02, 0x49, 0xda, 0xd3, 0x98, 0x08,
|
||||
0xea, 0xbf}},
|
||||
|
||||
{{0x62, 0x2a, 0xec, 0x25, 0xa2, 0xfe, 0x2c, 0xad, 0x70, 0x94, 0x68,
|
||||
0x0b, 0x7c, 0x64, 0x94, 0x02, 0x80, 0x08, 0x4c, 0x1a, 0x7c, 0xec,
|
||||
0x92, 0xb5},
|
||||
{0x00, 0x00, 0x00, 0x01, 0xaa}, 5,
|
||||
{0xf8, 0xdf, 0xbf, 0x04, 0xb0, 0x97, 0xe6, 0xd9, 0xdc, 0x07, 0x02,
|
||||
0x68, 0x6b, 0xcb, 0x34, 0x89, 0xd9, 0x1f, 0xd9, 0xa4, 0x51, 0x6b,
|
||||
0x70, 0x3e}},
|
||||
|
||||
{{0xd3, 0xf8, 0x29, 0x8c, 0xcb, 0x16, 0x64, 0x38, 0xdc, 0xb9, 0xb9,
|
||||
0x3e, 0xe5, 0xa7, 0x62, 0x92, 0x86, 0xa4, 0x91, 0xf8, 0x38, 0xf8,
|
||||
0x02, 0xfb},
|
||||
{0x6b, 0x65, 0x72, 0x62, 0x65, 0x72, 0x6f, 0x73}, 8,
|
||||
{0x23, 0x70, 0xda, 0x57, 0x5d, 0x2a, 0x3d, 0xa8, 0x64, 0xce, 0xbf,
|
||||
0xdc, 0x52, 0x04, 0xd5, 0x6d, 0xf7, 0x79, 0xa7, 0xdf, 0x43, 0xd9,
|
||||
0xda, 0x43}},
|
||||
|
||||
{{0xc1, 0x08, 0x16, 0x49, 0xad, 0xa7, 0x43, 0x62, 0xe6, 0xa1, 0x45,
|
||||
0x9d, 0x01, 0xdf, 0xd3, 0x0d, 0x67, 0xc2, 0x23, 0x4c, 0x94, 0x07,
|
||||
0x04, 0xda},
|
||||
{0x00, 0x00, 0x00, 0x01, 0x55}, 5,
|
||||
{0x34, 0x80, 0x57, 0xec, 0x98, 0xfd, 0xc4, 0x80, 0x16, 0x16, 0x1c,
|
||||
0x2a, 0x4c, 0x7a, 0x94, 0x3e, 0x92, 0xae, 0x49, 0x2c, 0x98, 0x91,
|
||||
0x75, 0xf7}},
|
||||
|
||||
{{0x5d, 0x15, 0x4a, 0xf2, 0x38, 0xf4, 0x67, 0x13, 0x15, 0x57, 0x19,
|
||||
0xd5, 0x5e, 0x2f, 0x1f, 0x79, 0x0d, 0xd6, 0x61, 0xf2, 0x79, 0xa7,
|
||||
0x91, 0x7c},
|
||||
{0x00, 0x00, 0x00, 0x01, 0xaa}, 5,
|
||||
{0xa8, 0x80, 0x8a, 0xc2, 0x67, 0xda, 0xda, 0x3d, 0xcb, 0xe9, 0xa7,
|
||||
0xc8, 0x46, 0x26, 0xfb, 0xc7, 0x61, 0xc2, 0x94, 0xb0, 0x13, 0x15,
|
||||
0xe5, 0xc1}},
|
||||
|
||||
{{0x79, 0x85, 0x62, 0xe0, 0x49, 0x85, 0x2f, 0x57, 0xdc, 0x8c, 0x34,
|
||||
0x3b, 0xa1, 0x7f, 0x2c, 0xa1, 0xd9, 0x73, 0x94, 0xef, 0xc8, 0xad,
|
||||
0xc4, 0x43},
|
||||
{0x00, 0x00, 0x00, 0x01, 0x55}, 5,
|
||||
{0xc8, 0x13, 0xf8, 0x8a, 0x3b, 0xe3, 0xb3, 0x34, 0xf7, 0x54, 0x25,
|
||||
0xce, 0x91, 0x75, 0xfb, 0xe3, 0xc8, 0x49, 0x3b, 0x89, 0xc8, 0x70,
|
||||
0x3b, 0x49}},
|
||||
|
||||
{{0x26, 0xdc, 0xe3, 0x34, 0xb5, 0x45, 0x29, 0x2f, 0x2f, 0xea, 0xb9,
|
||||
0xa8, 0x70, 0x1a, 0x89, 0xa4, 0xb9, 0x9e, 0xb9, 0x94, 0x2c, 0xec,
|
||||
0xd0, 0x16},
|
||||
{0x00, 0x00, 0x00, 0x01, 0xaa}, 5,
|
||||
{0xf4, 0x8f, 0xfd, 0x6e, 0x83, 0xf8, 0x3e, 0x73, 0x54, 0xe6, 0x94,
|
||||
0xfd, 0x25, 0x2c, 0xf8, 0x3b, 0xfe, 0x58, 0xf7, 0xd5, 0xba, 0x37,
|
||||
0xec, 0x5d}},
|
||||
};
|
||||
#define N_TESTS (sizeof(tests) / sizeof(tests[0]))
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct krb5_key_state *key, *dk;
|
||||
uint8_t *dkp;
|
||||
int j, i;
|
||||
|
||||
for (j = 0; j < N_TESTS; j++) {
|
||||
struct des3_dk_test *t = &tests[j];
|
||||
key = krb5_create_key(&des3_encryption_class);
|
||||
krb5_set_key(key, t->key);
|
||||
dk = krb5_derive_key(key, t->usage, t->usagelen);
|
||||
krb5_free_key(key);
|
||||
if (memcmp(dk->ks_key, t->dk, 24)) {
|
||||
printf("DES3 dk(");
|
||||
for (i = 0; i < 24; i++)
|
||||
printf("%02x", t->key[i]);
|
||||
printf(", ");
|
||||
for (i = 0; i < t->usagelen; i++)
|
||||
printf("%02x", t->usage[i]);
|
||||
printf(") failed\n");
|
||||
printf("should be: ");
|
||||
for (i = 0; i < 24; i++)
|
||||
printf("%02x", t->dk[i]);
|
||||
printf("\n result was: ");
|
||||
dkp = dk->ks_key;
|
||||
for (i = 0; i < 24; i++)
|
||||
printf("%02x", dkp[i]);
|
||||
printf("\n");
|
||||
}
|
||||
krb5_free_key(dk);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
#endif
|
2100
sys/kgssapi/krb5/krb5_mech.c
Normal file
2100
sys/kgssapi/krb5/krb5_mech.c
Normal file
File diff suppressed because it is too large
Load Diff
55
sys/modules/kgssapi/Makefile
Normal file
55
sys/modules/kgssapi/Makefile
Normal file
@ -0,0 +1,55 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.PATH: ${.CURDIR}/../../kgssapi ${.CURDIR}/../../rpc/rpcsec_gss
|
||||
KMOD= kgssapi
|
||||
|
||||
SRCS= gss_accept_sec_context.c \
|
||||
gss_add_oid_set_member.c \
|
||||
gss_acquire_cred.c \
|
||||
gss_canonicalize_name.c \
|
||||
gss_create_empty_oid_set.c \
|
||||
gss_delete_sec_context.c \
|
||||
gss_display_status.c \
|
||||
gss_export_name.c \
|
||||
gss_get_mic.c \
|
||||
gss_init_sec_context.c \
|
||||
gss_impl.c \
|
||||
gss_import_name.c \
|
||||
gss_names.c \
|
||||
gss_pname_to_uid.c \
|
||||
gss_release_buffer.c \
|
||||
gss_release_cred.c \
|
||||
gss_release_name.c \
|
||||
gss_release_oid_set.c \
|
||||
gss_set_cred_option.c \
|
||||
gss_test_oid_set_member.c \
|
||||
gss_unwrap.c \
|
||||
gss_verify_mic.c \
|
||||
gss_wrap.c \
|
||||
gss_wrap_size_limit.c \
|
||||
gssd_prot.c
|
||||
|
||||
SRCS+= rpcsec_gss.c \
|
||||
rpcsec_gss_conf.c \
|
||||
rpcsec_gss_misc.c \
|
||||
rpcsec_gss_prot.c \
|
||||
svc_rpcsec_gss.c
|
||||
|
||||
SRCS+= kgss_if.h kgss_if.c
|
||||
MFILES= kgssapi/kgss_if.m
|
||||
|
||||
SRCS+= gssd.h gssd_xdr.c gssd_clnt.c
|
||||
CLEANFILES= gssd.h gssd_xdr.c gssd_clnt.c
|
||||
|
||||
S= ${.CURDIR}/../..
|
||||
|
||||
gssd.h: $S/kgssapi/gssd.x
|
||||
rpcgen -hM $S/kgssapi/gssd.x | grep -v pthread.h > gssd.h
|
||||
|
||||
gssd_xdr.c: $S/kgssapi/gssd.x
|
||||
rpcgen -c $S/kgssapi/gssd.x -o gssd_xdr.c
|
||||
|
||||
gssd_clnt.c: $S/kgssapi/gssd.x
|
||||
rpcgen -lM $S/kgssapi/gssd.x | grep -v string.h > gssd_clnt.c
|
||||
|
||||
.include <bsd.kmod.mk>
|
21
sys/modules/kgssapi_krb5/Makefile
Normal file
21
sys/modules/kgssapi_krb5/Makefile
Normal file
@ -0,0 +1,21 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.PATH: ${.CURDIR}/../../kgssapi/krb5
|
||||
KMOD= kgssapi_krb5
|
||||
|
||||
SRCS= krb5_mech.c \
|
||||
kcrypto.c \
|
||||
kcrypto_des.c \
|
||||
kcrypto_des3.c \
|
||||
kcrypto_aes.c \
|
||||
kcrypto_arcfour.c
|
||||
|
||||
SRCS+= kgss_if.h gssd.h
|
||||
MFILES= kgssapi/kgss_if.m
|
||||
|
||||
S= ${.CURDIR}/../..
|
||||
|
||||
gssd.h: $S/kgssapi/gssd.x
|
||||
rpcgen -hM $S/kgssapi/gssd.x | grep -v pthread.h > gssd.h
|
||||
|
||||
.include <bsd.kmod.mk>
|
@ -6,11 +6,11 @@
|
||||
KMOD= nfsclient
|
||||
SRCS= vnode_if.h \
|
||||
nfs_bio.c nfs_lock.c nfs_node.c nfs_socket.c nfs_subs.c nfs_nfsiod.c \
|
||||
nfs_vfsops.c nfs_vnops.c nfs_common.c \
|
||||
nfs_vfsops.c nfs_vnops.c nfs_common.c nfs_krpc.c \
|
||||
opt_inet.h opt_nfs.h opt_bootp.h opt_nfsroot.h
|
||||
SRCS+= nfs4_dev.c nfs4_idmap.c nfs4_socket.c nfs4_subs.c \
|
||||
nfs4_vfs_subs.c nfs4_vfsops.c nfs4_vn_subs.c nfs4_vnops.c
|
||||
SRCS+= opt_inet6.h
|
||||
SRCS+= opt_inet6.h opt_kgssapi.h
|
||||
|
||||
# USE THE RPCCLNT:
|
||||
CFLAGS+= -DRPCCLNT_DEBUG
|
||||
|
@ -3,8 +3,8 @@
|
||||
.PATH: ${.CURDIR}/../../nfsserver ${.CURDIR}/../../nfs
|
||||
KMOD= nfsserver
|
||||
SRCS= vnode_if.h \
|
||||
nfs_serv.c nfs_srvsock.c nfs_srvcache.c nfs_srvsubs.c nfs_syscalls.c \
|
||||
nfs_common.c \
|
||||
nfs_serv.c nfs_srvkrpc.c nfs_srvsock.c nfs_srvcache.c nfs_srvsubs.c \
|
||||
nfs_syscalls.c nfs_common.c \
|
||||
opt_mac.h \
|
||||
opt_nfs.h
|
||||
SRCS+= opt_inet6.h
|
||||
|
@ -132,7 +132,9 @@ MALLOC_DECLARE(M_NFSDIRECTIO);
|
||||
|
||||
extern struct uma_zone *nfsmount_zone;
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
extern struct callout nfs_callout;
|
||||
#endif
|
||||
extern struct nfsstats nfsstats;
|
||||
extern struct mtx nfs_iod_mtx;
|
||||
|
||||
@ -157,6 +159,8 @@ extern int nfsv3_procid[NFS_NPROCS];
|
||||
(e) != ERESTART && (e) != EWOULDBLOCK && \
|
||||
((s) & PR_CONNREQUIRED) == 0)
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
|
||||
/*
|
||||
* Nfs outstanding request list element
|
||||
*/
|
||||
@ -196,6 +200,17 @@ extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
|
||||
#define R_GETONEREP 0x80 /* Probe for one reply only */
|
||||
#define R_PIN_REQ 0x100 /* Pin request down (rexmit in prog or other) */
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* This is only needed to keep things working while we support
|
||||
* compiling for both RPC implementations.
|
||||
*/
|
||||
struct nfsreq;
|
||||
struct nfsmount;
|
||||
|
||||
#endif
|
||||
|
||||
struct buf;
|
||||
struct socket;
|
||||
struct uio;
|
||||
@ -291,12 +306,18 @@ vfs_init_t nfs_init;
|
||||
vfs_uninit_t nfs_uninit;
|
||||
int nfs_mountroot(struct mount *mp, struct thread *td);
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
#ifndef NFS4_USE_RPCCLNT
|
||||
int nfs_send(struct socket *, struct sockaddr *, struct mbuf *,
|
||||
struct nfsreq *);
|
||||
int nfs_connect_lock(struct nfsreq *);
|
||||
void nfs_connect_unlock(struct nfsreq *);
|
||||
void nfs_up(struct nfsreq *, struct nfsmount *, struct thread *,
|
||||
const char *, int);
|
||||
void nfs_down(struct nfsreq *, struct nfsmount *, struct thread *,
|
||||
const char *, int, int);
|
||||
#endif /* ! NFS4_USE_RPCCLNT */
|
||||
#endif
|
||||
|
||||
int nfs_vinvalbuf(struct vnode *, int, struct thread *, int);
|
||||
int nfs_readrpc(struct vnode *, struct uio *, struct ucred *);
|
||||
@ -309,10 +330,6 @@ int nfs_nfsiodnew(void);
|
||||
int nfs_asyncio(struct nfsmount *, struct buf *, struct ucred *, struct thread *);
|
||||
int nfs_doio(struct vnode *, struct buf *, struct ucred *, struct thread *);
|
||||
void nfs_doio_directwrite (struct buf *);
|
||||
void nfs_up(struct nfsreq *, struct nfsmount *, struct thread *,
|
||||
const char *, int);
|
||||
void nfs_down(struct nfsreq *, struct nfsmount *, struct thread *,
|
||||
const char *, int, int);
|
||||
int nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *);
|
||||
int nfs_sigintr(struct nfsmount *, struct nfsreq *, struct thread *);
|
||||
int nfs_readdirplusrpc(struct vnode *, struct uio *, struct ucred *);
|
||||
|
769
sys/nfsclient/nfs_krpc.c
Normal file
769
sys/nfsclient/nfs_krpc.c
Normal file
@ -0,0 +1,769 @@
|
||||
/*-
|
||||
* Copyright (c) 1989, 1991, 1993, 1995
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Rick Macklem at The University of Guelph.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)nfs_socket.c 8.5 (Berkeley) 3/30/95
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Socket operations for use by nfs
|
||||
*/
|
||||
|
||||
#include "opt_inet6.h"
|
||||
#include "opt_kgssapi.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/limits.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/syscallsubr.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/syslog.h>
|
||||
#include <sys/vnode.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpcclnt.h>
|
||||
|
||||
#include <nfs/rpcv2.h>
|
||||
#include <nfs/nfsproto.h>
|
||||
#include <nfsclient/nfs.h>
|
||||
#include <nfs/xdr_subs.h>
|
||||
#include <nfsclient/nfsm_subs.h>
|
||||
#include <nfsclient/nfsmount.h>
|
||||
#include <nfsclient/nfsnode.h>
|
||||
|
||||
#include <nfs4client/nfs4.h>
|
||||
|
||||
#ifndef NFS_LEGACYRPC
|
||||
|
||||
static int nfs_realign_test;
|
||||
static int nfs_realign_count;
|
||||
static int nfs_bufpackets = 4;
|
||||
static int nfs_reconnects;
|
||||
static int nfs3_jukebox_delay = 10;
|
||||
static int nfs_skip_wcc_data_onerr = 1;
|
||||
static int fake_wchan;
|
||||
|
||||
SYSCTL_DECL(_vfs_nfs);
|
||||
|
||||
SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_test, CTLFLAG_RW, &nfs_realign_test, 0,
|
||||
"Number of realign tests done");
|
||||
SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_count, CTLFLAG_RW, &nfs_realign_count, 0,
|
||||
"Number of mbuf realignments done");
|
||||
SYSCTL_INT(_vfs_nfs, OID_AUTO, bufpackets, CTLFLAG_RW, &nfs_bufpackets, 0,
|
||||
"Buffer reservation size 2 < x < 64");
|
||||
SYSCTL_INT(_vfs_nfs, OID_AUTO, reconnects, CTLFLAG_RD, &nfs_reconnects, 0,
|
||||
"Number of times the nfs client has had to reconnect");
|
||||
SYSCTL_INT(_vfs_nfs, OID_AUTO, nfs3_jukebox_delay, CTLFLAG_RW, &nfs3_jukebox_delay, 0,
|
||||
"Number of seconds to delay a retry after receiving EJUKEBOX");
|
||||
SYSCTL_INT(_vfs_nfs, OID_AUTO, skip_wcc_data_onerr, CTLFLAG_RW, &nfs_skip_wcc_data_onerr, 0,
|
||||
"Disable weak cache consistency checking when server returns an error");
|
||||
|
||||
static void nfs_down(struct nfsmount *, struct thread *, const char *,
|
||||
int, int);
|
||||
static void nfs_up(struct nfsmount *, struct thread *, const char *,
|
||||
int, int);
|
||||
static int nfs_msg(struct thread *, const char *, const char *, int);
|
||||
|
||||
extern int nfsv2_procid[];
|
||||
|
||||
struct nfs_cached_auth {
|
||||
int ca_refs; /* refcount, including 1 from the cache */
|
||||
uid_t ca_uid; /* uid that corresponds to this auth */
|
||||
AUTH *ca_auth; /* RPC auth handle */
|
||||
};
|
||||
|
||||
/*
|
||||
* RTT estimator
|
||||
*/
|
||||
|
||||
static enum nfs_rto_timer_t nfs_proct[NFS_NPROCS] = {
|
||||
NFS_DEFAULT_TIMER, /* NULL */
|
||||
NFS_GETATTR_TIMER, /* GETATTR */
|
||||
NFS_DEFAULT_TIMER, /* SETATTR */
|
||||
NFS_LOOKUP_TIMER, /* LOOKUP */
|
||||
NFS_GETATTR_TIMER, /* ACCESS */
|
||||
NFS_READ_TIMER, /* READLINK */
|
||||
NFS_READ_TIMER, /* READ */
|
||||
NFS_WRITE_TIMER, /* WRITE */
|
||||
NFS_DEFAULT_TIMER, /* CREATE */
|
||||
NFS_DEFAULT_TIMER, /* MKDIR */
|
||||
NFS_DEFAULT_TIMER, /* SYMLINK */
|
||||
NFS_DEFAULT_TIMER, /* MKNOD */
|
||||
NFS_DEFAULT_TIMER, /* REMOVE */
|
||||
NFS_DEFAULT_TIMER, /* RMDIR */
|
||||
NFS_DEFAULT_TIMER, /* RENAME */
|
||||
NFS_DEFAULT_TIMER, /* LINK */
|
||||
NFS_READ_TIMER, /* READDIR */
|
||||
NFS_READ_TIMER, /* READDIRPLUS */
|
||||
NFS_DEFAULT_TIMER, /* FSSTAT */
|
||||
NFS_DEFAULT_TIMER, /* FSINFO */
|
||||
NFS_DEFAULT_TIMER, /* PATHCONF */
|
||||
NFS_DEFAULT_TIMER, /* COMMIT */
|
||||
NFS_DEFAULT_TIMER, /* NOOP */
|
||||
};
|
||||
|
||||
/*
|
||||
* Choose the correct RTT timer for this NFS procedure.
|
||||
*/
|
||||
static inline enum nfs_rto_timer_t
|
||||
nfs_rto_timer(u_int32_t procnum)
|
||||
{
|
||||
return nfs_proct[procnum];
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the RTT estimator state for a new mount point.
|
||||
*/
|
||||
static void
|
||||
nfs_init_rtt(struct nfsmount *nmp)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NFS_MAX_TIMER; i++) {
|
||||
nmp->nm_timers[i].rt_srtt = hz;
|
||||
nmp->nm_timers[i].rt_deviate = 0;
|
||||
nmp->nm_timers[i].rt_rtxcur = hz;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize sockets and congestion for a new NFS connection.
|
||||
* We do not free the sockaddr if error.
|
||||
*/
|
||||
int
|
||||
nfs_connect(struct nfsmount *nmp, struct nfsreq *rep)
|
||||
{
|
||||
int rcvreserve, sndreserve;
|
||||
int pktscale;
|
||||
struct sockaddr *saddr;
|
||||
struct ucred *origcred;
|
||||
struct thread *td = curthread;
|
||||
CLIENT *client;
|
||||
struct netconfig *nconf;
|
||||
rpcvers_t vers;
|
||||
int one = 1, retries;
|
||||
|
||||
/*
|
||||
* We need to establish the socket using the credentials of
|
||||
* the mountpoint. Some parts of this process (such as
|
||||
* sobind() and soconnect()) will use the curent thread's
|
||||
* credential instead of the socket credential. To work
|
||||
* around this, temporarily change the current thread's
|
||||
* credential to that of the mountpoint.
|
||||
*
|
||||
* XXX: It would be better to explicitly pass the correct
|
||||
* credential to sobind() and soconnect().
|
||||
*/
|
||||
origcred = td->td_ucred;
|
||||
td->td_ucred = nmp->nm_mountp->mnt_cred;
|
||||
saddr = nmp->nm_nam;
|
||||
|
||||
vers = NFS_VER2;
|
||||
if (nmp->nm_flag & NFSMNT_NFSV3)
|
||||
vers = NFS_VER3;
|
||||
else if (nmp->nm_flag & NFSMNT_NFSV4)
|
||||
vers = NFS_VER4;
|
||||
if (saddr->sa_family == AF_INET)
|
||||
if (nmp->nm_sotype == SOCK_DGRAM)
|
||||
nconf = getnetconfigent("udp");
|
||||
else
|
||||
nconf = getnetconfigent("tcp");
|
||||
else
|
||||
if (nmp->nm_sotype == SOCK_DGRAM)
|
||||
nconf = getnetconfigent("udp6");
|
||||
else
|
||||
nconf = getnetconfigent("tcp6");
|
||||
|
||||
/*
|
||||
* Get buffer reservation size from sysctl, but impose reasonable
|
||||
* limits.
|
||||
*/
|
||||
pktscale = nfs_bufpackets;
|
||||
if (pktscale < 2)
|
||||
pktscale = 2;
|
||||
if (pktscale > 64)
|
||||
pktscale = 64;
|
||||
mtx_lock(&nmp->nm_mtx);
|
||||
if (nmp->nm_sotype == SOCK_DGRAM) {
|
||||
sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR) * pktscale;
|
||||
rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
|
||||
NFS_MAXPKTHDR) * pktscale;
|
||||
} else if (nmp->nm_sotype == SOCK_SEQPACKET) {
|
||||
sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR) * pktscale;
|
||||
rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
|
||||
NFS_MAXPKTHDR) * pktscale;
|
||||
} else {
|
||||
if (nmp->nm_sotype != SOCK_STREAM)
|
||||
panic("nfscon sotype");
|
||||
sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR +
|
||||
sizeof (u_int32_t)) * pktscale;
|
||||
rcvreserve = (nmp->nm_rsize + NFS_MAXPKTHDR +
|
||||
sizeof (u_int32_t)) * pktscale;
|
||||
}
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
|
||||
client = clnt_reconnect_create(nconf, saddr, NFS_PROG, vers,
|
||||
sndreserve, rcvreserve);
|
||||
CLNT_CONTROL(client, CLSET_WAITCHAN, "nfsreq");
|
||||
if (nmp->nm_flag & NFSMNT_INT)
|
||||
CLNT_CONTROL(client, CLSET_INTERRUPTIBLE, &one);
|
||||
if (nmp->nm_flag & NFSMNT_RESVPORT)
|
||||
CLNT_CONTROL(client, CLSET_PRIVPORT, &one);
|
||||
if (nmp->nm_flag & NFSMNT_SOFT)
|
||||
retries = nmp->nm_retry;
|
||||
else
|
||||
retries = INT_MAX;
|
||||
CLNT_CONTROL(client, CLSET_RETRIES, &retries);
|
||||
|
||||
mtx_lock(&nmp->nm_mtx);
|
||||
if (nmp->nm_client) {
|
||||
/*
|
||||
* Someone else already connected.
|
||||
*/
|
||||
CLNT_RELEASE(client);
|
||||
} else {
|
||||
nmp->nm_client = client;
|
||||
}
|
||||
|
||||
/*
|
||||
* Protocols that do not require connections may be optionally left
|
||||
* unconnected for servers that reply from a port other than NFS_PORT.
|
||||
*/
|
||||
if (!(nmp->nm_flag & NFSMNT_NOCONN)) {
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
CLNT_CONTROL(client, CLSET_CONNECT, &one);
|
||||
} else {
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
}
|
||||
|
||||
/* Restore current thread's credentials. */
|
||||
td->td_ucred = origcred;
|
||||
|
||||
mtx_lock(&nmp->nm_mtx);
|
||||
/* Initialize other non-zero congestion variables */
|
||||
nfs_init_rtt(nmp);
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* NFS disconnect. Clean up and unlink.
|
||||
*/
|
||||
void
|
||||
nfs_disconnect(struct nfsmount *nmp)
|
||||
{
|
||||
CLIENT *client;
|
||||
|
||||
mtx_lock(&nmp->nm_mtx);
|
||||
if (nmp->nm_client) {
|
||||
client = nmp->nm_client;
|
||||
nmp->nm_client = NULL;
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
#ifdef KGSSAPI
|
||||
rpc_gss_secpurge(client);
|
||||
#endif
|
||||
CLNT_CLOSE(client);
|
||||
CLNT_RELEASE(client);
|
||||
} else {
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nfs_safedisconnect(struct nfsmount *nmp)
|
||||
{
|
||||
|
||||
nfs_disconnect(nmp);
|
||||
}
|
||||
|
||||
static AUTH *
|
||||
nfs_getauth(struct nfsmount *nmp, struct ucred *cred)
|
||||
{
|
||||
#ifdef KGSSAPI
|
||||
rpc_gss_service_t svc;
|
||||
AUTH *auth;
|
||||
#endif
|
||||
|
||||
switch (nmp->nm_secflavor) {
|
||||
#ifdef KGSSAPI
|
||||
case RPCSEC_GSS_KRB5:
|
||||
case RPCSEC_GSS_KRB5I:
|
||||
case RPCSEC_GSS_KRB5P:
|
||||
if (!nmp->nm_mech_oid) {
|
||||
if (!rpc_gss_mech_to_oid("kerberosv5",
|
||||
&nmp->nm_mech_oid))
|
||||
return (NULL);
|
||||
}
|
||||
if (nmp->nm_secflavor == RPCSEC_GSS_KRB5)
|
||||
svc = rpc_gss_svc_none;
|
||||
else if (nmp->nm_secflavor == RPCSEC_GSS_KRB5I)
|
||||
svc = rpc_gss_svc_integrity;
|
||||
else
|
||||
svc = rpc_gss_svc_privacy;
|
||||
auth = rpc_gss_secfind(nmp->nm_client, cred,
|
||||
nmp->nm_principal, nmp->nm_mech_oid, svc);
|
||||
if (auth)
|
||||
return (auth);
|
||||
/* fallthrough */
|
||||
#endif
|
||||
case AUTH_SYS:
|
||||
default:
|
||||
return (authunix_create(cred));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback from the RPC code to generate up/down notifications.
|
||||
*/
|
||||
|
||||
struct nfs_feedback_arg {
|
||||
struct nfsmount *nf_mount;
|
||||
int nf_lastmsg; /* last tprintf */
|
||||
int nf_tprintfmsg;
|
||||
struct thread *nf_td;
|
||||
};
|
||||
|
||||
static void
|
||||
nfs_feedback(int type, int proc, void *arg)
|
||||
{
|
||||
struct nfs_feedback_arg *nf = (struct nfs_feedback_arg *) arg;
|
||||
struct nfsmount *nmp = nf->nf_mount;
|
||||
struct timeval now;
|
||||
|
||||
getmicrouptime(&now);
|
||||
|
||||
switch (type) {
|
||||
case FEEDBACK_REXMIT2:
|
||||
case FEEDBACK_RECONNECT:
|
||||
if (nf->nf_lastmsg + nmp->nm_tprintf_delay < now.tv_sec) {
|
||||
nfs_down(nmp, nf->nf_td,
|
||||
"not responding", 0, NFSSTA_TIMEO);
|
||||
nf->nf_tprintfmsg = TRUE;
|
||||
nf->nf_lastmsg = now.tv_sec;
|
||||
}
|
||||
break;
|
||||
|
||||
case FEEDBACK_OK:
|
||||
nfs_up(nf->nf_mount, nf->nf_td,
|
||||
"is alive again", NFSSTA_TIMEO, nf->nf_tprintfmsg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* nfs_request - goes something like this
|
||||
* - fill in request struct
|
||||
* - links it into list
|
||||
* - calls nfs_send() for first transmit
|
||||
* - calls nfs_receive() to get reply
|
||||
* - break down rpc header and return with nfs reply pointed to
|
||||
* by mrep or error
|
||||
* nb: always frees up mreq mbuf list
|
||||
*/
|
||||
int
|
||||
nfs_request(struct vnode *vp, struct mbuf *mreq, int procnum,
|
||||
struct thread *td, struct ucred *cred, struct mbuf **mrp,
|
||||
struct mbuf **mdp, caddr_t *dposp)
|
||||
{
|
||||
struct mbuf *mrep;
|
||||
u_int32_t *tl;
|
||||
struct nfsmount *nmp;
|
||||
struct mbuf *md;
|
||||
time_t waituntil;
|
||||
caddr_t dpos;
|
||||
int error = 0;
|
||||
struct timeval now;
|
||||
AUTH *auth = NULL;
|
||||
enum nfs_rto_timer_t timer;
|
||||
struct nfs_feedback_arg nf;
|
||||
struct rpc_callextra ext;
|
||||
enum clnt_stat stat;
|
||||
struct timeval timo;
|
||||
|
||||
/* Reject requests while attempting a forced unmount. */
|
||||
if (vp->v_mount->mnt_kern_flag & MNTK_UNMOUNTF) {
|
||||
m_freem(mreq);
|
||||
return (ESTALE);
|
||||
}
|
||||
nmp = VFSTONFS(vp->v_mount);
|
||||
if ((nmp->nm_flag & NFSMNT_NFSV4) != 0)
|
||||
return nfs4_request(vp, mreq, procnum, td, cred, mrp, mdp, dposp);
|
||||
bzero(&nf, sizeof(struct nfs_feedback_arg));
|
||||
nf.nf_mount = nmp;
|
||||
nf.nf_td = td;
|
||||
getmicrouptime(&now);
|
||||
nf.nf_lastmsg = now.tv_sec -
|
||||
((nmp->nm_tprintf_delay) - (nmp->nm_tprintf_initial_delay));
|
||||
|
||||
/*
|
||||
* XXX if not already connected call nfs_connect now. Longer
|
||||
* term, change nfs_mount to call nfs_connect unconditionally
|
||||
* and let clnt_reconnect_create handle reconnects.
|
||||
*/
|
||||
if (!nmp->nm_client)
|
||||
nfs_connect(nmp, NULL);
|
||||
|
||||
auth = nfs_getauth(nmp, cred);
|
||||
if (!auth) {
|
||||
m_freem(mreq);
|
||||
return (EACCES);
|
||||
}
|
||||
bzero(&ext, sizeof(ext));
|
||||
ext.rc_auth = auth;
|
||||
|
||||
ext.rc_feedback = nfs_feedback;
|
||||
ext.rc_feedback_arg = &nf;
|
||||
|
||||
/*
|
||||
* Use a conservative timeout for RPCs other than getattr,
|
||||
* lookup, read or write. The justification for doing "other"
|
||||
* this way is that these RPCs happen so infrequently that
|
||||
* timer est. would probably be stale. Also, since many of
|
||||
* these RPCs are non-idempotent, a conservative timeout is
|
||||
* desired.
|
||||
*/
|
||||
timer = nfs_rto_timer(procnum);
|
||||
if (timer != NFS_DEFAULT_TIMER) {
|
||||
ext.rc_timers = &nmp->nm_timers[timer - 1];
|
||||
} else {
|
||||
ext.rc_timers = NULL;
|
||||
}
|
||||
|
||||
nfsstats.rpcrequests++;
|
||||
tryagain:
|
||||
timo.tv_sec = nmp->nm_timeo / NFS_HZ;
|
||||
timo.tv_usec = (nmp->nm_timeo * 1000000) / NFS_HZ;
|
||||
mrep = NULL;
|
||||
stat = CLNT_CALL_MBUF(nmp->nm_client, &ext,
|
||||
(nmp->nm_flag & NFSMNT_NFSV3) ? procnum : nfsv2_procid[procnum],
|
||||
mreq, &mrep, timo);
|
||||
|
||||
/*
|
||||
* If there was a successful reply and a tprintf msg.
|
||||
* tprintf a response.
|
||||
*/
|
||||
if (stat == RPC_SUCCESS) {
|
||||
error = 0;
|
||||
} else if (stat == RPC_TIMEDOUT) {
|
||||
error = ETIMEDOUT;
|
||||
} else if (stat == RPC_VERSMISMATCH) {
|
||||
error = EOPNOTSUPP;
|
||||
} else if (stat == RPC_PROGVERSMISMATCH) {
|
||||
error = EPROTONOSUPPORT;
|
||||
} else {
|
||||
error = EACCES;
|
||||
}
|
||||
md = mrep;
|
||||
if (error) {
|
||||
m_freem(mreq);
|
||||
AUTH_DESTROY(auth);
|
||||
return (error);
|
||||
}
|
||||
|
||||
KASSERT(mrep != NULL, ("mrep shouldn't be NULL if no error\n"));
|
||||
|
||||
dpos = mtod(mrep, caddr_t);
|
||||
tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
|
||||
if (*tl != 0) {
|
||||
error = fxdr_unsigned(int, *tl);
|
||||
if ((nmp->nm_flag & NFSMNT_NFSV3) &&
|
||||
error == NFSERR_TRYLATER) {
|
||||
m_freem(mrep);
|
||||
error = 0;
|
||||
waituntil = time_second + nfs3_jukebox_delay;
|
||||
while (time_second < waituntil) {
|
||||
(void) tsleep(&fake_wchan, PSOCK, "nqnfstry", hz);
|
||||
}
|
||||
goto tryagain;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the File Handle was stale, invalidate the lookup
|
||||
* cache, just in case.
|
||||
*/
|
||||
if (error == ESTALE)
|
||||
cache_purge(vp);
|
||||
/*
|
||||
* Skip wcc data on NFS errors for now. NetApp filers
|
||||
* return corrupt postop attrs in the wcc data for NFS
|
||||
* err EROFS. Not sure if they could return corrupt
|
||||
* postop attrs for others errors.
|
||||
*/
|
||||
if ((nmp->nm_flag & NFSMNT_NFSV3) && !nfs_skip_wcc_data_onerr) {
|
||||
*mrp = mrep;
|
||||
*mdp = md;
|
||||
*dposp = dpos;
|
||||
error |= NFSERR_RETERR;
|
||||
} else
|
||||
m_freem(mrep);
|
||||
m_freem(mreq);
|
||||
AUTH_DESTROY(auth);
|
||||
return (error);
|
||||
}
|
||||
|
||||
m_freem(mreq);
|
||||
*mrp = mrep;
|
||||
*mdp = md;
|
||||
*dposp = dpos;
|
||||
AUTH_DESTROY(auth);
|
||||
return (0);
|
||||
|
||||
nfsmout:
|
||||
m_freem(mreq);
|
||||
if (auth)
|
||||
AUTH_DESTROY(auth);
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Mark all of an nfs mount's outstanding requests with R_SOFTTERM and
|
||||
* wait for all requests to complete. This is used by forced unmounts
|
||||
* to terminate any outstanding RPCs.
|
||||
*/
|
||||
int
|
||||
nfs_nmcancelreqs(struct nfsmount *nmp)
|
||||
{
|
||||
|
||||
if (nmp->nm_client)
|
||||
CLNT_CLOSE(nmp->nm_client);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Any signal that can interrupt an NFS operation in an intr mount
|
||||
* should be added to this set. SIGSTOP and SIGKILL cannot be masked.
|
||||
*/
|
||||
int nfs_sig_set[] = {
|
||||
SIGINT,
|
||||
SIGTERM,
|
||||
SIGHUP,
|
||||
SIGKILL,
|
||||
SIGSTOP,
|
||||
SIGQUIT
|
||||
};
|
||||
|
||||
/*
|
||||
* Check to see if one of the signals in our subset is pending on
|
||||
* the process (in an intr mount).
|
||||
*/
|
||||
static int
|
||||
nfs_sig_pending(sigset_t set)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < sizeof(nfs_sig_set)/sizeof(int) ; i++)
|
||||
if (SIGISMEMBER(set, nfs_sig_set[i]))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* The set/restore sigmask functions are used to (temporarily) overwrite
|
||||
* the process p_sigmask during an RPC call (for example). These are also
|
||||
* used in other places in the NFS client that might tsleep().
|
||||
*/
|
||||
void
|
||||
nfs_set_sigmask(struct thread *td, sigset_t *oldset)
|
||||
{
|
||||
sigset_t newset;
|
||||
int i;
|
||||
struct proc *p;
|
||||
|
||||
SIGFILLSET(newset);
|
||||
if (td == NULL)
|
||||
td = curthread; /* XXX */
|
||||
p = td->td_proc;
|
||||
/* Remove the NFS set of signals from newset */
|
||||
PROC_LOCK(p);
|
||||
mtx_lock(&p->p_sigacts->ps_mtx);
|
||||
for (i = 0 ; i < sizeof(nfs_sig_set)/sizeof(int) ; i++) {
|
||||
/*
|
||||
* But make sure we leave the ones already masked
|
||||
* by the process, ie. remove the signal from the
|
||||
* temporary signalmask only if it wasn't already
|
||||
* in p_sigmask.
|
||||
*/
|
||||
if (!SIGISMEMBER(td->td_sigmask, nfs_sig_set[i]) &&
|
||||
!SIGISMEMBER(p->p_sigacts->ps_sigignore, nfs_sig_set[i]))
|
||||
SIGDELSET(newset, nfs_sig_set[i]);
|
||||
}
|
||||
mtx_unlock(&p->p_sigacts->ps_mtx);
|
||||
PROC_UNLOCK(p);
|
||||
kern_sigprocmask(td, SIG_SETMASK, &newset, oldset, 0);
|
||||
}
|
||||
|
||||
void
|
||||
nfs_restore_sigmask(struct thread *td, sigset_t *set)
|
||||
{
|
||||
if (td == NULL)
|
||||
td = curthread; /* XXX */
|
||||
kern_sigprocmask(td, SIG_SETMASK, set, NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* NFS wrapper to msleep(), that shoves a new p_sigmask and restores the
|
||||
* old one after msleep() returns.
|
||||
*/
|
||||
int
|
||||
nfs_msleep(struct thread *td, void *ident, struct mtx *mtx, int priority, char *wmesg, int timo)
|
||||
{
|
||||
sigset_t oldset;
|
||||
int error;
|
||||
struct proc *p;
|
||||
|
||||
if ((priority & PCATCH) == 0)
|
||||
return msleep(ident, mtx, priority, wmesg, timo);
|
||||
if (td == NULL)
|
||||
td = curthread; /* XXX */
|
||||
nfs_set_sigmask(td, &oldset);
|
||||
error = msleep(ident, mtx, priority, wmesg, timo);
|
||||
nfs_restore_sigmask(td, &oldset);
|
||||
p = td->td_proc;
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for a termination condition pending on the process.
|
||||
* This is used for NFSMNT_INT mounts.
|
||||
*/
|
||||
int
|
||||
nfs_sigintr(struct nfsmount *nmp, struct nfsreq *rep, struct thread *td)
|
||||
{
|
||||
struct proc *p;
|
||||
sigset_t tmpset;
|
||||
|
||||
if ((nmp->nm_flag & NFSMNT_NFSV4) != 0)
|
||||
return nfs4_sigintr(nmp, rep, td);
|
||||
/* Terminate all requests while attempting a forced unmount. */
|
||||
if (nmp->nm_mountp->mnt_kern_flag & MNTK_UNMOUNTF)
|
||||
return (EIO);
|
||||
if (!(nmp->nm_flag & NFSMNT_INT))
|
||||
return (0);
|
||||
if (td == NULL)
|
||||
return (0);
|
||||
p = td->td_proc;
|
||||
PROC_LOCK(p);
|
||||
tmpset = p->p_siglist;
|
||||
SIGSETOR(tmpset, td->td_siglist);
|
||||
SIGSETNAND(tmpset, td->td_sigmask);
|
||||
mtx_lock(&p->p_sigacts->ps_mtx);
|
||||
SIGSETNAND(tmpset, p->p_sigacts->ps_sigignore);
|
||||
mtx_unlock(&p->p_sigacts->ps_mtx);
|
||||
if ((SIGNOTEMPTY(p->p_siglist) || SIGNOTEMPTY(td->td_siglist))
|
||||
&& nfs_sig_pending(tmpset)) {
|
||||
PROC_UNLOCK(p);
|
||||
return (EINTR);
|
||||
}
|
||||
PROC_UNLOCK(p);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
nfs_msg(struct thread *td, const char *server, const char *msg, int error)
|
||||
{
|
||||
struct proc *p;
|
||||
|
||||
p = td ? td->td_proc : NULL;
|
||||
if (error) {
|
||||
tprintf(p, LOG_INFO, "nfs server %s: %s, error %d\n", server,
|
||||
msg, error);
|
||||
} else {
|
||||
tprintf(p, LOG_INFO, "nfs server %s: %s\n", server, msg);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
nfs_down(struct nfsmount *nmp, struct thread *td, const char *msg,
|
||||
int error, int flags)
|
||||
{
|
||||
if (nmp == NULL)
|
||||
return;
|
||||
mtx_lock(&nmp->nm_mtx);
|
||||
if ((flags & NFSSTA_TIMEO) && !(nmp->nm_state & NFSSTA_TIMEO)) {
|
||||
nmp->nm_state |= NFSSTA_TIMEO;
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,
|
||||
VQ_NOTRESP, 0);
|
||||
} else
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
mtx_lock(&nmp->nm_mtx);
|
||||
if ((flags & NFSSTA_LOCKTIMEO) && !(nmp->nm_state & NFSSTA_LOCKTIMEO)) {
|
||||
nmp->nm_state |= NFSSTA_LOCKTIMEO;
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,
|
||||
VQ_NOTRESPLOCK, 0);
|
||||
} else
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
nfs_msg(td, nmp->nm_mountp->mnt_stat.f_mntfromname, msg, error);
|
||||
}
|
||||
|
||||
static void
|
||||
nfs_up(struct nfsmount *nmp, struct thread *td, const char *msg,
|
||||
int flags, int tprintfmsg)
|
||||
{
|
||||
if (nmp == NULL)
|
||||
return;
|
||||
if (tprintfmsg) {
|
||||
nfs_msg(td, nmp->nm_mountp->mnt_stat.f_mntfromname, msg, 0);
|
||||
}
|
||||
|
||||
mtx_lock(&nmp->nm_mtx);
|
||||
if ((flags & NFSSTA_TIMEO) && (nmp->nm_state & NFSSTA_TIMEO)) {
|
||||
nmp->nm_state &= ~NFSSTA_TIMEO;
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,
|
||||
VQ_NOTRESP, 1);
|
||||
} else
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
|
||||
mtx_lock(&nmp->nm_mtx);
|
||||
if ((flags & NFSSTA_LOCKTIMEO) && (nmp->nm_state & NFSSTA_LOCKTIMEO)) {
|
||||
nmp->nm_state &= ~NFSSTA_LOCKTIMEO;
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,
|
||||
VQ_NOTRESPLOCK, 1);
|
||||
} else
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
}
|
||||
|
||||
#endif /* !NFS_LEGACYRPC */
|
@ -74,6 +74,8 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <nfs4client/nfs4.h>
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
@ -1976,3 +1978,5 @@ nfs_up(rep, nmp, td, msg, flags)
|
||||
mtx_unlock(&nmp->nm_mtx);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* NFS_LEGACYRPC */
|
||||
|
@ -99,8 +99,10 @@ static enum vtype nv2tov_type[8]= {
|
||||
int nfs_ticks;
|
||||
int nfs_pbuf_freecnt = -1; /* start out unlimited */
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
struct nfs_reqq nfs_reqq;
|
||||
struct mtx nfs_reqq_mtx;
|
||||
#endif
|
||||
struct nfs_bufq nfs_bufq;
|
||||
static struct mtx nfs_xid_mtx;
|
||||
|
||||
@ -430,9 +432,11 @@ nfs_init(struct vfsconf *vfsp)
|
||||
/*
|
||||
* Initialize reply list and start timer
|
||||
*/
|
||||
#ifdef NFS_LEGACYRPC
|
||||
TAILQ_INIT(&nfs_reqq);
|
||||
callout_init(&nfs_callout, CALLOUT_MPSAFE);
|
||||
mtx_init(&nfs_reqq_mtx, "NFS reqq lock", NULL, MTX_DEF);
|
||||
callout_init(&nfs_callout, CALLOUT_MPSAFE);
|
||||
#endif
|
||||
mtx_init(&nfs_iod_mtx, "NFS iod lock", NULL, MTX_DEF);
|
||||
mtx_init(&nfs_xid_mtx, "NFS xid lock", NULL, MTX_DEF);
|
||||
|
||||
@ -446,10 +450,12 @@ nfs_uninit(struct vfsconf *vfsp)
|
||||
{
|
||||
int i;
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
callout_stop(&nfs_callout);
|
||||
|
||||
KASSERT(TAILQ_EMPTY(&nfs_reqq),
|
||||
("nfs_uninit: request queue not empty"));
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Tell all nfsiod processes to exit. Clear nfs_iodmax, and wakeup
|
||||
|
@ -67,6 +67,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <rpc/rpcclnt.h>
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
#include <nfs/rpcv2.h>
|
||||
#include <nfs/nfsproto.h>
|
||||
@ -142,6 +143,12 @@ VFS_SET(nfs_vfsops, nfs, VFCF_NETWORK);
|
||||
|
||||
/* So that loader and kldload(2) can find us, wherever we are.. */
|
||||
MODULE_VERSION(nfs, 1);
|
||||
#ifndef NFS_LEGACYRPC
|
||||
MODULE_DEPEND(nfs, krpc, 1, 1, 1);
|
||||
#endif
|
||||
#ifdef KGSSAPI
|
||||
MODULE_DEPEND(nfs, kgssapi, 1, 1, 1);
|
||||
#endif
|
||||
|
||||
static struct nfs_rpcops nfs_rpcops = {
|
||||
nfs_readrpc,
|
||||
@ -546,6 +553,26 @@ nfs_mountdiskless(char *path,
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifndef NFS_LEGACYRPC
|
||||
static int
|
||||
nfs_sec_name_to_num(char *sec)
|
||||
{
|
||||
if (!strcmp(sec, "krb5"))
|
||||
return (RPCSEC_GSS_KRB5);
|
||||
if (!strcmp(sec, "krb5i"))
|
||||
return (RPCSEC_GSS_KRB5I);
|
||||
if (!strcmp(sec, "krb5p"))
|
||||
return (RPCSEC_GSS_KRB5P);
|
||||
if (!strcmp(sec, "sys"))
|
||||
return (AUTH_SYS);
|
||||
/*
|
||||
* Userland should validate the string but we will try and
|
||||
* cope with unexpected values.
|
||||
*/
|
||||
return (AUTH_SYS);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
nfs_decode_args(struct mount *mp, struct nfsmount *nmp, struct nfs_args *argp,
|
||||
const char *hostname)
|
||||
@ -554,6 +581,10 @@ nfs_decode_args(struct mount *mp, struct nfsmount *nmp, struct nfs_args *argp,
|
||||
int adjsock;
|
||||
int maxio;
|
||||
char *p;
|
||||
#ifndef NFS_LEGACYRPC
|
||||
char *secname;
|
||||
char *principal;
|
||||
#endif
|
||||
|
||||
s = splnet();
|
||||
|
||||
@ -705,7 +736,13 @@ nfs_decode_args(struct mount *mp, struct nfsmount *nmp, struct nfs_args *argp,
|
||||
nmp->nm_sotype = argp->sotype;
|
||||
nmp->nm_soproto = argp->proto;
|
||||
|
||||
if (nmp->nm_so && adjsock) {
|
||||
if (
|
||||
#ifdef NFS_LEGACYRPC
|
||||
nmp->nm_so
|
||||
#else
|
||||
nmp->nm_client
|
||||
#endif
|
||||
&& adjsock) {
|
||||
nfs_safedisconnect(nmp);
|
||||
if (nmp->nm_sotype == SOCK_DGRAM)
|
||||
while (nfs_connect(nmp, NULL)) {
|
||||
@ -721,6 +758,24 @@ nfs_decode_args(struct mount *mp, struct nfsmount *nmp, struct nfs_args *argp,
|
||||
if (p)
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
#ifndef NFS_LEGACYRPC
|
||||
if (vfs_getopt(mp->mnt_optnew, "sec",
|
||||
(void **) &secname, NULL) == 0) {
|
||||
nmp->nm_secflavor = nfs_sec_name_to_num(secname);
|
||||
} else {
|
||||
nmp->nm_secflavor = AUTH_SYS;
|
||||
}
|
||||
|
||||
if (vfs_getopt(mp->mnt_optnew, "principal",
|
||||
(void **) &principal, NULL) == 0) {
|
||||
strlcpy(nmp->nm_principal, principal,
|
||||
sizeof(nmp->nm_principal));
|
||||
} else {
|
||||
snprintf(nmp->nm_principal, sizeof(nmp->nm_principal),
|
||||
"nfs@%s", nmp->nm_hostname);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static const char *nfs_opts[] = { "from", "nfs_args",
|
||||
@ -729,8 +784,8 @@ static const char *nfs_opts[] = { "from", "nfs_args",
|
||||
"async", "dumbtimer", "noconn", "nolockd", "intr", "rdirplus", "resvport",
|
||||
"readdirsize", "soft", "hard", "mntudp", "tcp", "udp", "wsize", "rsize",
|
||||
"retrans", "acregmin", "acregmax", "acdirmin", "acdirmax",
|
||||
"deadthresh", "hostname", "timeout", "addr", "fh", "nfsv3",
|
||||
"maxgroups",
|
||||
"deadthresh", "hostname", "timeout", "addr", "fh", "nfsv3", "sec",
|
||||
"maxgroups", "principal",
|
||||
NULL };
|
||||
|
||||
/*
|
||||
|
@ -36,6 +36,25 @@
|
||||
#ifndef _NFSCLIENT_NFSMOUNT_H_
|
||||
#define _NFSCLIENT_NFSMOUNT_H_
|
||||
|
||||
#ifndef NFS_LEGACYRPC
|
||||
|
||||
#undef RPC_SUCCESS
|
||||
#undef RPC_PROGUNAVAIL
|
||||
#undef RPC_PROCUNAVAIL
|
||||
#undef AUTH_OK
|
||||
#undef AUTH_BADCRED
|
||||
#undef AUTH_BADVERF
|
||||
#undef AUTH_TOOWEAK
|
||||
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/clnt.h>
|
||||
#include <rpc/rpcsec_gss.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
|
||||
struct nfs_tcp_mountstate {
|
||||
int rpcresid;
|
||||
#define NFS_TCP_EXPECT_RPCMARKER 0x0001 /* Expect to see a RPC/TCP marker next */
|
||||
@ -45,6 +64,8 @@ struct nfs_tcp_mountstate {
|
||||
int sock_send_inprog;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Mount structure.
|
||||
* One allocated on every NFS mount.
|
||||
@ -59,18 +80,22 @@ struct nfsmount {
|
||||
u_char nm_fh[NFSX_V4FH]; /* File handle of root dir */
|
||||
int nm_fhsize; /* Size of root file handle */
|
||||
struct rpcclnt nm_rpcclnt; /* rpc state */
|
||||
#ifdef NFS_LEGACYRPC
|
||||
struct socket *nm_so; /* Rpc socket */
|
||||
#endif
|
||||
int nm_sotype; /* Type of socket */
|
||||
int nm_soproto; /* and protocol */
|
||||
int nm_soflags; /* pr_flags for socket protocol */
|
||||
struct sockaddr *nm_nam; /* Addr of server */
|
||||
int nm_timeo; /* Init timer for NFSMNT_DUMBTIMR */
|
||||
int nm_retry; /* Max retries */
|
||||
#ifdef NFS_LEGACYRPC
|
||||
int nm_srtt[NFS_MAX_TIMER], /* RTT Timers for rpcs */
|
||||
nm_sdrtt[NFS_MAX_TIMER];
|
||||
int nm_sent; /* Request send count */
|
||||
int nm_cwnd; /* Request send window */
|
||||
int nm_timeouts; /* Request timeouts */
|
||||
#endif
|
||||
int nm_deadthresh; /* Threshold of timeouts-->dead server*/
|
||||
int nm_rsize; /* Max size of read rpc */
|
||||
int nm_wsize; /* Max size of write rpc */
|
||||
@ -90,8 +115,17 @@ struct nfsmount {
|
||||
struct nfs_rpcops *nm_rpcops;
|
||||
int nm_tprintf_initial_delay; /* initial delay */
|
||||
int nm_tprintf_delay; /* interval for messages */
|
||||
#ifdef NFS_LEGACYRPC
|
||||
struct nfs_tcp_mountstate nm_nfstcpstate;
|
||||
#endif
|
||||
char nm_hostname[MNAMELEN]; /* server's name */
|
||||
#ifndef NFS_LEGACYRPC
|
||||
int nm_secflavor; /* auth flavor to use for rpc */
|
||||
struct __rpc_client *nm_client;
|
||||
struct rpc_timers nm_timers[NFS_MAX_TIMER]; /* RTT Timers for rpcs */
|
||||
char nm_principal[MNAMELEN]; /* GSS-API principal of server */
|
||||
gss_OID nm_mech_oid; /* OID of selected GSS-API mechanism */
|
||||
#endif
|
||||
|
||||
/* NFSv4 */
|
||||
uint64_t nm_clientid;
|
||||
|
@ -89,12 +89,25 @@
|
||||
* Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
|
||||
* should ever try and use it.
|
||||
*/
|
||||
struct nfsd_args {
|
||||
|
||||
/*
|
||||
* Add a socket to monitor for NFS requests.
|
||||
*/
|
||||
struct nfsd_addsock_args {
|
||||
int sock; /* Socket to serve */
|
||||
caddr_t name; /* Client addr for connection based sockets */
|
||||
int namelen; /* Length of name */
|
||||
};
|
||||
|
||||
/*
|
||||
* Start processing requests.
|
||||
*/
|
||||
struct nfsd_nfsd_args {
|
||||
const char *principal; /* GSS-API service principal name */
|
||||
int minthreads; /* minimum service thread count */
|
||||
int maxthreads; /* maximum service thread count */
|
||||
};
|
||||
|
||||
/*
|
||||
* XXX to allow amd to include nfs.h without nfsproto.h
|
||||
*/
|
||||
@ -105,8 +118,9 @@ struct nfsd_args {
|
||||
/*
|
||||
* Flags for nfssvc() system call.
|
||||
*/
|
||||
#define NFSSVC_NFSD 0x004
|
||||
#define NFSSVC_OLDNFSD 0x004
|
||||
#define NFSSVC_ADDSOCK 0x008
|
||||
#define NFSSVC_NFSD 0x010
|
||||
|
||||
/*
|
||||
* vfs.nfsrv sysctl(3) identifiers
|
||||
@ -167,6 +181,7 @@ extern int32_t (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *nd,
|
||||
#define NWDELAYHASH(sock, f) \
|
||||
(&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
/*
|
||||
* Network address hash list element
|
||||
*/
|
||||
@ -257,11 +272,37 @@ struct nfsrv_descript {
|
||||
struct timeval nd_starttime; /* Time RPC initiated */
|
||||
fhandle_t nd_fh; /* File handle */
|
||||
struct ucred *nd_cr; /* Credentials */
|
||||
int nd_credflavor; /* Security flavor */
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* This structure is used by the server for describing each request.
|
||||
*/
|
||||
struct nfsrv_descript {
|
||||
struct mbuf *nd_mrep; /* Request mbuf list */
|
||||
struct mbuf *nd_md; /* Current dissect mbuf */
|
||||
struct mbuf *nd_mreq; /* Reply mbuf list */
|
||||
struct sockaddr *nd_nam; /* and socket addr */
|
||||
struct sockaddr *nd_nam2; /* return socket addr */
|
||||
caddr_t nd_dpos; /* Current dissect pos */
|
||||
u_int32_t nd_procnum; /* RPC # */
|
||||
int nd_stable; /* storage type */
|
||||
int nd_flag; /* nd_flag */
|
||||
int nd_repstat; /* Reply status */
|
||||
fhandle_t nd_fh; /* File handle */
|
||||
struct ucred *nd_cr; /* Credentials */
|
||||
int nd_credflavor; /* Security flavor */
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* Bits for "nd_flag" */
|
||||
#define ND_NFSV3 0x08
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
|
||||
extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
|
||||
extern int nfsd_head_flag;
|
||||
#define NFSD_CHECKSLP 0x01
|
||||
@ -273,6 +314,8 @@ extern int nfsd_head_flag;
|
||||
((o)->nd_eoff >= (n)->nd_off && \
|
||||
!bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Defines for WebNFS
|
||||
*/
|
||||
@ -315,38 +358,42 @@ extern int nfs_debug;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
int netaddr_match(int, union nethostaddr *, struct sockaddr *);
|
||||
int nfs_getreq(struct nfsrv_descript *, struct nfsd *, int);
|
||||
int nfsrv_send(struct socket *, struct sockaddr *, struct mbuf *);
|
||||
struct mbuf *nfs_rephead(int, struct nfsrv_descript *, int, struct mbuf **,
|
||||
caddr_t *);
|
||||
int nfsrv_dorec(struct nfssvc_sock *, struct nfsd *,
|
||||
struct nfsrv_descript **);
|
||||
int nfs_slplock(struct nfssvc_sock *, int);
|
||||
void nfs_slpunlock(struct nfssvc_sock *);
|
||||
void nfsrv_initcache(void);
|
||||
void nfsrv_destroycache(void);
|
||||
void nfsrv_timer(void *);
|
||||
int nfsrv_getcache(struct nfsrv_descript *, struct mbuf **);
|
||||
void nfsrv_updatecache(struct nfsrv_descript *, int, struct mbuf *);
|
||||
void nfsrv_cleancache(void);
|
||||
void nfsrv_rcv(struct socket *so, void *arg, int waitflag);
|
||||
void nfsrv_slpderef(struct nfssvc_sock *slp);
|
||||
void nfsrv_wakenfsd(struct nfssvc_sock *slp);
|
||||
int nfsrv_writegather(struct nfsrv_descript **, struct nfssvc_sock *,
|
||||
struct mbuf **);
|
||||
#endif
|
||||
struct mbuf *nfs_rephead(int, struct nfsrv_descript *, int, struct mbuf **,
|
||||
caddr_t *);
|
||||
void nfsm_srvfattr(struct nfsrv_descript *, struct vattr *,
|
||||
struct nfs_fattr *);
|
||||
void nfsm_srvwcc(struct nfsrv_descript *, int, struct vattr *, int,
|
||||
struct vattr *, struct mbuf **, char **);
|
||||
void nfsm_srvpostopattr(struct nfsrv_descript *, int, struct vattr *,
|
||||
struct mbuf **, char **);
|
||||
int netaddr_match(int, union nethostaddr *, struct sockaddr *);
|
||||
int nfs_namei(struct nameidata *, fhandle_t *, int,
|
||||
struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
|
||||
int nfs_namei(struct nameidata *, struct nfsrv_descript *, fhandle_t *,
|
||||
int, struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
|
||||
caddr_t *, struct vnode **, int, struct vattr *, int *, int);
|
||||
void nfsm_adj(struct mbuf *, int, int);
|
||||
int nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
|
||||
void nfsrv_initcache(void);
|
||||
void nfsrv_destroycache(void);
|
||||
void nfsrv_timer(void *);
|
||||
int nfsrv_dorec(struct nfssvc_sock *, struct nfsd *,
|
||||
struct nfsrv_descript **);
|
||||
int nfsrv_getcache(struct nfsrv_descript *, struct mbuf **);
|
||||
void nfsrv_updatecache(struct nfsrv_descript *, int, struct mbuf *);
|
||||
void nfsrv_cleancache(void);
|
||||
void nfsrv_init(int);
|
||||
int nfsrv_errmap(struct nfsrv_descript *, int);
|
||||
void nfsrvw_sort(gid_t *, int);
|
||||
void nfsrv_wakenfsd(struct nfssvc_sock *slp);
|
||||
int nfsrv_writegather(struct nfsrv_descript **, struct nfssvc_sock *,
|
||||
struct mbuf **);
|
||||
|
||||
int nfsrv3_access(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
struct mbuf **mrq);
|
||||
@ -354,8 +401,9 @@ int nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
struct mbuf **mrq);
|
||||
int nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
struct mbuf **mrq);
|
||||
int nfsrv_fhtovp(fhandle_t *, int, struct vnode **, int *, struct ucred *,
|
||||
struct nfssvc_sock *, struct sockaddr *, int *, int);
|
||||
int nfsrv_fhtovp(fhandle_t *, int, struct vnode **, int *,
|
||||
struct nfsrv_descript *, struct nfssvc_sock *, struct sockaddr *,
|
||||
int *, int);
|
||||
int nfsrv_setpublicfs(struct mount *, struct netexport *,
|
||||
struct export_args *);
|
||||
int nfs_ispublicfh(fhandle_t *);
|
||||
@ -399,8 +447,6 @@ int nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
struct mbuf **mrq);
|
||||
int nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
struct mbuf **mrq);
|
||||
void nfsrv_rcv(struct socket *so, void *arg, int waitflag);
|
||||
void nfsrv_slpderef(struct nfssvc_sock *slp);
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#endif
|
||||
|
597
sys/nfsserver/nfs_fha.c
Normal file
597
sys/nfsserver/nfs_fha.c
Normal file
@ -0,0 +1,597 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/sysproto.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/sbuf.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <nfs/xdr_subs.h>
|
||||
#include <nfs/rpcv2.h>
|
||||
#include <nfs/nfsproto.h>
|
||||
#include <nfsserver/nfs.h>
|
||||
#include <nfsserver/nfsm_subs.h>
|
||||
#include <nfsserver/nfs_fha.h>
|
||||
|
||||
#ifndef NFS_LEGACYRPC
|
||||
|
||||
static MALLOC_DEFINE(M_NFS_FHA, "NFS FHA", "NFS FHA");
|
||||
|
||||
/* Sysctl defaults. */
|
||||
#define DEF_BIN_SHIFT 18 /* 256k */
|
||||
#define DEF_MAX_NFSDS_PER_FH 8
|
||||
#define DEF_MAX_REQS_PER_NFSD 4
|
||||
|
||||
struct fha_ctls {
|
||||
u_int32_t bin_shift;
|
||||
u_int32_t max_nfsds_per_fh;
|
||||
u_int32_t max_reqs_per_nfsd;
|
||||
} fha_ctls;
|
||||
|
||||
struct sysctl_ctx_list fha_clist;
|
||||
|
||||
SYSCTL_DECL(_vfs_nfsrv);
|
||||
SYSCTL_DECL(_vfs_nfsrv_fha);
|
||||
|
||||
/* Static sysctl node for the fha from the top-level vfs_nfsrv node. */
|
||||
SYSCTL_NODE(_vfs_nfsrv, OID_AUTO, fha, CTLFLAG_RD, 0, "fha node");
|
||||
|
||||
/* This is the global structure that represents the state of the fha system. */
|
||||
static struct fha_global {
|
||||
struct fha_hash_entry_list *hashtable;
|
||||
u_long hashmask;
|
||||
} g_fha;
|
||||
|
||||
/*
|
||||
* These are the entries in the filehandle hash. They talk about a specific
|
||||
* file, requests against which are being handled by one or more nfsds. We keep
|
||||
* a chain of nfsds against the file. We only have more than one if reads are
|
||||
* ongoing, and then only if the reads affect disparate regions of the file.
|
||||
*
|
||||
* In general, we want to assign a new request to an existing nfsd if it is
|
||||
* going to contend with work happening already on that nfsd, or if the
|
||||
* operation is a read and the nfsd is already handling a proximate read. We
|
||||
* do this to avoid jumping around in the read stream unnecessarily, and to
|
||||
* avoid contention between threads over single files.
|
||||
*/
|
||||
struct fha_hash_entry {
|
||||
LIST_ENTRY(fha_hash_entry) link;
|
||||
u_int64_t fh;
|
||||
u_int16_t num_reads;
|
||||
u_int16_t num_writes;
|
||||
u_int8_t num_threads;
|
||||
struct svcthread_list threads;
|
||||
};
|
||||
LIST_HEAD(fha_hash_entry_list, fha_hash_entry);
|
||||
|
||||
/* A structure used for passing around data internally. */
|
||||
struct fha_info {
|
||||
u_int64_t fh;
|
||||
off_t offset;
|
||||
int locktype;
|
||||
};
|
||||
|
||||
static int fhe_stats_sysctl(SYSCTL_HANDLER_ARGS);
|
||||
|
||||
static void
|
||||
nfs_fha_init(void *foo)
|
||||
{
|
||||
|
||||
/*
|
||||
* A small hash table to map filehandles to fha_hash_entry
|
||||
* structures.
|
||||
*/
|
||||
g_fha.hashtable = hashinit(256, M_NFS_FHA, &g_fha.hashmask);
|
||||
|
||||
/*
|
||||
* Initialize the sysctl context list for the fha module.
|
||||
*/
|
||||
sysctl_ctx_init(&fha_clist);
|
||||
|
||||
fha_ctls.bin_shift = DEF_BIN_SHIFT;
|
||||
fha_ctls.max_nfsds_per_fh = DEF_MAX_NFSDS_PER_FH;
|
||||
fha_ctls.max_reqs_per_nfsd = DEF_MAX_REQS_PER_NFSD;
|
||||
|
||||
SYSCTL_ADD_UINT(&fha_clist, SYSCTL_STATIC_CHILDREN(_vfs_nfsrv_fha),
|
||||
OID_AUTO, "bin_shift", CTLFLAG_RW,
|
||||
&fha_ctls.bin_shift, 0, "For FHA reads, no two requests will "
|
||||
"contend if they're 2^(bin_shift) bytes apart");
|
||||
|
||||
SYSCTL_ADD_UINT(&fha_clist, SYSCTL_STATIC_CHILDREN(_vfs_nfsrv_fha),
|
||||
OID_AUTO, "max_nfsds_per_fh", CTLFLAG_RW,
|
||||
&fha_ctls.max_nfsds_per_fh, 0, "Maximum nfsd threads that "
|
||||
"should be working on requests for the same file handle");
|
||||
|
||||
SYSCTL_ADD_UINT(&fha_clist, SYSCTL_STATIC_CHILDREN(_vfs_nfsrv_fha),
|
||||
OID_AUTO, "max_reqs_per_nfsd", CTLFLAG_RW,
|
||||
&fha_ctls.max_reqs_per_nfsd, 0, "Maximum requests that "
|
||||
"single nfsd thread should be working on at any time");
|
||||
|
||||
SYSCTL_ADD_OID(&fha_clist, SYSCTL_STATIC_CHILDREN(_vfs_nfsrv_fha),
|
||||
OID_AUTO, "fhe_stats", CTLTYPE_STRING | CTLFLAG_RD, 0, 0,
|
||||
fhe_stats_sysctl, "A", "");
|
||||
}
|
||||
|
||||
static void
|
||||
nfs_fha_uninit(void *foo)
|
||||
{
|
||||
|
||||
hashdestroy(g_fha.hashtable, M_NFS_FHA, g_fha.hashmask);
|
||||
}
|
||||
|
||||
SYSINIT(nfs_fha, SI_SUB_ROOT_CONF, SI_ORDER_ANY, nfs_fha_init, NULL);
|
||||
SYSUNINIT(nfs_fha, SI_SUB_ROOT_CONF, SI_ORDER_ANY, nfs_fha_uninit, NULL);
|
||||
|
||||
/*
|
||||
* This just specifies that offsets should obey affinity when within
|
||||
* the same 1Mbyte (1<<20) chunk for the file (reads only for now).
|
||||
*/
|
||||
static void
|
||||
fha_extract_info(struct svc_req *req, struct fha_info *i)
|
||||
{
|
||||
struct mbuf *md = req->rq_args;
|
||||
fhandle_t fh;
|
||||
caddr_t dpos = mtod(md, caddr_t);
|
||||
static u_int64_t random_fh = 0;
|
||||
int error;
|
||||
int v3 = (req->rq_vers == 3);
|
||||
u_int32_t *tl;
|
||||
rpcproc_t procnum;
|
||||
|
||||
/*
|
||||
* We start off with a random fh. If we get a reasonable
|
||||
* procnum, we set the fh. If there's a concept of offset
|
||||
* that we're interested in, we set that.
|
||||
*/
|
||||
i->fh = ++random_fh;
|
||||
i->offset = 0;
|
||||
i->locktype = LK_EXCLUSIVE;
|
||||
|
||||
/*
|
||||
* Extract the procnum and convert to v3 form if necessary.
|
||||
*/
|
||||
procnum = req->rq_proc;
|
||||
if (!v3)
|
||||
procnum = nfsrv_nfsv3_procid[procnum];
|
||||
|
||||
/*
|
||||
* We do affinity for most. However, we divide a realm of affinity
|
||||
* by file offset so as to allow for concurrent random access. We
|
||||
* only do this for reads today, but this may change when IFS supports
|
||||
* efficient concurrent writes.
|
||||
*/
|
||||
if (procnum == NFSPROC_FSSTAT ||
|
||||
procnum == NFSPROC_FSINFO ||
|
||||
procnum == NFSPROC_PATHCONF ||
|
||||
procnum == NFSPROC_NOOP ||
|
||||
procnum == NFSPROC_NULL)
|
||||
goto out;
|
||||
|
||||
/* Grab the filehandle. */
|
||||
error = nfsm_srvmtofh_xx(&fh, v3, &md, &dpos);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
i->fh = *(const u_int64_t *)(fh.fh_fid.fid_data);
|
||||
|
||||
/* Content ourselves with zero offset for all but reads. */
|
||||
if (procnum != NFSPROC_READ)
|
||||
goto out;
|
||||
|
||||
if (v3) {
|
||||
tl = nfsm_dissect_xx_nonblock(2 * NFSX_UNSIGNED, &md, &dpos);
|
||||
if (tl == NULL)
|
||||
goto out;
|
||||
i->offset = fxdr_hyper(tl);
|
||||
} else {
|
||||
tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, &md, &dpos);
|
||||
if (tl == NULL)
|
||||
goto out;
|
||||
i->offset = fxdr_unsigned(u_int32_t, *tl);
|
||||
}
|
||||
out:
|
||||
switch (procnum) {
|
||||
case NFSPROC_NULL:
|
||||
case NFSPROC_GETATTR:
|
||||
case NFSPROC_LOOKUP:
|
||||
case NFSPROC_ACCESS:
|
||||
case NFSPROC_READLINK:
|
||||
case NFSPROC_READ:
|
||||
case NFSPROC_READDIR:
|
||||
case NFSPROC_READDIRPLUS:
|
||||
i->locktype = LK_SHARED;
|
||||
break;
|
||||
case NFSPROC_SETATTR:
|
||||
case NFSPROC_WRITE:
|
||||
case NFSPROC_CREATE:
|
||||
case NFSPROC_MKDIR:
|
||||
case NFSPROC_SYMLINK:
|
||||
case NFSPROC_MKNOD:
|
||||
case NFSPROC_REMOVE:
|
||||
case NFSPROC_RMDIR:
|
||||
case NFSPROC_RENAME:
|
||||
case NFSPROC_LINK:
|
||||
case NFSPROC_FSSTAT:
|
||||
case NFSPROC_FSINFO:
|
||||
case NFSPROC_PATHCONF:
|
||||
case NFSPROC_COMMIT:
|
||||
case NFSPROC_NOOP:
|
||||
i->locktype = LK_EXCLUSIVE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static struct fha_hash_entry *
|
||||
fha_hash_entry_new(u_int64_t fh)
|
||||
{
|
||||
struct fha_hash_entry *e;
|
||||
|
||||
e = malloc(sizeof(*e), M_NFS_FHA, M_WAITOK);
|
||||
e->fh = fh;
|
||||
e->num_reads = 0;
|
||||
e->num_writes = 0;
|
||||
e->num_threads = 0;
|
||||
LIST_INIT(&e->threads);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static void
|
||||
fha_hash_entry_destroy(struct fha_hash_entry *e)
|
||||
{
|
||||
|
||||
if (e->num_reads + e->num_writes)
|
||||
panic("nonempty fhe");
|
||||
free(e, M_NFS_FHA);
|
||||
}
|
||||
|
||||
static void
|
||||
fha_hash_entry_remove(struct fha_hash_entry *e)
|
||||
{
|
||||
|
||||
LIST_REMOVE(e, link);
|
||||
fha_hash_entry_destroy(e);
|
||||
}
|
||||
|
||||
static struct fha_hash_entry *
|
||||
fha_hash_entry_lookup(SVCPOOL *pool, u_int64_t fh)
|
||||
{
|
||||
struct fha_hash_entry *fhe, *new_fhe;
|
||||
|
||||
LIST_FOREACH(fhe, &g_fha.hashtable[fh % g_fha.hashmask], link) {
|
||||
if (fhe->fh == fh)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!fhe) {
|
||||
/* Allocate a new entry. */
|
||||
mtx_unlock(&pool->sp_lock);
|
||||
new_fhe = fha_hash_entry_new(fh);
|
||||
mtx_lock(&pool->sp_lock);
|
||||
|
||||
/* Double-check to make sure we still need the new entry. */
|
||||
LIST_FOREACH(fhe, &g_fha.hashtable[fh % g_fha.hashmask], link) {
|
||||
if (fhe->fh == fh)
|
||||
break;
|
||||
}
|
||||
if (!fhe) {
|
||||
fhe = new_fhe;
|
||||
LIST_INSERT_HEAD(&g_fha.hashtable[fh % g_fha.hashmask],
|
||||
fhe, link);
|
||||
} else {
|
||||
fha_hash_entry_destroy(new_fhe);
|
||||
}
|
||||
}
|
||||
|
||||
return fhe;
|
||||
}
|
||||
|
||||
static void
|
||||
fha_hash_entry_add_thread(struct fha_hash_entry *fhe, SVCTHREAD *thread)
|
||||
{
|
||||
LIST_INSERT_HEAD(&fhe->threads, thread, st_alink);
|
||||
fhe->num_threads++;
|
||||
}
|
||||
|
||||
static void
|
||||
fha_hash_entry_remove_thread(struct fha_hash_entry *fhe, SVCTHREAD *thread)
|
||||
{
|
||||
|
||||
LIST_REMOVE(thread, st_alink);
|
||||
fhe->num_threads--;
|
||||
}
|
||||
|
||||
/*
|
||||
* Account for an ongoing operation associated with this file.
|
||||
*/
|
||||
static void
|
||||
fha_hash_entry_add_op(struct fha_hash_entry *fhe, int locktype, int count)
|
||||
{
|
||||
|
||||
if (LK_EXCLUSIVE == locktype)
|
||||
fhe->num_writes += count;
|
||||
else
|
||||
fhe->num_reads += count;
|
||||
}
|
||||
|
||||
static SVCTHREAD *
|
||||
get_idle_thread(SVCPOOL *pool)
|
||||
{
|
||||
SVCTHREAD *st;
|
||||
|
||||
LIST_FOREACH(st, &pool->sp_idlethreads, st_ilink) {
|
||||
if (st->st_xprt == NULL && STAILQ_EMPTY(&st->st_reqs))
|
||||
return (st);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get the service thread currently associated with the fhe that is
|
||||
* appropriate to handle this operation.
|
||||
*/
|
||||
SVCTHREAD *
|
||||
fha_hash_entry_choose_thread(SVCPOOL *pool, struct fha_hash_entry *fhe,
|
||||
struct fha_info *i, SVCTHREAD *this_thread);
|
||||
|
||||
SVCTHREAD *
|
||||
fha_hash_entry_choose_thread(SVCPOOL *pool, struct fha_hash_entry *fhe,
|
||||
struct fha_info *i, SVCTHREAD *this_thread)
|
||||
{
|
||||
SVCTHREAD *thread, *min_thread = NULL;
|
||||
int req_count, min_count = 0;
|
||||
off_t offset1, offset2;
|
||||
|
||||
LIST_FOREACH(thread, &fhe->threads, st_alink) {
|
||||
req_count = thread->st_reqcount;
|
||||
|
||||
/* If there are any writes in progress, use the first thread. */
|
||||
if (fhe->num_writes) {
|
||||
#if 0
|
||||
ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
|
||||
"fha: %p(%d)w", thread, req_count);
|
||||
#endif
|
||||
return (thread);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for read locality, making sure that we won't
|
||||
* exceed our per-thread load limit in the process.
|
||||
*/
|
||||
offset1 = i->offset >> fha_ctls.bin_shift;
|
||||
offset2 = STAILQ_FIRST(&thread->st_reqs)->rq_p3
|
||||
>> fha_ctls.bin_shift;
|
||||
if (offset1 == offset2) {
|
||||
if ((fha_ctls.max_reqs_per_nfsd == 0) ||
|
||||
(req_count < fha_ctls.max_reqs_per_nfsd)) {
|
||||
#if 0
|
||||
ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
|
||||
"fha: %p(%d)r", thread, req_count);
|
||||
#endif
|
||||
return (thread);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We don't have a locality match, so skip this thread,
|
||||
* but keep track of the most attractive thread in case
|
||||
* we need to come back to it later.
|
||||
*/
|
||||
#if 0
|
||||
ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
|
||||
"fha: %p(%d)s off1 %llu off2 %llu", thread,
|
||||
req_count, offset1, offset2);
|
||||
#endif
|
||||
if ((min_thread == NULL) || (req_count < min_count)) {
|
||||
min_count = req_count;
|
||||
min_thread = thread;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* We didn't find a good match yet. See if we can add
|
||||
* a new thread to this file handle entry's thread list.
|
||||
*/
|
||||
if ((fha_ctls.max_nfsds_per_fh == 0) ||
|
||||
(fhe->num_threads < fha_ctls.max_nfsds_per_fh)) {
|
||||
/*
|
||||
* We can add a new thread, so try for an idle thread
|
||||
* first, and fall back to this_thread if none are idle.
|
||||
*/
|
||||
if (STAILQ_EMPTY(&this_thread->st_reqs)) {
|
||||
thread = this_thread;
|
||||
#if 0
|
||||
ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
|
||||
"fha: %p(%d)t", thread, thread->st_reqcount);
|
||||
#endif
|
||||
} else if ((thread = get_idle_thread(pool))) {
|
||||
#if 0
|
||||
ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
|
||||
"fha: %p(%d)i", thread, thread->st_reqcount);
|
||||
#endif
|
||||
} else {
|
||||
thread = this_thread;
|
||||
#if 0
|
||||
ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO,
|
||||
"fha: %p(%d)b", thread, thread->st_reqcount);
|
||||
#endif
|
||||
}
|
||||
fha_hash_entry_add_thread(fhe, thread);
|
||||
} else {
|
||||
/*
|
||||
* We don't want to use any more threads for this file, so
|
||||
* go back to the most attractive nfsd we're already using.
|
||||
*/
|
||||
thread = min_thread;
|
||||
}
|
||||
|
||||
return (thread);
|
||||
}
|
||||
|
||||
/*
|
||||
* After getting a request, try to assign it to some thread. Usually we
|
||||
* handle it ourselves.
|
||||
*/
|
||||
SVCTHREAD *
|
||||
fha_assign(SVCTHREAD *this_thread, struct svc_req *req)
|
||||
{
|
||||
SVCPOOL *pool;
|
||||
SVCTHREAD *thread;
|
||||
struct fha_info i;
|
||||
struct fha_hash_entry *fhe;
|
||||
|
||||
/*
|
||||
* Only do placement if this is an NFS request.
|
||||
*/
|
||||
if (req->rq_prog != NFS_PROG)
|
||||
return (this_thread);
|
||||
|
||||
if (req->rq_vers != 2 && req->rq_vers != 3)
|
||||
return (this_thread);
|
||||
|
||||
pool = req->rq_xprt->xp_pool;
|
||||
fha_extract_info(req, &i);
|
||||
|
||||
/*
|
||||
* We save the offset associated with this request for later
|
||||
* nfsd matching.
|
||||
*/
|
||||
fhe = fha_hash_entry_lookup(pool, i.fh);
|
||||
req->rq_p1 = fhe;
|
||||
req->rq_p2 = i.locktype;
|
||||
req->rq_p3 = i.offset;
|
||||
|
||||
/*
|
||||
* Choose a thread, taking into consideration locality, thread load,
|
||||
* and the number of threads already working on this file.
|
||||
*/
|
||||
thread = fha_hash_entry_choose_thread(pool, fhe, &i, this_thread);
|
||||
KASSERT(thread, ("fha_assign: NULL thread!"));
|
||||
fha_hash_entry_add_op(fhe, i.locktype, 1);
|
||||
|
||||
return (thread);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when we're done with an operation. The request has already
|
||||
* been de-queued.
|
||||
*/
|
||||
void
|
||||
fha_nd_complete(SVCTHREAD *thread, struct svc_req *req)
|
||||
{
|
||||
struct fha_hash_entry *fhe = req->rq_p1;
|
||||
|
||||
/*
|
||||
* This may be called for reqs that didn't go through
|
||||
* fha_assign (e.g. extra NULL ops used for RPCSEC_GSS.
|
||||
*/
|
||||
if (!fhe)
|
||||
return;
|
||||
|
||||
fha_hash_entry_add_op(fhe, req->rq_p2, -1);
|
||||
|
||||
if (thread->st_reqcount == 0) {
|
||||
fha_hash_entry_remove_thread(fhe, thread);
|
||||
if (0 == fhe->num_reads + fhe->num_writes)
|
||||
fha_hash_entry_remove(fhe);
|
||||
}
|
||||
}
|
||||
|
||||
extern SVCPOOL *nfsrv_pool;
|
||||
|
||||
static int
|
||||
fhe_stats_sysctl(SYSCTL_HANDLER_ARGS)
|
||||
{
|
||||
int error, count, i;
|
||||
struct sbuf sb;
|
||||
struct fha_hash_entry *fhe;
|
||||
bool_t first = TRUE;
|
||||
SVCTHREAD *thread;
|
||||
|
||||
sbuf_new(&sb, NULL, 4096, SBUF_FIXEDLEN);
|
||||
|
||||
if (!nfsrv_pool) {
|
||||
sbuf_printf(&sb, "NFSD not running\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
mtx_lock(&nfsrv_pool->sp_lock);
|
||||
count = 0;
|
||||
for (i = 0; i <= g_fha.hashmask; i++)
|
||||
if (!LIST_EMPTY(&g_fha.hashtable[i]))
|
||||
count++;
|
||||
|
||||
if (count == 0) {
|
||||
sbuf_printf(&sb, "No file handle entries.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0; i <= g_fha.hashmask; i++) {
|
||||
LIST_FOREACH(fhe, &g_fha.hashtable[i], link) {
|
||||
sbuf_printf(&sb, "%sfhe %p: {\n", first ? "" : ", ", fhe);
|
||||
|
||||
sbuf_printf(&sb, " fh: %ju\n", (uintmax_t) fhe->fh);
|
||||
sbuf_printf(&sb, " num_reads: %d\n", fhe->num_reads);
|
||||
sbuf_printf(&sb, " num_writes: %d\n", fhe->num_writes);
|
||||
sbuf_printf(&sb, " num_threads: %d\n", fhe->num_threads);
|
||||
|
||||
LIST_FOREACH(thread, &fhe->threads, st_alink) {
|
||||
sbuf_printf(&sb, " thread %p (count %d)\n",
|
||||
thread, thread->st_reqcount);
|
||||
}
|
||||
|
||||
sbuf_printf(&sb, "}");
|
||||
first = FALSE;
|
||||
|
||||
/* Limit the output. */
|
||||
if (++count > 128) {
|
||||
sbuf_printf(&sb, "...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (nfsrv_pool)
|
||||
mtx_unlock(&nfsrv_pool->sp_lock);
|
||||
sbuf_trim(&sb);
|
||||
sbuf_finish(&sb);
|
||||
error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
|
||||
sbuf_delete(&sb);
|
||||
return (error);
|
||||
}
|
||||
|
||||
#endif /* !NFS_LEGACYRPC */
|
28
sys/nfsserver/nfs_fha.h
Normal file
28
sys/nfsserver/nfs_fha.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/* $FreeBSD$ */
|
||||
|
||||
void fha_nd_complete(SVCTHREAD *, struct svc_req *);
|
||||
SVCTHREAD *fha_assign(SVCTHREAD *, struct svc_req *);
|
@ -142,8 +142,10 @@ SYSCTL_STRUCT(_vfs_nfsrv, NFS_NFSRVSTATS, nfsrvstats, CTLFLAG_RW,
|
||||
|
||||
static int nfsrv_access(struct vnode *, accmode_t, struct ucred *,
|
||||
int, int);
|
||||
#ifdef NFS_LEGACYRPC
|
||||
static void nfsrvw_coalesce(struct nfsrv_descript *,
|
||||
struct nfsrv_descript *);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Clear nameidata fields that are tested in nsfmout cleanup code prior
|
||||
@ -216,7 +218,7 @@ nfsrv3_access(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
fhp = &nfh.fh_generic;
|
||||
nfsm_srvmtofh(fhp);
|
||||
tl = nfsm_dissect_nonblock(u_int32_t *, NFSX_UNSIGNED);
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
if (error) {
|
||||
nfsm_reply(NFSX_UNSIGNED);
|
||||
@ -283,7 +285,7 @@ nfsrv_getattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
vfslocked = 0;
|
||||
fhp = &nfh.fh_generic;
|
||||
nfsm_srvmtofh(fhp);
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, cred, slp, nam,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp, nam,
|
||||
&rdonly, TRUE);
|
||||
if (error) {
|
||||
nfsm_reply(0);
|
||||
@ -392,7 +394,7 @@ nfsrv_setattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
/*
|
||||
* Now that we have all the fields, lets do it.
|
||||
*/
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &tvfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &tvfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
vfslocked = nfsrv_lockedpair(vfslocked, tvfslocked);
|
||||
if (error) {
|
||||
@ -505,7 +507,7 @@ nfsrv_lookup(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
nd.ni_cnd.cn_cred = cred;
|
||||
nd.ni_cnd.cn_nameiop = LOOKUP;
|
||||
nd.ni_cnd.cn_flags = LOCKLEAF | SAVESTART | MPSAFE;
|
||||
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
|
||||
error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos,
|
||||
&dirp, v3, &dirattr, &dirattr_ret, pubflag);
|
||||
vfslocked = NDHASGIANT(&nd);
|
||||
|
||||
@ -715,7 +717,7 @@ nfsrv_readlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
uiop->uio_rw = UIO_READ;
|
||||
uiop->uio_segflg = UIO_SYSSPACE;
|
||||
uiop->uio_td = NULL;
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
if (error) {
|
||||
nfsm_reply(2 * NFSX_UNSIGNED);
|
||||
@ -811,7 +813,7 @@ nfsrv_read(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
* as well.
|
||||
*/
|
||||
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
if (error) {
|
||||
vp = NULL;
|
||||
@ -1112,7 +1114,7 @@ nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
error = 0;
|
||||
goto nfsmout;
|
||||
}
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &tvfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &tvfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
vfslocked = nfsrv_lockedpair(vfslocked, tvfslocked);
|
||||
if (error) {
|
||||
@ -1227,6 +1229,16 @@ nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
return(error);
|
||||
}
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
|
||||
/*
|
||||
* XXX dfr - write gathering isn't supported by the new RPC code since
|
||||
* its really only useful for NFSv2. If there is a real need, we could
|
||||
* attempt to fit it into the filehandle affinity system, e.g. by
|
||||
* looking to see if there are queued write requests that overlap this
|
||||
* one.
|
||||
*/
|
||||
|
||||
/*
|
||||
* For the purposes of write gathering, we must decide if the credential
|
||||
* associated with two pending requests have equivilent privileges. Since
|
||||
@ -1432,7 +1444,7 @@ nfsrv_writegather(struct nfsrv_descript **ndp, struct nfssvc_sock *slp,
|
||||
cred = nfsd->nd_cr;
|
||||
v3 = (nfsd->nd_flag & ND_NFSV3);
|
||||
forat_ret = aftat_ret = 1;
|
||||
error = nfsrv_fhtovp(&nfsd->nd_fh, 1, &vp, &vfslocked, cred,
|
||||
error = nfsrv_fhtovp(&nfsd->nd_fh, 1, &vp, &vfslocked, nfsd,
|
||||
slp, nfsd->nd_nam, &rdonly, TRUE);
|
||||
if (!error) {
|
||||
if (v3)
|
||||
@ -1634,6 +1646,8 @@ nfsrvw_coalesce(struct nfsrv_descript *owp, struct nfsrv_descript *nfsd)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* nfs create service
|
||||
* now does a truncate to 0 length via. setattr if it already exists
|
||||
@ -1697,7 +1711,7 @@ nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
* be valid at all if an error occurs so we have to invalidate it
|
||||
* prior to calling nfsm_reply ( which might goto nfsmout ).
|
||||
*/
|
||||
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
|
||||
error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos,
|
||||
&dirp, v3, &dirfor, &dirfor_ret, FALSE);
|
||||
vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd);
|
||||
if (dirp && !v3) {
|
||||
@ -1987,7 +2001,7 @@ nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
* nfsmout.
|
||||
*/
|
||||
|
||||
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
|
||||
error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos,
|
||||
&dirp, v3, &dirfor, &dirfor_ret, FALSE);
|
||||
vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd);
|
||||
if (error) {
|
||||
@ -2169,7 +2183,7 @@ nfsrv_remove(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
nd.ni_cnd.cn_cred = cred;
|
||||
nd.ni_cnd.cn_nameiop = DELETE;
|
||||
nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | MPSAFE;
|
||||
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
|
||||
error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos,
|
||||
&dirp, v3, &dirfor, &dirfor_ret, FALSE);
|
||||
vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd);
|
||||
if (dirp && !v3) {
|
||||
@ -2296,7 +2310,7 @@ nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
fromnd.ni_cnd.cn_cred = cred;
|
||||
fromnd.ni_cnd.cn_nameiop = DELETE;
|
||||
fromnd.ni_cnd.cn_flags = WANTPARENT | SAVESTART | MPSAFE;
|
||||
error = nfs_namei(&fromnd, ffhp, len, slp, nam, &md,
|
||||
error = nfs_namei(&fromnd, nfsd, ffhp, len, slp, nam, &md,
|
||||
&dpos, &fdirp, v3, &fdirfor, &fdirfor_ret, FALSE);
|
||||
vfslocked = nfsrv_lockedpair_nd(vfslocked, &fromnd);
|
||||
if (fdirp && !v3) {
|
||||
@ -2319,7 +2333,7 @@ nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
tond.ni_cnd.cn_cred = cred;
|
||||
tond.ni_cnd.cn_nameiop = RENAME;
|
||||
tond.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART | MPSAFE;
|
||||
error = nfs_namei(&tond, tfhp, len2, slp, nam, &md,
|
||||
error = nfs_namei(&tond, nfsd, tfhp, len2, slp, nam, &md,
|
||||
&dpos, &tdirp, v3, &tdirfor, &tdirfor_ret, FALSE);
|
||||
vfslocked = nfsrv_lockedpair_nd(vfslocked, &tond);
|
||||
if (tdirp && !v3) {
|
||||
@ -2512,7 +2526,7 @@ nfsrv_link(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
nfsm_srvmtofh(dfhp);
|
||||
nfsm_srvnamesiz(len);
|
||||
|
||||
error = nfsrv_fhtovp(fhp, TRUE, &vp, &tvfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, TRUE, &vp, &tvfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
vfslocked = nfsrv_lockedpair(vfslocked, tvfslocked);
|
||||
if (error) {
|
||||
@ -2535,7 +2549,7 @@ nfsrv_link(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
nd.ni_cnd.cn_cred = cred;
|
||||
nd.ni_cnd.cn_nameiop = CREATE;
|
||||
nd.ni_cnd.cn_flags = LOCKPARENT | MPSAFE | MPSAFE;
|
||||
error = nfs_namei(&nd, dfhp, len, slp, nam, &md, &dpos,
|
||||
error = nfs_namei(&nd, nfsd, dfhp, len, slp, nam, &md, &dpos,
|
||||
&dirp, v3, &dirfor, &dirfor_ret, FALSE);
|
||||
vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd);
|
||||
if (dirp && !v3) {
|
||||
@ -2664,7 +2678,7 @@ nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
nd.ni_cnd.cn_cred = cred;
|
||||
nd.ni_cnd.cn_nameiop = CREATE;
|
||||
nd.ni_cnd.cn_flags = LOCKPARENT | SAVESTART | MPSAFE;
|
||||
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
|
||||
error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos,
|
||||
&dirp, v3, &dirfor, &dirfor_ret, FALSE);
|
||||
vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd);
|
||||
if (error == 0) {
|
||||
@ -2847,7 +2861,7 @@ nfsrv_mkdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
nd.ni_cnd.cn_nameiop = CREATE;
|
||||
nd.ni_cnd.cn_flags = LOCKPARENT | MPSAFE;
|
||||
|
||||
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
|
||||
error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos,
|
||||
&dirp, v3, &dirfor, &dirfor_ret, FALSE);
|
||||
vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd);
|
||||
if (dirp && !v3) {
|
||||
@ -3005,7 +3019,7 @@ nfsrv_rmdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
nd.ni_cnd.cn_cred = cred;
|
||||
nd.ni_cnd.cn_nameiop = DELETE;
|
||||
nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | MPSAFE;
|
||||
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
|
||||
error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos,
|
||||
&dirp, v3, &dirfor, &dirfor_ret, FALSE);
|
||||
vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd);
|
||||
if (dirp && !v3) {
|
||||
@ -3180,7 +3194,7 @@ nfsrv_readdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
if (siz > xfer)
|
||||
siz = xfer;
|
||||
fullsiz = siz;
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
if (!error && vp->v_type != VDIR) {
|
||||
error = ENOTDIR;
|
||||
@ -3474,7 +3488,7 @@ nfsrv_readdirplus(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
if (siz > xfer)
|
||||
siz = xfer;
|
||||
fullsiz = siz;
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
if (!error && vp->v_type != VDIR) {
|
||||
error = ENOTDIR;
|
||||
@ -3815,7 +3829,7 @@ nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
off = fxdr_hyper(tl);
|
||||
tl += 2;
|
||||
cnt = fxdr_unsigned(int, *tl);
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &tvfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &tvfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
vfslocked = nfsrv_lockedpair(vfslocked, tvfslocked);
|
||||
if (error) {
|
||||
@ -3960,7 +3974,7 @@ nfsrv_statfs(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
vfslocked = 0;
|
||||
fhp = &nfh.fh_generic;
|
||||
nfsm_srvmtofh(fhp);
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
if (error) {
|
||||
nfsm_reply(NFSX_UNSIGNED);
|
||||
@ -4055,7 +4069,7 @@ nfsrv_fsinfo(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
fhp = &nfh.fh_generic;
|
||||
vfslocked = 0;
|
||||
nfsm_srvmtofh(fhp);
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
if (error) {
|
||||
nfsm_reply(NFSX_UNSIGNED);
|
||||
@ -4080,10 +4094,7 @@ nfsrv_fsinfo(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
* There should be filesystem VFS OP(s) to get this information.
|
||||
* For now, assume ufs.
|
||||
*/
|
||||
if (slp->ns_so->so_type == SOCK_DGRAM)
|
||||
pref = NFS_MAXDGRAMDATA;
|
||||
else
|
||||
pref = NFS_MAXDATA;
|
||||
pref = NFS_SRVMAXDATA(nfsd);
|
||||
sip->fs_rtmax = txdr_unsigned(pref);
|
||||
sip->fs_rtpref = txdr_unsigned(pref);
|
||||
sip->fs_rtmult = txdr_unsigned(NFS_FABLKSIZE);
|
||||
@ -4133,7 +4144,7 @@ nfsrv_pathconf(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
vfslocked = 0;
|
||||
fhp = &nfh.fh_generic;
|
||||
nfsm_srvmtofh(fhp);
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, cred, slp,
|
||||
error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp,
|
||||
nam, &rdonly, TRUE);
|
||||
if (error) {
|
||||
nfsm_reply(NFSX_UNSIGNED);
|
||||
|
@ -57,6 +57,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include <nfsserver/nfs.h>
|
||||
#include <nfsserver/nfsrvcache.h>
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
|
||||
static long numnfsrvcache;
|
||||
static long desirednfsrvcache;
|
||||
|
||||
@ -385,3 +387,5 @@ nfsrv_cleancache(void)
|
||||
}
|
||||
numnfsrvcache = 0;
|
||||
}
|
||||
|
||||
#endif /* NFS_LEGACYRPC */
|
||||
|
565
sys/nfsserver/nfs_srvkrpc.c
Normal file
565
sys/nfsserver/nfs_srvkrpc.c
Normal file
@ -0,0 +1,565 @@
|
||||
/*-
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Rick Macklem at The University of Guelph.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)nfs_syscalls.c 8.5 (Berkeley) 3/30/95
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "opt_inet6.h"
|
||||
#include "opt_kgssapi.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/sysproto.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/priv.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/bio.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <sys/domain.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <sys/namei.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/lockf.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#ifdef INET6
|
||||
#include <net/if.h>
|
||||
#include <netinet6/in6_var.h>
|
||||
#endif
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpcsec_gss.h>
|
||||
#include <rpc/replay.h>
|
||||
|
||||
#include <nfs/xdr_subs.h>
|
||||
#include <nfs/rpcv2.h>
|
||||
#include <nfs/nfsproto.h>
|
||||
#include <nfsserver/nfs.h>
|
||||
#include <nfsserver/nfsm_subs.h>
|
||||
#include <nfsserver/nfsrvcache.h>
|
||||
#include <nfsserver/nfs_fha.h>
|
||||
|
||||
#ifndef NFS_LEGACYRPC
|
||||
|
||||
static MALLOC_DEFINE(M_NFSSVC, "nfss_srvsock", "Nfs server structure");
|
||||
|
||||
MALLOC_DEFINE(M_NFSRVDESC, "nfss_srvdesc", "NFS server socket descriptor");
|
||||
MALLOC_DEFINE(M_NFSD, "nfss_daemon", "Nfs server daemon structure");
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
SYSCTL_DECL(_vfs_nfsrv);
|
||||
|
||||
SVCPOOL *nfsrv_pool;
|
||||
int nfsd_waiting = 0;
|
||||
int nfsrv_numnfsd = 0;
|
||||
static int nfs_realign_test;
|
||||
static int nfs_realign_count;
|
||||
struct callout nfsrv_callout;
|
||||
static eventhandler_tag nfsrv_nmbclusters_tag;
|
||||
|
||||
static int nfs_privport = 0;
|
||||
SYSCTL_INT(_vfs_nfsrv, NFS_NFSPRIVPORT, nfs_privport, CTLFLAG_RW,
|
||||
&nfs_privport, 0,
|
||||
"Only allow clients using a privileged port");
|
||||
SYSCTL_INT(_vfs_nfsrv, OID_AUTO, gatherdelay, CTLFLAG_RW,
|
||||
&nfsrvw_procrastinate, 0,
|
||||
"Delay value for write gathering");
|
||||
SYSCTL_INT(_vfs_nfsrv, OID_AUTO, gatherdelay_v3, CTLFLAG_RW,
|
||||
&nfsrvw_procrastinate_v3, 0,
|
||||
"Delay in seconds for NFSv3 write gathering");
|
||||
SYSCTL_INT(_vfs_nfsrv, OID_AUTO, realign_test, CTLFLAG_RW,
|
||||
&nfs_realign_test, 0, "");
|
||||
SYSCTL_INT(_vfs_nfsrv, OID_AUTO, realign_count, CTLFLAG_RW,
|
||||
&nfs_realign_count, 0, "");
|
||||
|
||||
static int nfssvc_addsock(struct file *, struct thread *);
|
||||
static int nfssvc_nfsd(struct thread *, struct nfsd_nfsd_args *);
|
||||
|
||||
extern u_long sb_max_adj;
|
||||
|
||||
int32_t (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *nd,
|
||||
struct nfssvc_sock *slp, struct mbuf **mreqp) = {
|
||||
nfsrv_null,
|
||||
nfsrv_getattr,
|
||||
nfsrv_setattr,
|
||||
nfsrv_lookup,
|
||||
nfsrv3_access,
|
||||
nfsrv_readlink,
|
||||
nfsrv_read,
|
||||
nfsrv_write,
|
||||
nfsrv_create,
|
||||
nfsrv_mkdir,
|
||||
nfsrv_symlink,
|
||||
nfsrv_mknod,
|
||||
nfsrv_remove,
|
||||
nfsrv_rmdir,
|
||||
nfsrv_rename,
|
||||
nfsrv_link,
|
||||
nfsrv_readdir,
|
||||
nfsrv_readdirplus,
|
||||
nfsrv_statfs,
|
||||
nfsrv_fsinfo,
|
||||
nfsrv_pathconf,
|
||||
nfsrv_commit,
|
||||
nfsrv_noop
|
||||
};
|
||||
|
||||
/*
|
||||
* NFS server system calls
|
||||
*/
|
||||
|
||||
/*
|
||||
* Nfs server psuedo system call for the nfsd's
|
||||
* Based on the flag value it either:
|
||||
* - adds a socket to the selection list
|
||||
* - remains in the kernel as an nfsd
|
||||
* - remains in the kernel as an nfsiod
|
||||
* For INET6 we suppose that nfsd provides only IN6P_IPV6_V6ONLY sockets
|
||||
* and that mountd provides
|
||||
* - sockaddr with no IPv4-mapped addresses
|
||||
* - mask for both INET and INET6 families if there is IPv4-mapped overlap
|
||||
*/
|
||||
#ifndef _SYS_SYSPROTO_H_
|
||||
struct nfssvc_args {
|
||||
int flag;
|
||||
caddr_t argp;
|
||||
};
|
||||
#endif
|
||||
int
|
||||
nfssvc(struct thread *td, struct nfssvc_args *uap)
|
||||
{
|
||||
struct file *fp;
|
||||
struct nfsd_addsock_args addsockarg;
|
||||
struct nfsd_nfsd_args nfsdarg;
|
||||
int error;
|
||||
|
||||
KASSERT(!mtx_owned(&Giant), ("nfssvc(): called with Giant"));
|
||||
|
||||
error = priv_check(td, PRIV_NFS_DAEMON);
|
||||
if (error)
|
||||
return (error);
|
||||
if (uap->flag & NFSSVC_ADDSOCK) {
|
||||
error = copyin(uap->argp, (caddr_t)&addsockarg,
|
||||
sizeof(addsockarg));
|
||||
if (error)
|
||||
return (error);
|
||||
if ((error = fget(td, addsockarg.sock, &fp)) != 0)
|
||||
return (error);
|
||||
if (fp->f_type != DTYPE_SOCKET) {
|
||||
fdrop(fp, td);
|
||||
return (error); /* XXXRW: Should be EINVAL? */
|
||||
}
|
||||
error = nfssvc_addsock(fp, td);
|
||||
fdrop(fp, td);
|
||||
} else if (uap->flag & NFSSVC_OLDNFSD) {
|
||||
error = nfssvc_nfsd(td, NULL);
|
||||
} else if (uap->flag & NFSSVC_NFSD) {
|
||||
if (!uap->argp)
|
||||
return (EINVAL);
|
||||
error = copyin(uap->argp, (caddr_t)&nfsdarg,
|
||||
sizeof(nfsdarg));
|
||||
if (error)
|
||||
return (error);
|
||||
error = nfssvc_nfsd(td, &nfsdarg);
|
||||
} else {
|
||||
error = ENXIO;
|
||||
}
|
||||
if (error == EINTR || error == ERESTART)
|
||||
error = 0;
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate the rpc reply header
|
||||
* siz arg. is used to decide if adding a cluster is worthwhile
|
||||
*/
|
||||
struct mbuf *
|
||||
nfs_rephead(int siz, struct nfsrv_descript *nd, int err,
|
||||
struct mbuf **mbp, caddr_t *bposp)
|
||||
{
|
||||
u_int32_t *tl;
|
||||
struct mbuf *mreq;
|
||||
caddr_t bpos;
|
||||
struct mbuf *mb;
|
||||
|
||||
if (err == EBADRPC)
|
||||
return (NULL);
|
||||
|
||||
nd->nd_repstat = err;
|
||||
if (err && (nd->nd_flag & ND_NFSV3) == 0) /* XXX recheck */
|
||||
siz = 0;
|
||||
|
||||
MGET(mreq, M_WAIT, MT_DATA);
|
||||
|
||||
/*
|
||||
* If this is a big reply, use a cluster
|
||||
*/
|
||||
mreq->m_len = 0;
|
||||
if (siz >= MINCLSIZE) {
|
||||
MCLGET(mreq, M_WAIT);
|
||||
}
|
||||
mb = mreq;
|
||||
bpos = mtod(mb, caddr_t);
|
||||
|
||||
if (err != NFSERR_RETVOID) {
|
||||
tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
|
||||
if (err)
|
||||
*tl = txdr_unsigned(nfsrv_errmap(nd, err));
|
||||
else
|
||||
*tl = 0;
|
||||
}
|
||||
|
||||
*mbp = mb;
|
||||
*bposp = bpos;
|
||||
if (err != 0 && err != NFSERR_RETVOID)
|
||||
nfsrvstats.srvrpc_errs++;
|
||||
|
||||
return (mreq);
|
||||
}
|
||||
|
||||
/*
|
||||
* nfs_realign:
|
||||
*
|
||||
* Check for badly aligned mbuf data and realign by copying the unaligned
|
||||
* portion of the data into a new mbuf chain and freeing the portions
|
||||
* of the old chain that were replaced.
|
||||
*
|
||||
* We cannot simply realign the data within the existing mbuf chain
|
||||
* because the underlying buffers may contain other rpc commands and
|
||||
* we cannot afford to overwrite them.
|
||||
*
|
||||
* We would prefer to avoid this situation entirely. The situation does
|
||||
* not occur with NFS/UDP and is supposed to only occassionally occur
|
||||
* with TCP. Use vfs.nfs.realign_count and realign_test to check this.
|
||||
*/
|
||||
static void
|
||||
nfs_realign(struct mbuf **pm) /* XXX COMMON */
|
||||
{
|
||||
struct mbuf *m;
|
||||
struct mbuf *n = NULL;
|
||||
int off = 0;
|
||||
|
||||
++nfs_realign_test;
|
||||
while ((m = *pm) != NULL) {
|
||||
if ((m->m_len & 0x3) || (mtod(m, intptr_t) & 0x3)) {
|
||||
MGET(n, M_WAIT, MT_DATA);
|
||||
if (m->m_len >= MINCLSIZE) {
|
||||
MCLGET(n, M_WAIT);
|
||||
}
|
||||
n->m_len = 0;
|
||||
break;
|
||||
}
|
||||
pm = &m->m_next;
|
||||
}
|
||||
|
||||
/*
|
||||
* If n is non-NULL, loop on m copying data, then replace the
|
||||
* portion of the chain that had to be realigned.
|
||||
*/
|
||||
if (n != NULL) {
|
||||
++nfs_realign_count;
|
||||
while (m) {
|
||||
m_copyback(n, off, m->m_len, mtod(m, caddr_t));
|
||||
off += m->m_len;
|
||||
m = m->m_next;
|
||||
}
|
||||
m_freem(*pm);
|
||||
*pm = n;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nfssvc_program(struct svc_req *rqst, SVCXPRT *xprt)
|
||||
{
|
||||
rpcproc_t procnum;
|
||||
int32_t (*proc)(struct nfsrv_descript *nd, struct nfssvc_sock *slp,
|
||||
struct mbuf **mreqp);
|
||||
int flag;
|
||||
struct nfsrv_descript nd;
|
||||
struct mbuf *mreq, *mrep;
|
||||
int error;
|
||||
|
||||
if (rqst->rq_vers == NFS_VER2) {
|
||||
if (rqst->rq_proc > NFSV2PROC_STATFS) {
|
||||
svcerr_noproc(rqst);
|
||||
svc_freereq(rqst);
|
||||
return;
|
||||
}
|
||||
procnum = nfsrv_nfsv3_procid[rqst->rq_proc];
|
||||
flag = 0;
|
||||
} else {
|
||||
if (rqst->rq_proc >= NFS_NPROCS) {
|
||||
svcerr_noproc(rqst);
|
||||
svc_freereq(rqst);
|
||||
return;
|
||||
}
|
||||
procnum = rqst->rq_proc;
|
||||
flag = ND_NFSV3;
|
||||
}
|
||||
proc = nfsrv3_procs[procnum];
|
||||
|
||||
mreq = mrep = NULL;
|
||||
mreq = rqst->rq_args;
|
||||
rqst->rq_args = NULL;
|
||||
nfs_realign(&mreq);
|
||||
|
||||
/*
|
||||
* Note: we want rq_addr, not svc_getrpccaller -
|
||||
* NFS_SRVMAXDATA uses a NULL value for nd_nam2 to detect TCP
|
||||
* mounts.
|
||||
*/
|
||||
memset(&nd, 0, sizeof(nd));
|
||||
nd.nd_md = nd.nd_mrep = mreq;
|
||||
nd.nd_dpos = mtod(mreq, caddr_t);
|
||||
nd.nd_nam = (struct sockaddr *) &xprt->xp_ltaddr;
|
||||
nd.nd_nam2 = rqst->rq_addr;
|
||||
nd.nd_procnum = procnum;
|
||||
nd.nd_cr = NULL;
|
||||
nd.nd_flag = flag;
|
||||
|
||||
if (proc != nfsrv_null) {
|
||||
if (!svc_getcred(rqst, &nd.nd_cr, &nd.nd_credflavor)) {
|
||||
svcerr_weakauth(rqst);
|
||||
svc_freereq(rqst);
|
||||
return;
|
||||
}
|
||||
#ifdef MAC
|
||||
mac_cred_associate_nfsd(nd.nd_cr);
|
||||
#endif
|
||||
}
|
||||
nfsrvstats.srvrpccnt[nd.nd_procnum]++;
|
||||
|
||||
error = proc(&nd, NULL, &mrep);
|
||||
|
||||
if (nd.nd_cr)
|
||||
crfree(nd.nd_cr);
|
||||
|
||||
if (mrep == NULL) {
|
||||
svcerr_decode(rqst);
|
||||
svc_freereq(rqst);
|
||||
return;
|
||||
}
|
||||
if (error && error != NFSERR_RETVOID) {
|
||||
svcerr_systemerr(rqst);
|
||||
svc_freereq(rqst);
|
||||
return;
|
||||
}
|
||||
if (!svc_sendreply_mbuf(rqst, mrep))
|
||||
svcerr_systemerr(rqst);
|
||||
svc_freereq(rqst);
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds a socket to the list for servicing by nfsds.
|
||||
*/
|
||||
static int
|
||||
nfssvc_addsock(struct file *fp, struct thread *td)
|
||||
{
|
||||
int siz;
|
||||
struct socket *so;
|
||||
int error;
|
||||
SVCXPRT *xprt;
|
||||
|
||||
so = fp->f_data;
|
||||
|
||||
siz = sb_max_adj;
|
||||
error = soreserve(so, siz, siz);
|
||||
if (error) {
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Steal the socket from userland so that it doesn't close
|
||||
* unexpectedly.
|
||||
*/
|
||||
if (so->so_type == SOCK_DGRAM)
|
||||
xprt = svc_dg_create(nfsrv_pool, so, 0, 0);
|
||||
else
|
||||
xprt = svc_vc_create(nfsrv_pool, so, 0, 0);
|
||||
if (xprt) {
|
||||
fp->f_ops = &badfileops;
|
||||
fp->f_data = NULL;
|
||||
svc_reg(xprt, NFS_PROG, NFS_VER2, nfssvc_program, NULL);
|
||||
svc_reg(xprt, NFS_PROG, NFS_VER3, nfssvc_program, NULL);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by nfssvc() for nfsds. Just loops around servicing rpc requests
|
||||
* until it is killed by a signal.
|
||||
*/
|
||||
static int
|
||||
nfssvc_nfsd(struct thread *td, struct nfsd_nfsd_args *args)
|
||||
{
|
||||
#ifdef KGSSAPI
|
||||
char principal[128];
|
||||
int error;
|
||||
#endif
|
||||
|
||||
#ifdef KGSSAPI
|
||||
if (args) {
|
||||
error = copyinstr(args->principal, principal,
|
||||
sizeof(principal), NULL);
|
||||
if (error)
|
||||
return (error);
|
||||
} else {
|
||||
snprintf(principal, sizeof(principal), "nfs@%s", hostname);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Only the first nfsd actually does any work. The RPC code
|
||||
* adds threads to it as needed. Any extra processes offered
|
||||
* by nfsd just exit. If nfsd is new enough, it will call us
|
||||
* once with a structure that specifies how many threads to
|
||||
* use.
|
||||
*/
|
||||
NFSD_LOCK();
|
||||
if (nfsrv_numnfsd == 0) {
|
||||
nfsrv_numnfsd++;
|
||||
|
||||
NFSD_UNLOCK();
|
||||
|
||||
#ifdef KGSSAPI
|
||||
rpc_gss_set_svc_name(principal, "kerberosv5",
|
||||
GSS_C_INDEFINITE, NFS_PROG, NFS_VER2);
|
||||
rpc_gss_set_svc_name(principal, "kerberosv5",
|
||||
GSS_C_INDEFINITE, NFS_PROG, NFS_VER3);
|
||||
#endif
|
||||
|
||||
if (args) {
|
||||
nfsrv_pool->sp_minthreads = args->minthreads;
|
||||
nfsrv_pool->sp_maxthreads = args->maxthreads;
|
||||
} else {
|
||||
nfsrv_pool->sp_minthreads = 4;
|
||||
nfsrv_pool->sp_maxthreads = 4;
|
||||
}
|
||||
|
||||
svc_run(nfsrv_pool);
|
||||
|
||||
#ifdef KGSSAPI
|
||||
rpc_gss_clear_svc_name(NFS_PROG, NFS_VER2);
|
||||
rpc_gss_clear_svc_name(NFS_PROG, NFS_VER3);
|
||||
#endif
|
||||
|
||||
NFSD_LOCK();
|
||||
nfsrv_numnfsd--;
|
||||
nfsrv_init(TRUE);
|
||||
}
|
||||
NFSD_UNLOCK();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Size the NFS server's duplicate request cache at 1/2 the
|
||||
* nmbclusters, floating within a (64, 2048) range. This is to
|
||||
* prevent all mbuf clusters being tied up in the NFS dupreq
|
||||
* cache for small values of nmbclusters.
|
||||
*/
|
||||
static size_t
|
||||
nfsrv_replay_size(void)
|
||||
{
|
||||
size_t replaysiz;
|
||||
|
||||
replaysiz = nmbclusters / 2;
|
||||
if (replaysiz > NFSRVCACHE_MAX_SIZE)
|
||||
replaysiz = NFSRVCACHE_MAX_SIZE;
|
||||
if (replaysiz < NFSRVCACHE_MIN_SIZE)
|
||||
replaysiz = NFSRVCACHE_MIN_SIZE;
|
||||
replaysiz *= MCLBYTES;
|
||||
|
||||
return (replaysiz);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when nmbclusters changes - we resize the replay cache
|
||||
* accordingly.
|
||||
*/
|
||||
static void
|
||||
nfsrv_nmbclusters_change(void *tag)
|
||||
{
|
||||
|
||||
if (nfsrv_pool)
|
||||
replay_setsize(nfsrv_pool->sp_rcache, nfsrv_replay_size());
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the data structures for the server.
|
||||
* Handshake with any new nfsds starting up to avoid any chance of
|
||||
* corruption.
|
||||
*/
|
||||
void
|
||||
nfsrv_init(int terminating)
|
||||
{
|
||||
|
||||
NFSD_LOCK_ASSERT();
|
||||
|
||||
if (terminating) {
|
||||
NFSD_UNLOCK();
|
||||
EVENTHANDLER_DEREGISTER(nmbclusters_change,
|
||||
nfsrv_nmbclusters_tag);
|
||||
svcpool_destroy(nfsrv_pool);
|
||||
nfsrv_pool = NULL;
|
||||
NFSD_LOCK();
|
||||
} else
|
||||
nfs_pub.np_valid = 0;
|
||||
|
||||
NFSD_UNLOCK();
|
||||
|
||||
nfsrv_pool = svcpool_create("nfsd", SYSCTL_STATIC_CHILDREN(_vfs_nfsrv));
|
||||
nfsrv_pool->sp_rcache = replay_newcache(nfsrv_replay_size());
|
||||
nfsrv_pool->sp_assign = fha_assign;
|
||||
nfsrv_pool->sp_done = fha_nd_complete;
|
||||
nfsrv_nmbclusters_tag = EVENTHANDLER_REGISTER(nmbclusters_change,
|
||||
nfsrv_nmbclusters_change, NULL, EVENTHANDLER_PRI_FIRST);
|
||||
|
||||
NFSD_LOCK();
|
||||
}
|
||||
|
||||
#endif /* !NFS_LEGACYRPC */
|
@ -70,6 +70,8 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <security/mac/mac_framework.h>
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
@ -383,6 +385,7 @@ nfs_getreq(struct nfsrv_descript *nd, struct nfsd *nfsd, int has_header)
|
||||
}
|
||||
if (len > 0)
|
||||
nfsm_adv(nfsm_rndup(len));
|
||||
nd->nd_credflavor = RPCAUTH_UNIX;
|
||||
} else {
|
||||
nd->nd_repstat = (NFSERR_AUTHERR | AUTH_REJECTCRED);
|
||||
nd->nd_procnum = NFSPROC_NOOP;
|
||||
@ -809,3 +812,5 @@ nfsrv_timer(void *arg)
|
||||
NFSD_UNLOCK();
|
||||
callout_reset(&nfsrv_callout, nfsrv_ticks, nfsrv_timer, NULL);
|
||||
}
|
||||
|
||||
#endif /* NFS_LEGACYRPC */
|
||||
|
@ -93,10 +93,12 @@ static const nfstype nfsv2_type[9] = { NFNON, NFREG, NFDIR, NFBLK, NFCHR,
|
||||
|
||||
int nfsrv_ticks;
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
struct nfssvc_sockhead nfssvc_sockhead;
|
||||
int nfssvc_sockhead_flag;
|
||||
struct nfsd_head nfsd_head;
|
||||
int nfsd_head_flag;
|
||||
#endif
|
||||
|
||||
static int nfssvc_offset = SYS_nfssvc;
|
||||
static struct sysent nfssvc_prev_sysent;
|
||||
@ -545,12 +547,18 @@ nfsrv_modevent(module_t mod, int type, void *data)
|
||||
if (nfsrv_ticks < 1)
|
||||
nfsrv_ticks = 1;
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
nfsrv_initcache(); /* Init the server request cache */
|
||||
NFSD_LOCK();
|
||||
nfsrv_init(0); /* Init server data structures */
|
||||
callout_init(&nfsrv_callout, CALLOUT_MPSAFE);
|
||||
NFSD_UNLOCK();
|
||||
nfsrv_timer(0);
|
||||
#else
|
||||
NFSD_LOCK();
|
||||
nfsrv_init(0); /* Init server data structures */
|
||||
NFSD_UNLOCK();
|
||||
#endif
|
||||
|
||||
error = syscall_register(&nfssvc_offset, &nfssvc_sysent,
|
||||
&nfssvc_prev_sysent);
|
||||
@ -568,7 +576,9 @@ nfsrv_modevent(module_t mod, int type, void *data)
|
||||
if (registered)
|
||||
syscall_deregister(&nfssvc_offset, &nfssvc_prev_sysent);
|
||||
callout_drain(&nfsrv_callout);
|
||||
#ifdef NFS_LEGACYRPC
|
||||
nfsrv_destroycache(); /* Free the server request cache */
|
||||
#endif
|
||||
mtx_destroy(&nfsd_mtx);
|
||||
break;
|
||||
default:
|
||||
@ -604,8 +614,9 @@ MODULE_VERSION(nfsserver, 1);
|
||||
* released by the caller.
|
||||
*/
|
||||
int
|
||||
nfs_namei(struct nameidata *ndp, fhandle_t *fhp, int len,
|
||||
struct nfssvc_sock *slp, struct sockaddr *nam, struct mbuf **mdp,
|
||||
nfs_namei(struct nameidata *ndp, struct nfsrv_descript *nfsd,
|
||||
fhandle_t *fhp, int len, struct nfssvc_sock *slp,
|
||||
struct sockaddr *nam, struct mbuf **mdp,
|
||||
caddr_t *dposp, struct vnode **retdirp, int v3, struct vattr *retdirattrp,
|
||||
int *retdirattr_retp, int pubflag)
|
||||
{
|
||||
@ -667,7 +678,7 @@ nfs_namei(struct nameidata *ndp, fhandle_t *fhp, int len,
|
||||
* Extract and set starting directory.
|
||||
*/
|
||||
error = nfsrv_fhtovp(fhp, FALSE, &dp, &dvfslocked,
|
||||
ndp->ni_cnd.cn_cred, slp, nam, &rdonly, pubflag);
|
||||
nfsd, slp, nam, &rdonly, pubflag);
|
||||
if (error)
|
||||
goto out;
|
||||
vfslocked = VFS_LOCK_GIANT(dp->v_mount);
|
||||
@ -1079,17 +1090,21 @@ nfsm_srvfattr(struct nfsrv_descript *nfsd, struct vattr *vap,
|
||||
*/
|
||||
int
|
||||
nfsrv_fhtovp(fhandle_t *fhp, int lockflag, struct vnode **vpp, int *vfslockedp,
|
||||
struct ucred *cred, struct nfssvc_sock *slp, struct sockaddr *nam,
|
||||
int *rdonlyp, int pubflag)
|
||||
struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
||||
struct sockaddr *nam, int *rdonlyp, int pubflag)
|
||||
{
|
||||
struct mount *mp;
|
||||
int i;
|
||||
struct ucred *credanon;
|
||||
struct ucred *cred, *credanon;
|
||||
int error, exflags;
|
||||
#ifdef MNT_EXNORESPORT /* XXX needs mountd and /etc/exports help yet */
|
||||
struct sockaddr_int *saddr;
|
||||
#endif
|
||||
int credflavor;
|
||||
int vfslocked;
|
||||
int numsecflavors, *secflavors;
|
||||
int v3 = nfsd->nd_flag & ND_NFSV3;
|
||||
int mountreq;
|
||||
|
||||
*vfslockedp = 0;
|
||||
*vpp = NULL;
|
||||
@ -1104,9 +1119,35 @@ nfsrv_fhtovp(fhandle_t *fhp, int lockflag, struct vnode **vpp, int *vfslockedp,
|
||||
if (!mp)
|
||||
return (ESTALE);
|
||||
vfslocked = VFS_LOCK_GIANT(mp);
|
||||
error = VFS_CHECKEXP(mp, nam, &exflags, &credanon);
|
||||
error = VFS_CHECKEXP(mp, nam, &exflags, &credanon,
|
||||
&numsecflavors, &secflavors);
|
||||
if (error)
|
||||
goto out;
|
||||
credflavor = nfsd->nd_credflavor;
|
||||
for (i = 0; i < numsecflavors; i++) {
|
||||
if (secflavors[i] == credflavor)
|
||||
break;
|
||||
}
|
||||
if (i == numsecflavors) {
|
||||
/*
|
||||
* RFC 2623 section 2.3.2 - allow certain procedures
|
||||
* used at NFS client mount time even if they have
|
||||
* weak authentication.
|
||||
*/
|
||||
mountreq = FALSE;
|
||||
if (v3) {
|
||||
if (nfsd->nd_procnum == NFSPROC_FSINFO)
|
||||
mountreq = TRUE;
|
||||
} else {
|
||||
if (nfsd->nd_procnum == NFSPROC_FSSTAT
|
||||
|| nfsd->nd_procnum == NFSPROC_GETATTR)
|
||||
mountreq = TRUE;
|
||||
}
|
||||
if (!mountreq) {
|
||||
error = NFSERR_AUTHERR | AUTH_REJECTCRED;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
error = VFS_FHTOVP(mp, &fhp->fh_fid, vpp);
|
||||
if (error)
|
||||
goto out;
|
||||
@ -1126,6 +1167,7 @@ nfsrv_fhtovp(fhandle_t *fhp, int lockflag, struct vnode **vpp, int *vfslockedp,
|
||||
/*
|
||||
* Check/setup credentials.
|
||||
*/
|
||||
cred = nfsd->nd_cr;
|
||||
if (cred->cr_uid == 0 || (exflags & MNT_EXPORTANON)) {
|
||||
cred->cr_uid = credanon->cr_uid;
|
||||
for (i = 0; i < credanon->cr_ngroups && i < NGROUPS; i++)
|
||||
@ -1168,6 +1210,8 @@ nfs_ispublicfh(fhandle_t *fhp)
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
|
||||
/*
|
||||
* This function compares two net addresses by family and returns TRUE
|
||||
* if they are the same host.
|
||||
@ -1210,6 +1254,8 @@ netaddr_match(int family, union nethostaddr *haddr, struct sockaddr *nam)
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Map errnos to NFS error numbers. For Version 3 also filter out error
|
||||
* numbers not specified for the associated procedure.
|
||||
@ -1364,13 +1410,12 @@ nfsm_clget_xx(u_int32_t **tl, struct mbuf *mb, struct mbuf **mp,
|
||||
}
|
||||
|
||||
int
|
||||
nfsm_srvmtofh_xx(fhandle_t *f, struct nfsrv_descript *nfsd, struct mbuf **md,
|
||||
caddr_t *dpos)
|
||||
nfsm_srvmtofh_xx(fhandle_t *f, int v3, struct mbuf **md, caddr_t *dpos)
|
||||
{
|
||||
u_int32_t *tl;
|
||||
int fhlen;
|
||||
|
||||
if (nfsd->nd_flag & ND_NFSV3) {
|
||||
if (v3) {
|
||||
tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
|
||||
if (tl == NULL)
|
||||
return EBADRPC;
|
||||
|
@ -73,6 +73,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include <nfsserver/nfsm_subs.h>
|
||||
#include <nfsserver/nfsrvcache.h>
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
|
||||
static MALLOC_DEFINE(M_NFSSVC, "nfss_srvsock", "Nfs server structure");
|
||||
|
||||
MALLOC_DEFINE(M_NFSRVDESC, "nfss_srvdesc", "NFS server socket descriptor");
|
||||
@ -130,7 +132,7 @@ nfssvc(struct thread *td, struct nfssvc_args *uap)
|
||||
{
|
||||
struct file *fp;
|
||||
struct sockaddr *nam;
|
||||
struct nfsd_args nfsdarg;
|
||||
struct nfsd_addsock_args nfsdarg;
|
||||
int error;
|
||||
|
||||
KASSERT(!mtx_owned(&Giant), ("nfssvc(): called with Giant"));
|
||||
@ -170,7 +172,7 @@ nfssvc(struct thread *td, struct nfssvc_args *uap)
|
||||
}
|
||||
error = nfssvc_addsock(fp, nam);
|
||||
fdrop(fp, td);
|
||||
} else if (uap->flag & NFSSVC_NFSD) {
|
||||
} else if (uap->flag & NFSSVC_OLDNFSD) {
|
||||
error = nfssvc_nfsd();
|
||||
} else {
|
||||
error = ENXIO;
|
||||
@ -727,3 +729,5 @@ nfsrv_init(int terminating)
|
||||
TAILQ_INSERT_TAIL(&nfssvc_sockhead, nfs_cltpsock, ns_chain);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* NFS_LEGACYRPC */
|
||||
|
@ -75,8 +75,7 @@
|
||||
int nfsm_srvstrsiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos);
|
||||
int nfsm_srvnamesiz_xx(int *s, int m, struct mbuf **md, caddr_t *dpos);
|
||||
int nfsm_srvnamesiz0_xx(int *s, int m, struct mbuf **md, caddr_t *dpos);
|
||||
int nfsm_srvmtofh_xx(fhandle_t *f, struct nfsrv_descript *nfsd,
|
||||
struct mbuf **md, caddr_t *dpos);
|
||||
int nfsm_srvmtofh_xx(fhandle_t *f, int v3, struct mbuf **md, caddr_t *dpos);
|
||||
int nfsm_srvsattr_xx(struct vattr *a, struct mbuf **md, caddr_t *dpos);
|
||||
|
||||
#define nfsm_srvstrsiz(s, m) \
|
||||
@ -112,7 +111,7 @@ do { \
|
||||
#define nfsm_srvmtofh(f) \
|
||||
do { \
|
||||
int t1; \
|
||||
t1 = nfsm_srvmtofh_xx((f), nfsd, &md, &dpos); \
|
||||
t1 = nfsm_srvmtofh_xx((f), nfsd->nd_flag & ND_NFSV3, &md, &dpos); \
|
||||
if (t1) { \
|
||||
error = t1; \
|
||||
nfsm_reply(0); \
|
||||
|
@ -44,6 +44,8 @@
|
||||
#define NFSRVCACHE_MAX_SIZE 2048
|
||||
#define NFSRVCACHE_MIN_SIZE 64
|
||||
|
||||
#ifdef NFS_LEGACYRPC
|
||||
|
||||
struct nfsrvcache {
|
||||
TAILQ_ENTRY(nfsrvcache) rc_lru; /* LRU chain */
|
||||
LIST_ENTRY(nfsrvcache) rc_hash; /* Hash chain */
|
||||
@ -83,3 +85,5 @@ struct nfsrvcache {
|
||||
#define RC_NAM 0x40
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -93,7 +93,7 @@ extern void nlm_host_release(struct nlm_host *host);
|
||||
* Return an RPC client handle that can be used to talk to the NLM
|
||||
* running on the given host.
|
||||
*/
|
||||
extern CLIENT *nlm_host_get_rpc(struct nlm_host *host);
|
||||
extern CLIENT *nlm_host_get_rpc(struct nlm_host *host, bool_t isserver);
|
||||
|
||||
/*
|
||||
* Return the system ID for a host.
|
||||
|
@ -267,6 +267,7 @@ nlm_advlock_internal(struct vnode *vp, void *id, int op, struct flock *fl,
|
||||
|
||||
ext.rc_feedback = nlm_feedback;
|
||||
ext.rc_feedback_arg = &nf;
|
||||
ext.rc_timers = NULL;
|
||||
|
||||
ns = NULL;
|
||||
if (flags & F_FLOCK) {
|
||||
@ -753,7 +754,7 @@ nlm_setlock(struct nlm_host *host, struct rpc_callextra *ext,
|
||||
|
||||
retry = 5*hz;
|
||||
for (;;) {
|
||||
client = nlm_host_get_rpc(host);
|
||||
client = nlm_host_get_rpc(host, FALSE);
|
||||
if (!client)
|
||||
return (ENOLCK); /* XXX retry? */
|
||||
|
||||
@ -834,7 +835,7 @@ nlm_setlock(struct nlm_host *host, struct rpc_callextra *ext,
|
||||
cancel.alock = args.alock;
|
||||
|
||||
do {
|
||||
client = nlm_host_get_rpc(host);
|
||||
client = nlm_host_get_rpc(host, FALSE);
|
||||
if (!client)
|
||||
/* XXX retry? */
|
||||
return (ENOLCK);
|
||||
@ -942,7 +943,7 @@ nlm_clearlock(struct nlm_host *host, struct rpc_callextra *ext,
|
||||
return (error);
|
||||
|
||||
for (;;) {
|
||||
client = nlm_host_get_rpc(host);
|
||||
client = nlm_host_get_rpc(host, FALSE);
|
||||
if (!client)
|
||||
return (ENOLCK); /* XXX retry? */
|
||||
|
||||
@ -1023,7 +1024,7 @@ nlm_getlock(struct nlm_host *host, struct rpc_callextra *ext,
|
||||
args.exclusive = exclusive;
|
||||
|
||||
for (;;) {
|
||||
client = nlm_host_get_rpc(host);
|
||||
client = nlm_host_get_rpc(host, FALSE);
|
||||
if (!client)
|
||||
return (ENOLCK); /* XXX retry? */
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
#include "opt_inet6.h"
|
||||
#include "opt_nfs.h"
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
@ -205,6 +206,12 @@ enum nlm_host_state {
|
||||
NLM_MONITOR_FAILED,
|
||||
NLM_RECOVERING
|
||||
};
|
||||
|
||||
struct nlm_rpc {
|
||||
CLIENT *nr_client; /* (l) RPC client handle */
|
||||
time_t nr_create_time; /* (l) when client was created */
|
||||
};
|
||||
|
||||
struct nlm_host {
|
||||
struct mtx nh_lock;
|
||||
volatile u_int nh_refs; /* (a) reference count */
|
||||
@ -213,12 +220,12 @@ struct nlm_host {
|
||||
uint32_t nh_sysid; /* (c) our allocaed system ID */
|
||||
char nh_sysid_string[10]; /* (c) string rep. of sysid */
|
||||
struct sockaddr_storage nh_addr; /* (s) remote address of host */
|
||||
CLIENT *nh_rpc; /* (l) RPC handle to send to host */
|
||||
struct nlm_rpc nh_srvrpc; /* (l) RPC for server replies */
|
||||
struct nlm_rpc nh_clntrpc; /* (l) RPC for client requests */
|
||||
rpcvers_t nh_vers; /* (s) NLM version of host */
|
||||
int nh_state; /* (s) last seen NSM state of host */
|
||||
enum nlm_host_state nh_monstate; /* (l) local NSM monitoring state */
|
||||
time_t nh_idle_timeout; /* (s) Time at which host is idle */
|
||||
time_t nh_rpc_create_time; /* (s) Time we create RPC client */
|
||||
struct sysctl_ctx_list nh_sysctl; /* (c) vfs.nlm.sysid nodes */
|
||||
struct nlm_async_lock_list nh_pending; /* (l) pending async locks */
|
||||
struct nlm_async_lock_list nh_finished; /* (l) finished async locks */
|
||||
@ -283,7 +290,7 @@ nlm_copy_netobj(struct netobj *dst, struct netobj *src,
|
||||
static CLIENT *
|
||||
nlm_get_rpc(struct sockaddr *sa, rpcprog_t prog, rpcvers_t vers)
|
||||
{
|
||||
const char *wchan = "nlmrcv";
|
||||
char *wchan = "nlmrcv";
|
||||
const char* protofmly;
|
||||
struct sockaddr_storage ss;
|
||||
struct socket *so;
|
||||
@ -472,7 +479,7 @@ nlm_get_rpc(struct sockaddr *sa, rpcprog_t prog, rpcvers_t vers)
|
||||
|
||||
rpcb = clnt_reconnect_create(nconf, (struct sockaddr *)&ss,
|
||||
prog, vers, 0, 0);
|
||||
CLNT_CONTROL(rpcb, CLSET_WAITCHAN, &wchan);
|
||||
CLNT_CONTROL(rpcb, CLSET_WAITCHAN, wchan);
|
||||
rpcb->cl_auth = nlm_auth;
|
||||
|
||||
} else {
|
||||
@ -482,7 +489,7 @@ nlm_get_rpc(struct sockaddr *sa, rpcprog_t prog, rpcvers_t vers)
|
||||
CLNT_CONTROL(rpcb, CLSET_SVC_ADDR, &ss);
|
||||
CLNT_CONTROL(rpcb, CLSET_PROG, &prog);
|
||||
CLNT_CONTROL(rpcb, CLSET_VERS, &vers);
|
||||
CLNT_CONTROL(rpcb, CLSET_WAITCHAN, &wchan);
|
||||
CLNT_CONTROL(rpcb, CLSET_WAITCHAN, wchan);
|
||||
rpcb->cl_auth = nlm_auth;
|
||||
}
|
||||
|
||||
@ -646,13 +653,17 @@ nlm_host_destroy(struct nlm_host *host)
|
||||
TAILQ_REMOVE(&nlm_hosts, host, nh_link);
|
||||
mtx_unlock(&nlm_global_lock);
|
||||
|
||||
if (host->nh_rpc)
|
||||
CLNT_RELEASE(host->nh_rpc);
|
||||
if (host->nh_srvrpc.nr_client)
|
||||
CLNT_RELEASE(host->nh_srvrpc.nr_client);
|
||||
if (host->nh_clntrpc.nr_client)
|
||||
CLNT_RELEASE(host->nh_clntrpc.nr_client);
|
||||
mtx_destroy(&host->nh_lock);
|
||||
sysctl_ctx_free(&host->nh_sysctl);
|
||||
free(host, M_NLM);
|
||||
}
|
||||
|
||||
#ifdef NFSCLIENT
|
||||
|
||||
/*
|
||||
* Thread start callback for client lock recovery
|
||||
*/
|
||||
@ -677,6 +688,8 @@ nlm_client_recovery_start(void *arg)
|
||||
kthread_exit();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is called when we receive a host state change notification. We
|
||||
* unlock any active locks owned by the host. When rpc.lockd is
|
||||
@ -716,6 +729,7 @@ nlm_host_notify(struct nlm_host *host, int newstate)
|
||||
lf_clearremotesys(host->nh_sysid);
|
||||
host->nh_state = newstate;
|
||||
|
||||
#ifdef NFSCLIENT
|
||||
/*
|
||||
* If we have any remote locks for this host (i.e. it
|
||||
* represents a remote NFS server that our local NFS client
|
||||
@ -730,6 +744,7 @@ nlm_host_notify(struct nlm_host *host, int newstate)
|
||||
kthread_add(nlm_client_recovery_start, host, curproc, &td, 0, 0,
|
||||
"NFS lock recovery for %s", host->nh_caller_name);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@ -783,7 +798,6 @@ nlm_create_host(const char* caller_name)
|
||||
host->nh_sysid = nlm_next_sysid++;
|
||||
snprintf(host->nh_sysid_string, sizeof(host->nh_sysid_string),
|
||||
"%d", host->nh_sysid);
|
||||
host->nh_rpc = NULL;
|
||||
host->nh_vers = 0;
|
||||
host->nh_state = 0;
|
||||
host->nh_monstate = NLM_UNMONITORED;
|
||||
@ -933,15 +947,15 @@ nlm_find_host_by_name(const char *name, const struct sockaddr *addr,
|
||||
* have an RPC client handle, make sure the address is
|
||||
* the same, otherwise discard the client handle.
|
||||
*/
|
||||
if (host->nh_addr.ss_len && host->nh_rpc) {
|
||||
if (host->nh_addr.ss_len && host->nh_srvrpc.nr_client) {
|
||||
if (!nlm_compare_addr(
|
||||
(struct sockaddr *) &host->nh_addr,
|
||||
addr)
|
||||
|| host->nh_vers != vers) {
|
||||
CLIENT *client;
|
||||
mtx_lock(&host->nh_lock);
|
||||
client = host->nh_rpc;
|
||||
host->nh_rpc = NULL;
|
||||
client = host->nh_srvrpc.nr_client;
|
||||
host->nh_srvrpc.nr_client = NULL;
|
||||
mtx_unlock(&host->nh_lock);
|
||||
if (client) {
|
||||
CLNT_RELEASE(client);
|
||||
@ -1173,12 +1187,18 @@ nlm_host_monitor(struct nlm_host *host, int state)
|
||||
* running on the given host.
|
||||
*/
|
||||
CLIENT *
|
||||
nlm_host_get_rpc(struct nlm_host *host)
|
||||
nlm_host_get_rpc(struct nlm_host *host, bool_t isserver)
|
||||
{
|
||||
struct nlm_rpc *rpc;
|
||||
CLIENT *client;
|
||||
|
||||
mtx_lock(&host->nh_lock);
|
||||
|
||||
if (isserver)
|
||||
rpc = &host->nh_srvrpc;
|
||||
else
|
||||
rpc = &host->nh_clntrpc;
|
||||
|
||||
/*
|
||||
* We can't hold onto RPC handles for too long - the async
|
||||
* call/reply protocol used by some NLM clients makes it hard
|
||||
@ -1187,33 +1207,33 @@ nlm_host_get_rpc(struct nlm_host *host)
|
||||
* holding any locks, it won't bother to notify us. We
|
||||
* expire the RPC handles after two minutes.
|
||||
*/
|
||||
if (host->nh_rpc && time_uptime > host->nh_rpc_create_time + 2*60) {
|
||||
client = host->nh_rpc;
|
||||
host->nh_rpc = NULL;
|
||||
if (rpc->nr_client && time_uptime > rpc->nr_create_time + 2*60) {
|
||||
client = rpc->nr_client;
|
||||
rpc->nr_client = NULL;
|
||||
mtx_unlock(&host->nh_lock);
|
||||
CLNT_RELEASE(client);
|
||||
mtx_lock(&host->nh_lock);
|
||||
}
|
||||
|
||||
if (!host->nh_rpc) {
|
||||
if (!rpc->nr_client) {
|
||||
mtx_unlock(&host->nh_lock);
|
||||
client = nlm_get_rpc((struct sockaddr *)&host->nh_addr,
|
||||
NLM_PROG, host->nh_vers);
|
||||
mtx_lock(&host->nh_lock);
|
||||
|
||||
if (client) {
|
||||
if (host->nh_rpc) {
|
||||
if (rpc->nr_client) {
|
||||
mtx_unlock(&host->nh_lock);
|
||||
CLNT_DESTROY(client);
|
||||
mtx_lock(&host->nh_lock);
|
||||
} else {
|
||||
host->nh_rpc = client;
|
||||
host->nh_rpc_create_time = time_uptime;
|
||||
rpc->nr_client = client;
|
||||
rpc->nr_create_time = time_uptime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
client = host->nh_rpc;
|
||||
client = rpc->nr_client;
|
||||
if (client)
|
||||
CLNT_ACQUIRE(client);
|
||||
mtx_unlock(&host->nh_lock);
|
||||
@ -1439,8 +1459,10 @@ nlm_server_main(int addr_count, char **addrs)
|
||||
enum clnt_stat stat;
|
||||
struct nlm_host *host, *nhost;
|
||||
struct nlm_waiting_lock *nw;
|
||||
#ifdef NFSCLIENT
|
||||
vop_advlock_t *old_nfs_advlock;
|
||||
vop_reclaim_t *old_nfs_reclaim;
|
||||
#endif
|
||||
int v4_used;
|
||||
#ifdef INET6
|
||||
int v6_used;
|
||||
@ -1512,7 +1534,7 @@ nlm_server_main(int addr_count, char **addrs)
|
||||
goto out;
|
||||
}
|
||||
|
||||
pool = svcpool_create();
|
||||
pool = svcpool_create("NLM", NULL);
|
||||
|
||||
error = nlm_register_services(pool, addr_count, addrs);
|
||||
if (error)
|
||||
@ -1541,16 +1563,20 @@ nlm_server_main(int addr_count, char **addrs)
|
||||
printf("NLM: local NSM state is %d\n", smstat.state);
|
||||
nlm_nsm_state = smstat.state;
|
||||
|
||||
#ifdef NFSCLIENT
|
||||
old_nfs_advlock = nfs_advlock_p;
|
||||
nfs_advlock_p = nlm_advlock;
|
||||
old_nfs_reclaim = nfs_reclaim_p;
|
||||
nfs_reclaim_p = nlm_reclaim;
|
||||
#endif
|
||||
|
||||
svc_run(pool);
|
||||
error = 0;
|
||||
|
||||
#ifdef NFSCLIENT
|
||||
nfs_advlock_p = old_nfs_advlock;
|
||||
nfs_reclaim_p = old_nfs_reclaim;
|
||||
#endif
|
||||
|
||||
out:
|
||||
if (pool)
|
||||
@ -1595,7 +1621,8 @@ nlm_server_main(int addr_count, char **addrs)
|
||||
}
|
||||
TAILQ_FOREACH_SAFE(host, &nlm_hosts, nh_link, nhost) {
|
||||
mtx_lock(&host->nh_lock);
|
||||
if (host->nh_rpc) {
|
||||
if (host->nh_srvrpc.nr_client
|
||||
|| host->nh_clntrpc.nr_client) {
|
||||
if (host->nh_addr.ss_family == AF_INET)
|
||||
v4_used++;
|
||||
#ifdef INET6
|
||||
@ -1607,7 +1634,12 @@ nlm_server_main(int addr_count, char **addrs)
|
||||
* correctly with the fact that a socket may
|
||||
* be used by many rpc handles.
|
||||
*/
|
||||
CLNT_CONTROL(host->nh_rpc, CLSET_FD_CLOSE, 0);
|
||||
if (host->nh_srvrpc.nr_client)
|
||||
CLNT_CONTROL(host->nh_srvrpc.nr_client,
|
||||
CLSET_FD_CLOSE, 0);
|
||||
if (host->nh_clntrpc.nr_client)
|
||||
CLNT_CONTROL(host->nh_clntrpc.nr_client,
|
||||
CLSET_FD_CLOSE, 0);
|
||||
}
|
||||
mtx_unlock(&host->nh_lock);
|
||||
}
|
||||
@ -1687,11 +1719,10 @@ static int
|
||||
nlm_get_vfs_state(struct nlm_host *host, struct svc_req *rqstp,
|
||||
fhandle_t *fhp, struct vfs_state *vs)
|
||||
{
|
||||
int error, exflags, freecred;
|
||||
int error, exflags;
|
||||
struct ucred *cred = NULL, *credanon;
|
||||
|
||||
memset(vs, 0, sizeof(*vs));
|
||||
freecred = FALSE;
|
||||
|
||||
vs->vs_mp = vfs_getvfs(&fhp->fh_fsid);
|
||||
if (!vs->vs_mp) {
|
||||
@ -1700,7 +1731,7 @@ nlm_get_vfs_state(struct nlm_host *host, struct svc_req *rqstp,
|
||||
vs->vs_vfslocked = VFS_LOCK_GIANT(vs->vs_mp);
|
||||
|
||||
error = VFS_CHECKEXP(vs->vs_mp, (struct sockaddr *)&host->nh_addr,
|
||||
&exflags, &credanon);
|
||||
&exflags, &credanon, NULL, NULL);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
@ -1714,16 +1745,13 @@ nlm_get_vfs_state(struct nlm_host *host, struct svc_req *rqstp,
|
||||
goto out;
|
||||
vs->vs_vnlocked = TRUE;
|
||||
|
||||
cred = crget();
|
||||
freecred = TRUE;
|
||||
if (!svc_getcred(rqstp, cred, NULL)) {
|
||||
if (!svc_getcred(rqstp, &cred, NULL)) {
|
||||
error = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (cred->cr_uid == 0 || (exflags & MNT_EXPORTANON)) {
|
||||
crfree(cred);
|
||||
cred = credanon;
|
||||
freecred = FALSE;
|
||||
cred = crhold(credanon);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1741,7 +1769,7 @@ nlm_get_vfs_state(struct nlm_host *host, struct svc_req *rqstp,
|
||||
vs->vs_vnlocked = FALSE;
|
||||
|
||||
out:
|
||||
if (freecred)
|
||||
if (cred)
|
||||
crfree(cred);
|
||||
|
||||
return (error);
|
||||
@ -1788,7 +1816,7 @@ nlm_do_test(nlm4_testargs *argp, nlm4_testres *result, struct svc_req *rqstp,
|
||||
memset(&vs, 0, sizeof(vs));
|
||||
|
||||
host = nlm_find_host_by_name(argp->alock.caller_name,
|
||||
(struct sockaddr *) rqstp->rq_xprt->xp_rtaddr.buf, rqstp->rq_vers);
|
||||
svc_getrpccaller(rqstp), rqstp->rq_vers);
|
||||
if (!host) {
|
||||
result->stat.stat = nlm4_denied_nolocks;
|
||||
return (ENOMEM);
|
||||
@ -1866,7 +1894,7 @@ nlm_do_test(nlm4_testargs *argp, nlm4_testres *result, struct svc_req *rqstp,
|
||||
out:
|
||||
nlm_release_vfs_state(&vs);
|
||||
if (rpcp)
|
||||
*rpcp = nlm_host_get_rpc(host);
|
||||
*rpcp = nlm_host_get_rpc(host, TRUE);
|
||||
nlm_host_release(host);
|
||||
return (0);
|
||||
}
|
||||
@ -1885,7 +1913,7 @@ nlm_do_lock(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp,
|
||||
memset(&vs, 0, sizeof(vs));
|
||||
|
||||
host = nlm_find_host_by_name(argp->alock.caller_name,
|
||||
(struct sockaddr *) rqstp->rq_xprt->xp_rtaddr.buf, rqstp->rq_vers);
|
||||
svc_getrpccaller(rqstp), rqstp->rq_vers);
|
||||
if (!host) {
|
||||
result->stat.stat = nlm4_denied_nolocks;
|
||||
return (ENOMEM);
|
||||
@ -1937,7 +1965,7 @@ nlm_do_lock(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp,
|
||||
/*
|
||||
* First, make sure we can contact the host's NLM.
|
||||
*/
|
||||
client = nlm_host_get_rpc(host);
|
||||
client = nlm_host_get_rpc(host, TRUE);
|
||||
if (!client) {
|
||||
result->stat.stat = nlm4_failed;
|
||||
goto out;
|
||||
@ -2049,7 +2077,7 @@ nlm_do_lock(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp,
|
||||
out:
|
||||
nlm_release_vfs_state(&vs);
|
||||
if (rpcp)
|
||||
*rpcp = nlm_host_get_rpc(host);
|
||||
*rpcp = nlm_host_get_rpc(host, TRUE);
|
||||
nlm_host_release(host);
|
||||
return (0);
|
||||
}
|
||||
@ -2069,7 +2097,7 @@ nlm_do_cancel(nlm4_cancargs *argp, nlm4_res *result, struct svc_req *rqstp,
|
||||
memset(&vs, 0, sizeof(vs));
|
||||
|
||||
host = nlm_find_host_by_name(argp->alock.caller_name,
|
||||
(struct sockaddr *) rqstp->rq_xprt->xp_rtaddr.buf, rqstp->rq_vers);
|
||||
svc_getrpccaller(rqstp), rqstp->rq_vers);
|
||||
if (!host) {
|
||||
result->stat.stat = nlm4_denied_nolocks;
|
||||
return (ENOMEM);
|
||||
@ -2140,7 +2168,7 @@ nlm_do_cancel(nlm4_cancargs *argp, nlm4_res *result, struct svc_req *rqstp,
|
||||
out:
|
||||
nlm_release_vfs_state(&vs);
|
||||
if (rpcp)
|
||||
*rpcp = nlm_host_get_rpc(host);
|
||||
*rpcp = nlm_host_get_rpc(host, TRUE);
|
||||
nlm_host_release(host);
|
||||
return (0);
|
||||
}
|
||||
@ -2159,7 +2187,7 @@ nlm_do_unlock(nlm4_unlockargs *argp, nlm4_res *result, struct svc_req *rqstp,
|
||||
memset(&vs, 0, sizeof(vs));
|
||||
|
||||
host = nlm_find_host_by_name(argp->alock.caller_name,
|
||||
(struct sockaddr *) rqstp->rq_xprt->xp_rtaddr.buf, rqstp->rq_vers);
|
||||
svc_getrpccaller(rqstp), rqstp->rq_vers);
|
||||
if (!host) {
|
||||
result->stat.stat = nlm4_denied_nolocks;
|
||||
return (ENOMEM);
|
||||
@ -2203,7 +2231,7 @@ nlm_do_unlock(nlm4_unlockargs *argp, nlm4_res *result, struct svc_req *rqstp,
|
||||
out:
|
||||
nlm_release_vfs_state(&vs);
|
||||
if (rpcp)
|
||||
*rpcp = nlm_host_get_rpc(host);
|
||||
*rpcp = nlm_host_get_rpc(host, TRUE);
|
||||
nlm_host_release(host);
|
||||
return (0);
|
||||
}
|
||||
@ -2218,9 +2246,7 @@ nlm_do_granted(nlm4_testargs *argp, nlm4_res *result, struct svc_req *rqstp,
|
||||
|
||||
memset(result, 0, sizeof(*result));
|
||||
|
||||
host = nlm_find_host_by_addr(
|
||||
(struct sockaddr *) rqstp->rq_xprt->xp_rtaddr.buf,
|
||||
rqstp->rq_vers);
|
||||
host = nlm_find_host_by_addr(svc_getrpccaller(rqstp), rqstp->rq_vers);
|
||||
if (!host) {
|
||||
result->stat.stat = nlm4_denied_nolocks;
|
||||
return (ENOMEM);
|
||||
@ -2247,7 +2273,7 @@ nlm_do_granted(nlm4_testargs *argp, nlm4_res *result, struct svc_req *rqstp,
|
||||
}
|
||||
mtx_unlock(&nlm_global_lock);
|
||||
if (rpcp)
|
||||
*rpcp = nlm_host_get_rpc(host);
|
||||
*rpcp = nlm_host_get_rpc(host, TRUE);
|
||||
nlm_host_release(host);
|
||||
return (0);
|
||||
}
|
||||
|
@ -57,8 +57,9 @@ nlm_prog_0(struct svc_req *rqstp, SVCXPRT *transp)
|
||||
|
||||
switch (rqstp->rq_proc) {
|
||||
case NULLPROC:
|
||||
(void) svc_sendreply(transp,
|
||||
(void) svc_sendreply(rqstp,
|
||||
(xdrproc_t) xdr_void, (char *)NULL);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
|
||||
case NLM_SM_NOTIFY:
|
||||
@ -68,19 +69,22 @@ nlm_prog_0(struct svc_req *rqstp, SVCXPRT *transp)
|
||||
break;
|
||||
|
||||
default:
|
||||
svcerr_noproc(transp);
|
||||
svcerr_noproc(rqstp);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
}
|
||||
(void) memset((char *)&argument, 0, sizeof (argument));
|
||||
if (!svc_getargs(transp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
svcerr_decode(transp);
|
||||
if (!svc_getargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
svcerr_decode(rqstp);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
}
|
||||
retval = (bool_t) (*local)((char *)&argument, (void *)&result, rqstp);
|
||||
if (retval > 0 && !svc_sendreply(transp, xdr_result, (char *)&result)) {
|
||||
svcerr_systemerr(transp);
|
||||
if (retval > 0 && !svc_sendreply(rqstp, xdr_result, (char *)&result)) {
|
||||
svcerr_systemerr(rqstp);
|
||||
}
|
||||
if (!svc_freeargs(transp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
svc_freereq(rqstp);
|
||||
if (!svc_freeargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
printf("unable to free arguments");
|
||||
//exit(1);
|
||||
}
|
||||
@ -121,8 +125,9 @@ nlm_prog_1(struct svc_req *rqstp, SVCXPRT *transp)
|
||||
|
||||
switch (rqstp->rq_proc) {
|
||||
case NULLPROC:
|
||||
(void) svc_sendreply(transp,
|
||||
(void) svc_sendreply(rqstp,
|
||||
(xdrproc_t) xdr_void, (char *)NULL);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
|
||||
case NLM_TEST:
|
||||
@ -216,22 +221,25 @@ nlm_prog_1(struct svc_req *rqstp, SVCXPRT *transp)
|
||||
break;
|
||||
|
||||
default:
|
||||
svcerr_noproc(transp);
|
||||
svcerr_noproc(rqstp);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
}
|
||||
(void) memset((char *)&argument, 0, sizeof (argument));
|
||||
if (!svc_getargs(transp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
svcerr_decode(transp);
|
||||
if (!svc_getargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
svcerr_decode(rqstp);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
}
|
||||
retval = (bool_t) (*local)((char *)&argument, (void *)&result, rqstp);
|
||||
if (retval > 0 && !svc_sendreply(transp, xdr_result, (char *)&result)) {
|
||||
svcerr_systemerr(transp);
|
||||
if (retval > 0 && !svc_sendreply(rqstp, xdr_result, (char *)&result)) {
|
||||
svcerr_systemerr(rqstp);
|
||||
}
|
||||
if (!svc_freeargs(transp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
if (!svc_freeargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
printf("unable to free arguments");
|
||||
//exit(1);
|
||||
}
|
||||
svc_freereq(rqstp);
|
||||
if (!nlm_prog_1_freeresult(transp, xdr_result, (caddr_t) &result))
|
||||
printf("unable to free results");
|
||||
|
||||
@ -258,8 +266,9 @@ nlm_prog_3(struct svc_req *rqstp, SVCXPRT *transp)
|
||||
|
||||
switch (rqstp->rq_proc) {
|
||||
case NULLPROC:
|
||||
(void) svc_sendreply(transp,
|
||||
(void) svc_sendreply(rqstp,
|
||||
(xdrproc_t) xdr_void, (char *)NULL);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
|
||||
case NLM_TEST:
|
||||
@ -305,22 +314,25 @@ nlm_prog_3(struct svc_req *rqstp, SVCXPRT *transp)
|
||||
break;
|
||||
|
||||
default:
|
||||
svcerr_noproc(transp);
|
||||
svcerr_noproc(rqstp);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
}
|
||||
(void) memset((char *)&argument, 0, sizeof (argument));
|
||||
if (!svc_getargs(transp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
svcerr_decode(transp);
|
||||
if (!svc_getargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
svcerr_decode(rqstp);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
}
|
||||
retval = (bool_t) (*local)((char *)&argument, (void *)&result, rqstp);
|
||||
if (retval > 0 && !svc_sendreply(transp, xdr_result, (char *)&result)) {
|
||||
svcerr_systemerr(transp);
|
||||
if (retval > 0 && !svc_sendreply(rqstp, xdr_result, (char *)&result)) {
|
||||
svcerr_systemerr(rqstp);
|
||||
}
|
||||
if (!svc_freeargs(transp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
if (!svc_freeargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
printf("unable to free arguments");
|
||||
//exit(1);
|
||||
}
|
||||
svc_freereq(rqstp);
|
||||
if (!nlm_prog_3_freeresult(transp, xdr_result, (caddr_t) &result))
|
||||
printf("unable to free results");
|
||||
|
||||
@ -367,8 +379,9 @@ nlm_prog_4(struct svc_req *rqstp, SVCXPRT *transp)
|
||||
|
||||
switch (rqstp->rq_proc) {
|
||||
case NULLPROC:
|
||||
(void) svc_sendreply(transp,
|
||||
(void) svc_sendreply(rqstp,
|
||||
(xdrproc_t) xdr_void, (char *)NULL);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
|
||||
case NLM4_TEST:
|
||||
@ -486,22 +499,25 @@ nlm_prog_4(struct svc_req *rqstp, SVCXPRT *transp)
|
||||
break;
|
||||
|
||||
default:
|
||||
svcerr_noproc(transp);
|
||||
svcerr_noproc(rqstp);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
}
|
||||
(void) memset((char *)&argument, 0, sizeof (argument));
|
||||
if (!svc_getargs(transp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
svcerr_decode(transp);
|
||||
if (!svc_getargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
svcerr_decode(rqstp);
|
||||
svc_freereq(rqstp);
|
||||
return;
|
||||
}
|
||||
retval = (bool_t) (*local)((char *)&argument, (void *)&result, rqstp);
|
||||
if (retval > 0 && !svc_sendreply(transp, xdr_result, (char *)&result)) {
|
||||
svcerr_systemerr(transp);
|
||||
if (retval > 0 && !svc_sendreply(rqstp, xdr_result, (char *)&result)) {
|
||||
svcerr_systemerr(rqstp);
|
||||
}
|
||||
if (!svc_freeargs(transp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
if (!svc_freeargs(rqstp, xdr_argument, (char *)(caddr_t) &argument)) {
|
||||
printf("unable to free arguments");
|
||||
//exit(1);
|
||||
}
|
||||
svc_freereq(rqstp);
|
||||
if (!nlm_prog_4_freeresult(transp, xdr_result, (caddr_t) &result))
|
||||
printf("unable to free results");
|
||||
|
||||
|
@ -132,7 +132,7 @@ enum auth_stat {
|
||||
* failed locally
|
||||
*/
|
||||
AUTH_INVALIDRESP=6, /* bogus response verifier */
|
||||
AUTH_FAILED=7 /* some unknown reason */
|
||||
AUTH_FAILED=7, /* some unknown reason */
|
||||
#ifdef KERBEROS
|
||||
/*
|
||||
* kerberos errors
|
||||
@ -142,8 +142,14 @@ enum auth_stat {
|
||||
AUTH_TIMEEXPIRE = 9, /* time of credential expired */
|
||||
AUTH_TKT_FILE = 10, /* something wrong with ticket file */
|
||||
AUTH_DECODE = 11, /* can't decode authenticator */
|
||||
AUTH_NET_ADDR = 12 /* wrong net address in ticket */
|
||||
AUTH_NET_ADDR = 12, /* wrong net address in ticket */
|
||||
#endif /* KERBEROS */
|
||||
/*
|
||||
* RPCSEC_GSS errors
|
||||
*/
|
||||
RPCSEC_GSS_CREDPROBLEM = 13,
|
||||
RPCSEC_GSS_CTXPROBLEM = 14,
|
||||
RPCSEC_GSS_NODISPATCH = 0x8000000
|
||||
};
|
||||
|
||||
union des_block {
|
||||
@ -171,6 +177,7 @@ struct opaque_auth {
|
||||
/*
|
||||
* Auth handle, interface to client side authenticators.
|
||||
*/
|
||||
struct rpc_err;
|
||||
typedef struct __auth {
|
||||
struct opaque_auth ah_cred;
|
||||
struct opaque_auth ah_verf;
|
||||
@ -178,10 +185,11 @@ typedef struct __auth {
|
||||
struct auth_ops {
|
||||
void (*ah_nextverf) (struct __auth *);
|
||||
/* nextverf & serialize */
|
||||
int (*ah_marshal) (struct __auth *, XDR *);
|
||||
int (*ah_marshal) (struct __auth *, uint32_t, XDR *,
|
||||
struct mbuf *);
|
||||
/* validate verifier */
|
||||
int (*ah_validate) (struct __auth *,
|
||||
struct opaque_auth *);
|
||||
int (*ah_validate) (struct __auth *, uint32_t,
|
||||
struct opaque_auth *, struct mbuf **);
|
||||
/* refresh credentials */
|
||||
int (*ah_refresh) (struct __auth *, void *);
|
||||
/* destroy this structure */
|
||||
@ -201,29 +209,18 @@ typedef struct __auth {
|
||||
*/
|
||||
#define AUTH_NEXTVERF(auth) \
|
||||
((*((auth)->ah_ops->ah_nextverf))(auth))
|
||||
#define auth_nextverf(auth) \
|
||||
((*((auth)->ah_ops->ah_nextverf))(auth))
|
||||
|
||||
#define AUTH_MARSHALL(auth, xdrs) \
|
||||
((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
|
||||
#define auth_marshall(auth, xdrs) \
|
||||
((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
|
||||
#define AUTH_MARSHALL(auth, xid, xdrs, args) \
|
||||
((*((auth)->ah_ops->ah_marshal))(auth, xid, xdrs, args))
|
||||
|
||||
#define AUTH_VALIDATE(auth, verfp) \
|
||||
((*((auth)->ah_ops->ah_validate))((auth), verfp))
|
||||
#define auth_validate(auth, verfp) \
|
||||
((*((auth)->ah_ops->ah_validate))((auth), verfp))
|
||||
#define AUTH_VALIDATE(auth, xid, verfp, resultsp) \
|
||||
((*((auth)->ah_ops->ah_validate))((auth), xid, verfp, resultsp))
|
||||
|
||||
#define AUTH_REFRESH(auth, msg) \
|
||||
((*((auth)->ah_ops->ah_refresh))(auth, msg))
|
||||
#define auth_refresh(auth, msg) \
|
||||
((*((auth)->ah_ops->ah_refresh))(auth, msg))
|
||||
|
||||
#define AUTH_DESTROY(auth) \
|
||||
((*((auth)->ah_ops->ah_destroy))(auth))
|
||||
#define auth_destroy(auth) \
|
||||
((*((auth)->ah_ops->ah_destroy))(auth))
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
extern struct opaque_auth _null_auth;
|
||||
@ -357,5 +354,13 @@ __END_DECLS
|
||||
#define AUTH_DH 3 /* for Diffie-Hellman mechanism */
|
||||
#define AUTH_DES AUTH_DH /* for backward compatibility */
|
||||
#define AUTH_KERB 4 /* kerberos style */
|
||||
#define RPCSEC_GSS 6 /* RPCSEC_GSS */
|
||||
|
||||
/*
|
||||
* Pseudo auth flavors for RPCSEC_GSS.
|
||||
*/
|
||||
#define RPCSEC_GSS_KRB5 390003
|
||||
#define RPCSEC_GSS_KRB5I 390004
|
||||
#define RPCSEC_GSS_KRB5P 390005
|
||||
|
||||
#endif /* !_RPC_AUTH_H */
|
||||
|
@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/clnt.h>
|
||||
|
||||
#define MAX_MARSHAL_SIZE 20
|
||||
|
||||
@ -61,9 +62,10 @@ __FBSDID("$FreeBSD$");
|
||||
* Authenticator operations routines
|
||||
*/
|
||||
|
||||
static bool_t authnone_marshal (AUTH *, XDR *);
|
||||
static bool_t authnone_marshal (AUTH *, uint32_t, XDR *, struct mbuf *);
|
||||
static void authnone_verf (AUTH *);
|
||||
static bool_t authnone_validate (AUTH *, struct opaque_auth *);
|
||||
static bool_t authnone_validate (AUTH *, uint32_t, struct opaque_auth *,
|
||||
struct mbuf **);
|
||||
static bool_t authnone_refresh (AUTH *, void *);
|
||||
static void authnone_destroy (AUTH *);
|
||||
|
||||
@ -72,7 +74,7 @@ static struct auth_ops authnone_ops = {
|
||||
.ah_marshal = authnone_marshal,
|
||||
.ah_validate = authnone_validate,
|
||||
.ah_refresh = authnone_refresh,
|
||||
.ah_destroy = authnone_destroy
|
||||
.ah_destroy = authnone_destroy,
|
||||
};
|
||||
|
||||
struct authnone_private {
|
||||
@ -109,13 +111,18 @@ authnone_create()
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
authnone_marshal(AUTH *client, XDR *xdrs)
|
||||
authnone_marshal(AUTH *client, uint32_t xid, XDR *xdrs, struct mbuf *args)
|
||||
{
|
||||
struct authnone_private *ap = &authnone_private;
|
||||
|
||||
KASSERT(xdrs != NULL, ("authnone_marshal: xdrs is null"));
|
||||
|
||||
return (xdrs->x_ops->x_putbytes(xdrs, ap->mclient, ap->mcnt));
|
||||
if (!XDR_PUTBYTES(xdrs, ap->mclient, ap->mcnt))
|
||||
return (FALSE);
|
||||
|
||||
xdrmbuf_append(xdrs, args);
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/* All these unused parameters are required to keep ANSI-C from grumbling */
|
||||
@ -127,7 +134,8 @@ authnone_verf(AUTH *client)
|
||||
|
||||
/*ARGSUSED*/
|
||||
static bool_t
|
||||
authnone_validate(AUTH *client, struct opaque_auth *opaque)
|
||||
authnone_validate(AUTH *client, uint32_t xid, struct opaque_auth *opaque,
|
||||
struct mbuf **mrepp)
|
||||
{
|
||||
|
||||
return (TRUE);
|
||||
|
@ -62,13 +62,15 @@ __FBSDID("$FreeBSD$");
|
||||
#include <rpc/types.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <rpc/auth.h>
|
||||
#include <rpc/clnt.h>
|
||||
|
||||
#include <rpc/rpc_com.h>
|
||||
|
||||
/* auth_unix.c */
|
||||
static void authunix_nextverf (AUTH *);
|
||||
static bool_t authunix_marshal (AUTH *, XDR *);
|
||||
static bool_t authunix_validate (AUTH *, struct opaque_auth *);
|
||||
static bool_t authunix_marshal (AUTH *, uint32_t, XDR *, struct mbuf *);
|
||||
static bool_t authunix_validate (AUTH *, uint32_t, struct opaque_auth *,
|
||||
struct mbuf **);
|
||||
static bool_t authunix_refresh (AUTH *, void *);
|
||||
static void authunix_destroy (AUTH *);
|
||||
static void marshal_new_auth (AUTH *);
|
||||
@ -78,7 +80,7 @@ static struct auth_ops authunix_ops = {
|
||||
.ah_marshal = authunix_marshal,
|
||||
.ah_validate = authunix_validate,
|
||||
.ah_refresh = authunix_refresh,
|
||||
.ah_destroy = authunix_destroy
|
||||
.ah_destroy = authunix_destroy,
|
||||
};
|
||||
|
||||
/*
|
||||
@ -246,23 +248,32 @@ authunix_nextverf(AUTH *auth)
|
||||
}
|
||||
|
||||
static bool_t
|
||||
authunix_marshal(AUTH *auth, XDR *xdrs)
|
||||
authunix_marshal(AUTH *auth, uint32_t xid, XDR *xdrs, struct mbuf *args)
|
||||
{
|
||||
struct audata *au;
|
||||
|
||||
au = AUTH_PRIVATE(auth);
|
||||
return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos));
|
||||
if (!XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos))
|
||||
return (FALSE);
|
||||
|
||||
xdrmbuf_append(xdrs, args);
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static bool_t
|
||||
authunix_validate(AUTH *auth, struct opaque_auth *verf)
|
||||
authunix_validate(AUTH *auth, uint32_t xid, struct opaque_auth *verf,
|
||||
struct mbuf **mrepp)
|
||||
{
|
||||
struct audata *au;
|
||||
XDR xdrs;
|
||||
XDR txdrs;
|
||||
|
||||
if (!verf)
|
||||
return (TRUE);
|
||||
|
||||
if (verf->oa_flavor == AUTH_SHORT) {
|
||||
au = AUTH_PRIVATE(auth);
|
||||
xdrmem_create(&xdrs, verf->oa_base, verf->oa_length,
|
||||
xdrmem_create(&txdrs, verf->oa_base, verf->oa_length,
|
||||
XDR_DECODE);
|
||||
|
||||
if (au->au_shcred.oa_base != NULL) {
|
||||
@ -270,16 +281,17 @@ authunix_validate(AUTH *auth, struct opaque_auth *verf)
|
||||
au->au_shcred.oa_length);
|
||||
au->au_shcred.oa_base = NULL;
|
||||
}
|
||||
if (xdr_opaque_auth(&xdrs, &au->au_shcred)) {
|
||||
if (xdr_opaque_auth(&txdrs, &au->au_shcred)) {
|
||||
auth->ah_cred = au->au_shcred;
|
||||
} else {
|
||||
xdrs.x_op = XDR_FREE;
|
||||
(void)xdr_opaque_auth(&xdrs, &au->au_shcred);
|
||||
txdrs.x_op = XDR_FREE;
|
||||
(void)xdr_opaque_auth(&txdrs, &au->au_shcred);
|
||||
au->au_shcred.oa_base = NULL;
|
||||
auth->ah_cred = au->au_origcred;
|
||||
}
|
||||
marshal_new_auth(auth);
|
||||
}
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
@ -117,6 +117,15 @@ struct rpc_err {
|
||||
*/
|
||||
typedef void rpc_feedback(int cmd, int procnum, void *);
|
||||
|
||||
/*
|
||||
* Timers used for the pseudo-transport protocol when using datagrams
|
||||
*/
|
||||
struct rpc_timers {
|
||||
u_short rt_srtt; /* smoothed round-trip time */
|
||||
u_short rt_deviate; /* estimated deviation */
|
||||
u_long rt_rtxcur; /* current (backed-off) rto */
|
||||
};
|
||||
|
||||
/*
|
||||
* A structure used with CLNT_CALL_EXT to pass extra information used
|
||||
* while processing an RPC call.
|
||||
@ -125,6 +134,8 @@ struct rpc_callextra {
|
||||
AUTH *rc_auth; /* auth handle to use for this call */
|
||||
rpc_feedback *rc_feedback; /* callback for retransmits etc. */
|
||||
void *rc_feedback_arg; /* argument for callback */
|
||||
struct rpc_timers *rc_timers; /* optional RTT timers */
|
||||
struct rpc_err rc_err; /* detailed call status */
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -140,8 +151,8 @@ typedef struct __rpc_client {
|
||||
struct clnt_ops {
|
||||
/* call remote procedure */
|
||||
enum clnt_stat (*cl_call)(struct __rpc_client *,
|
||||
struct rpc_callextra *, rpcproc_t, xdrproc_t, void *,
|
||||
xdrproc_t, void *, struct timeval);
|
||||
struct rpc_callextra *, rpcproc_t,
|
||||
struct mbuf *, struct mbuf **, struct timeval);
|
||||
/* abort a call */
|
||||
void (*cl_abort)(struct __rpc_client *);
|
||||
/* get specific error code */
|
||||
@ -150,6 +161,8 @@ typedef struct __rpc_client {
|
||||
/* frees results */
|
||||
bool_t (*cl_freeres)(struct __rpc_client *,
|
||||
xdrproc_t, void *);
|
||||
/* close the connection and terminate pending RPCs */
|
||||
void (*cl_close)(struct __rpc_client *);
|
||||
/* destroy this structure */
|
||||
void (*cl_destroy)(struct __rpc_client *);
|
||||
/* the ioctl() of rpc */
|
||||
@ -183,15 +196,6 @@ typedef struct __rpc_client {
|
||||
char *cl_tp; /* device name */
|
||||
} CLIENT;
|
||||
|
||||
/*
|
||||
* Timers used for the pseudo-transport protocol when using datagrams
|
||||
*/
|
||||
struct rpc_timers {
|
||||
u_short rt_srtt; /* smoothed round-trip time */
|
||||
u_short rt_deviate; /* estimated deviation */
|
||||
u_long rt_rtxcur; /* current (backed-off) rto */
|
||||
};
|
||||
|
||||
/*
|
||||
* Feedback values used for possible congestion and rate control
|
||||
*/
|
||||
@ -221,6 +225,32 @@ struct rpc_timers {
|
||||
if (refcount_release(&(rh)->cl_refs)) \
|
||||
CLNT_DESTROY(rh)
|
||||
|
||||
/*
|
||||
* void
|
||||
* CLNT_CLOSE(rh);
|
||||
* CLIENT *rh;
|
||||
*/
|
||||
#define CLNT_CLOSE(rh) ((*(rh)->cl_ops->cl_close)(rh))
|
||||
|
||||
enum clnt_stat clnt_call_private(CLIENT *, struct rpc_callextra *, rpcproc_t,
|
||||
xdrproc_t, void *, xdrproc_t, void *, struct timeval);
|
||||
|
||||
/*
|
||||
* enum clnt_stat
|
||||
* CLNT_CALL_MBUF(rh, ext, proc, mreq, mrepp, timeout)
|
||||
* CLIENT *rh;
|
||||
* struct rpc_callextra *ext;
|
||||
* rpcproc_t proc;
|
||||
* struct mbuf *mreq;
|
||||
* struct mbuf **mrepp;
|
||||
* struct timeval timeout;
|
||||
*
|
||||
* Call arguments in mreq which is consumed by the call (even if there
|
||||
* is an error). Results returned in *mrepp.
|
||||
*/
|
||||
#define CLNT_CALL_MBUF(rh, ext, proc, mreq, mrepp, secs) \
|
||||
((*(rh)->cl_ops->cl_call)(rh, ext, proc, mreq, mrepp, secs))
|
||||
|
||||
/*
|
||||
* enum clnt_stat
|
||||
* CLNT_CALL_EXT(rh, ext, proc, xargs, argsp, xres, resp, timeout)
|
||||
@ -234,8 +264,8 @@ struct rpc_timers {
|
||||
* struct timeval timeout;
|
||||
*/
|
||||
#define CLNT_CALL_EXT(rh, ext, proc, xargs, argsp, xres, resp, secs) \
|
||||
((*(rh)->cl_ops->cl_call)(rh, ext, proc, xargs, \
|
||||
argsp, xres, resp, secs))
|
||||
clnt_call_private(rh, ext, proc, xargs, \
|
||||
argsp, xres, resp, secs)
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -250,12 +280,12 @@ struct rpc_timers {
|
||||
* struct timeval timeout;
|
||||
*/
|
||||
#ifdef _KERNEL
|
||||
#define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
|
||||
((*(rh)->cl_ops->cl_call)(rh, NULL, proc, xargs, \
|
||||
argsp, xres, resp, secs))
|
||||
#define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
|
||||
((*(rh)->cl_ops->cl_call)(rh, NULL, proc, xargs, \
|
||||
argsp, xres, resp, secs))
|
||||
#define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
|
||||
clnt_call_private(rh, NULL, proc, xargs, \
|
||||
argsp, xres, resp, secs)
|
||||
#define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
|
||||
clnt_call_private(rh, NULL, proc, xargs, \
|
||||
argsp, xres, resp, secs)
|
||||
#else
|
||||
#define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
|
||||
((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \
|
||||
@ -340,6 +370,8 @@ struct rpc_timers {
|
||||
#define CLGET_INTERRUPTIBLE 24 /* set interruptible flag */
|
||||
#define CLSET_RETRIES 25 /* set retry count for reconnect */
|
||||
#define CLGET_RETRIES 26 /* get retry count for reconnect */
|
||||
#define CLSET_PRIVPORT 27 /* set privileged source port flag */
|
||||
#define CLGET_PRIVPORT 28 /* get privileged source port flag */
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -72,11 +72,12 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
static bool_t time_not_ok(struct timeval *);
|
||||
static enum clnt_stat clnt_dg_call(CLIENT *, struct rpc_callextra *,
|
||||
rpcproc_t, xdrproc_t, void *, xdrproc_t, void *, struct timeval);
|
||||
rpcproc_t, struct mbuf *, struct mbuf **, struct timeval);
|
||||
static void clnt_dg_geterr(CLIENT *, struct rpc_err *);
|
||||
static bool_t clnt_dg_freeres(CLIENT *, xdrproc_t, void *);
|
||||
static void clnt_dg_abort(CLIENT *);
|
||||
static bool_t clnt_dg_control(CLIENT *, u_int, void *);
|
||||
static void clnt_dg_close(CLIENT *);
|
||||
static void clnt_dg_destroy(CLIENT *);
|
||||
static void clnt_dg_soupcall(struct socket *so, void *arg, int waitflag);
|
||||
|
||||
@ -85,6 +86,7 @@ static struct clnt_ops clnt_dg_ops = {
|
||||
.cl_abort = clnt_dg_abort,
|
||||
.cl_geterr = clnt_dg_geterr,
|
||||
.cl_freeres = clnt_dg_freeres,
|
||||
.cl_close = clnt_dg_close,
|
||||
.cl_destroy = clnt_dg_destroy,
|
||||
.cl_control = clnt_dg_control
|
||||
};
|
||||
@ -102,6 +104,7 @@ struct cu_request {
|
||||
uint32_t cr_xid; /* XID of request */
|
||||
struct mbuf *cr_mrep; /* reply received by upcall */
|
||||
int cr_error; /* any error from upcall */
|
||||
char cr_verf[MAX_AUTH_BYTES]; /* reply verf */
|
||||
};
|
||||
|
||||
TAILQ_HEAD(cu_request_list, cu_request);
|
||||
@ -120,7 +123,6 @@ struct cu_socket {
|
||||
struct mtx cs_lock;
|
||||
int cs_refs; /* Count of clients */
|
||||
struct cu_request_list cs_pending; /* Requests awaiting replies */
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
@ -128,7 +130,8 @@ struct cu_socket {
|
||||
*/
|
||||
struct cu_data {
|
||||
int cu_threads; /* # threads in clnt_vc_call */
|
||||
bool_t cu_closing; /* TRUE if we are destroying */
|
||||
bool_t cu_closing; /* TRUE if we are closing */
|
||||
bool_t cu_closed; /* TRUE if we are closed */
|
||||
struct socket *cu_socket; /* connection socket */
|
||||
bool_t cu_closeit; /* opened by library */
|
||||
struct sockaddr_storage cu_raddr; /* remote address */
|
||||
@ -146,8 +149,14 @@ struct cu_data {
|
||||
int cu_connected; /* Have done connect(). */
|
||||
const char *cu_waitchan;
|
||||
int cu_waitflag;
|
||||
int cu_cwnd; /* congestion window */
|
||||
int cu_sent; /* number of in-flight RPCs */
|
||||
bool_t cu_cwnd_wait;
|
||||
};
|
||||
|
||||
#define CWNDSCALE 256
|
||||
#define MAXCWND (32 * CWNDSCALE)
|
||||
|
||||
/*
|
||||
* Connection less client creation returns with client handle parameters.
|
||||
* Default options are set, which the user can change using clnt_control().
|
||||
@ -211,6 +220,7 @@ clnt_dg_create(
|
||||
cu = mem_alloc(sizeof (*cu));
|
||||
cu->cu_threads = 0;
|
||||
cu->cu_closing = FALSE;
|
||||
cu->cu_closed = FALSE;
|
||||
(void) memcpy(&cu->cu_raddr, svcaddr, (size_t)svcaddr->sa_len);
|
||||
cu->cu_rlen = svcaddr->sa_len;
|
||||
/* Other values can also be set through clnt_control() */
|
||||
@ -225,6 +235,9 @@ clnt_dg_create(
|
||||
cu->cu_connected = FALSE;
|
||||
cu->cu_waitchan = "rpcrecv";
|
||||
cu->cu_waitflag = 0;
|
||||
cu->cu_cwnd = MAXCWND / 2;
|
||||
cu->cu_sent = 0;
|
||||
cu->cu_cwnd_wait = FALSE;
|
||||
(void) getmicrotime(&now);
|
||||
cu->cu_xid = __RPC_GETXID(&now);
|
||||
call_msg.rm_xid = cu->cu_xid;
|
||||
@ -304,15 +317,16 @@ clnt_dg_call(
|
||||
CLIENT *cl, /* client handle */
|
||||
struct rpc_callextra *ext, /* call metadata */
|
||||
rpcproc_t proc, /* procedure number */
|
||||
xdrproc_t xargs, /* xdr routine for args */
|
||||
void *argsp, /* pointer to args */
|
||||
xdrproc_t xresults, /* xdr routine for results */
|
||||
void *resultsp, /* pointer to results */
|
||||
struct mbuf *args, /* pointer to args */
|
||||
struct mbuf **resultsp, /* pointer to results */
|
||||
struct timeval utimeout) /* seconds to wait before giving up */
|
||||
{
|
||||
struct cu_data *cu = (struct cu_data *)cl->cl_private;
|
||||
struct cu_socket *cs = (struct cu_socket *) cu->cu_socket->so_upcallarg;
|
||||
struct rpc_timers *rt;
|
||||
AUTH *auth;
|
||||
struct rpc_err *errp;
|
||||
enum clnt_stat stat;
|
||||
XDR xdrs;
|
||||
struct rpc_msg reply_msg;
|
||||
bool_t ok;
|
||||
@ -321,11 +335,11 @@ clnt_dg_call(
|
||||
struct timeval *tvp;
|
||||
int timeout;
|
||||
int retransmit_time;
|
||||
int next_sendtime, starttime, time_waited, tv;
|
||||
int next_sendtime, starttime, rtt, time_waited, tv = 0;
|
||||
struct sockaddr *sa;
|
||||
socklen_t salen;
|
||||
uint32_t xid;
|
||||
struct mbuf *mreq = NULL;
|
||||
uint32_t xid = 0;
|
||||
struct mbuf *mreq = NULL, *results;
|
||||
struct cu_request *cr;
|
||||
int error;
|
||||
|
||||
@ -333,17 +347,20 @@ clnt_dg_call(
|
||||
|
||||
mtx_lock(&cs->cs_lock);
|
||||
|
||||
if (cu->cu_closing) {
|
||||
if (cu->cu_closing || cu->cu_closed) {
|
||||
mtx_unlock(&cs->cs_lock);
|
||||
free(cr, M_RPC);
|
||||
return (RPC_CANTSEND);
|
||||
}
|
||||
cu->cu_threads++;
|
||||
|
||||
if (ext)
|
||||
if (ext) {
|
||||
auth = ext->rc_auth;
|
||||
else
|
||||
errp = &ext->rc_err;
|
||||
} else {
|
||||
auth = cl->cl_auth;
|
||||
errp = &cu->cu_error;
|
||||
}
|
||||
|
||||
cr->cr_client = cl;
|
||||
cr->cr_mrep = NULL;
|
||||
@ -365,8 +382,8 @@ clnt_dg_call(
|
||||
(struct sockaddr *)&cu->cu_raddr, curthread);
|
||||
mtx_lock(&cs->cs_lock);
|
||||
if (error) {
|
||||
cu->cu_error.re_errno = error;
|
||||
cu->cu_error.re_status = RPC_CANTSEND;
|
||||
errp->re_errno = error;
|
||||
errp->re_status = stat = RPC_CANTSEND;
|
||||
goto out;
|
||||
}
|
||||
cu->cu_connected = 1;
|
||||
@ -380,7 +397,15 @@ clnt_dg_call(
|
||||
}
|
||||
time_waited = 0;
|
||||
retrans = 0;
|
||||
retransmit_time = next_sendtime = tvtohz(&cu->cu_wait);
|
||||
if (ext && ext->rc_timers) {
|
||||
rt = ext->rc_timers;
|
||||
if (!rt->rt_rtxcur)
|
||||
rt->rt_rtxcur = tvtohz(&cu->cu_wait);
|
||||
retransmit_time = next_sendtime = rt->rt_rtxcur;
|
||||
} else {
|
||||
rt = NULL;
|
||||
retransmit_time = next_sendtime = tvtohz(&cu->cu_wait);
|
||||
}
|
||||
|
||||
starttime = ticks;
|
||||
|
||||
@ -394,9 +419,9 @@ clnt_dg_call(
|
||||
mtx_unlock(&cs->cs_lock);
|
||||
|
||||
MGETHDR(mreq, M_WAIT, MT_DATA);
|
||||
MCLGET(mreq, M_WAIT);
|
||||
mreq->m_len = 0;
|
||||
m_append(mreq, cu->cu_mcalllen, cu->cu_mcallc);
|
||||
KASSERT(cu->cu_mcalllen <= MHLEN, ("RPC header too big"));
|
||||
bcopy(cu->cu_mcallc, mreq->m_data, cu->cu_mcalllen);
|
||||
mreq->m_len = cu->cu_mcalllen;
|
||||
|
||||
/*
|
||||
* The XID is the first thing in the request.
|
||||
@ -405,20 +430,36 @@ clnt_dg_call(
|
||||
|
||||
xdrmbuf_create(&xdrs, mreq, XDR_ENCODE);
|
||||
|
||||
if (cu->cu_async == TRUE && xargs == NULL)
|
||||
if (cu->cu_async == TRUE && args == NULL)
|
||||
goto get_reply;
|
||||
|
||||
if ((! XDR_PUTINT32(&xdrs, &proc)) ||
|
||||
(! AUTH_MARSHALL(auth, &xdrs)) ||
|
||||
(! (*xargs)(&xdrs, argsp))) {
|
||||
cu->cu_error.re_status = RPC_CANTENCODEARGS;
|
||||
(! AUTH_MARSHALL(auth, xid, &xdrs,
|
||||
m_copym(args, 0, M_COPYALL, M_WAITOK)))) {
|
||||
errp->re_status = stat = RPC_CANTENCODEARGS;
|
||||
mtx_lock(&cs->cs_lock);
|
||||
goto out;
|
||||
}
|
||||
m_fixhdr(mreq);
|
||||
mreq->m_pkthdr.len = m_length(mreq, NULL);
|
||||
|
||||
cr->cr_xid = xid;
|
||||
mtx_lock(&cs->cs_lock);
|
||||
|
||||
/*
|
||||
* Try to get a place in the congestion window.
|
||||
*/
|
||||
while (cu->cu_sent >= cu->cu_cwnd) {
|
||||
cu->cu_cwnd_wait = TRUE;
|
||||
error = msleep(&cu->cu_cwnd_wait, &cs->cs_lock,
|
||||
cu->cu_waitflag, "rpccwnd", 0);
|
||||
if (error) {
|
||||
errp->re_errno = error;
|
||||
errp->re_status = stat = RPC_CANTSEND;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
cu->cu_sent += CWNDSCALE;
|
||||
|
||||
TAILQ_INSERT_TAIL(&cs->cs_pending, cr, cr_link);
|
||||
mtx_unlock(&cs->cs_lock);
|
||||
|
||||
@ -433,15 +474,22 @@ clnt_dg_call(
|
||||
* some clock time to spare while the packets are in flight.
|
||||
* (We assume that this is actually only executed once.)
|
||||
*/
|
||||
reply_msg.acpted_rply.ar_verf = _null_auth;
|
||||
reply_msg.acpted_rply.ar_results.where = resultsp;
|
||||
reply_msg.acpted_rply.ar_results.proc = xresults;
|
||||
reply_msg.acpted_rply.ar_verf.oa_flavor = AUTH_NULL;
|
||||
reply_msg.acpted_rply.ar_verf.oa_base = cr->cr_verf;
|
||||
reply_msg.acpted_rply.ar_verf.oa_length = 0;
|
||||
reply_msg.acpted_rply.ar_results.where = NULL;
|
||||
reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
|
||||
|
||||
mtx_lock(&cs->cs_lock);
|
||||
if (error) {
|
||||
TAILQ_REMOVE(&cs->cs_pending, cr, cr_link);
|
||||
cu->cu_error.re_errno = error;
|
||||
cu->cu_error.re_status = RPC_CANTSEND;
|
||||
errp->re_errno = error;
|
||||
errp->re_status = stat = RPC_CANTSEND;
|
||||
cu->cu_sent -= CWNDSCALE;
|
||||
if (cu->cu_cwnd_wait) {
|
||||
cu->cu_cwnd_wait = FALSE;
|
||||
wakeup(&cu->cu_cwnd_wait);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -451,12 +499,22 @@ clnt_dg_call(
|
||||
*/
|
||||
if (cr->cr_error) {
|
||||
TAILQ_REMOVE(&cs->cs_pending, cr, cr_link);
|
||||
cu->cu_error.re_errno = cr->cr_error;
|
||||
cu->cu_error.re_status = RPC_CANTRECV;
|
||||
errp->re_errno = cr->cr_error;
|
||||
errp->re_status = stat = RPC_CANTRECV;
|
||||
cu->cu_sent -= CWNDSCALE;
|
||||
if (cu->cu_cwnd_wait) {
|
||||
cu->cu_cwnd_wait = FALSE;
|
||||
wakeup(&cu->cu_cwnd_wait);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
if (cr->cr_mrep) {
|
||||
TAILQ_REMOVE(&cs->cs_pending, cr, cr_link);
|
||||
cu->cu_sent -= CWNDSCALE;
|
||||
if (cu->cu_cwnd_wait) {
|
||||
cu->cu_cwnd_wait = FALSE;
|
||||
wakeup(&cu->cu_cwnd_wait);
|
||||
}
|
||||
goto got_reply;
|
||||
}
|
||||
|
||||
@ -465,7 +523,12 @@ clnt_dg_call(
|
||||
*/
|
||||
if (timeout == 0) {
|
||||
TAILQ_REMOVE(&cs->cs_pending, cr, cr_link);
|
||||
cu->cu_error.re_status = RPC_TIMEDOUT;
|
||||
errp->re_status = stat = RPC_TIMEDOUT;
|
||||
cu->cu_sent -= CWNDSCALE;
|
||||
if (cu->cu_cwnd_wait) {
|
||||
cu->cu_cwnd_wait = FALSE;
|
||||
wakeup(&cu->cu_cwnd_wait);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -479,7 +542,7 @@ clnt_dg_call(
|
||||
tv -= time_waited;
|
||||
|
||||
if (tv > 0) {
|
||||
if (cu->cu_closing)
|
||||
if (cu->cu_closing || cu->cu_closed)
|
||||
error = 0;
|
||||
else
|
||||
error = msleep(cr, &cs->cs_lock,
|
||||
@ -489,6 +552,11 @@ clnt_dg_call(
|
||||
}
|
||||
|
||||
TAILQ_REMOVE(&cs->cs_pending, cr, cr_link);
|
||||
cu->cu_sent -= CWNDSCALE;
|
||||
if (cu->cu_cwnd_wait) {
|
||||
cu->cu_cwnd_wait = FALSE;
|
||||
wakeup(&cu->cu_cwnd_wait);
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
/*
|
||||
@ -497,10 +565,52 @@ clnt_dg_call(
|
||||
* otherwise we have a reply.
|
||||
*/
|
||||
if (cr->cr_error) {
|
||||
cu->cu_error.re_errno = cr->cr_error;
|
||||
cu->cu_error.re_status = RPC_CANTRECV;
|
||||
errp->re_errno = cr->cr_error;
|
||||
errp->re_status = stat = RPC_CANTRECV;
|
||||
goto out;
|
||||
}
|
||||
|
||||
cu->cu_cwnd += (CWNDSCALE * CWNDSCALE
|
||||
+ cu->cu_cwnd / 2) / cu->cu_cwnd;
|
||||
if (cu->cu_cwnd > MAXCWND)
|
||||
cu->cu_cwnd = MAXCWND;
|
||||
|
||||
if (rt) {
|
||||
/*
|
||||
* Add one to the time since a tick
|
||||
* count of N means that the actual
|
||||
* time taken was somewhere between N
|
||||
* and N+1.
|
||||
*/
|
||||
rtt = ticks - starttime + 1;
|
||||
|
||||
/*
|
||||
* Update our estimate of the round
|
||||
* trip time using roughly the
|
||||
* algorithm described in RFC
|
||||
* 2988. Given an RTT sample R:
|
||||
*
|
||||
* RTTVAR = (1-beta) * RTTVAR + beta * |SRTT-R|
|
||||
* SRTT = (1-alpha) * SRTT + alpha * R
|
||||
*
|
||||
* where alpha = 0.125 and beta = 0.25.
|
||||
*
|
||||
* The initial retransmit timeout is
|
||||
* SRTT + 4*RTTVAR and doubles on each
|
||||
* retransmision.
|
||||
*/
|
||||
if (rt->rt_srtt == 0) {
|
||||
rt->rt_srtt = rtt;
|
||||
rt->rt_deviate = rtt / 2;
|
||||
} else {
|
||||
int32_t error = rtt - rt->rt_srtt;
|
||||
rt->rt_srtt += error / 8;
|
||||
error = abs(error) - rt->rt_deviate;
|
||||
rt->rt_deviate += error / 4;
|
||||
}
|
||||
rt->rt_rtxcur = rt->rt_srtt + 4*rt->rt_deviate;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@ -510,11 +620,11 @@ clnt_dg_call(
|
||||
* re-send the request.
|
||||
*/
|
||||
if (error != EWOULDBLOCK) {
|
||||
cu->cu_error.re_errno = error;
|
||||
errp->re_errno = error;
|
||||
if (error == EINTR)
|
||||
cu->cu_error.re_status = RPC_INTR;
|
||||
errp->re_status = stat = RPC_INTR;
|
||||
else
|
||||
cu->cu_error.re_status = RPC_CANTRECV;
|
||||
errp->re_status = stat = RPC_CANTRECV;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -522,13 +632,16 @@ clnt_dg_call(
|
||||
|
||||
/* Check for timeout. */
|
||||
if (time_waited > timeout) {
|
||||
cu->cu_error.re_errno = EWOULDBLOCK;
|
||||
cu->cu_error.re_status = RPC_TIMEDOUT;
|
||||
errp->re_errno = EWOULDBLOCK;
|
||||
errp->re_status = stat = RPC_TIMEDOUT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Retransmit if necessary. */
|
||||
if (time_waited >= next_sendtime) {
|
||||
cu->cu_cwnd /= 2;
|
||||
if (cu->cu_cwnd < CWNDSCALE)
|
||||
cu->cu_cwnd = CWNDSCALE;
|
||||
if (ext && ext->rc_feedback) {
|
||||
mtx_unlock(&cs->cs_lock);
|
||||
if (retrans == 0)
|
||||
@ -539,9 +652,9 @@ clnt_dg_call(
|
||||
proc, ext->rc_feedback_arg);
|
||||
mtx_lock(&cs->cs_lock);
|
||||
}
|
||||
if (cu->cu_closing) {
|
||||
cu->cu_error.re_errno = ESHUTDOWN;
|
||||
cu->cu_error.re_status = RPC_CANTRECV;
|
||||
if (cu->cu_closing || cu->cu_closed) {
|
||||
errp->re_errno = ESHUTDOWN;
|
||||
errp->re_status = stat = RPC_CANTRECV;
|
||||
goto out;
|
||||
}
|
||||
retrans++;
|
||||
@ -566,47 +679,72 @@ clnt_dg_call(
|
||||
|
||||
xdrmbuf_create(&xdrs, cr->cr_mrep, XDR_DECODE);
|
||||
ok = xdr_replymsg(&xdrs, &reply_msg);
|
||||
XDR_DESTROY(&xdrs);
|
||||
cr->cr_mrep = NULL;
|
||||
|
||||
mtx_lock(&cs->cs_lock);
|
||||
|
||||
if (ok) {
|
||||
if ((reply_msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
|
||||
(reply_msg.acpted_rply.ar_stat == SUCCESS))
|
||||
cu->cu_error.re_status = RPC_SUCCESS;
|
||||
(reply_msg.acpted_rply.ar_stat == SUCCESS))
|
||||
errp->re_status = stat = RPC_SUCCESS;
|
||||
else
|
||||
_seterr_reply(&reply_msg, &(cu->cu_error));
|
||||
stat = _seterr_reply(&reply_msg, &(cu->cu_error));
|
||||
|
||||
if (cu->cu_error.re_status == RPC_SUCCESS) {
|
||||
if (! AUTH_VALIDATE(cl->cl_auth,
|
||||
&reply_msg.acpted_rply.ar_verf)) {
|
||||
cu->cu_error.re_status = RPC_AUTHERROR;
|
||||
cu->cu_error.re_why = AUTH_INVALIDRESP;
|
||||
}
|
||||
if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
|
||||
xdrs.x_op = XDR_FREE;
|
||||
(void) xdr_opaque_auth(&xdrs,
|
||||
&(reply_msg.acpted_rply.ar_verf));
|
||||
if (errp->re_status == RPC_SUCCESS) {
|
||||
results = xdrmbuf_getall(&xdrs);
|
||||
if (! AUTH_VALIDATE(auth, xid,
|
||||
&reply_msg.acpted_rply.ar_verf,
|
||||
&results)) {
|
||||
errp->re_status = stat = RPC_AUTHERROR;
|
||||
errp->re_why = AUTH_INVALIDRESP;
|
||||
if (retrans &&
|
||||
auth->ah_cred.oa_flavor == RPCSEC_GSS) {
|
||||
/*
|
||||
* If we retransmitted, its
|
||||
* possible that we will
|
||||
* receive a reply for one of
|
||||
* the earlier transmissions
|
||||
* (which will use an older
|
||||
* RPCSEC_GSS sequence
|
||||
* number). In this case, just
|
||||
* go back and listen for a
|
||||
* new reply. We could keep a
|
||||
* record of all the seq
|
||||
* numbers we have transmitted
|
||||
* so far so that we could
|
||||
* accept a reply for any of
|
||||
* them here.
|
||||
*/
|
||||
XDR_DESTROY(&xdrs);
|
||||
mtx_lock(&cs->cs_lock);
|
||||
TAILQ_INSERT_TAIL(&cs->cs_pending,
|
||||
cr, cr_link);
|
||||
cr->cr_mrep = NULL;
|
||||
goto get_reply;
|
||||
}
|
||||
} else {
|
||||
*resultsp = results;
|
||||
}
|
||||
} /* end successful completion */
|
||||
/*
|
||||
* If unsuccesful AND error is an authentication error
|
||||
* then refresh credentials and try again, else break
|
||||
*/
|
||||
else if (cu->cu_error.re_status == RPC_AUTHERROR)
|
||||
else if (stat == RPC_AUTHERROR)
|
||||
/* maybe our credentials need to be refreshed ... */
|
||||
if (nrefreshes > 0 &&
|
||||
AUTH_REFRESH(cl->cl_auth, &reply_msg)) {
|
||||
AUTH_REFRESH(auth, &reply_msg)) {
|
||||
nrefreshes--;
|
||||
XDR_DESTROY(&xdrs);
|
||||
mtx_lock(&cs->cs_lock);
|
||||
goto call_again;
|
||||
}
|
||||
/* end of unsuccessful completion */
|
||||
} /* end of valid reply message */
|
||||
else {
|
||||
cu->cu_error.re_status = RPC_CANTDECODERES;
|
||||
errp->re_status = stat = RPC_CANTDECODERES;
|
||||
|
||||
}
|
||||
XDR_DESTROY(&xdrs);
|
||||
mtx_lock(&cs->cs_lock);
|
||||
out:
|
||||
mtx_assert(&cs->cs_lock, MA_OWNED);
|
||||
|
||||
@ -621,9 +759,12 @@ clnt_dg_call(
|
||||
|
||||
mtx_unlock(&cs->cs_lock);
|
||||
|
||||
if (auth && stat != RPC_SUCCESS)
|
||||
AUTH_VALIDATE(auth, xid, NULL, NULL);
|
||||
|
||||
free(cr, M_RPC);
|
||||
|
||||
return (cu->cu_error.re_status);
|
||||
return (stat);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -759,7 +900,7 @@ clnt_dg_control(CLIENT *cl, u_int request, void *info)
|
||||
cu->cu_connect = *(int *)info;
|
||||
break;
|
||||
case CLSET_WAITCHAN:
|
||||
cu->cu_waitchan = *(const char **)info;
|
||||
cu->cu_waitchan = (const char *)info;
|
||||
break;
|
||||
case CLGET_WAITCHAN:
|
||||
*(const char **) info = cu->cu_waitchan;
|
||||
@ -785,16 +926,27 @@ clnt_dg_control(CLIENT *cl, u_int request, void *info)
|
||||
}
|
||||
|
||||
static void
|
||||
clnt_dg_destroy(CLIENT *cl)
|
||||
clnt_dg_close(CLIENT *cl)
|
||||
{
|
||||
struct cu_data *cu = (struct cu_data *)cl->cl_private;
|
||||
struct cu_socket *cs = (struct cu_socket *) cu->cu_socket->so_upcallarg;
|
||||
struct cu_request *cr;
|
||||
struct socket *so = NULL;
|
||||
bool_t lastsocketref;
|
||||
|
||||
mtx_lock(&cs->cs_lock);
|
||||
|
||||
if (cu->cu_closed) {
|
||||
mtx_unlock(&cs->cs_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cu->cu_closing) {
|
||||
while (cu->cu_closing)
|
||||
msleep(cu, &cs->cs_lock, 0, "rpcclose", 0);
|
||||
KASSERT(cu->cu_closed, ("client should be closed"));
|
||||
mtx_unlock(&cs->cs_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Abort any pending requests and wait until everyone
|
||||
* has finished with clnt_vc_call.
|
||||
@ -811,6 +963,25 @@ clnt_dg_destroy(CLIENT *cl)
|
||||
while (cu->cu_threads)
|
||||
msleep(cu, &cs->cs_lock, 0, "rpcclose", 0);
|
||||
|
||||
cu->cu_closing = FALSE;
|
||||
cu->cu_closed = TRUE;
|
||||
|
||||
mtx_unlock(&cs->cs_lock);
|
||||
wakeup(cu);
|
||||
}
|
||||
|
||||
static void
|
||||
clnt_dg_destroy(CLIENT *cl)
|
||||
{
|
||||
struct cu_data *cu = (struct cu_data *)cl->cl_private;
|
||||
struct cu_socket *cs = (struct cu_socket *) cu->cu_socket->so_upcallarg;
|
||||
struct socket *so = NULL;
|
||||
bool_t lastsocketref;
|
||||
|
||||
clnt_dg_close(cl);
|
||||
|
||||
mtx_lock(&cs->cs_lock);
|
||||
|
||||
cs->cs_refs--;
|
||||
if (cs->cs_refs == 0) {
|
||||
mtx_destroy(&cs->cs_lock);
|
||||
@ -894,7 +1065,8 @@ clnt_dg_soupcall(struct socket *so, void *arg, int waitflag)
|
||||
/*
|
||||
* The XID is in the first uint32_t of the reply.
|
||||
*/
|
||||
m = m_pullup(m, sizeof(xid));
|
||||
if (m->m_len < sizeof(xid))
|
||||
m = m_pullup(m, sizeof(xid));
|
||||
if (!m)
|
||||
/*
|
||||
* Should never happen.
|
||||
|
@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/limits.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
@ -46,11 +47,12 @@ __FBSDID("$FreeBSD$");
|
||||
#include <rpc/rpc_com.h>
|
||||
|
||||
static enum clnt_stat clnt_reconnect_call(CLIENT *, struct rpc_callextra *,
|
||||
rpcproc_t, xdrproc_t, void *, xdrproc_t, void *, struct timeval);
|
||||
rpcproc_t, struct mbuf *, struct mbuf **, struct timeval);
|
||||
static void clnt_reconnect_geterr(CLIENT *, struct rpc_err *);
|
||||
static bool_t clnt_reconnect_freeres(CLIENT *, xdrproc_t, void *);
|
||||
static void clnt_reconnect_abort(CLIENT *);
|
||||
static bool_t clnt_reconnect_control(CLIENT *, u_int, void *);
|
||||
static void clnt_reconnect_close(CLIENT *);
|
||||
static void clnt_reconnect_destroy(CLIENT *);
|
||||
|
||||
static struct clnt_ops clnt_reconnect_ops = {
|
||||
@ -58,10 +60,13 @@ static struct clnt_ops clnt_reconnect_ops = {
|
||||
.cl_abort = clnt_reconnect_abort,
|
||||
.cl_geterr = clnt_reconnect_geterr,
|
||||
.cl_freeres = clnt_reconnect_freeres,
|
||||
.cl_close = clnt_reconnect_close,
|
||||
.cl_destroy = clnt_reconnect_destroy,
|
||||
.cl_control = clnt_reconnect_control
|
||||
};
|
||||
|
||||
static int fake_wchan;
|
||||
|
||||
struct rc_data {
|
||||
struct mtx rc_lock;
|
||||
struct sockaddr_storage rc_addr; /* server address */
|
||||
@ -73,10 +78,14 @@ struct rc_data {
|
||||
struct timeval rc_timeout;
|
||||
struct timeval rc_retry;
|
||||
int rc_retries;
|
||||
const char *rc_waitchan;
|
||||
int rc_privport;
|
||||
char *rc_waitchan;
|
||||
int rc_intr;
|
||||
int rc_connecting;
|
||||
int rc_closed;
|
||||
struct ucred *rc_ucred;
|
||||
CLIENT* rc_client; /* underlying RPC client */
|
||||
struct rpc_err rc_err;
|
||||
};
|
||||
|
||||
CLIENT *
|
||||
@ -110,9 +119,12 @@ clnt_reconnect_create(
|
||||
rc->rc_retry.tv_sec = 3;
|
||||
rc->rc_retry.tv_usec = 0;
|
||||
rc->rc_retries = INT_MAX;
|
||||
rc->rc_privport = FALSE;
|
||||
rc->rc_waitchan = "rpcrecv";
|
||||
rc->rc_intr = 0;
|
||||
rc->rc_connecting = FALSE;
|
||||
rc->rc_closed = FALSE;
|
||||
rc->rc_ucred = crdup(curthread->td_ucred);
|
||||
rc->rc_client = NULL;
|
||||
|
||||
cl->cl_refs = 1;
|
||||
@ -127,16 +139,22 @@ clnt_reconnect_create(
|
||||
static enum clnt_stat
|
||||
clnt_reconnect_connect(CLIENT *cl)
|
||||
{
|
||||
struct thread *td = curthread;
|
||||
struct rc_data *rc = (struct rc_data *)cl->cl_private;
|
||||
struct socket *so;
|
||||
enum clnt_stat stat;
|
||||
int error;
|
||||
int one = 1;
|
||||
struct ucred *oldcred;
|
||||
|
||||
mtx_lock(&rc->rc_lock);
|
||||
again:
|
||||
if (rc->rc_closed) {
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
return (RPC_CANTSEND);
|
||||
}
|
||||
if (rc->rc_connecting) {
|
||||
while (!rc->rc_client) {
|
||||
while (!rc->rc_closed && !rc->rc_client) {
|
||||
error = msleep(rc, &rc->rc_lock,
|
||||
rc->rc_intr ? PCATCH : 0, "rpcrecon", 0);
|
||||
if (error) {
|
||||
@ -163,7 +181,11 @@ clnt_reconnect_connect(CLIENT *cl)
|
||||
rpc_createerr.cf_error.re_errno = 0;
|
||||
goto out;
|
||||
}
|
||||
if (rc->rc_privport)
|
||||
bindresvport(so, NULL);
|
||||
|
||||
oldcred = td->td_ucred;
|
||||
td->td_ucred = rc->rc_ucred;
|
||||
if (rc->rc_nconf->nc_semantics == NC_TPI_CLTS)
|
||||
rc->rc_client = clnt_dg_create(so,
|
||||
(struct sockaddr *) &rc->rc_addr, rc->rc_prog, rc->rc_vers,
|
||||
@ -172,8 +194,11 @@ clnt_reconnect_connect(CLIENT *cl)
|
||||
rc->rc_client = clnt_vc_create(so,
|
||||
(struct sockaddr *) &rc->rc_addr, rc->rc_prog, rc->rc_vers,
|
||||
rc->rc_sendsz, rc->rc_recvsz);
|
||||
td->td_ucred = oldcred;
|
||||
|
||||
if (!rc->rc_client) {
|
||||
soclose(so);
|
||||
rc->rc_err = rpc_createerr.cf_error;
|
||||
stat = rpc_createerr.cf_stat;
|
||||
goto out;
|
||||
}
|
||||
@ -182,12 +207,19 @@ clnt_reconnect_connect(CLIENT *cl)
|
||||
CLNT_CONTROL(rc->rc_client, CLSET_CONNECT, &one);
|
||||
CLNT_CONTROL(rc->rc_client, CLSET_TIMEOUT, &rc->rc_timeout);
|
||||
CLNT_CONTROL(rc->rc_client, CLSET_RETRY_TIMEOUT, &rc->rc_retry);
|
||||
CLNT_CONTROL(rc->rc_client, CLSET_WAITCHAN, &rc->rc_waitchan);
|
||||
CLNT_CONTROL(rc->rc_client, CLSET_WAITCHAN, rc->rc_waitchan);
|
||||
CLNT_CONTROL(rc->rc_client, CLSET_INTERRUPTIBLE, &rc->rc_intr);
|
||||
stat = RPC_SUCCESS;
|
||||
|
||||
out:
|
||||
mtx_lock(&rc->rc_lock);
|
||||
if (rc->rc_closed) {
|
||||
if (rc->rc_client) {
|
||||
CLNT_CLOSE(rc->rc_client);
|
||||
CLNT_RELEASE(rc->rc_client);
|
||||
rc->rc_client = NULL;
|
||||
}
|
||||
}
|
||||
rc->rc_connecting = FALSE;
|
||||
wakeup(rc);
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
@ -200,11 +232,9 @@ clnt_reconnect_call(
|
||||
CLIENT *cl, /* client handle */
|
||||
struct rpc_callextra *ext, /* call metadata */
|
||||
rpcproc_t proc, /* procedure number */
|
||||
xdrproc_t xargs, /* xdr routine for args */
|
||||
void *argsp, /* pointer to args */
|
||||
xdrproc_t xresults, /* xdr routine for results */
|
||||
void *resultsp, /* pointer to results */
|
||||
struct timeval utimeout) /* seconds to wait before giving up */
|
||||
struct mbuf *args, /* pointer to args */
|
||||
struct mbuf **resultsp, /* pointer to results */
|
||||
struct timeval utimeout)
|
||||
{
|
||||
struct rc_data *rc = (struct rc_data *)cl->cl_private;
|
||||
CLIENT *client;
|
||||
@ -213,18 +243,40 @@ clnt_reconnect_call(
|
||||
|
||||
tries = 0;
|
||||
do {
|
||||
if (rc->rc_closed) {
|
||||
return (RPC_CANTSEND);
|
||||
}
|
||||
|
||||
if (!rc->rc_client) {
|
||||
stat = clnt_reconnect_connect(cl);
|
||||
if (stat == RPC_SYSTEMERROR) {
|
||||
(void) tsleep(&fake_wchan, 0,
|
||||
"rpccon", hz);
|
||||
tries++;
|
||||
if (tries >= rc->rc_retries)
|
||||
return (stat);
|
||||
continue;
|
||||
}
|
||||
if (stat != RPC_SUCCESS)
|
||||
return (stat);
|
||||
}
|
||||
|
||||
mtx_lock(&rc->rc_lock);
|
||||
if (!rc->rc_client) {
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
stat = RPC_FAILED;
|
||||
continue;
|
||||
}
|
||||
CLNT_ACQUIRE(rc->rc_client);
|
||||
client = rc->rc_client;
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
stat = CLNT_CALL_EXT(client, ext, proc, xargs, argsp,
|
||||
xresults, resultsp, utimeout);
|
||||
stat = CLNT_CALL_MBUF(client, ext, proc, args,
|
||||
resultsp, utimeout);
|
||||
|
||||
if (stat != RPC_SUCCESS) {
|
||||
if (!ext)
|
||||
CLNT_GETERR(client, &rc->rc_err);
|
||||
}
|
||||
|
||||
CLNT_RELEASE(client);
|
||||
if (stat == RPC_TIMEDOUT) {
|
||||
@ -241,10 +293,8 @@ clnt_reconnect_call(
|
||||
}
|
||||
}
|
||||
|
||||
if (stat == RPC_INTR)
|
||||
break;
|
||||
|
||||
if (stat != RPC_SUCCESS) {
|
||||
if (stat == RPC_TIMEDOUT || stat == RPC_CANTSEND
|
||||
|| stat == RPC_CANTRECV) {
|
||||
tries++;
|
||||
if (tries >= rc->rc_retries)
|
||||
break;
|
||||
@ -263,9 +313,14 @@ clnt_reconnect_call(
|
||||
rc->rc_client = NULL;
|
||||
}
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (stat != RPC_SUCCESS);
|
||||
|
||||
KASSERT(stat != RPC_SUCCESS || *resultsp,
|
||||
("RPC_SUCCESS without reply"));
|
||||
|
||||
return (stat);
|
||||
}
|
||||
|
||||
@ -274,10 +329,7 @@ clnt_reconnect_geterr(CLIENT *cl, struct rpc_err *errp)
|
||||
{
|
||||
struct rc_data *rc = (struct rc_data *)cl->cl_private;
|
||||
|
||||
if (rc->rc_client)
|
||||
CLNT_GETERR(rc->rc_client, errp);
|
||||
else
|
||||
memset(errp, 0, sizeof(*errp));
|
||||
*errp = rc->rc_err;
|
||||
}
|
||||
|
||||
static bool_t
|
||||
@ -344,7 +396,7 @@ clnt_reconnect_control(CLIENT *cl, u_int request, void *info)
|
||||
break;
|
||||
|
||||
case CLSET_WAITCHAN:
|
||||
rc->rc_waitchan = *(const char **)info;
|
||||
rc->rc_waitchan = (char *)info;
|
||||
if (rc->rc_client)
|
||||
CLNT_CONTROL(rc->rc_client, request, info);
|
||||
break;
|
||||
@ -371,6 +423,14 @@ clnt_reconnect_control(CLIENT *cl, u_int request, void *info)
|
||||
*(int *) info = rc->rc_retries;
|
||||
break;
|
||||
|
||||
case CLSET_PRIVPORT:
|
||||
rc->rc_privport = *(int *) info;
|
||||
break;
|
||||
|
||||
case CLGET_PRIVPORT:
|
||||
*(int *) info = rc->rc_privport;
|
||||
break;
|
||||
|
||||
default:
|
||||
return (FALSE);
|
||||
}
|
||||
@ -378,6 +438,31 @@ clnt_reconnect_control(CLIENT *cl, u_int request, void *info)
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
clnt_reconnect_close(CLIENT *cl)
|
||||
{
|
||||
struct rc_data *rc = (struct rc_data *)cl->cl_private;
|
||||
CLIENT *client;
|
||||
|
||||
mtx_lock(&rc->rc_lock);
|
||||
|
||||
if (rc->rc_closed) {
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
rc->rc_closed = TRUE;
|
||||
client = rc->rc_client;
|
||||
rc->rc_client = NULL;
|
||||
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
|
||||
if (client) {
|
||||
CLNT_CLOSE(client);
|
||||
CLNT_RELEASE(client);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
clnt_reconnect_destroy(CLIENT *cl)
|
||||
{
|
||||
@ -385,6 +470,7 @@ clnt_reconnect_destroy(CLIENT *cl)
|
||||
|
||||
if (rc->rc_client)
|
||||
CLNT_DESTROY(rc->rc_client);
|
||||
crfree(rc->rc_ucred);
|
||||
mtx_destroy(&rc->rc_lock);
|
||||
mem_free(rc, sizeof(*rc));
|
||||
mem_free(cl, sizeof (CLIENT));
|
||||
|
@ -64,11 +64,13 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/pcpu.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/socketvar.h>
|
||||
#include <sys/syslog.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/uio.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpc_com.h>
|
||||
@ -81,11 +83,12 @@ struct cmessage {
|
||||
};
|
||||
|
||||
static enum clnt_stat clnt_vc_call(CLIENT *, struct rpc_callextra *,
|
||||
rpcproc_t, xdrproc_t, void *, xdrproc_t, void *, struct timeval);
|
||||
rpcproc_t, struct mbuf *, struct mbuf **, struct timeval);
|
||||
static void clnt_vc_geterr(CLIENT *, struct rpc_err *);
|
||||
static bool_t clnt_vc_freeres(CLIENT *, xdrproc_t, void *);
|
||||
static void clnt_vc_abort(CLIENT *);
|
||||
static bool_t clnt_vc_control(CLIENT *, u_int, void *);
|
||||
static void clnt_vc_close(CLIENT *);
|
||||
static void clnt_vc_destroy(CLIENT *);
|
||||
static bool_t time_not_ok(struct timeval *);
|
||||
static void clnt_vc_soupcall(struct socket *so, void *arg, int waitflag);
|
||||
@ -95,6 +98,7 @@ static struct clnt_ops clnt_vc_ops = {
|
||||
.cl_abort = clnt_vc_abort,
|
||||
.cl_geterr = clnt_vc_geterr,
|
||||
.cl_freeres = clnt_vc_freeres,
|
||||
.cl_close = clnt_vc_close,
|
||||
.cl_destroy = clnt_vc_destroy,
|
||||
.cl_control = clnt_vc_control
|
||||
};
|
||||
@ -109,6 +113,7 @@ struct ct_request {
|
||||
uint32_t cr_xid; /* XID of request */
|
||||
struct mbuf *cr_mrep; /* reply received by upcall */
|
||||
int cr_error; /* any error from upcall */
|
||||
char cr_verf[MAX_AUTH_BYTES]; /* reply verf */
|
||||
};
|
||||
|
||||
TAILQ_HEAD(ct_request_list, ct_request);
|
||||
@ -116,7 +121,8 @@ TAILQ_HEAD(ct_request_list, ct_request);
|
||||
struct ct_data {
|
||||
struct mtx ct_lock;
|
||||
int ct_threads; /* number of threads in clnt_vc_call */
|
||||
bool_t ct_closing; /* TRUE if we are destroying client */
|
||||
bool_t ct_closing; /* TRUE if we are closing */
|
||||
bool_t ct_closed; /* TRUE if we are closed */
|
||||
struct socket *ct_socket; /* connection socket */
|
||||
bool_t ct_closeit; /* close it on destroy */
|
||||
struct timeval ct_wait; /* wait interval in milliseconds */
|
||||
@ -165,7 +171,8 @@ clnt_vc_create(
|
||||
static uint32_t disrupt;
|
||||
struct __rpc_sockinfo si;
|
||||
XDR xdrs;
|
||||
int error, interrupted;
|
||||
int error, interrupted, one = 1;
|
||||
struct sockopt sopt;
|
||||
|
||||
if (disrupt == 0)
|
||||
disrupt = (uint32_t)(long)raddr;
|
||||
@ -176,6 +183,7 @@ clnt_vc_create(
|
||||
mtx_init(&ct->ct_lock, "ct->ct_lock", NULL, MTX_DEF);
|
||||
ct->ct_threads = 0;
|
||||
ct->ct_closing = FALSE;
|
||||
ct->ct_closed = FALSE;
|
||||
|
||||
if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) {
|
||||
error = soconnect(so, raddr, curthread);
|
||||
@ -208,6 +216,26 @@ clnt_vc_create(
|
||||
if (!__rpc_socket2sockinfo(so, &si))
|
||||
goto err;
|
||||
|
||||
if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
|
||||
bzero(&sopt, sizeof(sopt));
|
||||
sopt.sopt_dir = SOPT_SET;
|
||||
sopt.sopt_level = SOL_SOCKET;
|
||||
sopt.sopt_name = SO_KEEPALIVE;
|
||||
sopt.sopt_val = &one;
|
||||
sopt.sopt_valsize = sizeof(one);
|
||||
sosetopt(so, &sopt);
|
||||
}
|
||||
|
||||
if (so->so_proto->pr_protocol == IPPROTO_TCP) {
|
||||
bzero(&sopt, sizeof(sopt));
|
||||
sopt.sopt_dir = SOPT_SET;
|
||||
sopt.sopt_level = IPPROTO_TCP;
|
||||
sopt.sopt_name = TCP_NODELAY;
|
||||
sopt.sopt_val = &one;
|
||||
sopt.sopt_valsize = sizeof(one);
|
||||
sosetopt(so, &sopt);
|
||||
}
|
||||
|
||||
ct->ct_closeit = FALSE;
|
||||
|
||||
/*
|
||||
@ -255,6 +283,7 @@ clnt_vc_create(
|
||||
cl->cl_auth = authnone_create();
|
||||
sendsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsz);
|
||||
recvsz = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsz);
|
||||
soreserve(ct->ct_socket, sendsz, recvsz);
|
||||
|
||||
SOCKBUF_LOCK(&ct->ct_socket->so_rcv);
|
||||
ct->ct_socket->so_upcallarg = ct;
|
||||
@ -280,24 +309,24 @@ clnt_vc_create(
|
||||
|
||||
static enum clnt_stat
|
||||
clnt_vc_call(
|
||||
CLIENT *cl,
|
||||
struct rpc_callextra *ext,
|
||||
rpcproc_t proc,
|
||||
xdrproc_t xdr_args,
|
||||
void *args_ptr,
|
||||
xdrproc_t xdr_results,
|
||||
void *results_ptr,
|
||||
struct timeval utimeout)
|
||||
CLIENT *cl, /* client handle */
|
||||
struct rpc_callextra *ext, /* call metadata */
|
||||
rpcproc_t proc, /* procedure number */
|
||||
struct mbuf *args, /* pointer to args */
|
||||
struct mbuf **resultsp, /* pointer to results */
|
||||
struct timeval utimeout)
|
||||
{
|
||||
struct ct_data *ct = (struct ct_data *) cl->cl_private;
|
||||
AUTH *auth;
|
||||
struct rpc_err *errp;
|
||||
enum clnt_stat stat;
|
||||
XDR xdrs;
|
||||
struct rpc_msg reply_msg;
|
||||
bool_t ok;
|
||||
int nrefreshes = 2; /* number of times to refresh cred */
|
||||
struct timeval timeout;
|
||||
uint32_t xid;
|
||||
struct mbuf *mreq = NULL;
|
||||
struct mbuf *mreq = NULL, *results;
|
||||
struct ct_request *cr;
|
||||
int error;
|
||||
|
||||
@ -305,17 +334,20 @@ clnt_vc_call(
|
||||
|
||||
mtx_lock(&ct->ct_lock);
|
||||
|
||||
if (ct->ct_closing) {
|
||||
if (ct->ct_closing || ct->ct_closed) {
|
||||
mtx_unlock(&ct->ct_lock);
|
||||
free(cr, M_RPC);
|
||||
return (RPC_CANTSEND);
|
||||
}
|
||||
ct->ct_threads++;
|
||||
|
||||
if (ext)
|
||||
if (ext) {
|
||||
auth = ext->rc_auth;
|
||||
else
|
||||
errp = &ext->rc_err;
|
||||
} else {
|
||||
auth = cl->cl_auth;
|
||||
errp = &ct->ct_error;
|
||||
}
|
||||
|
||||
cr->cr_mrep = NULL;
|
||||
cr->cr_error = 0;
|
||||
@ -338,10 +370,11 @@ clnt_vc_call(
|
||||
* Leave space to pre-pend the record mark.
|
||||
*/
|
||||
MGETHDR(mreq, M_WAIT, MT_DATA);
|
||||
MCLGET(mreq, M_WAIT);
|
||||
mreq->m_len = 0;
|
||||
mreq->m_data += sizeof(uint32_t);
|
||||
m_append(mreq, ct->ct_mpos, ct->ct_mcallc);
|
||||
KASSERT(ct->ct_mpos + sizeof(uint32_t) <= MHLEN,
|
||||
("RPC header too big"));
|
||||
bcopy(ct->ct_mcallc, mreq->m_data, ct->ct_mpos);
|
||||
mreq->m_len = ct->ct_mpos;
|
||||
|
||||
/*
|
||||
* The XID is the first thing in the request.
|
||||
@ -350,17 +383,16 @@ clnt_vc_call(
|
||||
|
||||
xdrmbuf_create(&xdrs, mreq, XDR_ENCODE);
|
||||
|
||||
ct->ct_error.re_status = RPC_SUCCESS;
|
||||
errp->re_status = stat = RPC_SUCCESS;
|
||||
|
||||
if ((! XDR_PUTINT32(&xdrs, &proc)) ||
|
||||
(! AUTH_MARSHALL(auth, &xdrs)) ||
|
||||
(! (*xdr_args)(&xdrs, args_ptr))) {
|
||||
if (ct->ct_error.re_status == RPC_SUCCESS)
|
||||
ct->ct_error.re_status = RPC_CANTENCODEARGS;
|
||||
(! AUTH_MARSHALL(auth, xid, &xdrs,
|
||||
m_copym(args, 0, M_COPYALL, M_WAITOK)))) {
|
||||
errp->re_status = stat = RPC_CANTENCODEARGS;
|
||||
mtx_lock(&ct->ct_lock);
|
||||
goto out;
|
||||
}
|
||||
m_fixhdr(mreq);
|
||||
mreq->m_pkthdr.len = m_length(mreq, NULL);
|
||||
|
||||
/*
|
||||
* Prepend a record marker containing the packet length.
|
||||
@ -379,16 +411,27 @@ clnt_vc_call(
|
||||
*/
|
||||
error = sosend(ct->ct_socket, NULL, NULL, mreq, NULL, 0, curthread);
|
||||
mreq = NULL;
|
||||
if (error == EMSGSIZE) {
|
||||
SOCKBUF_LOCK(&ct->ct_socket->so_snd);
|
||||
sbwait(&ct->ct_socket->so_snd);
|
||||
SOCKBUF_UNLOCK(&ct->ct_socket->so_snd);
|
||||
AUTH_VALIDATE(auth, xid, NULL, NULL);
|
||||
mtx_lock(&ct->ct_lock);
|
||||
TAILQ_REMOVE(&ct->ct_pending, cr, cr_link);
|
||||
goto call_again;
|
||||
}
|
||||
|
||||
reply_msg.acpted_rply.ar_verf = _null_auth;
|
||||
reply_msg.acpted_rply.ar_results.where = results_ptr;
|
||||
reply_msg.acpted_rply.ar_results.proc = xdr_results;
|
||||
reply_msg.acpted_rply.ar_verf.oa_flavor = AUTH_NULL;
|
||||
reply_msg.acpted_rply.ar_verf.oa_base = cr->cr_verf;
|
||||
reply_msg.acpted_rply.ar_verf.oa_length = 0;
|
||||
reply_msg.acpted_rply.ar_results.where = NULL;
|
||||
reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
|
||||
|
||||
mtx_lock(&ct->ct_lock);
|
||||
if (error) {
|
||||
TAILQ_REMOVE(&ct->ct_pending, cr, cr_link);
|
||||
ct->ct_error.re_errno = error;
|
||||
ct->ct_error.re_status = RPC_CANTSEND;
|
||||
errp->re_errno = error;
|
||||
errp->re_status = stat = RPC_CANTSEND;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -399,8 +442,8 @@ clnt_vc_call(
|
||||
*/
|
||||
if (cr->cr_error) {
|
||||
TAILQ_REMOVE(&ct->ct_pending, cr, cr_link);
|
||||
ct->ct_error.re_errno = cr->cr_error;
|
||||
ct->ct_error.re_status = RPC_CANTRECV;
|
||||
errp->re_errno = cr->cr_error;
|
||||
errp->re_status = stat = RPC_CANTRECV;
|
||||
goto out;
|
||||
}
|
||||
if (cr->cr_mrep) {
|
||||
@ -413,7 +456,7 @@ clnt_vc_call(
|
||||
*/
|
||||
if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
|
||||
TAILQ_REMOVE(&ct->ct_pending, cr, cr_link);
|
||||
ct->ct_error.re_status = RPC_TIMEDOUT;
|
||||
errp->re_status = stat = RPC_TIMEDOUT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -428,17 +471,18 @@ clnt_vc_call(
|
||||
* on the list. Turn the error code into an
|
||||
* appropriate client status.
|
||||
*/
|
||||
ct->ct_error.re_errno = error;
|
||||
errp->re_errno = error;
|
||||
switch (error) {
|
||||
case EINTR:
|
||||
ct->ct_error.re_status = RPC_INTR;
|
||||
stat = RPC_INTR;
|
||||
break;
|
||||
case EWOULDBLOCK:
|
||||
ct->ct_error.re_status = RPC_TIMEDOUT;
|
||||
stat = RPC_TIMEDOUT;
|
||||
break;
|
||||
default:
|
||||
ct->ct_error.re_status = RPC_CANTRECV;
|
||||
stat = RPC_CANTRECV;
|
||||
}
|
||||
errp->re_status = stat;
|
||||
goto out;
|
||||
} else {
|
||||
/*
|
||||
@ -447,8 +491,8 @@ clnt_vc_call(
|
||||
* otherwise we have a reply.
|
||||
*/
|
||||
if (cr->cr_error) {
|
||||
ct->ct_error.re_errno = cr->cr_error;
|
||||
ct->ct_error.re_status = RPC_CANTRECV;
|
||||
errp->re_errno = cr->cr_error;
|
||||
errp->re_status = stat = RPC_CANTRECV;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@ -460,51 +504,59 @@ clnt_vc_call(
|
||||
*/
|
||||
mtx_unlock(&ct->ct_lock);
|
||||
|
||||
if (ext && ext->rc_feedback)
|
||||
ext->rc_feedback(FEEDBACK_OK, proc, ext->rc_feedback_arg);
|
||||
|
||||
xdrmbuf_create(&xdrs, cr->cr_mrep, XDR_DECODE);
|
||||
ok = xdr_replymsg(&xdrs, &reply_msg);
|
||||
XDR_DESTROY(&xdrs);
|
||||
cr->cr_mrep = NULL;
|
||||
|
||||
mtx_lock(&ct->ct_lock);
|
||||
|
||||
if (ok) {
|
||||
if ((reply_msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
|
||||
(reply_msg.acpted_rply.ar_stat == SUCCESS))
|
||||
ct->ct_error.re_status = RPC_SUCCESS;
|
||||
(reply_msg.acpted_rply.ar_stat == SUCCESS))
|
||||
errp->re_status = stat = RPC_SUCCESS;
|
||||
else
|
||||
_seterr_reply(&reply_msg, &(ct->ct_error));
|
||||
stat = _seterr_reply(&reply_msg, errp);
|
||||
|
||||
if (ct->ct_error.re_status == RPC_SUCCESS) {
|
||||
if (! AUTH_VALIDATE(cl->cl_auth,
|
||||
&reply_msg.acpted_rply.ar_verf)) {
|
||||
ct->ct_error.re_status = RPC_AUTHERROR;
|
||||
ct->ct_error.re_why = AUTH_INVALIDRESP;
|
||||
}
|
||||
if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
|
||||
xdrs.x_op = XDR_FREE;
|
||||
(void) xdr_opaque_auth(&xdrs,
|
||||
&(reply_msg.acpted_rply.ar_verf));
|
||||
if (stat == RPC_SUCCESS) {
|
||||
results = xdrmbuf_getall(&xdrs);
|
||||
if (!AUTH_VALIDATE(auth, xid,
|
||||
&reply_msg.acpted_rply.ar_verf,
|
||||
&results)) {
|
||||
errp->re_status = stat = RPC_AUTHERROR;
|
||||
errp->re_why = AUTH_INVALIDRESP;
|
||||
} else {
|
||||
KASSERT(results,
|
||||
("auth validated but no result"));
|
||||
*resultsp = results;
|
||||
}
|
||||
} /* end successful completion */
|
||||
/*
|
||||
* If unsuccesful AND error is an authentication error
|
||||
* then refresh credentials and try again, else break
|
||||
*/
|
||||
else if (ct->ct_error.re_status == RPC_AUTHERROR)
|
||||
else if (stat == RPC_AUTHERROR)
|
||||
/* maybe our credentials need to be refreshed ... */
|
||||
if (nrefreshes > 0 &&
|
||||
AUTH_REFRESH(cl->cl_auth, &reply_msg)) {
|
||||
AUTH_REFRESH(auth, &reply_msg)) {
|
||||
nrefreshes--;
|
||||
XDR_DESTROY(&xdrs);
|
||||
mtx_lock(&ct->ct_lock);
|
||||
goto call_again;
|
||||
}
|
||||
/* end of unsuccessful completion */
|
||||
} /* end of valid reply message */
|
||||
else {
|
||||
ct->ct_error.re_status = RPC_CANTDECODERES;
|
||||
errp->re_status = stat = RPC_CANTDECODERES;
|
||||
}
|
||||
XDR_DESTROY(&xdrs);
|
||||
mtx_lock(&ct->ct_lock);
|
||||
out:
|
||||
mtx_assert(&ct->ct_lock, MA_OWNED);
|
||||
|
||||
KASSERT(stat != RPC_SUCCESS || *resultsp,
|
||||
("RPC_SUCCESS without reply"));
|
||||
|
||||
if (mreq)
|
||||
m_freem(mreq);
|
||||
if (cr->cr_mrep)
|
||||
@ -516,9 +568,12 @@ clnt_vc_call(
|
||||
|
||||
mtx_unlock(&ct->ct_lock);
|
||||
|
||||
if (auth && stat != RPC_SUCCESS)
|
||||
AUTH_VALIDATE(auth, xid, NULL, NULL);
|
||||
|
||||
free(cr, M_RPC);
|
||||
|
||||
return (ct->ct_error.re_status);
|
||||
return (stat);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -642,7 +697,7 @@ clnt_vc_control(CLIENT *cl, u_int request, void *info)
|
||||
break;
|
||||
|
||||
case CLSET_WAITCHAN:
|
||||
ct->ct_waitchan = *(const char **)info;
|
||||
ct->ct_waitchan = (const char *)info;
|
||||
break;
|
||||
|
||||
case CLGET_WAITCHAN:
|
||||
@ -673,14 +728,26 @@ clnt_vc_control(CLIENT *cl, u_int request, void *info)
|
||||
}
|
||||
|
||||
static void
|
||||
clnt_vc_destroy(CLIENT *cl)
|
||||
clnt_vc_close(CLIENT *cl)
|
||||
{
|
||||
struct ct_data *ct = (struct ct_data *) cl->cl_private;
|
||||
struct ct_request *cr;
|
||||
struct socket *so = NULL;
|
||||
|
||||
mtx_lock(&ct->ct_lock);
|
||||
|
||||
if (ct->ct_closed) {
|
||||
mtx_unlock(&ct->ct_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ct->ct_closing) {
|
||||
while (ct->ct_closing)
|
||||
msleep(ct, &ct->ct_lock, 0, "rpcclose", 0);
|
||||
KASSERT(ct->ct_closed, ("client should be closed"));
|
||||
mtx_unlock(&ct->ct_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ct->ct_socket) {
|
||||
SOCKBUF_LOCK(&ct->ct_socket->so_rcv);
|
||||
ct->ct_socket->so_upcallarg = NULL;
|
||||
@ -701,7 +768,25 @@ clnt_vc_destroy(CLIENT *cl)
|
||||
|
||||
while (ct->ct_threads)
|
||||
msleep(ct, &ct->ct_lock, 0, "rpcclose", 0);
|
||||
}
|
||||
|
||||
ct->ct_closing = FALSE;
|
||||
ct->ct_closed = TRUE;
|
||||
mtx_unlock(&ct->ct_lock);
|
||||
wakeup(ct);
|
||||
}
|
||||
|
||||
static void
|
||||
clnt_vc_destroy(CLIENT *cl)
|
||||
{
|
||||
struct ct_data *ct = (struct ct_data *) cl->cl_private;
|
||||
struct socket *so = NULL;
|
||||
|
||||
clnt_vc_close(cl);
|
||||
|
||||
mtx_lock(&ct->ct_lock);
|
||||
|
||||
if (ct->ct_socket) {
|
||||
if (ct->ct_closeit) {
|
||||
so = ct->ct_socket;
|
||||
}
|
||||
@ -738,6 +823,7 @@ clnt_vc_soupcall(struct socket *so, void *arg, int waitflag)
|
||||
struct ct_request *cr;
|
||||
int error, rcvflag, foundreq;
|
||||
uint32_t xid, header;
|
||||
bool_t do_read;
|
||||
|
||||
uio.uio_td = curthread;
|
||||
do {
|
||||
@ -746,7 +832,6 @@ clnt_vc_soupcall(struct socket *so, void *arg, int waitflag)
|
||||
* record mark.
|
||||
*/
|
||||
if (ct->ct_record_resid == 0) {
|
||||
bool_t do_read;
|
||||
|
||||
/*
|
||||
* Make sure there is either a whole record
|
||||
@ -795,13 +880,28 @@ clnt_vc_soupcall(struct socket *so, void *arg, int waitflag)
|
||||
mtx_unlock(&ct->ct_lock);
|
||||
break;
|
||||
}
|
||||
memcpy(&header, mtod(m, uint32_t *), sizeof(uint32_t));
|
||||
bcopy(mtod(m, uint32_t *), &header, sizeof(uint32_t));
|
||||
header = ntohl(header);
|
||||
ct->ct_record = NULL;
|
||||
ct->ct_record_resid = header & 0x7fffffff;
|
||||
ct->ct_record_eor = ((header & 0x80000000) != 0);
|
||||
m_freem(m);
|
||||
} else {
|
||||
/*
|
||||
* Wait until the socket has the whole record
|
||||
* buffered.
|
||||
*/
|
||||
do_read = FALSE;
|
||||
SOCKBUF_LOCK(&so->so_rcv);
|
||||
if (so->so_rcv.sb_cc >= ct->ct_record_resid
|
||||
|| (so->so_rcv.sb_state & SBS_CANTRCVMORE)
|
||||
|| so->so_error)
|
||||
do_read = TRUE;
|
||||
SOCKBUF_UNLOCK(&so->so_rcv);
|
||||
|
||||
if (!do_read)
|
||||
return;
|
||||
|
||||
/*
|
||||
* We have the record mark. Read as much as
|
||||
* the socket has buffered up to the end of
|
||||
@ -839,13 +939,14 @@ clnt_vc_soupcall(struct socket *so, void *arg, int waitflag)
|
||||
* The XID is in the first uint32_t of
|
||||
* the reply.
|
||||
*/
|
||||
ct->ct_record =
|
||||
m_pullup(ct->ct_record, sizeof(xid));
|
||||
if (ct->ct_record->m_len < sizeof(xid))
|
||||
ct->ct_record =
|
||||
m_pullup(ct->ct_record,
|
||||
sizeof(xid));
|
||||
if (!ct->ct_record)
|
||||
break;
|
||||
memcpy(&xid,
|
||||
mtod(ct->ct_record, uint32_t *),
|
||||
sizeof(uint32_t));
|
||||
bcopy(mtod(ct->ct_record, uint32_t *),
|
||||
&xid, sizeof(uint32_t));
|
||||
xid = ntohl(xid);
|
||||
|
||||
mtx_lock(&ct->ct_lock);
|
||||
|
248
sys/rpc/replay.c
Normal file
248
sys/rpc/replay.c
Normal file
@ -0,0 +1,248 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/hash.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/replay.h>
|
||||
|
||||
struct replay_cache_entry {
|
||||
int rce_hash;
|
||||
struct rpc_msg rce_msg;
|
||||
struct sockaddr_storage rce_addr;
|
||||
struct rpc_msg rce_repmsg;
|
||||
struct mbuf *rce_repbody;
|
||||
|
||||
TAILQ_ENTRY(replay_cache_entry) rce_link;
|
||||
TAILQ_ENTRY(replay_cache_entry) rce_alllink;
|
||||
};
|
||||
TAILQ_HEAD(replay_cache_list, replay_cache_entry);
|
||||
|
||||
static struct replay_cache_entry *
|
||||
replay_alloc(struct replay_cache *rc, struct rpc_msg *msg,
|
||||
struct sockaddr *addr, int h);
|
||||
static void replay_free(struct replay_cache *rc,
|
||||
struct replay_cache_entry *rce);
|
||||
static void replay_prune(struct replay_cache *rc);
|
||||
|
||||
#define REPLAY_HASH_SIZE 256
|
||||
#define REPLAY_MAX 1024
|
||||
|
||||
struct replay_cache {
|
||||
struct replay_cache_list rc_cache[REPLAY_HASH_SIZE];
|
||||
struct replay_cache_list rc_all;
|
||||
struct mtx rc_lock;
|
||||
int rc_count;
|
||||
size_t rc_size;
|
||||
size_t rc_maxsize;
|
||||
};
|
||||
|
||||
struct replay_cache *
|
||||
replay_newcache(size_t maxsize)
|
||||
{
|
||||
struct replay_cache *rc;
|
||||
int i;
|
||||
|
||||
rc = malloc(sizeof(*rc), M_RPC, M_WAITOK|M_ZERO);
|
||||
for (i = 0; i < REPLAY_HASH_SIZE; i++)
|
||||
TAILQ_INIT(&rc->rc_cache[i]);
|
||||
TAILQ_INIT(&rc->rc_all);
|
||||
mtx_init(&rc->rc_lock, "rc_lock", NULL, MTX_DEF);
|
||||
rc->rc_maxsize = maxsize;
|
||||
|
||||
return (rc);
|
||||
}
|
||||
|
||||
void
|
||||
replay_setsize(struct replay_cache *rc, size_t newmaxsize)
|
||||
{
|
||||
|
||||
rc->rc_maxsize = newmaxsize;
|
||||
replay_prune(rc);
|
||||
}
|
||||
|
||||
void
|
||||
replay_freecache(struct replay_cache *rc)
|
||||
{
|
||||
|
||||
mtx_lock(&rc->rc_lock);
|
||||
while (TAILQ_FIRST(&rc->rc_all))
|
||||
replay_free(rc, TAILQ_FIRST(&rc->rc_all));
|
||||
mtx_destroy(&rc->rc_lock);
|
||||
free(rc, M_RPC);
|
||||
}
|
||||
|
||||
static struct replay_cache_entry *
|
||||
replay_alloc(struct replay_cache *rc,
|
||||
struct rpc_msg *msg, struct sockaddr *addr, int h)
|
||||
{
|
||||
struct replay_cache_entry *rce;
|
||||
|
||||
rc->rc_count++;
|
||||
rce = malloc(sizeof(*rce), M_RPC, M_NOWAIT|M_ZERO);
|
||||
rce->rce_hash = h;
|
||||
rce->rce_msg = *msg;
|
||||
bcopy(addr, &rce->rce_addr, addr->sa_len);
|
||||
|
||||
TAILQ_INSERT_HEAD(&rc->rc_cache[h], rce, rce_link);
|
||||
TAILQ_INSERT_HEAD(&rc->rc_all, rce, rce_alllink);
|
||||
|
||||
return (rce);
|
||||
}
|
||||
|
||||
static void
|
||||
replay_free(struct replay_cache *rc, struct replay_cache_entry *rce)
|
||||
{
|
||||
|
||||
rc->rc_count--;
|
||||
TAILQ_REMOVE(&rc->rc_cache[rce->rce_hash], rce, rce_link);
|
||||
TAILQ_REMOVE(&rc->rc_all, rce, rce_alllink);
|
||||
if (rce->rce_repbody) {
|
||||
rc->rc_size -= m_length(rce->rce_repbody, NULL);
|
||||
m_freem(rce->rce_repbody);
|
||||
}
|
||||
free(rce, M_RPC);
|
||||
}
|
||||
|
||||
static void
|
||||
replay_prune(struct replay_cache *rc)
|
||||
{
|
||||
struct replay_cache_entry *rce;
|
||||
bool_t freed_one;
|
||||
|
||||
if (rc->rc_count >= REPLAY_MAX || rc->rc_size > rc->rc_maxsize) {
|
||||
freed_one = FALSE;
|
||||
do {
|
||||
/*
|
||||
* Try to free an entry. Don't free in-progress entries
|
||||
*/
|
||||
TAILQ_FOREACH_REVERSE(rce, &rc->rc_all,
|
||||
replay_cache_list, rce_alllink) {
|
||||
if (rce->rce_repmsg.rm_xid) {
|
||||
replay_free(rc, rce);
|
||||
freed_one = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (freed_one
|
||||
&& (rc->rc_count >= REPLAY_MAX
|
||||
|| rc->rc_size > rc->rc_maxsize));
|
||||
}
|
||||
}
|
||||
|
||||
enum replay_state
|
||||
replay_find(struct replay_cache *rc, struct rpc_msg *msg,
|
||||
struct sockaddr *addr, struct rpc_msg *repmsg, struct mbuf **mp)
|
||||
{
|
||||
int h = HASHSTEP(HASHINIT, msg->rm_xid) % REPLAY_HASH_SIZE;
|
||||
struct replay_cache_entry *rce;
|
||||
|
||||
mtx_lock(&rc->rc_lock);
|
||||
TAILQ_FOREACH(rce, &rc->rc_cache[h], rce_link) {
|
||||
if (rce->rce_msg.rm_xid == msg->rm_xid
|
||||
&& rce->rce_msg.rm_call.cb_prog == msg->rm_call.cb_prog
|
||||
&& rce->rce_msg.rm_call.cb_vers == msg->rm_call.cb_vers
|
||||
&& rce->rce_msg.rm_call.cb_proc == msg->rm_call.cb_proc
|
||||
&& rce->rce_addr.ss_len == addr->sa_len
|
||||
&& bcmp(&rce->rce_addr, addr, addr->sa_len) == 0) {
|
||||
if (rce->rce_repmsg.rm_xid) {
|
||||
/*
|
||||
* We have a reply for this
|
||||
* message. Copy it and return. Keep
|
||||
* replay_all LRU sorted
|
||||
*/
|
||||
TAILQ_REMOVE(&rc->rc_all, rce, rce_alllink);
|
||||
TAILQ_INSERT_HEAD(&rc->rc_all, rce,
|
||||
rce_alllink);
|
||||
*repmsg = rce->rce_repmsg;
|
||||
if (rce->rce_repbody) {
|
||||
*mp = m_copym(rce->rce_repbody,
|
||||
0, M_COPYALL, M_NOWAIT);
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
if (!*mp)
|
||||
return (RS_ERROR);
|
||||
} else {
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
}
|
||||
return (RS_DONE);
|
||||
} else {
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
return (RS_INPROGRESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
replay_prune(rc);
|
||||
|
||||
rce = replay_alloc(rc, msg, addr, h);
|
||||
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
|
||||
if (!rce)
|
||||
return (RS_ERROR);
|
||||
else
|
||||
return (RS_NEW);
|
||||
}
|
||||
|
||||
void
|
||||
replay_setreply(struct replay_cache *rc,
|
||||
struct rpc_msg *repmsg, struct sockaddr *addr, struct mbuf *m)
|
||||
{
|
||||
int h = HASHSTEP(HASHINIT, repmsg->rm_xid) % REPLAY_HASH_SIZE;
|
||||
struct replay_cache_entry *rce;
|
||||
|
||||
/*
|
||||
* Copy the reply before the lock so we can sleep.
|
||||
*/
|
||||
if (m)
|
||||
m = m_copym(m, 0, M_COPYALL, M_WAITOK);
|
||||
|
||||
mtx_lock(&rc->rc_lock);
|
||||
TAILQ_FOREACH(rce, &rc->rc_cache[h], rce_link) {
|
||||
if (rce->rce_msg.rm_xid == repmsg->rm_xid
|
||||
&& rce->rce_addr.ss_len == addr->sa_len
|
||||
&& bcmp(&rce->rce_addr, addr, addr->sa_len) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rce) {
|
||||
rce->rce_repmsg = *repmsg;
|
||||
rce->rce_repbody = m;
|
||||
if (m)
|
||||
rc->rc_size += m_length(m, NULL);
|
||||
}
|
||||
mtx_unlock(&rc->rc_lock);
|
||||
}
|
85
sys/rpc/replay.h
Normal file
85
sys/rpc/replay.h
Normal file
@ -0,0 +1,85 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Isilon Inc http://www.isilon.com/
|
||||
* Authors: Doug Rabson <dfr@rabson.org>
|
||||
* Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _RPC_REPLAY_H
|
||||
#define _RPC_REPLAY_H
|
||||
|
||||
enum replay_state {
|
||||
RS_NEW, /* new request - caller should execute */
|
||||
RS_DONE, /* request was executed and reply sent */
|
||||
RS_INPROGRESS, /* request is being executed now */
|
||||
RS_ERROR /* allocation or other failure */
|
||||
};
|
||||
|
||||
struct replay_cache;
|
||||
|
||||
/*
|
||||
* Create a new replay cache.
|
||||
*/
|
||||
struct replay_cache *replay_newcache(size_t);
|
||||
|
||||
/*
|
||||
* Set the replay cache size.
|
||||
*/
|
||||
void replay_setsize(struct replay_cache *, size_t);
|
||||
|
||||
/*
|
||||
* Free a replay cache. Caller must ensure that no cache entries are
|
||||
* in-progress.
|
||||
*/
|
||||
void replay_freecache(struct replay_cache *rc);
|
||||
|
||||
/*
|
||||
* Check a replay cache for a message from a given address.
|
||||
*
|
||||
* If this is a new request, RS_NEW is returned. Caller should call
|
||||
* replay_setreply with the results of the request.
|
||||
*
|
||||
* If this is a request which is currently executing
|
||||
* (i.e. replay_setreply hasn't been called for it yet), RS_INPROGRESS
|
||||
* is returned. The caller should silently drop the request.
|
||||
*
|
||||
* If a reply to this message already exists, *repmsg and *mp are set
|
||||
* to point at the reply and, RS_DONE is returned. The caller should
|
||||
* re-send this reply.
|
||||
*
|
||||
* If the attempt to update the replay cache or copy a replay failed
|
||||
* for some reason (typically memory shortage), RS_ERROR is returned.
|
||||
*/
|
||||
enum replay_state replay_find(struct replay_cache *rc,
|
||||
struct rpc_msg *msg, struct sockaddr *addr,
|
||||
struct rpc_msg *repmsg, struct mbuf **mp);
|
||||
|
||||
/*
|
||||
* Call this after executing a request to record the reply.
|
||||
*/
|
||||
void replay_setreply(struct replay_cache *rc,
|
||||
struct rpc_msg *repmsg, struct sockaddr *addr, struct mbuf *m);
|
||||
|
||||
#endif /* !_RPC_REPLAY_H */
|
@ -115,6 +115,7 @@ extern const char *__rpc_inet_ntop(int af, const void * __restrict src,
|
||||
char * __restrict dst, socklen_t size);
|
||||
extern int __rpc_inet_pton(int af, const char * __restrict src,
|
||||
void * __restrict dst);
|
||||
extern int bindresvport(struct socket *so, struct sockaddr *sa);
|
||||
|
||||
struct xucred;
|
||||
struct __rpc_xdr;
|
||||
|
@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/protosw.h>
|
||||
@ -721,6 +722,139 @@ __rpc_sockisbound(struct socket *so)
|
||||
return bound;
|
||||
}
|
||||
|
||||
/*
|
||||
* Implement XDR-style API for RPC call.
|
||||
*/
|
||||
enum clnt_stat
|
||||
clnt_call_private(
|
||||
CLIENT *cl, /* client handle */
|
||||
struct rpc_callextra *ext, /* call metadata */
|
||||
rpcproc_t proc, /* procedure number */
|
||||
xdrproc_t xargs, /* xdr routine for args */
|
||||
void *argsp, /* pointer to args */
|
||||
xdrproc_t xresults, /* xdr routine for results */
|
||||
void *resultsp, /* pointer to results */
|
||||
struct timeval utimeout) /* seconds to wait before giving up */
|
||||
{
|
||||
XDR xdrs;
|
||||
struct mbuf *mreq;
|
||||
struct mbuf *mrep;
|
||||
enum clnt_stat stat;
|
||||
|
||||
MGET(mreq, M_WAIT, MT_DATA);
|
||||
MCLGET(mreq, M_WAIT);
|
||||
mreq->m_len = 0;
|
||||
|
||||
xdrmbuf_create(&xdrs, mreq, XDR_ENCODE);
|
||||
if (!xargs(&xdrs, argsp)) {
|
||||
m_freem(mreq);
|
||||
return (RPC_CANTENCODEARGS);
|
||||
}
|
||||
XDR_DESTROY(&xdrs);
|
||||
|
||||
stat = CLNT_CALL_MBUF(cl, ext, proc, mreq, &mrep, utimeout);
|
||||
m_freem(mreq);
|
||||
|
||||
if (stat == RPC_SUCCESS) {
|
||||
xdrmbuf_create(&xdrs, mrep, XDR_DECODE);
|
||||
if (!xresults(&xdrs, resultsp)) {
|
||||
XDR_DESTROY(&xdrs);
|
||||
return (RPC_CANTDECODERES);
|
||||
}
|
||||
XDR_DESTROY(&xdrs);
|
||||
}
|
||||
|
||||
return (stat);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bind a socket to a privileged IP port
|
||||
*/
|
||||
int
|
||||
bindresvport(struct socket *so, struct sockaddr *sa)
|
||||
{
|
||||
int old, error, af;
|
||||
bool_t freesa = FALSE;
|
||||
struct sockaddr_in *sin;
|
||||
#ifdef INET6
|
||||
struct sockaddr_in6 *sin6;
|
||||
#endif
|
||||
struct sockopt opt;
|
||||
int proto, portrange, portlow;
|
||||
u_int16_t *portp;
|
||||
socklen_t salen;
|
||||
|
||||
if (sa == NULL) {
|
||||
error = so->so_proto->pr_usrreqs->pru_sockaddr(so, &sa);
|
||||
if (error)
|
||||
return (error);
|
||||
freesa = TRUE;
|
||||
af = sa->sa_family;
|
||||
salen = sa->sa_len;
|
||||
memset(sa, 0, sa->sa_len);
|
||||
} else {
|
||||
af = sa->sa_family;
|
||||
salen = sa->sa_len;
|
||||
}
|
||||
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
proto = IPPROTO_IP;
|
||||
portrange = IP_PORTRANGE;
|
||||
portlow = IP_PORTRANGE_LOW;
|
||||
sin = (struct sockaddr_in *)sa;
|
||||
portp = &sin->sin_port;
|
||||
break;
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
proto = IPPROTO_IPV6;
|
||||
portrange = IPV6_PORTRANGE;
|
||||
portlow = IPV6_PORTRANGE_LOW;
|
||||
sin6 = (struct sockaddr_in6 *)sa;
|
||||
portp = &sin6->sin6_port;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return (EPFNOSUPPORT);
|
||||
}
|
||||
|
||||
sa->sa_family = af;
|
||||
sa->sa_len = salen;
|
||||
|
||||
if (*portp == 0) {
|
||||
bzero(&opt, sizeof(opt));
|
||||
opt.sopt_dir = SOPT_GET;
|
||||
opt.sopt_level = proto;
|
||||
opt.sopt_name = portrange;
|
||||
opt.sopt_val = &old;
|
||||
opt.sopt_valsize = sizeof(old);
|
||||
error = sogetopt(so, &opt);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
opt.sopt_dir = SOPT_SET;
|
||||
opt.sopt_val = &portlow;
|
||||
error = sosetopt(so, &opt);
|
||||
if (error)
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = sobind(so, sa, curthread);
|
||||
|
||||
if (*portp == 0) {
|
||||
if (error) {
|
||||
opt.sopt_dir = SOPT_SET;
|
||||
opt.sopt_val = &old;
|
||||
sosetopt(so, &opt);
|
||||
}
|
||||
}
|
||||
out:
|
||||
if (freesa)
|
||||
free(sa, M_SONAME);
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Kernel module glue
|
||||
*/
|
||||
|
@ -208,7 +208,7 @@ extern bool_t xdr_rejected_reply(XDR *, struct rejected_reply *);
|
||||
* struct rpc_msg *msg;
|
||||
* struct rpc_err *error;
|
||||
*/
|
||||
extern void _seterr_reply(struct rpc_msg *, struct rpc_err *);
|
||||
extern enum clnt_stat _seterr_reply(struct rpc_msg *, struct rpc_err *);
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_RPC_RPC_MSG_H */
|
||||
|
@ -64,8 +64,8 @@ MALLOC_DEFINE(M_RPC, "rpc", "Remote Procedure Call");
|
||||
|
||||
#define assert(exp) KASSERT(exp, ("bad arguments"))
|
||||
|
||||
static void accepted(enum accept_stat, struct rpc_err *);
|
||||
static void rejected(enum reject_stat, struct rpc_err *);
|
||||
static enum clnt_stat accepted(enum accept_stat, struct rpc_err *);
|
||||
static enum clnt_stat rejected(enum reject_stat, struct rpc_err *);
|
||||
|
||||
/* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
|
||||
|
||||
@ -111,7 +111,11 @@ xdr_accepted_reply(XDR *xdrs, struct accepted_reply *ar)
|
||||
switch (ar->ar_stat) {
|
||||
|
||||
case SUCCESS:
|
||||
return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where));
|
||||
if (ar->ar_results.proc != (xdrproc_t) xdr_void)
|
||||
return ((*(ar->ar_results.proc))(xdrs,
|
||||
ar->ar_results.where));
|
||||
else
|
||||
return (TRUE);
|
||||
|
||||
case PROG_MISMATCH:
|
||||
if (! xdr_uint32_t(xdrs, &(ar->ar_vers.low)))
|
||||
@ -171,12 +175,34 @@ static const struct xdr_discrim reply_dscrm[3] = {
|
||||
bool_t
|
||||
xdr_replymsg(XDR *xdrs, struct rpc_msg *rmsg)
|
||||
{
|
||||
int32_t *buf;
|
||||
enum msg_type *prm_direction;
|
||||
enum reply_stat *prp_stat;
|
||||
|
||||
assert(xdrs != NULL);
|
||||
assert(rmsg != NULL);
|
||||
|
||||
if (xdrs->x_op == XDR_DECODE) {
|
||||
buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT);
|
||||
if (buf != NULL) {
|
||||
rmsg->rm_xid = IXDR_GET_UINT32(buf);
|
||||
rmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
|
||||
if (rmsg->rm_direction != REPLY) {
|
||||
return (FALSE);
|
||||
}
|
||||
rmsg->rm_reply.rp_stat =
|
||||
IXDR_GET_ENUM(buf, enum reply_stat);
|
||||
if (rmsg->rm_reply.rp_stat == MSG_ACCEPTED)
|
||||
return (xdr_accepted_reply(xdrs,
|
||||
&rmsg->acpted_rply));
|
||||
else if (rmsg->rm_reply.rp_stat == MSG_DENIED)
|
||||
return (xdr_rejected_reply(xdrs,
|
||||
&rmsg->rjcted_rply));
|
||||
else
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
prm_direction = &rmsg->rm_direction;
|
||||
prp_stat = &rmsg->rm_reply.rp_stat;
|
||||
|
||||
@ -220,7 +246,7 @@ xdr_callhdr(XDR *xdrs, struct rpc_msg *cmsg)
|
||||
|
||||
/* ************************** Client utility routine ************* */
|
||||
|
||||
static void
|
||||
static enum clnt_stat
|
||||
accepted(enum accept_stat acpt_stat, struct rpc_err *error)
|
||||
{
|
||||
|
||||
@ -230,36 +256,32 @@ accepted(enum accept_stat acpt_stat, struct rpc_err *error)
|
||||
|
||||
case PROG_UNAVAIL:
|
||||
error->re_status = RPC_PROGUNAVAIL;
|
||||
return;
|
||||
return (RPC_PROGUNAVAIL);
|
||||
|
||||
case PROG_MISMATCH:
|
||||
error->re_status = RPC_PROGVERSMISMATCH;
|
||||
return;
|
||||
return (RPC_PROGVERSMISMATCH);
|
||||
|
||||
case PROC_UNAVAIL:
|
||||
error->re_status = RPC_PROCUNAVAIL;
|
||||
return;
|
||||
return (RPC_PROCUNAVAIL);
|
||||
|
||||
case GARBAGE_ARGS:
|
||||
error->re_status = RPC_CANTDECODEARGS;
|
||||
return;
|
||||
return (RPC_CANTDECODEARGS);
|
||||
|
||||
case SYSTEM_ERR:
|
||||
error->re_status = RPC_SYSTEMERROR;
|
||||
return;
|
||||
return (RPC_SYSTEMERROR);
|
||||
|
||||
case SUCCESS:
|
||||
error->re_status = RPC_SUCCESS;
|
||||
return;
|
||||
return (RPC_SUCCESS);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
/* something's wrong, but we don't know what ... */
|
||||
error->re_status = RPC_FAILED;
|
||||
error->re_lb.s1 = (int32_t)MSG_ACCEPTED;
|
||||
error->re_lb.s2 = (int32_t)acpt_stat;
|
||||
return (RPC_FAILED);
|
||||
}
|
||||
|
||||
static void
|
||||
static enum clnt_stat
|
||||
rejected(enum reject_stat rjct_stat, struct rpc_err *error)
|
||||
{
|
||||
|
||||
@ -267,26 +289,25 @@ rejected(enum reject_stat rjct_stat, struct rpc_err *error)
|
||||
|
||||
switch (rjct_stat) {
|
||||
case RPC_MISMATCH:
|
||||
error->re_status = RPC_VERSMISMATCH;
|
||||
return;
|
||||
return (RPC_VERSMISMATCH);
|
||||
|
||||
case AUTH_ERROR:
|
||||
error->re_status = RPC_AUTHERROR;
|
||||
return;
|
||||
return (RPC_AUTHERROR);
|
||||
}
|
||||
/* something's wrong, but we don't know what ... */
|
||||
/* NOTREACHED */
|
||||
error->re_status = RPC_FAILED;
|
||||
error->re_lb.s1 = (int32_t)MSG_DENIED;
|
||||
error->re_lb.s2 = (int32_t)rjct_stat;
|
||||
return (RPC_FAILED);
|
||||
}
|
||||
|
||||
/*
|
||||
* given a reply message, fills in the error
|
||||
*/
|
||||
void
|
||||
enum clnt_stat
|
||||
_seterr_reply(struct rpc_msg *msg, struct rpc_err *error)
|
||||
{
|
||||
enum clnt_stat stat;
|
||||
|
||||
assert(msg != NULL);
|
||||
assert(error != NULL);
|
||||
@ -296,22 +317,24 @@ _seterr_reply(struct rpc_msg *msg, struct rpc_err *error)
|
||||
|
||||
case MSG_ACCEPTED:
|
||||
if (msg->acpted_rply.ar_stat == SUCCESS) {
|
||||
error->re_status = RPC_SUCCESS;
|
||||
return;
|
||||
stat = RPC_SUCCESS;
|
||||
return (stat);
|
||||
}
|
||||
accepted(msg->acpted_rply.ar_stat, error);
|
||||
stat = accepted(msg->acpted_rply.ar_stat, error);
|
||||
break;
|
||||
|
||||
case MSG_DENIED:
|
||||
rejected(msg->rjcted_rply.rj_stat, error);
|
||||
stat = rejected(msg->rjcted_rply.rj_stat, error);
|
||||
break;
|
||||
|
||||
default:
|
||||
error->re_status = RPC_FAILED;
|
||||
stat = RPC_FAILED;
|
||||
error->re_lb.s1 = (int32_t)(msg->rm_reply.rp_stat);
|
||||
break;
|
||||
}
|
||||
switch (error->re_status) {
|
||||
error->re_status = stat;
|
||||
|
||||
switch (stat) {
|
||||
|
||||
case RPC_VERSMISMATCH:
|
||||
error->re_vers.low = msg->rjcted_rply.rj_vers.low;
|
||||
@ -345,4 +368,6 @@ _seterr_reply(struct rpc_msg *msg, struct rpc_err *error)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (stat);
|
||||
}
|
||||
|
189
sys/rpc/rpcsec_gss.h
Normal file
189
sys/rpc/rpcsec_gss.h
Normal file
@ -0,0 +1,189 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Doug Rabson
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _RPCSEC_GSS_H
|
||||
#define _RPCSEC_GSS_H
|
||||
|
||||
#include <kgssapi/gssapi.h>
|
||||
|
||||
#ifndef MAX_GSS_MECH
|
||||
#define MAX_GSS_MECH 64
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define the types of security service required for rpc_gss_seccreate().
|
||||
*/
|
||||
typedef enum {
|
||||
rpc_gss_svc_default = 0,
|
||||
rpc_gss_svc_none = 1,
|
||||
rpc_gss_svc_integrity = 2,
|
||||
rpc_gss_svc_privacy = 3
|
||||
} rpc_gss_service_t;
|
||||
|
||||
/*
|
||||
* Structure containing options for rpc_gss_seccreate().
|
||||
*/
|
||||
typedef struct {
|
||||
int req_flags; /* GSS request bits */
|
||||
int time_req; /* requested credential lifetime */
|
||||
gss_cred_id_t my_cred; /* GSS credential */
|
||||
gss_channel_bindings_t input_channel_bindings;
|
||||
} rpc_gss_options_req_t;
|
||||
|
||||
/*
|
||||
* Structure containing options returned by rpc_gss_seccreate().
|
||||
*/
|
||||
typedef struct {
|
||||
int major_status;
|
||||
int minor_status;
|
||||
u_int rpcsec_version;
|
||||
int ret_flags;
|
||||
int time_req;
|
||||
gss_ctx_id_t gss_context;
|
||||
char actual_mechanism[MAX_GSS_MECH];
|
||||
} rpc_gss_options_ret_t;
|
||||
|
||||
/*
|
||||
* Client principal type. Used as an argument to
|
||||
* rpc_gss_get_principal_name(). Also referenced by the
|
||||
* rpc_gss_rawcred_t structure.
|
||||
*/
|
||||
typedef struct {
|
||||
int len;
|
||||
char name[1];
|
||||
} *rpc_gss_principal_t;
|
||||
|
||||
/*
|
||||
* Structure for raw credentials used by rpc_gss_getcred() and
|
||||
* rpc_gss_set_callback().
|
||||
*/
|
||||
typedef struct {
|
||||
u_int version; /* RPC version number */
|
||||
const char *mechanism; /* security mechanism */
|
||||
const char *qop; /* quality of protection */
|
||||
rpc_gss_principal_t client_principal; /* client name */
|
||||
const char *svc_principal; /* server name */
|
||||
rpc_gss_service_t service; /* service type */
|
||||
} rpc_gss_rawcred_t;
|
||||
|
||||
/*
|
||||
* Unix credentials derived from raw credentials. Returned by
|
||||
* rpc_gss_getcred().
|
||||
*/
|
||||
typedef struct {
|
||||
uid_t uid; /* user ID */
|
||||
gid_t gid; /* group ID */
|
||||
short gidlen;
|
||||
gid_t *gidlist; /* list of groups */
|
||||
} rpc_gss_ucred_t;
|
||||
|
||||
/*
|
||||
* Structure used to enforce a particular QOP and service.
|
||||
*/
|
||||
typedef struct {
|
||||
bool_t locked;
|
||||
rpc_gss_rawcred_t *raw_cred;
|
||||
} rpc_gss_lock_t;
|
||||
|
||||
/*
|
||||
* Callback structure used by rpc_gss_set_callback().
|
||||
*/
|
||||
typedef struct {
|
||||
u_int program; /* RPC program number */
|
||||
u_int version; /* RPC version number */
|
||||
/* user defined callback */
|
||||
bool_t (*callback)(struct svc_req *req,
|
||||
gss_cred_id_t deleg,
|
||||
gss_ctx_id_t gss_context,
|
||||
rpc_gss_lock_t *lock,
|
||||
void **cookie);
|
||||
} rpc_gss_callback_t;
|
||||
|
||||
/*
|
||||
* Structure used to return error information by rpc_gss_get_error()
|
||||
*/
|
||||
typedef struct {
|
||||
int rpc_gss_error;
|
||||
int system_error; /* same as errno */
|
||||
} rpc_gss_error_t;
|
||||
|
||||
/*
|
||||
* Values for rpc_gss_error
|
||||
*/
|
||||
#define RPC_GSS_ER_SUCCESS 0 /* no error */
|
||||
#define RPC_GSS_ER_SYSTEMERROR 1 /* system error */
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#ifdef _KERNEL
|
||||
AUTH *rpc_gss_secfind(CLIENT *clnt, struct ucred *cred,
|
||||
const char *principal, gss_OID mech_oid, rpc_gss_service_t service);
|
||||
void rpc_gss_secpurge(CLIENT *clnt);
|
||||
#endif
|
||||
AUTH *rpc_gss_seccreate(CLIENT *clnt, struct ucred *cred,
|
||||
const char *principal, const char *mechanism, rpc_gss_service_t service,
|
||||
const char *qop, rpc_gss_options_req_t *options_req,
|
||||
rpc_gss_options_ret_t *options_ret);
|
||||
bool_t rpc_gss_set_defaults(AUTH *auth, rpc_gss_service_t service,
|
||||
const char *qop);
|
||||
int rpc_gss_max_data_length(AUTH *handle, int max_tp_unit_len);
|
||||
void rpc_gss_get_error(rpc_gss_error_t *error);
|
||||
|
||||
bool_t rpc_gss_mech_to_oid(const char *mech, gss_OID *oid_ret);
|
||||
bool_t rpc_gss_oid_to_mech(gss_OID oid, const char **mech_ret);
|
||||
bool_t rpc_gss_qop_to_num(const char *qop, const char *mech, u_int *num_ret);
|
||||
const char **rpc_gss_get_mechanisms(void);
|
||||
const char **rpc_gss_get_mech_info(const char *mech, rpc_gss_service_t *service);
|
||||
bool_t rpc_gss_get_versions(u_int *vers_hi, u_int *vers_lo);
|
||||
bool_t rpc_gss_is_installed(const char *mech);
|
||||
|
||||
bool_t rpc_gss_set_svc_name(const char *principal, const char *mechanism,
|
||||
u_int req_time, u_int program, u_int version);
|
||||
void rpc_gss_clear_svc_name(u_int program, u_int version);
|
||||
bool_t rpc_gss_getcred(struct svc_req *req, rpc_gss_rawcred_t **rcred,
|
||||
rpc_gss_ucred_t **ucred, void **cookie);
|
||||
bool_t rpc_gss_set_callback(rpc_gss_callback_t *cb);
|
||||
void rpc_gss_clear_callback(rpc_gss_callback_t *cb);
|
||||
bool_t rpc_gss_get_principal_name(rpc_gss_principal_t *principal,
|
||||
const char *mech, const char *name, const char *node, const char *domain);
|
||||
int rpc_gss_svc_max_data_length(struct svc_req *req, int max_tp_unit_len);
|
||||
|
||||
/*
|
||||
* Internal interface from the RPC implementation.
|
||||
*/
|
||||
#ifndef _KERNEL
|
||||
bool_t __rpc_gss_wrap(AUTH *auth, void *header, size_t headerlen,
|
||||
XDR* xdrs, xdrproc_t xdr_args, void *args_ptr);
|
||||
bool_t __rpc_gss_unwrap(AUTH *auth, XDR* xdrs, xdrproc_t xdr_args,
|
||||
void *args_ptr);
|
||||
#endif
|
||||
bool_t __rpc_gss_set_error(int rpc_gss_error, int system_error);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_RPCSEC_GSS_H */
|
1064
sys/rpc/rpcsec_gss/rpcsec_gss.c
Normal file
1064
sys/rpc/rpcsec_gss/rpcsec_gss.c
Normal file
File diff suppressed because it is too large
Load Diff
163
sys/rpc/rpcsec_gss/rpcsec_gss_conf.c
Normal file
163
sys/rpc/rpcsec_gss/rpcsec_gss_conf.c
Normal file
@ -0,0 +1,163 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Doug Rabson
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpcsec_gss.h>
|
||||
|
||||
#include "rpcsec_gss_int.h"
|
||||
|
||||
bool_t
|
||||
rpc_gss_mech_to_oid(const char *mech, gss_OID *oid_ret)
|
||||
{
|
||||
gss_OID oid = kgss_find_mech_by_name(mech);
|
||||
|
||||
if (oid) {
|
||||
*oid_ret = oid;
|
||||
return (TRUE);
|
||||
}
|
||||
_rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
rpc_gss_oid_to_mech(gss_OID oid, const char **mech_ret)
|
||||
{
|
||||
const char *name = kgss_find_mech_by_oid(oid);
|
||||
|
||||
if (name) {
|
||||
*mech_ret = name;
|
||||
return (TRUE);
|
||||
}
|
||||
_rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
rpc_gss_qop_to_num(const char *qop, const char *mech, u_int *num_ret)
|
||||
{
|
||||
|
||||
if (!strcmp(qop, "default")) {
|
||||
*num_ret = GSS_C_QOP_DEFAULT;
|
||||
return (TRUE);
|
||||
}
|
||||
_rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
const char *
|
||||
_rpc_gss_num_to_qop(const char *mech, u_int num)
|
||||
{
|
||||
|
||||
if (num == GSS_C_QOP_DEFAULT)
|
||||
return "default";
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const char **
|
||||
rpc_gss_get_mechanisms(void)
|
||||
{
|
||||
static const char **mech_names = NULL;
|
||||
struct kgss_mech *km;
|
||||
int count;
|
||||
|
||||
if (mech_names)
|
||||
return (mech_names);
|
||||
|
||||
count = 0;
|
||||
LIST_FOREACH(km, &kgss_mechs, km_link) {
|
||||
count++;
|
||||
}
|
||||
count++;
|
||||
|
||||
mech_names = malloc(count * sizeof(const char *), M_RPC, M_WAITOK);
|
||||
count = 0;
|
||||
LIST_FOREACH(km, &kgss_mechs, km_link) {
|
||||
mech_names[count++] = km->km_mech_name;
|
||||
}
|
||||
mech_names[count++] = NULL;
|
||||
|
||||
return (mech_names);
|
||||
}
|
||||
|
||||
#if 0
|
||||
const char **
|
||||
rpc_gss_get_mech_info(const char *mech, rpc_gss_service_t *service)
|
||||
{
|
||||
struct mech_info *info;
|
||||
|
||||
_rpc_gss_load_mech();
|
||||
_rpc_gss_load_qop();
|
||||
SLIST_FOREACH(info, &mechs, link) {
|
||||
if (!strcmp(mech, info->name)) {
|
||||
/*
|
||||
* I'm not sure what to do with service
|
||||
* here. The Solaris manpages are not clear on
|
||||
* the subject and the OpenSolaris code just
|
||||
* sets it to rpc_gss_svc_privacy
|
||||
* unconditionally with a comment noting that
|
||||
* it is bogus.
|
||||
*/
|
||||
*service = rpc_gss_svc_privacy;
|
||||
return info->qops;
|
||||
}
|
||||
}
|
||||
|
||||
_rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
|
||||
return (NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool_t
|
||||
rpc_gss_get_versions(u_int *vers_hi, u_int *vers_lo)
|
||||
{
|
||||
|
||||
*vers_hi = 1;
|
||||
*vers_lo = 1;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
bool_t
|
||||
rpc_gss_is_installed(const char *mech)
|
||||
{
|
||||
gss_OID oid = kgss_find_mech_by_name(mech);
|
||||
|
||||
if (oid)
|
||||
return (TRUE);
|
||||
else
|
||||
return (FALSE);
|
||||
}
|
||||
|
94
sys/rpc/rpcsec_gss/rpcsec_gss_int.h
Normal file
94
sys/rpc/rpcsec_gss/rpcsec_gss_int.h
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
rpcsec_gss.h
|
||||
|
||||
Copyright (c) 2000 The Regents of the University of Michigan.
|
||||
All rights reserved.
|
||||
|
||||
Copyright (c) 2000 Dug Song <dugsong@UMICH.EDU>.
|
||||
All rights reserved, all wrongs reversed.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the University nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
$Id: auth_gss.h,v 1.12 2001/04/30 19:44:47 andros Exp $
|
||||
*/
|
||||
/* $FreeBSD$ */
|
||||
|
||||
#ifndef _RPCSEC_GSS_INT_H
|
||||
#define _RPCSEC_GSS_INT_H
|
||||
|
||||
#include <kgssapi/gssapi_impl.h>
|
||||
|
||||
/* RPCSEC_GSS control procedures. */
|
||||
typedef enum {
|
||||
RPCSEC_GSS_DATA = 0,
|
||||
RPCSEC_GSS_INIT = 1,
|
||||
RPCSEC_GSS_CONTINUE_INIT = 2,
|
||||
RPCSEC_GSS_DESTROY = 3
|
||||
} rpc_gss_proc_t;
|
||||
|
||||
#define RPCSEC_GSS_VERSION 1
|
||||
|
||||
/* Credentials. */
|
||||
struct rpc_gss_cred {
|
||||
u_int gc_version; /* version */
|
||||
rpc_gss_proc_t gc_proc; /* control procedure */
|
||||
u_int gc_seq; /* sequence number */
|
||||
rpc_gss_service_t gc_svc; /* service */
|
||||
gss_buffer_desc gc_handle; /* handle to server-side context */
|
||||
};
|
||||
|
||||
/* Context creation response. */
|
||||
struct rpc_gss_init_res {
|
||||
gss_buffer_desc gr_handle; /* handle to server-side context */
|
||||
u_int gr_major; /* major status */
|
||||
u_int gr_minor; /* minor status */
|
||||
u_int gr_win; /* sequence window */
|
||||
gss_buffer_desc gr_token; /* token */
|
||||
};
|
||||
|
||||
/* Maximum sequence number value. */
|
||||
#define MAXSEQ 0x80000000
|
||||
|
||||
/* Prototypes. */
|
||||
__BEGIN_DECLS
|
||||
|
||||
bool_t xdr_rpc_gss_cred(XDR *xdrs, struct rpc_gss_cred *p);
|
||||
bool_t xdr_rpc_gss_init_res(XDR *xdrs, struct rpc_gss_init_res *p);
|
||||
bool_t xdr_rpc_gss_wrap_data(struct mbuf **argsp,
|
||||
gss_ctx_id_t ctx, gss_qop_t qop, rpc_gss_service_t svc,
|
||||
u_int seq);
|
||||
bool_t xdr_rpc_gss_unwrap_data(struct mbuf **resultsp,
|
||||
gss_ctx_id_t ctx, gss_qop_t qop, rpc_gss_service_t svc, u_int seq);
|
||||
const char *_rpc_gss_num_to_qop(const char *mech, u_int num);
|
||||
void _rpc_gss_set_error(int rpc_gss_error, int system_error);
|
||||
|
||||
void rpc_gss_log_debug(const char *fmt, ...);
|
||||
void rpc_gss_log_status(const char *m, gss_OID mech, OM_uint32 major,
|
||||
OM_uint32 minor);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_RPCSEC_GSS_INT_H */
|
53
sys/rpc/rpcsec_gss/rpcsec_gss_misc.c
Normal file
53
sys/rpc/rpcsec_gss/rpcsec_gss_misc.c
Normal file
@ -0,0 +1,53 @@
|
||||
/*-
|
||||
* Copyright (c) 2008 Doug Rabson
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpcsec_gss.h>
|
||||
|
||||
#include "rpcsec_gss_int.h"
|
||||
|
||||
static rpc_gss_error_t _rpc_gss_error;
|
||||
|
||||
void
|
||||
_rpc_gss_set_error(int rpc_gss_error, int system_error)
|
||||
{
|
||||
|
||||
_rpc_gss_error.rpc_gss_error = rpc_gss_error;
|
||||
_rpc_gss_error.system_error = system_error;
|
||||
}
|
||||
|
||||
void
|
||||
rpc_gss_get_error(rpc_gss_error_t *error)
|
||||
{
|
||||
|
||||
*error = _rpc_gss_error;
|
||||
}
|
359
sys/rpc/rpcsec_gss/rpcsec_gss_prot.c
Normal file
359
sys/rpc/rpcsec_gss/rpcsec_gss_prot.c
Normal file
@ -0,0 +1,359 @@
|
||||
/*
|
||||
rpcsec_gss_prot.c
|
||||
|
||||
Copyright (c) 2000 The Regents of the University of Michigan.
|
||||
All rights reserved.
|
||||
|
||||
Copyright (c) 2000 Dug Song <dugsong@UMICH.EDU>.
|
||||
All rights reserved, all wrongs reversed.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the University nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
$Id: authgss_prot.c,v 1.18 2000/09/01 04:14:03 dugsong Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kobj.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/mutex.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpcsec_gss.h>
|
||||
|
||||
#include "rpcsec_gss_int.h"
|
||||
|
||||
#define MAX_GSS_SIZE 10240 /* XXX */
|
||||
|
||||
#if 0 /* use the one from kgssapi */
|
||||
bool_t
|
||||
xdr_gss_buffer_desc(XDR *xdrs, gss_buffer_desc *p)
|
||||
{
|
||||
char *val;
|
||||
u_int len;
|
||||
bool_t ret;
|
||||
|
||||
val = p->value;
|
||||
len = p->length;
|
||||
ret = xdr_bytes(xdrs, &val, &len, MAX_GSS_SIZE);
|
||||
p->value = val;
|
||||
p->length = len;
|
||||
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool_t
|
||||
xdr_rpc_gss_cred(XDR *xdrs, struct rpc_gss_cred *p)
|
||||
{
|
||||
enum_t proc, svc;
|
||||
bool_t ret;
|
||||
|
||||
proc = p->gc_proc;
|
||||
svc = p->gc_svc;
|
||||
ret = (xdr_u_int(xdrs, &p->gc_version) &&
|
||||
xdr_enum(xdrs, &proc) &&
|
||||
xdr_u_int(xdrs, &p->gc_seq) &&
|
||||
xdr_enum(xdrs, &svc) &&
|
||||
xdr_gss_buffer_desc(xdrs, &p->gc_handle));
|
||||
p->gc_proc = proc;
|
||||
p->gc_svc = svc;
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_gss_init_res(XDR *xdrs, struct rpc_gss_init_res *p)
|
||||
{
|
||||
|
||||
return (xdr_gss_buffer_desc(xdrs, &p->gr_handle) &&
|
||||
xdr_u_int(xdrs, &p->gr_major) &&
|
||||
xdr_u_int(xdrs, &p->gr_minor) &&
|
||||
xdr_u_int(xdrs, &p->gr_win) &&
|
||||
xdr_gss_buffer_desc(xdrs, &p->gr_token));
|
||||
}
|
||||
|
||||
static void
|
||||
put_uint32(struct mbuf **mp, uint32_t v)
|
||||
{
|
||||
struct mbuf *m = *mp;
|
||||
uint32_t n;
|
||||
|
||||
M_PREPEND(m, sizeof(uint32_t), M_WAIT);
|
||||
n = htonl(v);
|
||||
bcopy(&n, mtod(m, uint32_t *), sizeof(uint32_t));
|
||||
*mp = m;
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_gss_wrap_data(struct mbuf **argsp,
|
||||
gss_ctx_id_t ctx, gss_qop_t qop,
|
||||
rpc_gss_service_t svc, u_int seq)
|
||||
{
|
||||
struct mbuf *args, *mic;
|
||||
OM_uint32 maj_stat, min_stat;
|
||||
int conf_state;
|
||||
u_int len;
|
||||
static char zpad[4];
|
||||
|
||||
args = *argsp;
|
||||
|
||||
/*
|
||||
* Prepend the sequence number before calling gss_get_mic or gss_wrap.
|
||||
*/
|
||||
put_uint32(&args, seq);
|
||||
len = m_length(args, NULL);
|
||||
|
||||
if (svc == rpc_gss_svc_integrity) {
|
||||
/* Checksum rpc_gss_data_t. */
|
||||
maj_stat = gss_get_mic_mbuf(&min_stat, ctx, qop, args, &mic);
|
||||
if (maj_stat != GSS_S_COMPLETE) {
|
||||
rpc_gss_log_debug("gss_get_mic failed");
|
||||
m_freem(args);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Marshal databody_integ. Note that since args is
|
||||
* already RPC encoded, there will be no padding.
|
||||
*/
|
||||
put_uint32(&args, len);
|
||||
|
||||
/*
|
||||
* Marshal checksum. This is likely to need padding.
|
||||
*/
|
||||
len = m_length(mic, NULL);
|
||||
put_uint32(&mic, len);
|
||||
if (len != RNDUP(len)) {
|
||||
m_append(mic, RNDUP(len) - len, zpad);
|
||||
}
|
||||
|
||||
/*
|
||||
* Concatenate databody_integ with checksum.
|
||||
*/
|
||||
m_cat(args, mic);
|
||||
} else if (svc == rpc_gss_svc_privacy) {
|
||||
/* Encrypt rpc_gss_data_t. */
|
||||
maj_stat = gss_wrap_mbuf(&min_stat, ctx, TRUE, qop,
|
||||
&args, &conf_state);
|
||||
if (maj_stat != GSS_S_COMPLETE) {
|
||||
rpc_gss_log_status("gss_wrap", NULL,
|
||||
maj_stat, min_stat);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Marshal databody_priv and deal with RPC padding.
|
||||
*/
|
||||
len = m_length(args, NULL);
|
||||
put_uint32(&args, len);
|
||||
if (len != RNDUP(len)) {
|
||||
m_append(args, RNDUP(len) - len, zpad);
|
||||
}
|
||||
}
|
||||
*argsp = args;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
get_uint32(struct mbuf **mp)
|
||||
{
|
||||
struct mbuf *m = *mp;
|
||||
uint32_t n;
|
||||
|
||||
if (m->m_len < sizeof(uint32_t)) {
|
||||
m = m_pullup(m, sizeof(uint32_t));
|
||||
if (!m) {
|
||||
*mp = NULL;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
bcopy(mtod(m, uint32_t *), &n, sizeof(uint32_t));
|
||||
m_adj(m, sizeof(uint32_t));
|
||||
*mp = m;
|
||||
return (ntohl(n));
|
||||
}
|
||||
|
||||
static void
|
||||
m_trim(struct mbuf *m, int len)
|
||||
{
|
||||
struct mbuf *n;
|
||||
int off;
|
||||
|
||||
n = m_getptr(m, len, &off);
|
||||
if (n) {
|
||||
n->m_len = off;
|
||||
if (n->m_next) {
|
||||
m_freem(n->m_next);
|
||||
n->m_next = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool_t
|
||||
xdr_rpc_gss_unwrap_data(struct mbuf **resultsp,
|
||||
gss_ctx_id_t ctx, gss_qop_t qop,
|
||||
rpc_gss_service_t svc, u_int seq)
|
||||
{
|
||||
struct mbuf *results, *message, *mic;
|
||||
uint32_t len, cklen;
|
||||
OM_uint32 maj_stat, min_stat;
|
||||
u_int seq_num, conf_state, qop_state;
|
||||
|
||||
results = *resultsp;
|
||||
*resultsp = NULL;
|
||||
|
||||
message = NULL;
|
||||
if (svc == rpc_gss_svc_integrity) {
|
||||
/*
|
||||
* Extract the seq+message part. Remember that there
|
||||
* may be extra RPC padding in the checksum. The
|
||||
* message part is RPC encoded already so no
|
||||
* padding.
|
||||
*/
|
||||
len = get_uint32(&results);
|
||||
message = results;
|
||||
results = m_split(results, len, M_WAIT);
|
||||
if (!results) {
|
||||
m_freem(message);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract the MIC and make it contiguous.
|
||||
*/
|
||||
cklen = get_uint32(&results);
|
||||
KASSERT(cklen <= MHLEN, ("unexpected large GSS-API checksum"));
|
||||
mic = results;
|
||||
if (cklen > mic->m_len)
|
||||
mic = m_pullup(mic, cklen);
|
||||
if (cklen != RNDUP(cklen))
|
||||
m_trim(mic, cklen);
|
||||
|
||||
/* Verify checksum and QOP. */
|
||||
maj_stat = gss_verify_mic_mbuf(&min_stat, ctx,
|
||||
message, mic, &qop_state);
|
||||
m_freem(mic);
|
||||
|
||||
if (maj_stat != GSS_S_COMPLETE || qop_state != qop) {
|
||||
m_freem(message);
|
||||
rpc_gss_log_status("gss_verify_mic", NULL,
|
||||
maj_stat, min_stat);
|
||||
return (FALSE);
|
||||
}
|
||||
} else if (svc == rpc_gss_svc_privacy) {
|
||||
/* Decode databody_priv. */
|
||||
len = get_uint32(&results);
|
||||
|
||||
/* Decrypt databody. */
|
||||
message = results;
|
||||
if (len != RNDUP(len))
|
||||
m_trim(message, len);
|
||||
maj_stat = gss_unwrap_mbuf(&min_stat, ctx, &message,
|
||||
&conf_state, &qop_state);
|
||||
|
||||
/* Verify encryption and QOP. */
|
||||
if (maj_stat != GSS_S_COMPLETE) {
|
||||
rpc_gss_log_status("gss_unwrap", NULL,
|
||||
maj_stat, min_stat);
|
||||
return (FALSE);
|
||||
}
|
||||
if (qop_state != qop || conf_state != TRUE) {
|
||||
m_freem(results);
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Decode rpc_gss_data_t (sequence number + arguments). */
|
||||
seq_num = get_uint32(&message);
|
||||
|
||||
/* Verify sequence number. */
|
||||
if (seq_num != seq) {
|
||||
rpc_gss_log_debug("wrong sequence number in databody");
|
||||
m_freem(message);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
*resultsp = message;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <ctype.h>
|
||||
|
||||
void
|
||||
rpc_gss_log_debug(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "rpcsec_gss: ");
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
rpc_gss_log_status(const char *m, gss_OID mech, OM_uint32 maj_stat, OM_uint32 min_stat)
|
||||
{
|
||||
OM_uint32 min;
|
||||
gss_buffer_desc msg;
|
||||
int msg_ctx = 0;
|
||||
|
||||
fprintf(stderr, "rpcsec_gss: %s: ", m);
|
||||
|
||||
gss_display_status(&min, maj_stat, GSS_C_GSS_CODE, GSS_C_NULL_OID,
|
||||
&msg_ctx, &msg);
|
||||
printf("%s - ", (char *)msg.value);
|
||||
gss_release_buffer(&min, &msg);
|
||||
|
||||
gss_display_status(&min, min_stat, GSS_C_MECH_CODE, mech,
|
||||
&msg_ctx, &msg);
|
||||
printf("%s\n", (char *)msg.value);
|
||||
gss_release_buffer(&min, &msg);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void
|
||||
rpc_gss_log_debug(__unused const char *fmt, ...)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
rpc_gss_log_status(__unused const char *m, __unused gss_OID mech,
|
||||
__unused OM_uint32 maj_stat, __unused OM_uint32 min_stat)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
1485
sys/rpc/rpcsec_gss/svc_rpcsec_gss.c
Normal file
1485
sys/rpc/rpcsec_gss/svc_rpcsec_gss.c
Normal file
File diff suppressed because it is too large
Load Diff
1072
sys/rpc/svc.c
1072
sys/rpc/svc.c
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user