svn commit: r184588 - in head: etc/gss etc/rc.d include/rpc
lib/libc/sys lib/libc/xdr lib/librpcsec_gss sbin/mount_nfs
sys/compat/freebsd32 sys/conf sys/fs/unionfs sys/kern
sys/kgssapi sys/kgssapi/...
Doug Rabson
dfr at FreeBSD.org
Mon Nov 3 02:38:01 PST 2008
Author: dfr
Date: Mon Nov 3 10:38:00 2008
New Revision: 184588
URL: http://svn.freebsd.org/changeset/base/184588
Log:
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
Added:
head/etc/rc.d/gssd (contents, props changed)
head/sys/kgssapi/
head/sys/kgssapi/gss_accept_sec_context.c (contents, props changed)
head/sys/kgssapi/gss_acquire_cred.c (contents, props changed)
head/sys/kgssapi/gss_add_oid_set_member.c (contents, props changed)
head/sys/kgssapi/gss_canonicalize_name.c (contents, props changed)
head/sys/kgssapi/gss_create_empty_oid_set.c (contents, props changed)
head/sys/kgssapi/gss_delete_sec_context.c (contents, props changed)
head/sys/kgssapi/gss_display_status.c (contents, props changed)
head/sys/kgssapi/gss_export_name.c (contents, props changed)
head/sys/kgssapi/gss_get_mic.c (contents, props changed)
head/sys/kgssapi/gss_impl.c (contents, props changed)
head/sys/kgssapi/gss_import_name.c (contents, props changed)
head/sys/kgssapi/gss_init_sec_context.c (contents, props changed)
head/sys/kgssapi/gss_names.c (contents, props changed)
head/sys/kgssapi/gss_pname_to_uid.c (contents, props changed)
head/sys/kgssapi/gss_release_buffer.c (contents, props changed)
head/sys/kgssapi/gss_release_cred.c (contents, props changed)
head/sys/kgssapi/gss_release_name.c (contents, props changed)
head/sys/kgssapi/gss_release_oid_set.c (contents, props changed)
head/sys/kgssapi/gss_set_cred_option.c (contents, props changed)
head/sys/kgssapi/gss_test_oid_set_member.c (contents, props changed)
head/sys/kgssapi/gss_unwrap.c (contents, props changed)
head/sys/kgssapi/gss_verify_mic.c (contents, props changed)
head/sys/kgssapi/gss_wrap.c (contents, props changed)
head/sys/kgssapi/gss_wrap_size_limit.c (contents, props changed)
head/sys/kgssapi/gssapi.h (contents, props changed)
head/sys/kgssapi/gssapi_impl.h (contents, props changed)
head/sys/kgssapi/gssd.x (contents, props changed)
head/sys/kgssapi/gssd_prot.c (contents, props changed)
head/sys/kgssapi/gsstest.c (contents, props changed)
head/sys/kgssapi/kgss_if.m (contents, props changed)
head/sys/kgssapi/krb5/
head/sys/kgssapi/krb5/kcrypto.c (contents, props changed)
head/sys/kgssapi/krb5/kcrypto.h (contents, props changed)
head/sys/kgssapi/krb5/kcrypto_aes.c (contents, props changed)
head/sys/kgssapi/krb5/kcrypto_arcfour.c (contents, props changed)
head/sys/kgssapi/krb5/kcrypto_des.c (contents, props changed)
head/sys/kgssapi/krb5/kcrypto_des3.c (contents, props changed)
head/sys/kgssapi/krb5/krb5_mech.c (contents, props changed)
head/sys/modules/kgssapi/
head/sys/modules/kgssapi/Makefile (contents, props changed)
head/sys/modules/kgssapi_krb5/
head/sys/modules/kgssapi_krb5/Makefile (contents, props changed)
head/sys/nfsclient/nfs_krpc.c (contents, props changed)
head/sys/nfsserver/nfs_fha.c (contents, props changed)
head/sys/nfsserver/nfs_fha.h (contents, props changed)
head/sys/nfsserver/nfs_srvkrpc.c (contents, props changed)
head/sys/rpc/replay.c (contents, props changed)
head/sys/rpc/replay.h (contents, props changed)
head/sys/rpc/rpcsec_gss/
head/sys/rpc/rpcsec_gss.h (contents, props changed)
head/sys/rpc/rpcsec_gss/rpcsec_gss.c (contents, props changed)
head/sys/rpc/rpcsec_gss/rpcsec_gss_conf.c (contents, props changed)
head/sys/rpc/rpcsec_gss/rpcsec_gss_int.h (contents, props changed)
head/sys/rpc/rpcsec_gss/rpcsec_gss_misc.c (contents, props changed)
head/sys/rpc/rpcsec_gss/rpcsec_gss_prot.c (contents, props changed)
head/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c (contents, props changed)
head/tools/regression/kgssapi/
head/tools/regression/kgssapi/Makefile (contents, props changed)
head/tools/regression/kgssapi/gsstest.c (contents, props changed)
head/tools/regression/rpcsec_gss/
head/tools/regression/rpcsec_gss/Makefile (contents, props changed)
head/tools/regression/rpcsec_gss/rpctest.c (contents, props changed)
head/usr.sbin/gssd/
head/usr.sbin/gssd/Makefile (contents, props changed)
head/usr.sbin/gssd/gssd.8 (contents, props changed)
head/usr.sbin/gssd/gssd.c (contents, props changed)
Modified:
head/etc/gss/mech
head/etc/rc.d/Makefile
head/etc/rc.d/nfsd
head/include/rpc/xdr.h
head/lib/libc/sys/Symbol.map
head/lib/libc/xdr/Symbol.map
head/lib/libc/xdr/xdr.c
head/lib/librpcsec_gss/svc_rpcsec_gss.c
head/sbin/mount_nfs/mount_nfs.c
head/sys/compat/freebsd32/syscalls.master
head/sys/conf/files
head/sys/conf/options
head/sys/fs/unionfs/union_vfsops.c
head/sys/kern/syscalls.master
head/sys/kern/vfs_export.c
head/sys/kern/vfs_mount.c
head/sys/modules/nfsclient/Makefile
head/sys/modules/nfsserver/Makefile
head/sys/nfsclient/nfs.h
head/sys/nfsclient/nfs_socket.c
head/sys/nfsclient/nfs_subs.c
head/sys/nfsclient/nfs_vfsops.c
head/sys/nfsclient/nfsmount.h
head/sys/nfsserver/nfs.h
head/sys/nfsserver/nfs_serv.c
head/sys/nfsserver/nfs_srvcache.c
head/sys/nfsserver/nfs_srvsock.c
head/sys/nfsserver/nfs_srvsubs.c
head/sys/nfsserver/nfs_syscalls.c
head/sys/nfsserver/nfsm_subs.h
head/sys/nfsserver/nfsrvcache.h
head/sys/nlm/nlm.h
head/sys/nlm/nlm_advlock.c
head/sys/nlm/nlm_prot_impl.c
head/sys/nlm/nlm_prot_svc.c
head/sys/rpc/auth.h
head/sys/rpc/auth_none.c
head/sys/rpc/auth_unix.c
head/sys/rpc/clnt.h
head/sys/rpc/clnt_dg.c
head/sys/rpc/clnt_rc.c
head/sys/rpc/clnt_vc.c
head/sys/rpc/rpc_com.h
head/sys/rpc/rpc_generic.c
head/sys/rpc/rpc_msg.h
head/sys/rpc/rpc_prot.c
head/sys/rpc/svc.c
head/sys/rpc/svc.h
head/sys/rpc/svc_auth.c
head/sys/rpc/svc_auth.h
head/sys/rpc/svc_auth_unix.c
head/sys/rpc/svc_dg.c
head/sys/rpc/svc_generic.c
head/sys/rpc/svc_vc.c
head/sys/rpc/xdr.h
head/sys/sys/mount.h
head/sys/xdr/xdr_mbuf.c
head/usr.sbin/Makefile
head/usr.sbin/mountd/exports.5
head/usr.sbin/mountd/mountd.c
head/usr.sbin/nfsd/nfsd.c
Modified: head/etc/gss/mech
==============================================================================
--- head/etc/gss/mech Mon Nov 3 10:22:19 2008 (r184587)
+++ head/etc/gss/mech Mon Nov 3 10:38:00 2008 (r184588)
@@ -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 -
Modified: head/etc/rc.d/Makefile
==============================================================================
--- head/etc/rc.d/Makefile Mon Nov 3 10:22:19 2008 (r184587)
+++ head/etc/rc.d/Makefile Mon Nov 3 10:38:00 2008 (r184588)
@@ -11,7 +11,7 @@ FILES= DAEMON FILESYSTEMS LOGIN NETWORKI
dmesg dumpon \
early.sh encswap \
fsck ftp-proxy ftpd \
- gbde geli geli2 \
+ gbde geli geli2 gssd \
hcsecd \
hostapd hostid hostname \
idmapd inetd initrandom \
Added: head/etc/rc.d/gssd
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/etc/rc.d/gssd Mon Nov 3 10:38:00 2008 (r184588)
@@ -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"
Modified: head/etc/rc.d/nfsd
==============================================================================
--- head/etc/rc.d/nfsd Mon Nov 3 10:22:19 2008 (r184587)
+++ head/etc/rc.d/nfsd Mon Nov 3 10:38:00 2008 (r184588)
@@ -4,7 +4,7 @@
#
# PROVIDE: nfsd
-# REQUIRE: mountd
+# REQUIRE: mountd hostname gssd
# KEYWORD: nojail shutdown
. /etc/rc.subr
Modified: head/include/rpc/xdr.h
==============================================================================
--- head/include/rpc/xdr.h Mon Nov 3 10:22:19 2008 (r184587)
+++ head/include/rpc/xdr.h Mon Nov 3 10:38:00 2008 (r184588)
@@ -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);
Modified: head/lib/libc/sys/Symbol.map
==============================================================================
--- head/lib/libc/sys/Symbol.map Mon Nov 3 10:22:19 2008 (r184587)
+++ head/lib/libc/sys/Symbol.map Mon Nov 3 10:38:00 2008 (r184588)
@@ -982,4 +982,5 @@ FBSDprivate_1.0 {
__sys_writev;
__error_unthreaded;
nlm_syscall;
+ gssd_syscall;
};
Modified: head/lib/libc/xdr/Symbol.map
==============================================================================
--- head/lib/libc/xdr/Symbol.map Mon Nov 3 10:22:19 2008 (r184587)
+++ head/lib/libc/xdr/Symbol.map Mon Nov 3 10:38:00 2008 (r184588)
@@ -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;
+};
Modified: head/lib/libc/xdr/xdr.c
==============================================================================
--- head/lib/libc/xdr/xdr.c Mon Nov 3 10:22:19 2008 (r184587)
+++ head/lib/libc/xdr/xdr.c Mon Nov 3 10:38:00 2008 (r184588)
@@ -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
Modified: head/lib/librpcsec_gss/svc_rpcsec_gss.c
==============================================================================
--- head/lib/librpcsec_gss/svc_rpcsec_gss.c Mon Nov 3 10:22:19 2008 (r184587)
+++ head/lib/librpcsec_gss/svc_rpcsec_gss.c Mon Nov 3 10:38:00 2008 (r184588)
@@ -168,7 +168,7 @@ rpc_gss_set_callback(rpc_gss_callback_t
{
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_princ
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_princ
*/
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_princ
}
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_rp
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,
* 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 sv
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 sv
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 sv
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 sv
* 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_
* 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_
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_gs
}
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
/* 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)) {
Modified: head/sbin/mount_nfs/mount_nfs.c
==============================================================================
--- head/sbin/mount_nfs/mount_nfs.c Mon Nov 3 10:22:19 2008 (r184587)
+++ head/sbin/mount_nfs/mount_nfs.c Mon Nov 3 10:38:00 2008 (r184588)
@@ -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);
@@ -635,6 +653,36 @@ fallback_mount(struct iovec *iov, int io
}
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)
{
struct addrinfo hints, *ai_nfs, *ai;
@@ -904,6 +952,7 @@ nfs_tryproto(struct addrinfo *ai, char *
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 @@ tryagain:
&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 @@ tryagain:
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);
Modified: head/sys/compat/freebsd32/syscalls.master
==============================================================================
--- head/sys/compat/freebsd32/syscalls.master Mon Nov 3 10:22:19 2008 (r184587)
+++ head/sys/compat/freebsd32/syscalls.master Mon Nov 3 10:38:00 2008 (r184588)
@@ -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
Modified: head/sys/conf/files
==============================================================================
--- head/sys/conf/files Mon Nov 3 10:22:19 2008 (r184587)
+++ head/sys/conf/files Mon Nov 3 10:38:00 2008 (r184588)
@@ -339,7 +339,7 @@ crypto/camellia/camellia.c optional cryp
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 nf
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" \
Modified: head/sys/conf/options
==============================================================================
--- head/sys/conf/options Mon Nov 3 10:22:19 2008 (r184587)
+++ head/sys/conf/options Mon Nov 3 10:38:00 2008 (r184588)
@@ -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
Modified: head/sys/fs/unionfs/union_vfsops.c
==============================================================================
--- head/sys/fs/unionfs/union_vfsops.c Mon Nov 3 10:22:19 2008 (r184587)
+++ head/sys/fs/unionfs/union_vfsops.c Mon Nov 3 10:38:00 2008 (r184588)
@@ -521,7 +521,7 @@ unionfs_fhtovp(struct mount *mp, struct
static int
unionfs_checkexp(struct mount *mp, struct sockaddr *nam, int *extflagsp,
- struct ucred **credanonp)
+ struct ucred **credanonp, int *numsecflavors, int **secflavors)
{
return (EOPNOTSUPP);
}
Modified: head/sys/kern/syscalls.master
==============================================================================
--- head/sys/kern/syscalls.master Mon Nov 3 10:22:19 2008 (r184587)
+++ head/sys/kern/syscalls.master Mon Nov 3 10:38:00 2008 (r184588)
@@ -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
Modified: head/sys/kern/vfs_export.c
==============================================================================
--- head/sys/kern/vfs_export.c Mon Nov 3 10:22:19 2008 (r184587)
+++ head/sys/kern/vfs_export.c Mon Nov 3 10:38:00 2008 (r184588)
@@ -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, stru
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, stru
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 expo
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, stru
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
return (EACCES);
*extflagsp = np->netc_exflags;
*credanonp = &np->netc_anon;
+ if (numsecflavors)
+ *numsecflavors = np->netc_numsecflavors;
+ if (secflavors)
+ *secflavors = np->netc_secflavors;
return (0);
}
Modified: head/sys/kern/vfs_mount.c
==============================================================================
--- head/sys/kern/vfs_mount.c Mon Nov 3 10:22:19 2008 (r184587)
+++ head/sys/kern/vfs_mount.c Mon Nov 3 10:38:00 2008 (r184588)
@@ -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) {
Added: head/sys/kgssapi/gss_accept_sec_context.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/sys/kgssapi/gss_accept_sec_context.c Mon Nov 3 10:38:00 2008 (r184588)
@@ -0,0 +1,138 @@
+/*-
+ * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
+ * Authors: Doug Rabson <dfr at rabson.org>
+ * Developed with Red Inc: Alfred Perlstein <alfred at 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);
+}
Added: head/sys/kgssapi/gss_acquire_cred.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/sys/kgssapi/gss_acquire_cred.c Mon Nov 3 10:38:00 2008 (r184588)
@@ -0,0 +1,105 @@
+/*-
+ * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
+ * Authors: Doug Rabson <dfr at rabson.org>
+ * Developed with Red Inc: Alfred Perlstein <alfred at 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;
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-all
mailing list