1 diff -rup nfs-utils-1.0.10.orig/configure.in nfs-utils-1.0.10/configure.in
2 --- nfs-utils-1.0.10.orig/configure.in 2006-11-15 21:26:08.000000000 -0700
3 +++ nfs-utils-1.0.10/configure.in 2006-12-15 15:11:52.000000000 -0700
4 @@ -17,61 +17,14 @@ AC_ARG_WITH(release,
9 - [ --with-statedir=/foo use state dir /foo [/var/lib/nfs]],
11 - statedir=/var/lib/nfs)
13 -AC_ARG_WITH(statduser,
14 - [AC_HELP_STRING([--with-statduser=rpcuser],
15 - [statd to run under @<:@rpcuser or nobody@:>@]
18 - if test "x$cross_compiling" = "xno"; then
19 - if grep -s '^rpcuser:' /etc/passwd > /dev/null; then
29 - [AC_HELP_STRING([--enable-nfsv3],
30 - [enable support for NFSv3 @<:@default=yes@:>@])],
31 - enable_nfsv3=$enableval,
33 - if test "$enable_nfsv3" = yes; then
34 - AC_DEFINE(NFS3_SUPPORTED, 1, [Define this if you want NFSv3 support compiled in])
38 - AC_SUBST(enable_nfsv3)
40 - [AC_HELP_STRING([--enable-nfsv4],
41 - [enable support for NFSv4 @<:@default=yes@:>@])],
42 - enable_nfsv4=$enableval,
44 - if test "$enable_nfsv4" = yes; then
45 - AC_DEFINE(NFS4_SUPPORTED, 1, [Define this if you want NFSv4 support compiled in])
52 - AC_SUBST(enable_nfsv4)
53 - AM_CONDITIONAL(CONFIG_NFSV4, [test "$enable_nfsv4" = "yes"])
55 [AC_HELP_STRING([--enable-gss],
56 [enable support for rpcsec_gss @<:@default=yes@:>@])],
57 enable_gss=$enableval,
59 if test "$enable_gss" = yes; then
60 - AC_DEFINE(GSS_SUPPORTED, 1, [Define this if you want rpcsec_gss support compiled in])
68 @@ -81,38 +34,6 @@ AC_ARG_ENABLE(gss,
71 AM_CONDITIONAL(CONFIG_GSS, [test "$enable_gss" = "yes"])
72 -AC_ARG_ENABLE(kprefix,
73 - [AC_HELP_STRING([--enable-kprefix], [install progs as rpc.knfsd etc])],
74 - test "$enableval" = "yes" && kprefix=k,
77 -AC_ARG_ENABLE(secure-statd,
78 - [AC_HELP_STRING([--enable-secure-statd],
79 - [Only lockd can use statd (security)])],
80 - test "$enableval" = "yes" && secure_statd=yes,
82 - if test "$secure_statd" = yes; then
83 - AC_DEFINE(RESTRICTED_STATD, 1, [Define this if you want to enable various security checks in statd. These checks basically keep anyone but lockd from using this service.])
85 - AC_SUBST(secure_statd)
86 -AC_ARG_ENABLE(rquotad,
87 - [AC_HELP_STRING([--enable-rquotad],
88 - [enable rquotad @<:@default=yes@:>@])],
89 - enable_rquotad=$enableval,
91 - if test "$enable_rquotad" = yes; then
96 - AM_CONDITIONAL(CONFIG_RQUOTAD, [test "$enable_rquotad" = "yes"])
99 - [AC_HELP_STRING([--enable-mount],
100 - [Create mount.nfs and don't use the util-linux mount(8) functionality. @<:@default=no@:>@])],
101 - enable_mount=$enableval,
103 - AM_CONDITIONAL(CONFIG_MOUNT, [test "$enable_mount" = "yes"])
105 # Check whether user wants TCP wrappers support
107 @@ -155,47 +76,17 @@ AC_CHECK_FUNC(connect, ,
108 AC_MSG_ERROR(Function 'socket' not found.), $LIBNSL))
110 AC_CHECK_LIB(crypt, crypt, [LIBCRYPT="-lcrypt"])
111 -if test "$enable_nfsv4" = yes; then
112 - AC_CHECK_LIB(event, event_dispatch, [libevent=1], AC_MSG_ERROR([libevent needed for nfsv4 support]))
113 - AC_CHECK_LIB(nfsidmap, nfs4_init_name_mapping, [libnfsidmap=1], AC_MSG_ERROR([libnfsidmap needed for nfsv4 support]))
114 - AC_CHECK_HEADERS(event.h, ,AC_MSG_ERROR([libevent needed for nfsv4 support]))
115 - AC_CHECK_HEADERS(nfsidmap.h, ,AC_MSG_ERROR([libnfsidmap needed for nfsv4 support]))
116 - dnl librpcsecgss already has a dependency on libgssapi,
117 - dnl but we need to make sure we get the right version
118 if test "$enable_gss" = yes; then
119 - PKG_CHECK_MODULES(RPCSECGSS, librpcsecgss >= 0.10, ,
120 - [AC_MSG_ERROR([Unable to locate information required to use librpcsecgss. If you have pkgconfig installed, you might try setting environment variable PKG_CONFIG_PATH to /usr/local/lib/pkgconfig])
123 PKG_CHECK_MODULES(GSSAPI, libgssapi >= 0.9)
127 -if test "$knfsd_cv_glibc2" = no; then
128 - AC_CHECK_LIB(bsd, daemon, [LIBBSD="-lbsd"])
134 if test "$enable_gss" = yes; then
135 - dnl 'gss' also depends on nfsidmap.h - at least for svcgssd_proc.c
136 - AC_CHECK_HEADERS(nfsidmap.h, ,AC_MSG_ERROR([libnfsidmap needed for gss support]))
137 - AC_CHECK_HEADERS(spkm3.h, ,AC_MSG_WARN([could not locate SPKM3 header; will not have SPKM3 support]))
138 - dnl the nfs4_set_debug function doesn't appear in all version of the library
139 - AC_CHECK_LIB(nfsidmap, nfs4_set_debug,
140 - AC_DEFINE(HAVE_NFS4_SET_DEBUG,1,
141 - [Whether nfs4_set_debug() is present in libnfsidmap]),)
143 dnl Check for Kerberos V5
146 - dnl This is not done until here because we need to have KRBLIBS set
147 - dnl ("librpcsecgss=1" is so that it doesn't get added to LIBS)
148 - AC_CHECK_LIB(rpcsecgss, authgss_create_default, [librpcsecgss=1], AC_MSG_ERROR([librpcsecgss needed for nfsv4 support]), -lgssapi -ldl)
149 - AC_CHECK_LIB(rpcsecgss, authgss_set_debug_level,
150 - AC_DEFINE(HAVE_AUTHGSS_SET_DEBUG_LEVEL, 1, [Define this if the rpcsec_gss library has the function authgss_set_debug_level]),, -lgssapi -ldl)
154 dnl *************************************************************
155 @@ -307,35 +198,7 @@ AC_SUBST([ACLOCAL_AMFLAGS], ["-I $ac_mac
161 - support/export/Makefile
162 - support/include/nfs/Makefile
163 - support/include/rpcsvc/Makefile
164 - support/include/sys/fs/Makefile
165 - support/include/sys/Makefile
166 - support/include/Makefile
167 - support/misc/Makefile
168 - support/nfs/Makefile
170 - tools/getiversion/Makefile
171 - tools/getkversion/Makefile
172 - tools/locktest/Makefile
173 - tools/nlmtest/Makefile
174 - tools/rpcdebug/Makefile
175 - tools/rpcgen/Makefile
177 - utils/exportfs/Makefile
178 - utils/gssd/Makefile
179 - utils/idmapd/Makefile
180 - utils/lockd/Makefile
181 - utils/mount/Makefile
182 - utils/mountd/Makefile
183 - utils/nfsd/Makefile
184 - utils/nfsstat/Makefile
185 - utils/nhfsstone/Makefile
186 - utils/rquotad/Makefile
187 - utils/showmount/Makefile
188 - utils/statd/Makefile])
189 + utils/gssd/Makefile])
192 diff -rup nfs-utils-1.0.10.orig/Makefile.am nfs-utils-1.0.10/Makefile.am
193 --- nfs-utils-1.0.10.orig/Makefile.am 2006-11-15 21:26:08.000000000 -0700
194 +++ nfs-utils-1.0.10/Makefile.am 2006-12-15 15:11:52.000000000 -0700
196 ## Process this file with automake to produce Makefile.in
198 -SUBDIRS = tools support utils linux-nfs
201 MAINTAINERCLEANFILES = Makefile.in
203 diff -rup nfs-utils-1.0.10.orig/utils/gssd/cacheio.c nfs-utils-1.0.10/utils/gssd/cacheio.c
204 --- nfs-utils-1.0.10.orig/utils/gssd/cacheio.c 2006-08-07 00:40:50.000000000 -0600
205 +++ nfs-utils-1.0.10/utils/gssd/cacheio.c 2006-12-15 15:12:23.000000000 -0700
206 @@ -227,7 +227,8 @@ int qword_get(char **bpp, char *dest, in
208 while (*bp == ' ') bp++;
211 +// why should we clear *dest???
216 diff -rup nfs-utils-1.0.10.orig/utils/gssd/context.c nfs-utils-1.0.10/utils/gssd/context.c
217 --- nfs-utils-1.0.10.orig/utils/gssd/context.c 2006-08-07 00:40:50.000000000 -0600
218 +++ nfs-utils-1.0.10/utils/gssd/context.c 2006-12-15 15:12:23.000000000 -0700
222 #include <gssapi/gssapi.h>
223 -#include <rpc/rpc.h>
224 -#include <rpc/auth_gss.h>
225 #include "gss_util.h"
226 #include "gss_oids.h"
227 #include "err_util.h"
228 diff -rup nfs-utils-1.0.10.orig/utils/gssd/context.h nfs-utils-1.0.10/utils/gssd/context.h
229 --- nfs-utils-1.0.10.orig/utils/gssd/context.h 2006-11-15 21:26:08.000000000 -0700
230 +++ nfs-utils-1.0.10/utils/gssd/context.h 2006-12-15 15:12:23.000000000 -0700
235 -#include <rpc/rpc.h>
237 /* Hopefully big enough to hold any serialized context */
238 #define MAX_CTX_LEN 4096
240 diff -rup nfs-utils-1.0.10.orig/utils/gssd/context_lucid.c nfs-utils-1.0.10/utils/gssd/context_lucid.c
241 --- nfs-utils-1.0.10.orig/utils/gssd/context_lucid.c 2006-11-15 21:26:08.000000000 -0700
242 +++ nfs-utils-1.0.10/utils/gssd/context_lucid.c 2006-12-15 15:12:23.000000000 -0700
247 -#include "gss_util.h"
248 -#include "gss_oids.h"
249 -#include "err_util.h"
250 -#include "context.h"
254 #include <gssapi/gssapi.h>
256 @@ -53,6 +49,11 @@ typedef uint64_t OM_uint64;
258 #include <gssapi/gssapi_krb5.h>
260 +#include "gss_util.h"
261 +#include "gss_oids.h"
262 +#include "err_util.h"
263 +#include "context.h"
266 write_lucid_keyblock(char **p, char *end, gss_krb5_lucid_key_t *key)
268 @@ -354,6 +355,7 @@ static int
269 prepare_krb5_rfc4121_buffer(gss_krb5_lucid_context_v1_t *lctx,
270 gss_buffer_desc *buf)
272 + static int constant_two = 2;
274 uint32_t v2_flags = 0;
275 gss_krb5_lucid_key_t enc_key;
276 @@ -372,7 +374,7 @@ prepare_krb5_rfc4121_buffer(gss_krb5_luc
277 end = buf->value + MAX_CTX_LEN;
280 - if (WRITE_BYTES(&p, end, lctx->initiate)) goto out_err;
281 + if (WRITE_BYTES(&p, end, constant_two)) goto out_err;
282 if (WRITE_BYTES(&p, end, lctx->endtime)) goto out_err;
285 @@ -434,14 +436,25 @@ prepare_krb5_rfc4121_buffer(gss_krb5_luc
289 - if (derive_key_lucid(&lctx->rfc1964_kd.ctx_key,
291 - KG_USAGE_SIGN, KEY_USAGE_SEED_CHECKSUM))
293 - if (write_bytes(&p, end, derived_key.data,
294 - derived_key.length))
296 - free(derived_key.data);
298 + * RC4 is special, it dosen't need key derivation. Actually
299 + * the Ke is based on plain text. Here we just let all three
300 + * key identical, kernel will handle everything. --ericm
302 + if (lctx->rfc1964_kd.ctx_key.type == ENCTYPE_ARCFOUR_HMAC) {
303 + if (write_bytes(&p, end, lctx->rfc1964_kd.ctx_key.data,
304 + lctx->rfc1964_kd.ctx_key.length))
307 + if (derive_key_lucid(&lctx->rfc1964_kd.ctx_key,
309 + KG_USAGE_SIGN, KEY_USAGE_SEED_CHECKSUM))
311 + if (write_bytes(&p, end, derived_key.data,
312 + derived_key.length))
314 + free(derived_key.data);
317 gss_krb5_lucid_key_t *keyptr;
318 uint32_t sign_usage, seal_usage;
319 @@ -451,6 +464,7 @@ prepare_krb5_rfc4121_buffer(gss_krb5_luc
321 keyptr = &lctx->cfx_kd.ctx_key;
324 if (lctx->initiate == 1) {
325 sign_usage = KG_USAGE_INITIATOR_SIGN;
326 seal_usage = KG_USAGE_INITIATOR_SEAL;
327 @@ -458,6 +472,19 @@ prepare_krb5_rfc4121_buffer(gss_krb5_luc
328 sign_usage = KG_USAGE_ACCEPTOR_SIGN;
329 seal_usage = KG_USAGE_ACCEPTOR_SEAL;
333 + * These are from rfc4142, but I don't understand: if we supply
334 + * different 'usage' value for client & server, then the peers
335 + * will have different derived keys. How could this work?
337 + * Here we simply use old SIGN/SEAL values until we find the
341 + sign_usage = KG_USAGE_SIGN;
342 + seal_usage = KG_USAGE_SEAL;
345 /* derive and send down: Ke, Ki, and Kc */
347 diff -rup nfs-utils-1.0.10.orig/utils/gssd/context_mit.c nfs-utils-1.0.10/utils/gssd/context_mit.c
348 --- nfs-utils-1.0.10.orig/utils/gssd/context_mit.c 2006-11-15 21:26:08.000000000 -0700
349 +++ nfs-utils-1.0.10/utils/gssd/context_mit.c 2006-12-15 15:12:23.000000000 -0700
352 #include <gssapi/gssapi.h>
354 -#include <rpc/auth_gss.h>
355 #include "gss_util.h"
356 #include "gss_oids.h"
357 #include "err_util.h"
358 @@ -333,12 +332,7 @@ serialize_krb5_ctx(gss_ctx_id_t ctx, gss
359 * keydata-2; ( Ki (Kseq for DES3) )
360 * keydata-3; ( Kc (derived checksum key) )
362 - if (kctx->initiate) {
363 - if (WRITE_BYTES(&p, end, constant_one)) goto out_err;
366 - if (WRITE_BYTES(&p, end, constant_zero)) goto out_err;
368 + if (WRITE_BYTES(&p, end, constant_two)) goto out_err;
369 if (WRITE_BYTES(&p, end, kctx->endtime)) goto out_err;
371 /* Only applicable flag for this is initiator */
372 diff -rup nfs-utils-1.0.10.orig/utils/gssd/context_spkm3.c nfs-utils-1.0.10/utils/gssd/context_spkm3.c
373 --- nfs-utils-1.0.10.orig/utils/gssd/context_spkm3.c 2006-11-15 21:26:08.000000000 -0700
374 +++ nfs-utils-1.0.10/utils/gssd/context_spkm3.c 2006-12-15 15:12:23.000000000 -0700
378 #include <gssapi/gssapi.h>
379 -#include <rpc/rpc.h>
380 -#include <rpc/auth_gss.h>
381 #include "gss_util.h"
382 #include "gss_oids.h"
383 #include "err_util.h"
384 diff -rup nfs-utils-1.0.10.orig/utils/gssd/err_util.c nfs-utils-1.0.10/utils/gssd/err_util.c
385 --- nfs-utils-1.0.10.orig/utils/gssd/err_util.c 2006-08-07 00:40:50.000000000 -0600
386 +++ nfs-utils-1.0.10/utils/gssd/err_util.c 2006-12-15 15:12:23.000000000 -0700
393 #include "err_util.h"
395 static int verbosity = 0;
396 @@ -91,3 +93,40 @@ printit:
397 /* reset the buffer */
398 memset(message_buf, 0, sizeof(message_buf));
401 +void print_hexl(int pri, unsigned char *cp, int length)
406 + printerr(pri, "length %d\n",length);
407 + printerr(pri, "\n");
409 + for (i = 0; i < length; i += 0x10) {
410 + printerr(pri, " %04x: ", (u_int)i);
412 + jm = jm > 16 ? 16 : jm;
414 + for (j = 0; j < jm; j++) {
416 + printerr(pri,"%02x ", (u_int)cp[i+j]);
418 + printerr(pri,"%02x", (u_int)cp[i+j]);
420 + for (; j < 16; j++) {
428 + for (j = 0; j < jm; j++) {
430 + c = isprint(c) ? c : '.';
431 + printerr(pri,"%c", c);
433 + printerr(pri,"\n");
437 diff -rup nfs-utils-1.0.10.orig/utils/gssd/err_util.h nfs-utils-1.0.10/utils/gssd/err_util.h
438 --- nfs-utils-1.0.10.orig/utils/gssd/err_util.h 2006-08-07 00:40:50.000000000 -0600
439 +++ nfs-utils-1.0.10/utils/gssd/err_util.h 2006-12-15 15:12:23.000000000 -0700
442 void initerr(char *progname, int verbosity, int fg);
443 void printerr(int priority, char *format, ...);
444 +void print_hexl(int pri, unsigned char *cp, int length);
446 #endif /* _ERR_UTIL_H_ */
447 diff -rup nfs-utils-1.0.10.orig/utils/gssd/gss_clnt_send_err.c nfs-utils-1.0.10/utils/gssd/gss_clnt_send_err.c
448 --- nfs-utils-1.0.10.orig/utils/gssd/gss_clnt_send_err.c 2006-08-07 00:40:50.000000000 -0600
449 +++ nfs-utils-1.0.10/utils/gssd/gss_clnt_send_err.c 2006-12-15 15:12:23.000000000 -0700
452 #include "write_bytes.h"
455 char pipefsdir[PATH_MAX] = GSSD_PIPEFS_DIR;
458 @@ -102,3 +103,4 @@ main(int argc, char *argv[])
463 diff -rup nfs-utils-1.0.10.orig/utils/gssd/gssd.c nfs-utils-1.0.10/utils/gssd/gssd.c
464 --- nfs-utils-1.0.10.orig/utils/gssd/gssd.c 2006-11-15 21:26:08.000000000 -0700
465 +++ nfs-utils-1.0.10/utils/gssd/gssd.c 2006-12-15 15:12:23.000000000 -0700
470 +#include <sys/types.h>
471 #include <sys/param.h>
472 #include <sys/socket.h>
473 -#include <rpc/rpc.h>
474 +#include <sys/wait.h>
475 +#include <sys/ipc.h>
476 +#include <sys/sem.h>
486 #include "err_util.h"
487 #include "gss_util.h"
488 #include "krb5_util.h"
489 +#include "lsupport.h"
491 char pipefs_dir[PATH_MAX] = GSSD_PIPEFS_DIR;
492 char pipefs_nfsdir[PATH_MAX] = GSSD_PIPEFS_DIR;
493 char keytabfile[PATH_MAX] = GSSD_DEFAULT_KEYTAB_FILE;
494 char ccachedir[PATH_MAX] = GSSD_DEFAULT_CRED_DIR;
495 int use_memcache = 0;
496 +int lgssd_mutex_downcall = -1;
500 +static int lgssd_create_mutex(int *semid)
505 + id = semget(IPC_PRIVATE, 1, IPC_CREAT);
507 + printerr(0, "semget: %s\n", strerror(errno));
512 + if (semctl(id, 0, SETVAL, arg) != 0) {
513 + printerr(0, "semctl: %s\n", strerror(errno));
514 + semctl(id, 1, IPC_RMID, arg);
522 +void lgssd_init_mutexs(void)
524 + if (lgssd_create_mutex(&lgssd_mutex_downcall)) {
525 + printerr(0, "can't create downcall mutex\n");
530 +void lgssd_fini_mutexs(void)
534 + if (lgssd_mutex_downcall != -1)
535 + semctl(lgssd_mutex_downcall, 1, IPC_RMID, arg);
538 +void lgssd_mutex_get(int semid)
540 + struct sembuf op[1] = { {0, -1, SEM_UNDO} };
543 + rc = semop(semid, op, 1);
545 + printerr(0, "exit on mutex_get err %d: %s\n",
546 + rc, strerror(errno));
551 +void lgssd_mutex_put(int semid)
553 + struct sembuf op[1] = { {0, 1, 0} };
556 + rc = semop(semid, op, 1);
558 + printerr(0, "ignore mutex_put err %d: %s\n",
559 + rc, strerror(errno));
563 +static void lgssd_cleanup(void)
567 + /* make sure all children finished */
569 + child_pid = waitpid(-1, NULL, 0);
573 + printerr(3, "cleanup: child %d terminated\n", child_pid);
576 + lgssd_fini_mutexs();
578 /* destroy krb5 machine creds */
579 gssd_destroy_krb5_machine_creds();
585 printerr(1, "exiting on signal %d\n", signal);
590 @@ -79,7 +166,7 @@ sig_hup(int signal)
592 usage(char *progname)
594 - fprintf(stderr, "usage: %s [-f] [-v] [-r] [-p pipefsdir] [-k keytab] [-d ccachedir]\n",
595 + fprintf(stderr, "usage: %s [-f] [-v] [-p pipefsdir] [-k keytab] [-d ccachedir]\n",
599 @@ -89,7 +176,6 @@ main(int argc, char *argv[])
603 - int rpc_verbosity = 0;
607 @@ -99,18 +185,12 @@ main(int argc, char *argv[])
612 - /* Accept but ignore this. Now the default. */
624 strncpy(pipefs_dir, optarg, sizeof(pipefs_dir));
625 if (pipefs_dir[sizeof(pipefs_dir)-1] != '\0')
626 @@ -131,10 +211,6 @@ main(int argc, char *argv[])
630 - snprintf(pipefs_nfsdir, sizeof(pipefs_nfsdir), "%s/%s",
631 - pipefs_dir, GSSD_SERVICE_NAME);
632 - if (pipefs_nfsdir[sizeof(pipefs_nfsdir)-1] != '\0')
633 - errx(1, "pipefs_nfsdir path name too long");
635 if ((progname = strrchr(argv[0], '/')))
637 @@ -142,30 +218,42 @@ main(int argc, char *argv[])
640 initerr(progname, verbosity, fg);
641 -#ifdef HAVE_AUTHGSS_SET_DEBUG_LEVEL
642 - authgss_set_debug_level(rpc_verbosity);
644 - if (rpc_verbosity > 0)
645 - printerr(0, "Warning: rpcsec_gss library does not "
646 - "support setting debug level\n");
649 if (gssd_check_mechs() != 0)
650 errx(1, "Problem with gssapi library");
652 + if (gssd_get_local_realm())
653 + errx(1, "get local realm");
655 if (!fg && daemon(0, 0) < 0)
658 + /* This should be checked _after_ daemon(), because we need to own
659 + * the undo-able semaphore by this process
661 + gssd_init_unique(GSSD_CLI);
663 + /* Process keytab file and get machine credentials. This will modify
664 + * disk status so do it after we are sure we are the only instance
666 + if (gssd_refresh_krb5_machine_creds())
669 signal(SIGINT, sig_die);
670 signal(SIGTERM, sig_die);
671 signal(SIGHUP, sig_hup);
673 - /* Process keytab file and get machine credentials */
674 - gssd_refresh_krb5_machine_creds();
676 /* Determine Kerberos information from the kernel */
677 gssd_obtain_kernel_krb5_info();
680 + lgssd_init_mutexs();
682 + printerr(0, "lgssd initialized and ready to serve\n");
686 - printerr(0, "gssd_run returned!\n");
689 + printerr(0, "lgssd exiting\n");
692 diff -rup nfs-utils-1.0.10.orig/utils/gssd/gssd.h nfs-utils-1.0.10/utils/gssd/gssd.h
693 --- nfs-utils-1.0.10.orig/utils/gssd/gssd.h 2006-11-15 21:26:08.000000000 -0700
694 +++ nfs-utils-1.0.10/utils/gssd/gssd.h 2006-12-15 15:12:23.000000000 -0700
696 #define GSSD_DEFAULT_CRED_PREFIX "krb5cc_"
697 #define GSSD_DEFAULT_MACHINE_CRED_SUFFIX "machine"
698 #define GSSD_DEFAULT_KEYTAB_FILE "/etc/krb5.keytab"
699 -#define GSSD_SERVICE_NAME "nfs"
700 -#define GSSD_SERVICE_NAME_LEN 3
701 +#define GSSD_SERVICE_MDS "lustre_mds"
702 +#define GSSD_SERVICE_OSS "lustre_oss"
703 +#define GSSD_SERVICE_MDS_NAMELEN 10
704 +#define GSSD_SERVICE_OSS_NAMELEN 10
706 +#define LUSTRE_ROOT_NAME "lustre_root"
707 +#define LUSTRE_ROOT_NAMELEN 11
710 * The gss mechanisms that we can handle
711 @@ -59,9 +64,9 @@ enum {AUTHTYPE_KRB5, AUTHTYPE_SPKM3, AUT
714 extern char pipefs_dir[PATH_MAX];
715 -extern char pipefs_nfsdir[PATH_MAX];
716 extern char keytabfile[PATH_MAX];
717 extern char ccachedir[PATH_MAX];
718 +extern char gethostname_ex[PATH_MAX];
719 extern int use_memcache;
721 TAILQ_HEAD(clnt_list_head, clnt_info) clnt_list;
722 @@ -71,10 +76,6 @@ struct clnt_info {
733 @@ -85,8 +86,14 @@ void init_client_list(void);
734 int update_client_list(void);
735 void handle_krb5_upcall(struct clnt_info *clp);
736 void handle_spkm3_upcall(struct clnt_info *clp);
737 -int gssd_acquire_cred(char *server_name);
738 -void gssd_run(void);
739 +void lgssd_run(void);
742 +extern int lgssd_mutex_downcall;
744 +void lgssd_init_mutexs(void);
745 +void lgssd_fini_mutexs(void);
746 +void lgssd_mutex_get(int semid);
747 +void lgssd_mutex_put(int semid);
749 #endif /* _RPC_GSSD_H_ */
750 diff -rup nfs-utils-1.0.10.orig/utils/gssd/gssd_main_loop.c nfs-utils-1.0.10/utils/gssd/gssd_main_loop.c
751 --- nfs-utils-1.0.10.orig/utils/gssd/gssd_main_loop.c 2006-11-15 21:26:08.000000000 -0700
752 +++ nfs-utils-1.0.10/utils/gssd/gssd_main_loop.c 2006-12-15 15:12:23.000000000 -0700
753 @@ -94,11 +94,13 @@ scan_poll_results(int ret)
761 struct sigaction dn_act;
763 + time_t child_check = 0;
766 /* Taken from linux/Documentation/dnotify.txt: */
767 dn_act.sa_sigaction = dir_notify_handler;
768 @@ -106,10 +108,10 @@ gssd_run()
769 dn_act.sa_flags = SA_SIGINFO;
770 sigaction(DNOTIFY_SIGNAL, &dn_act, NULL);
772 - if ((fd = open(pipefs_nfsdir, O_RDONLY)) == -1) {
773 + if ((fd = open(pipefs_dir, O_RDONLY)) == -1) {
774 printerr(0, "ERROR: failed to open %s: %s\n",
775 - pipefs_nfsdir, strerror(errno));
777 + pipefs_dir, strerror(errno));
780 fcntl(fd, F_SETSIG, DNOTIFY_SIGNAL);
781 fcntl(fd, F_NOTIFY, DN_CREATE|DN_DELETE|DN_MODIFY|DN_MULTISHOT);
782 @@ -119,12 +121,30 @@ gssd_run()
784 while (dir_changed) {
786 + printerr(2, "pipefs root dir changed\n");
787 if (update_client_list()) {
788 printerr(0, "ERROR: couldn't update "
795 + /* every 5s cleanup possible zombies of child processes */
796 + if (time(NULL) - child_check >= 5) {
797 + printerr(3, "check zombie children...\n");
800 + child_pid = waitpid(-1, NULL, WNOHANG);
801 + if (child_pid <= 0)
804 + printerr(2, "terminate zombie child: %d\n",
808 + child_check = time(NULL);
811 /* race condition here: dir_changed could be set before we
812 * enter the poll, and we'd never notice if it weren't for the
814 @@ -139,6 +159,7 @@ gssd_run()
815 scan_poll_results(ret);
822 diff -rup nfs-utils-1.0.10.orig/utils/gssd/gssd_proc.c nfs-utils-1.0.10/utils/gssd/gssd_proc.c
823 --- nfs-utils-1.0.10.orig/utils/gssd/gssd_proc.c 2006-11-15 21:26:08.000000000 -0700
824 +++ nfs-utils-1.0.10/utils/gssd/gssd_proc.c 2006-12-15 15:12:23.000000000 -0700
828 #include <sys/param.h>
829 -#include <rpc/rpc.h>
830 #include <sys/stat.h>
831 #include <sys/socket.h>
832 #include <arpa/inet.h>
834 #include "gss_oids.h"
835 #include "krb5_util.h"
837 +#include "lsupport.h"
841 @@ -99,86 +99,10 @@ struct pollfd * pollarray;
843 int pollsize; /* the size of pollaray (in pollfd's) */
845 -/* XXX buffer problems: */
847 -read_service_info(char *info_file_name, char **servicename, char **servername,
848 - int *prog, int *vers, char **protocol) {
849 -#define INFOBUFLEN 256
850 - char buf[INFOBUFLEN];
851 - static char dummy[128];
853 - static char service[128];
854 - static char address[128];
857 - char protoname[16];
860 - struct hostent *ent = NULL;
863 - *servicename = *servername = *protocol = NULL;
865 - if ((fd = open(info_file_name, O_RDONLY)) == -1) {
866 - printerr(0, "ERROR: can't open %s: %s\n", info_file_name,
870 - if ((nbytes = read(fd, buf, INFOBUFLEN)) == -1)
874 - numfields = sscanf(buf,"RPC server: %127s\n"
875 - "service: %127s %15s version %15s\n"
877 - "protocol: %15s\n",
879 - service, program, version,
883 - if (numfields == 5) {
884 - strcpy(protoname, "tcp");
885 - } else if (numfields != 6) {
889 - /* check service, program, and version */
890 - if(memcmp(service, "nfs", 3)) return -1;
891 - *prog = atoi(program + 1); /* skip open paren */
892 - *vers = atoi(version);
893 - if((*prog != 100003) || ((*vers != 2) && (*vers != 3) && (*vers != 4)))
896 - /* create service name */
897 - inaddr = inet_addr(address);
898 - if (!(ent = gethostbyaddr(&inaddr, sizeof(inaddr), AF_INET))) {
899 - printerr(0, "ERROR: can't resolve server %s name\n", address);
902 - if (!(*servername = calloc(strlen(ent->h_name) + 1, 1)))
904 - memcpy(*servername, ent->h_name, strlen(ent->h_name));
905 - snprintf(buf, INFOBUFLEN, "%s@%s", service, ent->h_name);
906 - if (!(*servicename = calloc(strlen(buf) + 1, 1)))
908 - memcpy(*servicename, buf, strlen(buf));
910 - if (!(*protocol = strdup(protoname)))
914 - printerr(0, "ERROR: failed to read service info\n");
915 - if (fd != -1) close(fd);
916 - if (*servername) free(*servername);
917 - if (*servicename) free(*servicename);
918 - if (*protocol) free(*protocol);
923 destroy_client(struct clnt_info *clp)
925 + printerr(3, "clp %p: dirname %s, krb5fd %d\n", clp, clp->dirname, clp->krb5_fd);
926 if (clp->krb5_poll_index != -1)
927 memset(&pollarray[clp->krb5_poll_index], 0,
928 sizeof(struct pollfd));
929 @@ -190,8 +114,6 @@ destroy_client(struct clnt_info *clp)
930 if (clp->spkm3_fd != -1) close(clp->spkm3_fd);
931 if (clp->dirname) free(clp->dirname);
932 if (clp->servicename) free(clp->servicename);
933 - if (clp->servername) free(clp->servername);
934 - if (clp->protocol) free(clp->protocol);
938 @@ -221,7 +143,6 @@ process_clnt_dir_files(struct clnt_info
942 - char info_file_name[32];
944 if (clp->krb5_fd == -1) {
945 snprintf(kname, sizeof(kname), "%s/krb5", clp->dirname);
946 @@ -233,13 +154,6 @@ process_clnt_dir_files(struct clnt_info
948 if((clp->krb5_fd == -1) && (clp->spkm3_fd == -1))
950 - snprintf(info_file_name, sizeof(info_file_name), "%s/info",
952 - if ((clp->servicename == NULL) &&
953 - read_service_info(info_file_name, &clp->servicename,
954 - &clp->servername, &clp->prog, &clp->vers,
960 @@ -273,6 +187,8 @@ insert_clnt_poll(struct clnt_info *clp)
962 pollarray[clp->krb5_poll_index].fd = clp->krb5_fd;
963 pollarray[clp->krb5_poll_index].events |= POLLIN;
964 + printerr(2, "monitoring krb5 channel under %s\n",
968 if ((clp->spkm3_fd != -1) && (clp->spkm3_poll_index == -1)) {
969 @@ -386,67 +302,106 @@ find_client(char *dirname)
971 update_client_list(void)
973 - struct dirent **namelist;
974 + char lustre_dir[PATH_MAX];
975 + struct dirent lustre_dirent = { .d_name = "lustre" };
976 + struct dirent *namelist[1];
977 + struct stat statbuf;
980 - if (chdir(pipefs_nfsdir) < 0) {
981 + if (chdir(pipefs_dir) < 0) {
982 printerr(0, "ERROR: can't chdir to %s: %s\n",
983 - pipefs_nfsdir, strerror(errno));
984 + pipefs_dir, strerror(errno));
988 - j = scandir(pipefs_nfsdir, &namelist, NULL, alphasort);
990 - printerr(0, "ERROR: can't scandir %s: %s\n",
991 - pipefs_nfsdir, strerror(errno));
993 + snprintf(lustre_dir, sizeof(lustre_dir), "%s/%s", pipefs_dir, "lustre");
994 + if (stat(lustre_dir, &statbuf) == 0) {
995 + namelist[0] = &lustre_dirent;
997 + printerr(2, "re-processing lustre directory\n");
999 + namelist[0] = NULL;
1001 + printerr(2, "lustre directory not exist\n");
1004 update_old_clients(namelist, j);
1005 for (i=0; i < j; i++) {
1006 - if (i < FD_ALLOC_BLOCK
1007 - && !strncmp(namelist[i]->d_name, "clnt", 4)
1008 - && !find_client(namelist[i]->d_name))
1009 + if (i < FD_ALLOC_BLOCK && !find_client(namelist[i]->d_name))
1010 process_clnt_dir(namelist[i]->d_name);
1011 - free(namelist[i]);
1019 +/* Context creation response. */
1020 +struct lustre_gss_init_res {
1021 + gss_buffer_desc gr_ctx; /* context handle */
1022 + u_int gr_major; /* major status */
1023 + u_int gr_minor; /* minor status */
1024 + u_int gr_win; /* sequence window */
1025 + gss_buffer_desc gr_token; /* token */
1028 +struct lustre_gss_data {
1029 + int lgd_established;
1030 + int lgd_lustre_svc; /* mds/oss */
1031 + int lgd_uid; /* uid */
1032 + char *lgd_uuid; /* client device uuid */
1033 + gss_name_t lgd_name; /* service name */
1035 + gss_OID lgd_mech; /* mech OID */
1036 + u_int lgd_req_flags; /* request flags */
1037 + gss_cred_id_t lgd_cred; /* credential */
1038 + gss_ctx_id_t lgd_ctx; /* session context */
1039 + gss_buffer_desc lgd_rmt_ctx; /* remote handle of context */
1040 + uint32_t lgd_seq_win; /* sequence window */
1047 -do_downcall(int k5_fd, uid_t uid, struct authgss_private_data *pd,
1048 - gss_buffer_desc *context_token)
1049 +do_downcall(int k5_fd, struct lgssd_upcall_data *updata,
1050 + struct lustre_gss_data *lgd, gss_buffer_desc *context_token)
1052 char *buf = NULL, *p = NULL, *end = NULL;
1053 unsigned int timeout = 0; /* XXX decide on a reasonable value */
1054 unsigned int buf_size = 0;
1056 - printerr(1, "doing downcall\n");
1057 - buf_size = sizeof(uid) + sizeof(timeout) + sizeof(pd->pd_seq_win) +
1058 - sizeof(pd->pd_ctx_hndl.length) + pd->pd_ctx_hndl.length +
1059 + printerr(2, "doing downcall\n");
1060 + buf_size = sizeof(updata->seq) + sizeof(timeout) +
1061 + sizeof(lgd->lgd_seq_win) +
1062 + sizeof(lgd->lgd_rmt_ctx.length) + lgd->lgd_rmt_ctx.length +
1063 sizeof(context_token->length) + context_token->length;
1064 p = buf = malloc(buf_size);
1065 end = buf + buf_size;
1067 - if (WRITE_BYTES(&p, end, uid)) goto out_err;
1068 + if (WRITE_BYTES(&p, end, updata->seq)) goto out_err;
1069 /* Not setting any timeout for now: */
1070 if (WRITE_BYTES(&p, end, timeout)) goto out_err;
1071 - if (WRITE_BYTES(&p, end, pd->pd_seq_win)) goto out_err;
1072 - if (write_buffer(&p, end, &pd->pd_ctx_hndl)) goto out_err;
1073 + if (WRITE_BYTES(&p, end, lgd->lgd_seq_win)) goto out_err;
1074 + if (write_buffer(&p, end, &lgd->lgd_rmt_ctx)) goto out_err;
1075 if (write_buffer(&p, end, context_token)) goto out_err;
1077 - if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
1078 + lgssd_mutex_get(lgssd_mutex_downcall);
1079 + if (write(k5_fd, buf, p - buf) < p - buf) {
1080 + lgssd_mutex_put(lgssd_mutex_downcall);
1083 + lgssd_mutex_put(lgssd_mutex_downcall);
1089 - printerr(0, "Failed to write downcall!\n");
1090 + printerr(0, "ERROR: Failed to write downcall!\n");
1095 -do_error_downcall(int k5_fd, uid_t uid, int err)
1096 +do_error_downcall(int k5_fd, uint32_t seq, int rpc_err, int gss_err)
1099 char *p = buf, *end = buf + 1024;
1100 @@ -455,19 +410,26 @@ do_error_downcall(int k5_fd, uid_t uid,
1102 printerr(1, "doing error downcall\n");
1104 - if (WRITE_BYTES(&p, end, uid)) goto out_err;
1105 + if (WRITE_BYTES(&p, end, seq)) goto out_err;
1106 if (WRITE_BYTES(&p, end, timeout)) goto out_err;
1107 /* use seq_win = 0 to indicate an error: */
1108 if (WRITE_BYTES(&p, end, zero)) goto out_err;
1109 - if (WRITE_BYTES(&p, end, err)) goto out_err;
1110 + if (WRITE_BYTES(&p, end, rpc_err)) goto out_err;
1111 + if (WRITE_BYTES(&p, end, gss_err)) goto out_err;
1113 - if (write(k5_fd, buf, p - buf) < p - buf) goto out_err;
1114 + lgssd_mutex_get(lgssd_mutex_downcall);
1115 + if (write(k5_fd, buf, p - buf) < p - buf) {
1116 + lgssd_mutex_put(lgssd_mutex_downcall);
1119 + lgssd_mutex_put(lgssd_mutex_downcall);
1122 printerr(0, "Failed to write error downcall!\n");
1128 * Create an RPC connection and establish an authenticated
1129 * gss context with a server.
1130 @@ -659,7 +621,287 @@ int create_auth_rpc_client(struct clnt_i
1137 +int do_negotiation(struct lustre_gss_data *lgd,
1138 + gss_buffer_desc *gss_token,
1139 + struct lustre_gss_init_res *gr,
1142 + char *file = "/proc/fs/lustre/sptlrpc/gss/init_channel";
1143 + struct lgssd_ioctl_param param;
1144 + struct passwd *pw;
1146 + char outbuf[8192];
1150 + pw = getpwuid(lgd->lgd_uid);
1152 + printerr(0, "no uid %u in local user database\n",
1157 + param.version = GSSD_INTERFACE_VERSION;
1158 + param.uuid = lgd->lgd_uuid;
1159 + param.lustre_svc = lgd->lgd_lustre_svc;
1160 + param.uid = lgd->lgd_uid;
1161 + param.gid = pw->pw_gid;
1162 + param.send_token_size = gss_token->length;
1163 + param.send_token = (char *) gss_token->value;
1164 + param.reply_buf_size = sizeof(outbuf);
1165 + param.reply_buf = outbuf;
1167 + fd = open(file, O_RDWR);
1169 + printerr(0, "can't open file %s\n", file);
1173 + ret = write(fd, ¶m, sizeof(param));
1175 + if (ret != sizeof(param)) {
1176 + printerr(0, "lustre ioctl err: %d\n", strerror(errno));
1180 + if (param.status) {
1182 + printerr(0, "status: %d (%s)\n",
1183 + param.status, strerror((int)param.status));
1184 + if (param.status == -ETIMEDOUT) {
1185 + /* kernel return -ETIMEDOUT means the rpc timedout,
1186 + * we should notify the caller to reinitiate the
1187 + * gss negotiation, by return -ERESTART
1189 + lgd->lgd_rpc_err = -ERESTART;
1190 + lgd->lgd_gss_err = 0;
1192 + lgd->lgd_rpc_err = param.status;
1193 + lgd->lgd_gss_err = 0;
1197 + p = (unsigned int *)outbuf;
1199 + gr->gr_major = *p++;
1200 + gr->gr_minor = *p++;
1201 + gr->gr_win = *p++;
1203 + gr->gr_ctx.length = *p++;
1204 + gr->gr_ctx.value = malloc(gr->gr_ctx.length);
1205 + memcpy(gr->gr_ctx.value, p, gr->gr_ctx.length);
1206 + p += (((gr->gr_ctx.length + 3) & ~3) / 4);
1208 + gr->gr_token.length = *p++;
1209 + gr->gr_token.value = malloc(gr->gr_token.length);
1210 + memcpy(gr->gr_token.value, p, gr->gr_token.length);
1211 + p += (((gr->gr_token.length + 3) & ~3) / 4);
1213 + printerr(2, "do_negotiation: receive handle len %d, token len %d\n",
1214 + gr->gr_ctx.length, gr->gr_token.length);
1220 +int gssd_refresh_lgd(struct lustre_gss_data *lgd)
1222 + struct lustre_gss_init_res gr;
1223 + gss_buffer_desc *recv_tokenp, send_token;
1224 + OM_uint32 maj_stat, min_stat, call_stat, ret_flags;
1226 + /* GSS context establishment loop. */
1227 + memset(&gr, 0, sizeof(gr));
1228 + recv_tokenp = GSS_C_NO_BUFFER;
1231 + /* print the token we just received */
1232 + if (recv_tokenp != GSS_C_NO_BUFFER) {
1233 + printerr(3, "The received token length %d\n",
1234 + recv_tokenp->length);
1235 + print_hexl(3, recv_tokenp->value, recv_tokenp->length);
1238 + maj_stat = gss_init_sec_context(&min_stat,
1243 + lgd->lgd_req_flags,
1245 + NULL, /* channel */
1247 + NULL, /* used mech */
1250 + NULL); /* time rec */
1252 + if (recv_tokenp != GSS_C_NO_BUFFER) {
1253 + gss_release_buffer(&min_stat, &gr.gr_token);
1254 + recv_tokenp = GSS_C_NO_BUFFER;
1256 + if (maj_stat != GSS_S_COMPLETE &&
1257 + maj_stat != GSS_S_CONTINUE_NEEDED) {
1258 + pgsserr("gss_init_sec_context", maj_stat, min_stat,
1262 + if (send_token.length != 0) {
1263 + memset(&gr, 0, sizeof(gr));
1265 + /* print the token we are about to send */
1266 + printerr(3, "token being sent length %d\n",
1267 + send_token.length);
1268 + print_hexl(3, send_token.value, send_token.length);
1270 + call_stat = do_negotiation(lgd, &send_token, &gr, 0);
1271 + gss_release_buffer(&min_stat, &send_token);
1273 + if (call_stat != 0 ||
1274 + (gr.gr_major != GSS_S_COMPLETE &&
1275 + gr.gr_major != GSS_S_CONTINUE_NEEDED)) {
1276 + printerr(0, "call stat %d, major stat 0x%x\n",
1277 + (int)call_stat, gr.gr_major);
1281 + if (gr.gr_ctx.length != 0) {
1282 + if (lgd->lgd_rmt_ctx.value)
1283 + gss_release_buffer(&min_stat,
1284 + &lgd->lgd_rmt_ctx);
1285 + lgd->lgd_rmt_ctx = gr.gr_ctx;
1287 + if (gr.gr_token.length != 0) {
1288 + if (maj_stat != GSS_S_CONTINUE_NEEDED)
1290 + recv_tokenp = &gr.gr_token;
1294 + /* GSS_S_COMPLETE => check gss header verifier,
1295 + * usually checked in gss_validate
1297 + if (maj_stat == GSS_S_COMPLETE) {
1298 + lgd->lgd_established = 1;
1299 + lgd->lgd_seq_win = gr.gr_win;
1303 + /* End context negotiation loop. */
1304 + if (!lgd->lgd_established) {
1305 + if (gr.gr_token.length != 0)
1306 + gss_release_buffer(&min_stat, &gr.gr_token);
1308 + printerr(0, "context negotiation failed\n");
1312 + printerr(2, "successfully refreshed lgd\n");
1317 +int gssd_create_lgd(struct clnt_info *clp,
1318 + struct lustre_gss_data *lgd,
1319 + struct lgssd_upcall_data *updata,
1322 + gss_buffer_desc sname;
1323 + OM_uint32 maj_stat, min_stat;
1326 + lgd->lgd_established = 0;
1327 + lgd->lgd_lustre_svc = updata->svc;
1328 + lgd->lgd_uid = updata->uid;
1329 + lgd->lgd_uuid = updata->obd;
1331 + switch (authtype) {
1332 + case AUTHTYPE_KRB5:
1333 + lgd->lgd_mech = (gss_OID) &krb5oid;
1334 + lgd->lgd_req_flags = GSS_C_MUTUAL_FLAG;
1336 + case AUTHTYPE_SPKM3:
1337 + lgd->lgd_mech = (gss_OID) &spkm3oid;
1338 + /* XXX sec.req_flags = GSS_C_ANON_FLAG;
1339 + * Need a way to switch....
1341 + lgd->lgd_req_flags = GSS_C_MUTUAL_FLAG;
1344 + printerr(0, "Invalid authentication type (%d)\n", authtype);
1348 + lgd->lgd_cred = GSS_C_NO_CREDENTIAL;
1349 + lgd->lgd_ctx = GSS_C_NO_CONTEXT;
1350 + lgd->lgd_rmt_ctx = (gss_buffer_desc) GSS_C_EMPTY_BUFFER;
1351 + lgd->lgd_seq_win = 0;
1353 + sname.value = clp->servicename;
1354 + sname.length = strlen(clp->servicename);
1356 + maj_stat = gss_import_name(&min_stat, &sname,
1357 + (gss_OID) GSS_C_NT_HOSTBASED_SERVICE,
1359 + if (maj_stat != GSS_S_COMPLETE) {
1360 + pgsserr(0, maj_stat, min_stat, lgd->lgd_mech);
1364 + retval = gssd_refresh_lgd(lgd);
1366 + if (lgd->lgd_name != GSS_C_NO_NAME)
1367 + gss_release_name(&min_stat, &lgd->lgd_name);
1369 + if (lgd->lgd_cred != GSS_C_NO_CREDENTIAL)
1370 + gss_release_cred(&min_stat, &lgd->lgd_cred);
1377 +void gssd_free_lgd(struct lustre_gss_data *lgd)
1379 + gss_buffer_t token = GSS_C_NO_BUFFER;
1380 + OM_uint32 maj_stat, min_stat;
1382 + if (lgd->lgd_ctx == GSS_C_NO_CONTEXT)
1385 + maj_stat = gss_delete_sec_context(&min_stat, &lgd->lgd_ctx, token);
1389 +int construct_service_name(struct clnt_info *clp,
1390 + struct lgssd_upcall_data *ud)
1392 + const int buflen = 256;
1393 + char name[buflen];
1395 + if (clp->servicename) {
1396 + free(clp->servicename);
1397 + clp->servicename = NULL;
1400 + if (lnet_nid2hostname(ud->nid, name, buflen))
1403 + clp->servicename = malloc(32 + strlen(name));
1404 + if (!clp->servicename) {
1405 + printerr(0, "can't alloc memory\n");
1408 + sprintf(clp->servicename, "%s@%s",
1409 + ud->svc == LUSTRE_GSS_SVC_MDS ?
1410 + GSSD_SERVICE_MDS : GSSD_SERVICE_OSS,
1412 + printerr(2, "constructed servicename: %s\n", clp->servicename);
1417 * this code uses the userland rpcsec gss library to create a krb5
1418 @@ -668,27 +910,78 @@ int create_auth_rpc_client(struct clnt_i
1420 handle_krb5_upcall(struct clnt_info *clp)
1423 - CLIENT *rpc_clnt = NULL;
1424 - AUTH *auth = NULL;
1425 - struct authgss_private_data pd;
1426 - gss_buffer_desc token;
1428 + gss_buffer_desc token = { 0, NULL };
1429 + struct lgssd_upcall_data updata;
1430 + struct lustre_gss_data lgd;
1431 char **credlist = NULL;
1435 - printerr(1, "handling krb5 upcall\n");
1436 + printerr(2, "handling krb5 upcall\n");
1439 - token.value = NULL;
1440 - memset(&pd, 0, sizeof(struct authgss_private_data));
1441 + memset(&lgd, 0, sizeof(lgd));
1442 + lgd.lgd_rpc_err = -EPERM; /* default error code */
1444 - if (read(clp->krb5_fd, &uid, sizeof(uid)) < sizeof(uid)) {
1445 - printerr(0, "WARNING: failed reading uid from krb5 "
1446 + read_rc = read(clp->krb5_fd, &updata, sizeof(updata));
1447 + if (read_rc < 0) {
1448 + printerr(0, "WARNING: failed reading from krb5 "
1449 "upcall pipe: %s\n", strerror(errno));
1452 + } else if (read_rc != sizeof(updata)) {
1453 + printerr(0, "upcall data mismatch: length %d, expect %d\n",
1454 + read_rc, sizeof(updata));
1456 + /* the sequence number must be the first field. if read >= 4
1457 + * bytes then we know at least sequence is fine, try to send
1458 + * error notification nicely.
1461 + do_error_downcall(clp->krb5_fd, updata.seq, -EPERM, 0);
1465 + /* fork child process */
1468 + printerr(0, "can't fork: %s\n", strerror(errno));
1469 + do_error_downcall(clp->krb5_fd, updata.seq, -EPERM, 0);
1471 + } else if (pid > 0) {
1472 + printerr(2, "forked child process: %d\n", pid);
1476 + printerr(1, "krb5 upcall: seq %u, uid %u, svc %u, nid 0x%llx, "
1477 + "pag %llx, obd %s\n", updata.seq, updata.uid, updata.svc,
1478 + updata.nid, updata.pag, updata.obd);
1480 + /* XXX in kernel pag is defined as "unsigned long", which might
1481 + * not keep original signed value after converted to u64.
1483 + if (updata.pag != updata.uid &&
1484 + ((updata.pag == 0xffffffffffffffffULL) ||
1485 + (updata.pag == 0xffffffff))) {
1486 + printerr(0, "uid %u: pag %llx not allowed\n",
1487 + updata.uid, updata.pag);
1488 + lgd.lgd_rpc_err = -EPROTO;
1489 + goto out_return_error;
1493 + if (updata.svc != LUSTRE_GSS_SVC_MDS &&
1494 + updata.svc != LUSTRE_GSS_SVC_OSS) {
1495 + printerr(0, "invalid svc %d\n", updata.svc);
1496 + lgd.lgd_rpc_err = -EPROTO;
1497 + goto out_return_error;
1499 + updata.obd[sizeof(updata.obd)-1] = '\0';
1501 + if (construct_service_name(clp, &updata)) {
1502 + printerr(0, "failed to construct service name\n");
1503 + goto out_return_error;
1506 + if (updata.uid == 0) {
1510 @@ -696,75 +989,66 @@ handle_krb5_upcall(struct clnt_info *clp
1511 * of them until one works or we've tried them all
1513 if (gssd_get_krb5_machine_cred_list(&credlist)) {
1514 - printerr(0, "WARNING: Failed to obtain machine "
1515 - "credentials for connection to "
1516 - "server %s\n", clp->servername);
1517 - goto out_return_error;
1518 + printerr(0, "ERROR: Failed to obtain machine "
1519 + "credentials for %s\n", clp->servicename);
1520 + goto out_return_error;
1522 for (ccname = credlist; ccname && *ccname; ccname++) {
1523 gssd_setup_krb5_machine_gss_ccache(*ccname);
1524 - if ((create_auth_rpc_client(clp, &rpc_clnt, &auth, uid,
1525 - AUTHTYPE_KRB5)) == 0) {
1526 + if ((gssd_create_lgd(clp, &lgd, &updata,
1527 + AUTHTYPE_KRB5)) == 0) {
1532 printerr(2, "WARNING: Failed to create krb5 context "
1533 "for user with uid %d with credentials "
1534 - "cache %s for server %s\n",
1535 - uid, *ccname, clp->servername);
1536 + "cache %s for service %s\n",
1537 + updata.uid, *ccname, clp->servicename);
1539 gssd_free_krb5_machine_cred_list(credlist);
1541 - printerr(0, "WARNING: Failed to create krb5 context "
1542 + printerr(0, "ERROR: Failed to create krb5 context "
1543 "for user with uid %d with any "
1544 - "credentials cache for server %s\n",
1545 - uid, clp->servername);
1546 + "credentials cache for service %s\n",
1547 + updata.uid, clp->servicename);
1548 goto out_return_error;
1552 /* Tell krb5 gss which credentials cache to use */
1553 - gssd_setup_krb5_user_gss_ccache(uid, clp->servername);
1554 + gssd_setup_krb5_user_gss_ccache(updata.pag, updata.uid,
1555 + clp->servicename);
1557 - if ((create_auth_rpc_client(clp, &rpc_clnt, &auth, uid,
1558 - AUTHTYPE_KRB5)) != 0) {
1559 + if ((gssd_create_lgd(clp, &lgd, &updata, AUTHTYPE_KRB5)) != 0) {
1560 printerr(0, "WARNING: Failed to create krb5 context "
1561 - "for user with uid %d for server %s\n",
1562 - uid, clp->servername);
1563 + "for user with uid %d for service %s\n",
1564 + updata.uid, clp->servicename);
1565 goto out_return_error;
1569 - if (!authgss_get_private_data(auth, &pd)) {
1570 - printerr(0, "WARNING: Failed to obtain authentication "
1571 - "data for user with uid %d for server %s\n",
1572 - uid, clp->servername);
1573 - goto out_return_error;
1576 - if (serialize_context_for_kernel(pd.pd_ctx, &token, &krb5oid)) {
1577 + if (serialize_context_for_kernel(lgd.lgd_ctx, &token, &krb5oid)) {
1578 printerr(0, "WARNING: Failed to serialize krb5 context for "
1579 - "user with uid %d for server %s\n",
1580 - uid, clp->servername);
1581 + "user with uid %d for service %s\n",
1582 + updata.uid, clp->servicename);
1583 goto out_return_error;
1586 - do_downcall(clp->krb5_fd, uid, &pd, &token);
1587 + printerr(1, "refreshed: %u@%s for %s\n",
1588 + updata.uid, updata.obd, clp->servicename);
1589 + do_downcall(clp->krb5_fd, &updata, &lgd, &token);
1594 - if (pd.pd_ctx_hndl.length != 0)
1595 - authgss_free_private_data(&pd);
1597 - AUTH_DESTROY(auth);
1599 - clnt_destroy(rpc_clnt);
1602 + gssd_free_lgd(&lgd);
1603 + exit(0); /* i'm child process */
1606 - do_error_downcall(clp->krb5_fd, uid, -1);
1607 + do_error_downcall(clp->krb5_fd, updata.seq,
1608 + lgd.lgd_rpc_err, lgd.lgd_gss_err);
1612 @@ -775,6 +1059,7 @@ out_return_error:
1614 handle_spkm3_upcall(struct clnt_info *clp)
1618 CLIENT *rpc_clnt = NULL;
1620 @@ -826,4 +1111,5 @@ out:
1622 do_error_downcall(clp->spkm3_fd, uid, -1);
1626 diff -rup nfs-utils-1.0.10.orig/utils/gssd/gss_util.c nfs-utils-1.0.10/utils/gssd/gss_util.c
1627 --- nfs-utils-1.0.10.orig/utils/gssd/gss_util.c 2006-08-07 00:40:50.000000000 -0600
1628 +++ nfs-utils-1.0.10/utils/gssd/gss_util.c 2006-12-15 15:12:23.000000000 -0700
1630 #ifdef HAVE_COM_ERR_H
1631 #include <com_err.h>
1633 +#include "lsupport.h"
1635 /* Global gssd_credentials handle */
1636 -gss_cred_id_t gssd_creds;
1637 +gss_cred_id_t gssd_cred_mds;
1638 +gss_cred_id_t gssd_cred_oss;
1639 +int gssd_cred_mds_valid = 0;
1640 +int gssd_cred_oss_valid = 0;
1642 +char *mds_local_realm = NULL;
1643 +char *oss_local_realm = NULL;
1645 gss_OID g_mechOid = GSS_C_NULL_OID;;
1647 @@ -183,15 +190,56 @@ pgsserr(char *msg, u_int32_t maj_stat, u
1648 display_status_2(msg, maj_stat, min_stat, mech);
1652 -gssd_acquire_cred(char *server_name)
1654 +int extract_realm_name(gss_buffer_desc *name, char **realm)
1659 + sname = malloc(name->length + 1);
1661 + printerr(0, "out of memory\n");
1665 + memcpy(sname, name->value, name->length);
1666 + sname[name->length] = '\0';
1667 + printerr(1, "service principal: %s\n", sname);
1669 + c = strchr(sname, '@');
1671 + printerr(2, "no realm found in principal, use default\n");
1672 + *realm = strdup(this_realm);
1674 + printerr(0, "failed to duplicate default realm\n");
1679 + *realm = strdup(c);
1681 + printerr(0, "failed to duplicated realm\n");
1691 +int gssd_acquire_cred(char *server_name, gss_cred_id_t *cred,
1692 + char **local_realm, int *valid)
1694 gss_buffer_desc name;
1695 gss_name_t target_name;
1696 u_int32_t maj_stat, min_stat;
1697 u_int32_t ignore_maj_stat, ignore_min_stat;
1698 + gss_OID name_type;
1699 gss_buffer_desc pbuf;
1703 name.value = (void *)server_name;
1704 name.length = strlen(server_name);
1706 @@ -201,12 +249,20 @@ gssd_acquire_cred(char *server_name)
1708 if (maj_stat != GSS_S_COMPLETE) {
1709 pgsserr("gss_import_name", maj_stat, min_stat, g_mechOid);
1714 + maj_stat = gss_display_name(&min_stat, target_name, &name, &name_type);
1715 + if (maj_stat != GSS_S_COMPLETE) {
1716 + pgsserr(0, maj_stat, min_stat, g_mechOid);
1719 + if (extract_realm_name(&name, local_realm))
1722 maj_stat = gss_acquire_cred(&min_stat, target_name, 0,
1723 GSS_C_NULL_OID_SET, GSS_C_ACCEPT,
1724 - &gssd_creds, NULL, NULL);
1725 + cred, NULL, NULL);
1727 if (maj_stat != GSS_S_COMPLETE) {
1728 pgsserr("gss_acquire_cred", maj_stat, min_stat, g_mechOid);
1729 @@ -218,11 +274,67 @@ gssd_acquire_cred(char *server_name)
1730 ignore_maj_stat = gss_release_buffer(&ignore_min_stat,
1737 ignore_maj_stat = gss_release_name(&ignore_min_stat, &target_name);
1739 - return (maj_stat == GSS_S_COMPLETE);
1740 + if (maj_stat != GSS_S_COMPLETE)
1745 +int gssd_prepare_creds(int must_srv_mds, int must_srv_oss)
1747 + if (gssd_acquire_cred(GSSD_SERVICE_MDS, &gssd_cred_mds,
1748 + &mds_local_realm, &gssd_cred_mds_valid)) {
1753 + if (gssd_acquire_cred(GSSD_SERVICE_OSS, &gssd_cred_oss,
1754 + &oss_local_realm, &gssd_cred_oss_valid)) {
1759 + if (!gssd_cred_mds_valid && !gssd_cred_oss_valid) {
1760 + printerr(0, "can't obtain both mds & oss creds, exit\n");
1764 + if (gssd_cred_mds_valid)
1765 + printerr(0, "Ready to serve Lustre MDS in realm %s\n",
1766 + mds_local_realm ? mds_local_realm : "N/A");
1767 + if (gssd_cred_oss_valid)
1768 + printerr(0, "Ready to serve Lustre OSS in realm %s\n",
1769 + oss_local_realm ? oss_local_realm : "N/A");
1774 +gss_cred_id_t gssd_select_svc_cred(int lustre_svc)
1776 + switch (lustre_svc) {
1777 + case LUSTRE_GSS_SVC_MDS:
1778 + if (!gssd_cred_mds_valid) {
1779 + printerr(0, "ERROR: service cred for mds not ready\n");
1782 + printerr(2, "select mds service cred\n");
1783 + return gssd_cred_mds;
1784 + case LUSTRE_GSS_SVC_OSS:
1785 + if (!gssd_cred_oss_valid) {
1786 + printerr(0, "ERROR: service cred for oss not ready\n");
1789 + printerr(2, "select oss service cred\n");
1790 + return gssd_cred_oss;
1792 + printerr(0, "ERROR: invalid lustre svc id %d\n", lustre_svc);
1798 int gssd_check_mechs(void)
1799 @@ -249,3 +361,42 @@ out:
1803 +/*********************************
1804 + * FIXME should be in krb5_util.c
1805 + *********************************/
1807 +#include "krb5_util.h"
1809 +/* realm of this node */
1810 +char *this_realm = NULL;
1812 +int gssd_get_local_realm(void)
1814 + krb5_context context = NULL;
1815 + krb5_error_code code;
1818 + if (this_realm != NULL)
1821 + code = krb5_init_context(&context);
1823 + printerr(0, "ERROR: get default realm: init ctx: %s\n",
1824 + error_message(code));
1828 + code = krb5_get_default_realm(context, &this_realm);
1830 + printerr(0, "ERROR: get default realm: %s\n",
1831 + error_message(code));
1836 + printerr(1, "Local realm: %s\n", this_realm);
1838 + krb5_free_context(context);
1842 diff -rup nfs-utils-1.0.10.orig/utils/gssd/gss_util.h nfs-utils-1.0.10/utils/gssd/gss_util.h
1843 --- nfs-utils-1.0.10.orig/utils/gssd/gss_util.h 2006-08-07 00:40:50.000000000 -0600
1844 +++ nfs-utils-1.0.10/utils/gssd/gss_util.h 2006-12-15 15:12:23.000000000 -0700
1846 #define _GSS_UTIL_H_
1849 -#include <rpc/rpc.h>
1850 #include "write_bytes.h"
1853 extern gss_cred_id_t gssd_creds;
1855 -int gssd_acquire_cred(char *server_name);
1856 void pgsserr(char *msg, u_int32_t maj_stat, u_int32_t min_stat,
1857 const gss_OID mech);
1858 int gssd_check_mechs(void);
1859 +int gssd_get_local_realm(void);
1861 #endif /* _GSS_UTIL_H_ */
1862 diff -rup nfs-utils-1.0.10.orig/utils/gssd/krb5_util.c nfs-utils-1.0.10/utils/gssd/krb5_util.c
1863 --- nfs-utils-1.0.10.orig/utils/gssd/krb5_util.c 2006-11-15 21:26:08.000000000 -0700
1864 +++ nfs-utils-1.0.10/utils/gssd/krb5_util.c 2006-12-15 15:12:23.000000000 -0700
1866 #include <rpc/rpc.h>
1867 #include <sys/types.h>
1868 #include <sys/stat.h>
1869 +#include <sys/utsname.h>
1870 #include <sys/socket.h>
1871 #include <arpa/inet.h>
1873 +#include <unistd.h>
1882 #include <gssapi/gssapi_krb5.h>
1885 -#include <rpc/auth_gss.h>
1888 #include "err_util.h"
1889 @@ -129,6 +131,9 @@ struct gssd_k5_kt_princ *gssd_k5_kt_prin
1890 int num_krb5_enctypes = 0;
1891 krb5_enctype *krb5_enctypes = NULL;
1893 +/* credential expire time in advance */
1894 +unsigned long machine_cred_expire_advance = 300; /* 5 mins */
1896 /*==========================*/
1897 /*=== Internal routines ===*/
1898 /*==========================*/
1899 @@ -137,11 +142,55 @@ static int select_krb5_ccache(const stru
1900 static int gssd_find_existing_krb5_ccache(uid_t uid, struct dirent **d);
1901 static int gssd_get_single_krb5_cred(krb5_context context,
1902 krb5_keytab kt, struct gssd_k5_kt_princ *ple);
1903 -static int gssd_have_realm_ple(void *realm);
1904 static int gssd_process_krb5_keytab(krb5_context context, krb5_keytab kt,
1908 + * convenient macros, these perhaps need further cleanup
1912 +#define KEYTAB_ENTRY_MATCH(kte, name) \
1914 + (kte).principal->data[0].length == (sizeof(name)-1) && \
1915 + strncmp((kte).principal->data[0].data, (name), sizeof(name)-1) == 0 \
1917 +#define KRB5_FREE_UNPARSED_NAME(ctx, name) \
1918 + krb5_free_unparsed_name((ctx), (name));
1919 +#define KRB5_STRDUP(str) \
1920 + strndup((str).data, (str).length)
1921 +#define KRB5_STRCMP(str, name) \
1923 + (str)->length != strlen(name) || \
1924 + strncmp((str)->data, (name), (str)->length) != 0 \
1926 +#define KRB5_STRCASECMP(str, name) \
1928 + (str)->length != strlen(name) || \
1929 + strncasecmp((str)->data, (name), (str)->length) != 0 \
1932 +#else /* !HAVE_KRB5 */
1934 +#define KEYTAB_ENTRY_MATCH(kte, name) \
1936 + strlen((kte).principal->name.name_string.val[0]) == \
1937 + (sizeof(name)-1) && \
1938 + strncmp(kte.principal->name.name_string.val[0], (name), \
1939 + sizeof(name)-1) == 0 \
1941 +#define KRB5_FREE_UNPARSED_NAME(ctx, name) \
1943 +#define KRB5_STRDUP(str) \
1945 +#define KRB5_STRCMP(str, name) \
1946 + strcmp((str), (name))
1947 +#define KRB5_STRCASECMP(str, name) \
1948 + strcmp((str), (name))
1950 +#endif /* HAVE_KRB5 */
1953 * Called from the scandir function to weed out potential krb5
1954 * credentials cache files
1956 @@ -294,7 +343,7 @@ gssd_get_single_krb5_cred(krb5_context c
1958 memset(&my_creds, 0, sizeof(my_creds));
1960 - if (ple->ccname && ple->endtime > now) {
1961 + if (ple->ccname && ple->endtime > now + machine_cred_expire_advance) {
1962 printerr(2, "INFO: Credentials in CC '%s' are good until %d\n",
1963 ple->ccname, ple->endtime);
1965 @@ -325,11 +374,7 @@ gssd_get_single_krb5_cred(krb5_context c
1966 "principal '%s' from keytab '%s'\n",
1967 error_message(code),
1968 pname ? pname : "<unparsable>", kt_name);
1970 - if (pname) krb5_free_unparsed_name(context, pname);
1972 - if (pname) free(pname);
1974 + if (pname) KRB5_FREE_UNPARSED_NAME(context, pname);
1978 @@ -378,15 +423,7 @@ gssd_get_single_krb5_cred(krb5_context c
1983 - * Determine if we already have a ple for the given realm
1986 - * 0 => no ple found for given realm
1987 - * 1 => found ple for given realm
1990 -gssd_have_realm_ple(void *r)
1991 +static struct gssd_k5_kt_princ * gssd_get_realm_ple(void *r)
1993 struct gssd_k5_kt_princ *ple;
1995 @@ -396,18 +433,76 @@ gssd_have_realm_ple(void *r)
1998 for (ple = gssd_k5_kt_princ_list; ple; ple = ple->next) {
2000 - if ((realm->length == strlen(ple->realm)) &&
2001 - (strncmp(realm->data, ple->realm, realm->length) == 0)) {
2003 - if (strcmp(realm, ple->realm) == 0) {
2007 + if (KRB5_STRCMP(realm, ple->realm) == 0)
2013 +static void gssd_free_ple(krb5_context kctx, struct gssd_k5_kt_princ *ple)
2016 + krb5_free_principal(kctx, ple->princ);
2020 + free(ple->ccname);
2024 +static int gssd_remove_ple(krb5_context kctx, struct gssd_k5_kt_princ *ple)
2026 + struct gssd_k5_kt_princ **prev = &gssd_k5_kt_princ_list;
2027 + struct gssd_k5_kt_princ *ent = gssd_k5_kt_princ_list;
2029 + for (; ent; prev = &ent->next, ent = ent->next) {
2033 + *prev = ent->next;
2034 + gssd_free_ple(kctx, ent);
2041 +struct gssd_k5_kt_princ *gssd_create_ple(krb5_context kctx,
2042 + krb5_principal principal)
2044 + struct gssd_k5_kt_princ *ple;
2045 + krb5_error_code code;
2047 + ple = malloc(sizeof(*ple));
2048 + if (ple == NULL) {
2049 + printerr(0, "ERROR: could not allocate storage "
2050 + "for principal list entry\n");
2054 + memset(ple, 0, sizeof(*ple));
2056 + ple->realm = KRB5_STRDUP(principal->realm);
2057 + if (ple->realm == NULL) {
2058 + printerr(0, "ERROR: not enough memory while copying realm to "
2059 + "principal list entry\n");
2063 + code = krb5_copy_principal(kctx, principal, &ple->princ);
2065 + printerr(0, "ERROR: %s while copying principal "
2066 + "to principal list entry\n",
2067 + error_message(code));
2073 + gssd_free_ple(kctx, ple);
2078 * Process the given keytab file and create a list of principals we
2079 * might use to perform mount operations.
2080 @@ -451,82 +546,106 @@ gssd_process_krb5_keytab(krb5_context co
2082 printerr(2, "Processing keytab entry for principal '%s'\n",
2085 - if ( (kte.principal->data[0].length == GSSD_SERVICE_NAME_LEN) &&
2086 - (strncmp(kte.principal->data[0].data, GSSD_SERVICE_NAME,
2087 - GSSD_SERVICE_NAME_LEN) == 0) &&
2089 - if ( (strlen(kte.principal->name.name_string.val[0]) == GSSD_SERVICE_NAME_LEN) &&
2090 - (strncmp(kte.principal->name.name_string.val[0], GSSD_SERVICE_NAME,
2091 - GSSD_SERVICE_NAME_LEN) == 0) &&
2094 - (!gssd_have_realm_ple((void *)&kte.principal->realm)) ) {
2095 - printerr(2, "We will use this entry (%s)\n", pname);
2096 - ple = malloc(sizeof(struct gssd_k5_kt_princ));
2097 - if (ple == NULL) {
2098 - printerr(0, "ERROR: could not allocate storage "
2099 - "for principal list entry\n");
2101 - krb5_free_unparsed_name(context, pname);
2108 + /* mds service entry:
2109 + * - hostname and realm should match this node
2110 + * - replace existing non-mds entry of this realm
2112 + if (KEYTAB_ENTRY_MATCH(kte, GSSD_SERVICE_MDS)) {
2113 + krb5_principal princ = kte.principal;
2114 + krb5_data *princ_host;
2115 + struct utsname utsbuf;
2116 + struct hostent *host;
2118 + if (KRB5_STRCASECMP(krb5_princ_realm(context, princ),
2119 + this_realm) != 0) {
2120 + printerr(2, "alien mds service entry, skip\n");
2123 - /* These will be filled in later */
2125 - ple->ccname = NULL;
2129 - strndup(kte.principal->realm.data,
2130 - kte.principal->realm.length))
2132 - strdup(kte.principal->realm))
2135 - printerr(0, "ERROR: %s while copying realm to "
2136 - "principal list entry\n",
2137 - "not enough memory");
2139 - krb5_free_unparsed_name(context, pname);
2146 + princ_host = krb5_princ_component(context, princ, 1);
2147 + if (princ_host == NULL) {
2148 + printerr(2, "mds service entry: no hostname in "
2149 + "principal, skip\n");
2152 - if ((code = krb5_copy_principal(context,
2153 - kte.principal, &ple->princ))) {
2154 - printerr(0, "ERROR: %s while copying principal "
2155 - "to principal list entry\n",
2156 - error_message(code));
2158 - krb5_free_unparsed_name(context, pname);
2165 + if (uname(&utsbuf)) {
2166 + printerr(2, "mds service entry: unable to get "
2167 + "UTS name, skip\n");
2170 - if (gssd_k5_kt_princ_list == NULL)
2171 - gssd_k5_kt_princ_list = ple;
2173 - ple->next = gssd_k5_kt_princ_list;
2174 - gssd_k5_kt_princ_list = ple;
2175 + host = gethostbyname(utsbuf.nodename);
2176 + if (host == NULL) {
2177 + printerr(2, "mds service entry: unable to get "
2178 + "local hostname, skip\n");
2184 + if (KRB5_STRCASECMP(princ_host, host->h_name) != 0) {
2185 + printerr(2, "mds service entry: hostname "
2186 + "doesn't match: %s - %.*s, skip\n",
2188 + princ_host->length, princ_host->data);
2192 + ple = gssd_get_realm_ple((void *)&kte.principal->realm);
2194 + if (ple->fl_mds) {
2195 + printerr(2,"mds service entry: found a"
2196 + "duplicated one, it's like a "
2197 + "mis-configuration, skip\n");
2201 + gssd_remove_ple(context, ple);
2202 + printerr(2, "mds service entry: replace an "
2203 + "existed non-mds one\n");
2205 + } else if (KEYTAB_ENTRY_MATCH(kte, LUSTRE_ROOT_NAME)) {
2206 + ple = gssd_get_realm_ple((void *)&kte.principal->realm);
2208 + if (ple->fl_mds || ple->fl_root) {
2209 + printerr(2, "root entry: found a "
2210 + "existed %s entry, skip\n",
2211 + ple->fl_mds ? "mds" : "root");
2215 + gssd_remove_ple(context, ple);
2216 + printerr(2, "root entry: replace an existed "
2217 + "non-mds non-root one\n");
2220 printerr(2, "We will NOT use this entry (%s)\n",
2225 - krb5_free_unparsed_name(context, pname);
2230 + /* construct ple */
2231 + printerr(2, "We will use this entry (%s)\n", pname);
2232 + ple = gssd_create_ple(context, kte.principal);
2233 + if (ple == NULL) {
2234 + KRB5_FREE_UNPARSED_NAME(context, pname);
2238 + /* add proper flags */
2239 + if (KEYTAB_ENTRY_MATCH(kte, GSSD_SERVICE_MDS))
2241 + else if (KEYTAB_ENTRY_MATCH(kte, LUSTRE_ROOT_NAME))
2245 + if (gssd_k5_kt_princ_list == NULL)
2246 + gssd_k5_kt_princ_list = ple;
2248 + ple->next = gssd_k5_kt_princ_list;
2249 + gssd_k5_kt_princ_list = ple;
2252 + KRB5_FREE_UNPARSED_NAME(context, pname);
2255 if ((code = krb5_kt_end_seq_get(context, kt, &cursor))) {
2256 @@ -634,14 +753,21 @@ parse_enctypes(char *enctypes)
2260 -gssd_setup_krb5_user_gss_ccache(uid_t uid, char *servername)
2261 +gssd_setup_krb5_user_gss_ccache(uint64_t pag, uid_t uid, char *servername)
2263 char buf[MAX_NETOBJ_SZ];
2266 - printerr(2, "getting credentials for client with uid %u for "
2267 - "server %s\n", uid, servername);
2268 + printerr(2, "getting credentials for client with pag %llx/uid %u for "
2269 + "server %s\n", pag, uid, servername);
2270 memset(buf, 0, sizeof(buf));
2273 + snprintf(buf, sizeof(buf), "FILE:%s/%spag_%llx",
2274 + ccachedir, GSSD_DEFAULT_CRED_PREFIX, pag);
2278 if (gssd_find_existing_krb5_ccache(uid, &d)) {
2279 snprintf(buf, sizeof(buf), "FILE:%s/%s",
2280 ccachedir, d->d_name);
2281 @@ -652,6 +778,7 @@ gssd_setup_krb5_user_gss_ccache(uid_t ui
2282 ccachedir, GSSD_DEFAULT_CRED_PREFIX, uid);
2283 printerr(2, "using %s as credentials cache for client with "
2284 "uid %u for server %s\n", buf, uid, servername);
2286 gssd_set_krb5_ccache_name(buf);
2289 @@ -702,7 +829,7 @@ gssd_refresh_krb5_machine_creds(void)
2293 - printerr(1, "Using keytab file '%s'\n", keytabfile);
2294 + printerr(2, "Using keytab file '%s'\n", keytabfile);
2296 if ((code = krb5_kt_resolve(context, keytabfile, &kt))) {
2297 printerr(0, "ERROR: %s while resolving keytab '%s'\n",
2298 @@ -717,12 +844,12 @@ gssd_refresh_krb5_machine_creds(void)
2299 if (gssd_k5_kt_princ_list == NULL) {
2300 printerr(0, "ERROR: No usable keytab entries found in "
2301 "keytab '%s'\n", keytabfile);
2302 - printerr(0, "Do you have a valid keytab entry for "
2303 - "%s/<your.host>@<YOUR.REALM> in "
2304 + printerr(0, "You must have a valid keytab entry for "
2305 + "%s/<your.host>@<YOUR.REALM> on MDT nodes, "
2306 + "and %s@<YOUR.REALM> on client nodes, in "
2307 "keytab file %s ?\n",
2308 - GSSD_SERVICE_NAME, keytabfile);
2309 - printerr(0, "Continuing without (machine) credentials "
2310 - "- nfs4 mounts with Kerberos will fail\n");
2311 + GSSD_SERVICE_MDS, LUSTRE_ROOT_NAME,
2316 @@ -872,6 +999,7 @@ gssd_destroy_krb5_machine_creds(void)
2317 krb5_free_context(context);
2321 #ifdef HAVE_SET_ALLOWABLE_ENCTYPES
2323 * this routine obtains a credentials handle via gss_acquire_cred()
2324 @@ -927,6 +1055,7 @@ limit_krb5_enctypes(struct rpc_gss_sec *
2327 #endif /* HAVE_SET_ALLOWABLE_ENCTYPES */
2331 * Obtain supported enctypes from kernel.
2332 diff -rup nfs-utils-1.0.10.orig/utils/gssd/krb5_util.h nfs-utils-1.0.10/utils/gssd/krb5_util.h
2333 --- nfs-utils-1.0.10.orig/utils/gssd/krb5_util.h 2006-11-15 21:26:08.000000000 -0700
2334 +++ nfs-utils-1.0.10/utils/gssd/krb5_util.h 2006-12-15 15:12:23.000000000 -0700
2336 struct gssd_k5_kt_princ {
2337 struct gssd_k5_kt_princ *next;
2338 krb5_principal princ;
2339 + unsigned int fl_root:1,
2343 krb5_timestamp endtime;
2347 -void gssd_setup_krb5_user_gss_ccache(uid_t uid, char *servername);
2348 +void gssd_setup_krb5_user_gss_ccache(uint64_t pag, uid_t uid, char *servername);
2349 int gssd_get_krb5_machine_cred_list(char ***list);
2350 int gssd_refresh_krb5_machine_creds(void);
2351 void gssd_free_krb5_machine_cred_list(char **list);
2352 @@ -25,8 +27,4 @@ void gssd_destroy_krb5_machine_creds(voi
2353 void gssd_obtain_kernel_krb5_info(void);
2356 -#ifdef HAVE_SET_ALLOWABLE_ENCTYPES
2357 -int limit_krb5_enctypes(struct rpc_gss_sec *sec, uid_t uid);
2360 #endif /* KRB5_UTIL_H */
2361 diff -rup nfs-utils-1.0.10.orig/utils/gssd/lsupport.c nfs-utils-1.0.10/utils/gssd/lsupport.c
2362 --- nfs-utils-1.0.10.orig/utils/gssd/lsupport.c 2006-11-15 21:41:25.000000000 -0700
2363 +++ nfs-utils-1.0.10/utils/gssd/lsupport.c 2006-12-15 15:12:23.000000000 -0700
2365 +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2366 + * vim:expandtab:shiftwidth=8:tabstop=8:
2368 + * Copyright (c) 2005 Cluster File Systems, Inc.
2370 + * This file is part of Lustre, http://www.lustre.org.
2372 + * Lustre is free software; you can redistribute it and/or
2373 + * modify it under the terms of version 2 of the GNU General Public
2374 + * License as published by the Free Software Foundation.
2376 + * Lustre is distributed in the hope that it will be useful,
2377 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2378 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2379 + * GNU General Public License for more details.
2381 + * You should have received a copy of the GNU General Public License
2382 + * along with Lustre; if not, write to the Free Software
2383 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2386 +#ifndef _GNU_SOURCE
2387 +#define _GNU_SOURCE
2389 +#include "config.h"
2390 +#include <sys/param.h>
2391 +#include <sys/utsname.h>
2392 +#include <sys/stat.h>
2393 +#include <sys/socket.h>
2394 +#include <arpa/inet.h>
2395 +#include <sys/types.h>
2396 +#include <sys/ipc.h>
2397 +#include <sys/sem.h>
2400 +#include <stdlib.h>
2403 +#include <string.h>
2404 +#include <dirent.h>
2407 +#include <signal.h>
2408 +#include <unistd.h>
2410 +#include <assert.h>
2411 +#ifdef HAVE_GETHOSTBYNAME
2412 +# include <netdb.h>
2415 +#include "err_util.h"
2417 +#include "lsupport.h"
2419 +/****************************************
2420 + * exclusive startup *
2421 + ****************************************/
2423 +static struct __sem_s {
2428 + [GSSD_CLI] = { "client", 0x3a92d473, 0 },
2429 + [GSSD_SVC] = { "server", 0x3b92d473, 0 },
2432 +void gssd_init_unique(int type)
2434 + struct __sem_s *sem = &sems[type];
2435 + struct sembuf sembuf;
2437 + assert(type == GSSD_CLI || type == GSSD_SVC);
2440 + sem->sem_id = semget(sem->sem_key, 1, IPC_CREAT | IPC_EXCL | 0700);
2441 + if (sem->sem_id == -1) {
2442 + if (errno != EEXIST) {
2443 + printerr(0, "Create sem: %s\n", strerror(errno));
2447 + /* already exist. Note there's still a small window racing
2448 + * with other processes, due to the stupid semaphore semantics.
2450 + sem->sem_id = semget(sem->sem_key, 0, 0700);
2451 + if (sem->sem_id == -1) {
2452 + if (errno == ENOENT) {
2453 + printerr(0, "another instance just exit, "
2458 + printerr(0, "Obtain sem: %s\n", strerror(errno));
2464 + if (semctl(sem->sem_id, 0, SETVAL, val) == -1) {
2465 + printerr(0, "Initialize sem: %s\n",
2471 + sembuf.sem_num = 0;
2472 + sembuf.sem_op = -1;
2473 + sembuf.sem_flg = IPC_NOWAIT | SEM_UNDO;
2475 + if (semop(sem->sem_id, &sembuf, 1) != 0) {
2476 + if (errno == EAGAIN) {
2477 + printerr(0, "Another instance is running, exit\n");
2480 + printerr(0, "Grab sem: %s\n", strerror(errno));
2484 + printerr(2, "Successfully created %s global identity\n", sem->name);
2487 +void gssd_exit_unique(int type)
2489 + assert(type == GSSD_CLI || type == GSSD_SVC);
2492 + * do nothing. we can't remove the sem here, otherwise the race
2493 + * window would be much bigger. So it's sad we have to leave the
2494 + * sem in the system forever.
2498 +/****************************************
2499 + * client side resolvation: *
2500 + * lnd/netid/nid => hostname *
2501 + ****************************************/
2503 +char gethostname_ex[PATH_MAX] = GSSD_DEFAULT_GETHOSTNAME_EX;
2505 +typedef int lnd_nid2hostname_t(char *lnd, uint32_t net, uint32_t addr,
2506 + char *buf, int buflen);
2508 +/* FIXME what about IPv6? */
2510 +int socklnd_nid2hostname(char *lnd, uint32_t net, uint32_t addr,
2511 + char *buf, int buflen)
2513 + struct hostent *ent;
2515 + addr = htonl(addr);
2516 + ent = gethostbyaddr(&addr, sizeof(addr), AF_INET);
2518 + printerr(0, "%s: can't resolve 0x%x\n", lnd, addr);
2521 + if (strlen(ent->h_name) >= buflen) {
2522 + printerr(0, "%s: name too long: %s\n", lnd, ent->h_name);
2525 + strcpy(buf, ent->h_name);
2527 + printerr(2, "%s: net 0x%x, addr 0x%x => %s\n",
2528 + lnd, net, addr, buf);
2533 +int lolnd_nid2hostname(char *lnd, uint32_t net, uint32_t addr,
2534 + char *buf, int buflen)
2536 + struct utsname uts;
2537 + struct hostent *ent;
2540 + printerr(0, "%s: addr is 0x%x, we expect 0\n", lnd, addr);
2544 + if (uname(&uts)) {
2545 + printerr(0, "%s: failed obtain local machine name\n", lnd);
2549 + ent = gethostbyname(uts.nodename);
2551 + printerr(0, "%s: failed obtain canonical name of %s\n",
2552 + lnd, uts.nodename);
2556 + if (strlen(ent->h_name) >= buflen) {
2557 + printerr(0, "%s: name too long: %s\n", lnd, ent->h_name);
2560 + strcpy(buf, ent->h_name);
2562 + printerr(2, "%s: addr 0x%x => %s\n", lnd, addr, buf);
2566 +static int is_space(char c)
2568 + return (c == ' ' || c == '\t' || c == '\n');
2572 +int external_nid2hostname(char *lnd, uint32_t net, uint32_t addr,
2573 + char *namebuf, int namebuflen)
2575 + const int bufsize = PATH_MAX + 256;
2576 + char buf[bufsize], *head, *tail;
2579 + sprintf(buf, "%s %s 0x%x 0x%x", gethostname_ex, lnd, net, addr);
2580 + printerr(2, "cmd: %s\n", buf);
2582 + fghn = popen(buf, "r");
2583 + if (fghn == NULL) {
2584 + printerr(0, "failed to call %s\n", gethostname_ex);
2588 + head = fgets(buf, bufsize, fghn);
2589 + if (head == NULL) {
2590 + printerr(0, "can't read from %s\n", gethostname_ex);
2593 + if (pclose(fghn) == -1)
2594 + printerr(1, "pclose failed, continue\n");
2596 + /* trim head/tail space */
2597 + while (is_space(*head))
2600 + tail = head + strlen(head);
2601 + if (tail <= head) {
2602 + printerr(0, "no output from %s\n", gethostname_ex);
2605 + while (is_space(*(tail - 1)))
2607 + if (tail <= head) {
2608 + printerr(0, "output are all space from %s\n", gethostname_ex);
2613 + /* start with '@' means error msg */
2614 + if (head[0] == '@') {
2615 + printerr(0, "error from %s: %s\n", gethostname_ex, &head[1]);
2619 + if (tail - head > namebuflen) {
2620 + printerr(0, "external hostname too long: %s\n", head);
2624 + printerr(2, "%s: net 0x%x, addr 0x%x => %s\n",
2625 + lnd, net, addr, head);
2626 + strcpy(namebuf, head);
2632 + lnd_nid2hostname_t *nid2name;
2633 +} converter[LND_ENUM_END_MARKER] = {
2634 + {"UNUSED0", NULL},
2635 + [QSWLND] = { "QSWLND", external_nid2hostname},
2636 + [SOCKLND] = { "SOCKLND", socklnd_nid2hostname},
2637 + [GMLND] = { "GMLND", external_nid2hostname},
2638 + [PTLLND] = { "PTLLND", external_nid2hostname },
2639 + [O2IBLND] = { "O2IBLND", external_nid2hostname },
2640 + [CIBLND] = { "CIBLND", external_nid2hostname },
2641 + [OPENIBLND] = { "OPENIBLND",external_nid2hostname },
2642 + [IIBLND] = { "IIBLND", external_nid2hostname },
2643 + [LOLND] = { "LOLND", lolnd_nid2hostname },
2644 + [RALND] = { "RALND", external_nid2hostname },
2645 + [VIBLND] = { "VIBLND", external_nid2hostname },
2648 +int lnet_nid2hostname(lnet_nid_t nid, char *buf, int buflen)
2650 + uint32_t lnd, net, addr;
2652 + addr = LNET_NIDADDR(nid);
2653 + net = LNET_NIDNET(nid);
2654 + lnd = LNET_NETTYP(net);
2656 + if (lnd >= LND_ENUM_END_MARKER) {
2657 + printerr(0, "ERROR: Unrecognized LND %u\n", lnd);
2661 + if (converter[lnd].nid2name == NULL) {
2662 + printerr(0, "ERROR: %s converter not ready\n",
2663 + converter[lnd].name);
2667 + return converter[lnd].nid2name(converter[lnd].name, net, addr,
2672 +/****************************************
2673 + * lnet support routine *
2674 + * (from lnet/libcfs/nidstrings.c *
2675 + ****************************************/
2677 +#define LNET_NIDSTR_SIZE 32 /* size of each one (see below for usage) */
2679 +static int libcfs_lo_str2addr(char *str, int nob, uint32_t *addr);
2680 +static void libcfs_ip_addr2str(uint32_t addr, char *str);
2681 +static int libcfs_ip_str2addr(char *str, int nob, uint32_t *addr);
2682 +static void libcfs_decnum_addr2str(uint32_t addr, char *str);
2683 +static void libcfs_hexnum_addr2str(uint32_t addr, char *str);
2684 +static int libcfs_num_str2addr(char *str, int nob, uint32_t *addr);
2690 + void (*nf_addr2str)(uint32_t addr, char *str);
2691 + int (*nf_str2addr)(char *str, int nob, uint32_t *addr);
2694 +static struct netstrfns libcfs_netstrfns[] = {
2695 + {/* .nf_type */ LOLND,
2696 + /* .nf_name */ "lo",
2697 + /* .nf_modname */ "klolnd",
2698 + /* .nf_addr2str */ libcfs_decnum_addr2str,
2699 + /* .nf_str2addr */ libcfs_lo_str2addr},
2700 + {/* .nf_type */ SOCKLND,
2701 + /* .nf_name */ "tcp",
2702 + /* .nf_modname */ "ksocklnd",
2703 + /* .nf_addr2str */ libcfs_ip_addr2str,
2704 + /* .nf_str2addr */ libcfs_ip_str2addr},
2705 + {/* .nf_type */ O2IBLND,
2706 + /* .nf_name */ "o2ib",
2707 + /* .nf_modname */ "ko2iblnd",
2708 + /* .nf_addr2str */ libcfs_ip_addr2str,
2709 + /* .nf_str2addr */ libcfs_ip_str2addr},
2710 + {/* .nf_type */ CIBLND,
2711 + /* .nf_name */ "cib",
2712 + /* .nf_modname */ "kciblnd",
2713 + /* .nf_addr2str */ libcfs_ip_addr2str,
2714 + /* .nf_str2addr */ libcfs_ip_str2addr},
2715 + {/* .nf_type */ OPENIBLND,
2716 + /* .nf_name */ "openib",
2717 + /* .nf_modname */ "kopeniblnd",
2718 + /* .nf_addr2str */ libcfs_ip_addr2str,
2719 + /* .nf_str2addr */ libcfs_ip_str2addr},
2720 + {/* .nf_type */ IIBLND,
2721 + /* .nf_name */ "iib",
2722 + /* .nf_modname */ "kiiblnd",
2723 + /* .nf_addr2str */ libcfs_ip_addr2str,
2724 + /* .nf_str2addr */ libcfs_ip_str2addr},
2725 + {/* .nf_type */ VIBLND,
2726 + /* .nf_name */ "vib",
2727 + /* .nf_modname */ "kviblnd",
2728 + /* .nf_addr2str */ libcfs_ip_addr2str,
2729 + /* .nf_str2addr */ libcfs_ip_str2addr},
2730 + {/* .nf_type */ RALND,
2731 + /* .nf_name */ "ra",
2732 + /* .nf_modname */ "kralnd",
2733 + /* .nf_addr2str */ libcfs_ip_addr2str,
2734 + /* .nf_str2addr */ libcfs_ip_str2addr},
2735 + {/* .nf_type */ QSWLND,
2736 + /* .nf_name */ "elan",
2737 + /* .nf_modname */ "kqswlnd",
2738 + /* .nf_addr2str */ libcfs_decnum_addr2str,
2739 + /* .nf_str2addr */ libcfs_num_str2addr},
2740 + {/* .nf_type */ GMLND,
2741 + /* .nf_name */ "gm",
2742 + /* .nf_modname */ "kgmlnd",
2743 + /* .nf_addr2str */ libcfs_hexnum_addr2str,
2744 + /* .nf_str2addr */ libcfs_num_str2addr},
2745 + {/* .nf_type */ PTLLND,
2746 + /* .nf_name */ "ptl",
2747 + /* .nf_modname */ "kptllnd",
2748 + /* .nf_addr2str */ libcfs_decnum_addr2str,
2749 + /* .nf_str2addr */ libcfs_num_str2addr},
2750 + /* placeholder for net0 alias. It MUST BE THE LAST ENTRY */
2751 + {/* .nf_type */ -1},
2754 +const int libcfs_nnetstrfns = sizeof(libcfs_netstrfns)/sizeof(libcfs_netstrfns[0]);
2757 +libcfs_lo_str2addr(char *str, int nob, uint32_t *addr)
2764 +libcfs_ip_addr2str(uint32_t addr, char *str)
2766 + snprintf(str, LNET_NIDSTR_SIZE, "%u.%u.%u.%u",
2767 + (addr >> 24) & 0xff, (addr >> 16) & 0xff,
2768 + (addr >> 8) & 0xff, addr & 0xff);
2771 +/* CAVEAT EMPTOR XscanfX
2772 + * I use "%n" at the end of a sscanf format to detect trailing junk. However
2773 + * sscanf may return immediately if it sees the terminating '0' in a string, so
2774 + * I initialise the %n variable to the expected length. If sscanf sets it;
2775 + * fine, if it doesn't, then the scan ended at the end of the string, which is
2779 +libcfs_ip_str2addr(char *str, int nob, uint32_t *addr)
2785 + int n = nob; /* XscanfX */
2788 + if (sscanf(str, "%u.%u.%u.%u%n", &a, &b, &c, &d, &n) >= 4 &&
2790 + (a & ~0xff) == 0 && (b & ~0xff) == 0 &&
2791 + (c & ~0xff) == 0 && (d & ~0xff) == 0) {
2792 + *addr = ((a<<24)|(b<<16)|(c<<8)|d);
2796 +#ifdef HAVE_GETHOSTBYNAME
2797 + /* known hostname? */
2798 + if (('a' <= str[0] && str[0] <= 'z') ||
2799 + ('A' <= str[0] && str[0] <= 'Z')) {
2802 + tmp = malloc(nob + 1);
2803 + if (tmp != NULL) {
2804 + struct hostent *he;
2806 + memcpy(tmp, str, nob);
2809 + he = gethostbyname(tmp);
2815 + uint32_t ip = *(uint32_t *)he->h_addr;
2817 + *addr = ntohl(ip);
2827 +libcfs_decnum_addr2str(uint32_t addr, char *str)
2829 + snprintf(str, LNET_NIDSTR_SIZE, "%u", addr);
2833 +libcfs_hexnum_addr2str(uint32_t addr, char *str)
2835 + snprintf(str, LNET_NIDSTR_SIZE, "0x%x", addr);
2839 +libcfs_num_str2addr(char *str, int nob, uint32_t *addr)
2844 + if (sscanf(str, "0x%x%n", addr, &n) >= 1 && n == nob)
2848 + if (sscanf(str, "0X%x%n", addr, &n) >= 1 && n == nob)
2852 + if (sscanf(str, "%u%n", addr, &n) >= 1 && n == nob)
2858 +static struct netstrfns *
2859 +libcfs_lnd2netstrfns(int lnd)
2864 + for (i = 0; i < libcfs_nnetstrfns; i++)
2865 + if (lnd == libcfs_netstrfns[i].nf_type)
2866 + return &libcfs_netstrfns[i];
2871 +static struct netstrfns *
2872 +libcfs_str2net_internal(char *str, uint32_t *net)
2874 + struct netstrfns *nf;
2879 + for (i = 0; i < libcfs_nnetstrfns; i++) {
2880 + nf = &libcfs_netstrfns[i];
2881 + if (nf->nf_type >= 0 &&
2882 + !strncmp(str, nf->nf_name, strlen(nf->nf_name)))
2886 + if (i == libcfs_nnetstrfns)
2889 + nob = strlen(nf->nf_name);
2891 + if (strlen(str) == (unsigned int)nob) {
2894 + if (nf->nf_type == LOLND) /* net number not allowed */
2899 + if (sscanf(str, "%u%n", &netnum, &i) < 1 ||
2900 + i != (int)strlen(str))
2904 + *net = LNET_MKNET(nf->nf_type, netnum);
2909 +libcfs_str2nid(char *str)
2911 + char *sep = strchr(str, '@');
2912 + struct netstrfns *nf;
2916 + if (sep != NULL) {
2917 + nf = libcfs_str2net_internal(sep + 1, &net);
2919 + return LNET_NID_ANY;
2921 + sep = str + strlen(str);
2922 + net = LNET_MKNET(SOCKLND, 0);
2923 + nf = libcfs_lnd2netstrfns(SOCKLND);
2925 + return LNET_NID_ANY;
2928 + if (!nf->nf_str2addr(str, sep - str, &addr))
2929 + return LNET_NID_ANY;
2931 + return LNET_MKNID(net, addr);
2934 +/****************************************
2935 + * user mapping database handling *
2936 + * (very rudiment) *
2937 + ****************************************/
2939 +#define MAPPING_GROW_SIZE 512
2940 +#define MAX_LINE_LEN 1024
2942 +struct user_map_item {
2943 + char *principal; /* NULL means match all */
2948 +struct user_mapping {
2951 + struct user_map_item *items;
2954 +static struct user_mapping mapping = {0, 0, NULL};
2955 +/* FIXME to be finished: monitor change of mapping database */
2956 +static int mapping_mtime = 0;
2959 +void cleanup_mapping(void)
2963 + for (n = 0; n < mapping.nitems; n++) {
2964 + if (mapping.items[n].principal)
2965 + free(mapping.items[n].principal);
2967 + mapping.nitems = 0;
2971 +int grow_mapping(int size)
2973 + struct user_map_item *new;
2976 + if (size <= mapping.size)
2979 + newsize = mapping.size + MAPPING_GROW_SIZE;
2980 + while (newsize < size)
2981 + newsize += MAPPING_GROW_SIZE;
2983 + new = malloc(newsize * sizeof(struct user_map_item));
2985 + printerr(0, "can't alloc mapping size %d\n", newsize);
2988 + memcpy(new, mapping.items, mapping.nitems * sizeof(void*));
2989 + free(mapping.items);
2990 + mapping.items = new;
2991 + mapping.size = newsize;
2995 +uid_t parse_uid(char *uidstr)
2997 + struct passwd *pw;
3001 + pw = getpwnam(uidstr);
3003 + return pw->pw_uid;
3005 + uid = strtol(uidstr, &p, 0);
3007 + return (uid_t) uid;
3013 +int read_mapping_db(void)
3015 + char princ[MAX_LINE_LEN];
3016 + char nid_str[MAX_LINE_LEN];
3017 + char dest[MAX_LINE_LEN];
3021 + char *line, linebuf[MAX_LINE_LEN];
3023 + /* cleanup old mappings */
3024 + cleanup_mapping();
3026 + f = fopen(MAPPING_DATABASE_FILE, "r");
3028 + printerr(0, "can't open mapping database: %s\n",
3029 + MAPPING_DATABASE_FILE);
3033 + while ((line = fgets(linebuf, MAX_LINE_LEN, f))) {
3036 + if (strlen(line) >= MAX_LINE_LEN) {
3037 + printerr(0, "invalid mapping db: line too long (%d)\n",
3039 + cleanup_mapping();
3043 + if (sscanf(line, "%s %s %s", princ, nid_str, dest) != 3) {
3044 + printerr(0, "mapping db: syntax error\n");
3045 + cleanup_mapping();
3049 + if (grow_mapping(mapping.nitems + 1)) {
3050 + printerr(0, "fail to grow mapping to %d\n",
3051 + mapping.nitems + 1);
3055 + if (!strcmp(princ, "*")) {
3058 + name = strdup(princ);
3060 + printerr(0, "fail to dup str %s\n", princ);
3065 + if (!strcmp(nid_str, "*")) {
3066 + nid = LNET_NID_ANY;
3068 + nid = libcfs_str2nid(nid_str);
3069 + if (nid == LNET_NID_ANY) {
3070 + printerr(0, "fail to parse nid %s\n", nid_str);
3075 + dest_uid = parse_uid(dest);
3076 + if (dest_uid == -1) {
3077 + printerr(0, "no valid user: %s\n", dest);
3083 + mapping.items[mapping.nitems].principal = name;
3084 + mapping.items[mapping.nitems].nid = nid;
3085 + mapping.items[mapping.nitems].uid = dest_uid;
3087 + printerr(1, "add mapping: %s(%s/0x%llx) ==> %d\n",
3088 + name ? name : "*", nid_str, nid, dest_uid);
3094 +static inline int mapping_changed(void)
3098 + if (stat(MAPPING_DATABASE_FILE, &st) == -1) {
3099 + /* stat failed, treat it like doesn't exist or be removed */
3100 + if (mapping_mtime == 0) {
3103 + printerr(0, "Warning: stat %s failed: %s\n",
3104 + MAPPING_DATABASE_FILE, strerror(errno));
3106 + mapping_mtime = 0;
3111 + if (st.st_mtime != mapping_mtime) {
3112 + mapping_mtime = st.st_mtime;
3119 +int lookup_mapping(char *princ, lnet_nid_t nid, uid_t *uid)
3123 + /* FIXME race condition here */
3124 + if (mapping_changed()) {
3125 + if (read_mapping_db())
3126 + printerr(0, "all remote users will be denied\n");
3129 + for (n = 0; n < mapping.nitems; n++) {
3130 + struct user_map_item *entry = &mapping.items[n];
3132 + if (entry->nid != LNET_NID_ANY && entry->nid != nid)
3134 + if (!entry->principal ||
3135 + !strcasecmp(entry->principal, princ)) {
3136 + printerr(1, "found mapping: %s ==> %d\n",
3137 + princ, entry->uid);
3138 + *uid = entry->uid;
3142 + printerr(2, "no mapping for %s/%#Lx\n", princ, nid);
3147 diff -rup nfs-utils-1.0.10.orig/utils/gssd/lsupport.h nfs-utils-1.0.10/utils/gssd/lsupport.h
3148 --- nfs-utils-1.0.10.orig/utils/gssd/lsupport.h 2006-11-15 21:41:23.000000000 -0700
3149 +++ nfs-utils-1.0.10/utils/gssd/lsupport.h 2006-12-15 15:12:23.000000000 -0700
3151 +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
3152 + * vim:expandtab:shiftwidth=8:tabstop=8:
3155 +#ifndef __LIBCFS_H__
3156 +#define __LIBCFS_H__
3158 +#include <unistd.h>
3159 +#include <stdint.h>
3161 +#define GSSD_CLI (0)
3162 +#define GSSD_SVC (1)
3164 +void gssd_init_unique(int type);
3165 +void gssd_exit_unique(int type);
3168 + * copied from lustre source
3171 +#define LUSTRE_GSS_SVC_MDS 0
3172 +#define LUSTRE_GSS_SVC_OSS 1
3174 +struct lgssd_upcall_data {
3184 +#define GSSD_INTERFACE_VERSION (1)
3186 +struct lgssd_ioctl_param {
3187 + int version; /* in */
3188 + char *uuid; /* in */
3189 + int lustre_svc; /* in */
3190 + uid_t uid; /* in */
3191 + gid_t gid; /* in */
3192 + long send_token_size;/* in */
3193 + char *send_token; /* in */
3194 + long reply_buf_size; /* in */
3195 + char *reply_buf; /* in */
3196 + long status; /* out */
3197 + long reply_length; /* out */
3200 +#define GSSD_DEFAULT_GETHOSTNAME_EX "/etc/lustre/nid2hostname"
3201 +#define MAPPING_DATABASE_FILE "/etc/lustre/idmap.conf"
3203 +typedef uint64_t lnet_nid_t;
3204 +typedef uint32_t lnet_netid_t;
3206 +#define LNET_NID_ANY ((lnet_nid_t) -1)
3207 +#define LNET_PID_ANY ((lnet_pid_t) -1)
3210 + /* Only add to these values (i.e. don't ever change or redefine them):
3211 + * network addresses depend on them... */
3223 + LND_ENUM_END_MARKER
3226 +int lnet_nid2hostname(lnet_nid_t nid, char *buf, int buflen);
3227 +int lookup_mapping(char *princ, uint64_t nid, uid_t *uid);
3228 +lnet_nid_t libcfs_str2nid(char *str);
3230 +/* how an LNET NID encodes net:address */
3231 +#define LNET_NIDADDR(nid) ((uint32_t)((nid) & 0xffffffff))
3232 +#define LNET_NIDNET(nid) ((uint32_t)(((nid) >> 32)) & 0xffffffff)
3233 +#define LNET_MKNID(net,addr) ((((uint64_t)(net))<<32)|((uint64_t)(addr)))
3234 +/* how net encodes type:number */
3235 +#define LNET_NETNUM(net) ((net) & 0xffff)
3236 +#define LNET_NETTYP(net) (((net) >> 16) & 0xffff)
3237 +#define LNET_MKNET(typ,num) ((((uint32_t)(typ))<<16)|((uint32_t)(num)))
3239 +#endif /* __LIBCFS_H__ */
3240 diff -rup nfs-utils-1.0.10.orig/utils/gssd/Makefile.am nfs-utils-1.0.10/utils/gssd/Makefile.am
3241 --- nfs-utils-1.0.10.orig/utils/gssd/Makefile.am 2006-11-15 21:26:08.000000000 -0700
3242 +++ nfs-utils-1.0.10/utils/gssd/Makefile.am 2006-12-15 15:11:52.000000000 -0700
3244 ## Process this file with automake to produce Makefile.in
3246 -man8_MANS = gssd.man svcgssd.man
3251 -sbin_PREFIXED = gssd svcgssd
3252 -sbin_PROGRAMS = $(sbin_PREFIXED) gss_clnt_send_err
3253 +sbin_PREFIXED = lgssd lsvcgssd
3254 +sbin_PROGRAMS = $(sbin_PREFIXED)
3255 sbin_SCRIPTS = gss_destroy_creds
3258 - gss_destroy_creds \
3264 @@ -21,13 +15,15 @@ COMMON_SRCS = \
3282 @@ -38,13 +34,12 @@ gssd_SOURCES = \
3286 -gssd_LDADD = $(RPCSECGSS_LIBS) $(KRBLIBS)
3287 -gssd_LDFLAGS = $(KRBLDFLAGS)
3288 +lgssd_LDADD = $(GSSAPI_LIBS) $(KRBLIBS)
3289 +lgssd_LDFLAGS = $(KRBLDFLAGS)
3291 -gssd_CFLAGS = $(AM_CFLAGS) $(CFLAGS) \
3292 - $(RPCSECGSS_CFLAGS) $(KRBCFLAGS)
3293 +lgssd_CFLAGS = $(AM_CFLAGS) $(CFLAGS) $(GSSAPI_CFLAGS) $(KRBCFLAGS)
3295 -svcgssd_SOURCES = \
3296 +lsvcgssd_SOURCES = \
3300 @@ -55,20 +50,11 @@ svcgssd_SOURCES = \
3305 - ../../support/nfs/libnfs.a \
3306 - $(RPCSECGSS_LIBS) -lnfsidmap \
3309 -svcgssd_LDFLAGS = $(KRBLDFLAGS)
3311 -svcgssd_CFLAGS = $(AM_CFLAGS) $(CFLAGS) \
3312 - $(RPCSECGSS_CFLAGS) $(KRBCFLAGS)
3313 +lsvcgssd_LDADD = $(GSSAPI_LIBS) $(KRBLIBS)
3315 -gss_clnt_send_err_SOURCES = gss_clnt_send_err.c
3316 +lsvcgssd_LDFLAGS = $(KRBLDFLAGS)
3318 -gss_clnt_send_err_CFLAGS = $(AM_CFLAGS) $(CFLAGS) \
3319 - $(RPCSECGSS_CFLAGS) $(KRBCFLAGS)
3320 +lsvcgssd_CFLAGS = $(AM_CFLAGS) $(CFLAGS) $(GSSAPI_CFLAGS) $(KRBCFLAGS)
3322 MAINTAINERCLEANFILES = Makefile.in
3324 @@ -92,23 +78,3 @@ uninstall-hook:
3328 -# XXX This makes some assumptions about what automake does.
3329 -# XXX But there is no install-man-hook or install-man-local.
3330 -install-man: install-man8 install-man-links
3331 -uninstall-man: uninstall-man8 uninstall-man-links
3334 - (cd $(DESTDIR)$(man8dir) && \
3335 - for m in $(man8_MANS) $(dist_man8_MANS) $(nodist_man8_MANS); do \
3336 - inst=`echo $$m | sed -e 's/man$$/8/'`; \
3337 - rm -f $(RPCPREFIX)$$inst ; \
3338 - $(LN_S) $$inst $(RPCPREFIX)$$inst ; \
3341 -uninstall-man-links:
3342 - (cd $(DESTDIR)$(man8dir) && \
3343 - for m in $(man8_MANS) $(dist_man8_MANS) $(nodist_man8_MANS); do \
3344 - inst=`echo $$m | sed -e 's/man$$/8/'`; \
3345 - rm -f $(RPCPREFIX)$$inst ; \
3348 diff -rup nfs-utils-1.0.10.orig/utils/gssd/svcgssd.c nfs-utils-1.0.10/utils/gssd/svcgssd.c
3349 --- nfs-utils-1.0.10.orig/utils/gssd/svcgssd.c 2006-08-07 00:40:50.000000000 -0600
3350 +++ nfs-utils-1.0.10/utils/gssd/svcgssd.c 2006-12-15 15:12:23.000000000 -0700
3352 #include <sys/types.h>
3353 #include <sys/stat.h>
3354 #include <sys/socket.h>
3355 -#include <rpc/rpc.h>
3363 -#include "nfslib.h"
3364 +#include <dirent.h>
3365 #include "svcgssd.h"
3366 #include "gss_util.h"
3367 #include "err_util.h"
3368 +#include "lsupport.h"
3373 + DIR *dir = opendir("/proc/self/fd");
3374 + if (dir != NULL) {
3375 + int dfd = dirfd(dir);
3378 + while ((d = readdir(dir)) != NULL) {
3380 + long n = strtol(d->d_name, &endp, 10);
3381 + if (*endp != '\0' && n >= min && n != dfd)
3386 + int fd = sysconf(_SC_OPEN_MAX);
3387 + while (--fd >= min)
3392 * mydaemon creates a pipe between the partent and child
3393 * process. The parent process will wait until the
3394 @@ -165,8 +186,8 @@ main(int argc, char *argv[])
3398 - int rpc_verbosity = 0;
3400 + int must_srv_mds = 0, must_srv_oss = 0;
3401 extern char *optarg;
3404 @@ -181,8 +202,13 @@ main(int argc, char *argv[])
3420 @@ -196,27 +222,18 @@ main(int argc, char *argv[])
3423 initerr(progname, verbosity, fg);
3424 -#ifdef HAVE_AUTHGSS_SET_DEBUG_LEVEL
3425 - authgss_set_debug_level(rpc_verbosity);
3427 - if (rpc_verbosity > 0)
3428 - printerr(0, "Warning: rpcsec_gss library does not "
3429 - "support setting debug level\n");
3432 if (gssd_check_mechs() != 0) {
3433 printerr(0, "ERROR: Problem with gssapi library\n");
3440 - signal(SIGINT, sig_die);
3441 - signal(SIGTERM, sig_die);
3442 - signal(SIGHUP, sig_hup);
3443 + if (gssd_get_local_realm()) {
3444 + printerr(0, "ERROR: Can't get Local Kerberos realm\n");
3448 - if (get_creds && !gssd_acquire_cred(GSSD_SERVICE_NAME)) {
3449 + if (get_creds && gssd_prepare_creds(must_srv_mds, must_srv_oss)) {
3450 printerr(0, "unable to obtain root (machine) credentials\n");
3451 printerr(0, "do you have a keytab entry for "
3452 "nfs/<your.host>@<YOUR.REALM> in "
3453 @@ -225,9 +242,18 @@ main(int argc, char *argv[])
3459 + signal(SIGINT, sig_die);
3460 + signal(SIGTERM, sig_die);
3461 + signal(SIGHUP, sig_hup);
3467 + gssd_init_unique(GSSD_SVC);
3470 printerr(0, "gssd_run returned!\n");
3473 diff -rup nfs-utils-1.0.10.orig/utils/gssd/svcgssd.h nfs-utils-1.0.10/utils/gssd/svcgssd.h
3474 --- nfs-utils-1.0.10.orig/utils/gssd/svcgssd.h 2006-08-07 00:40:50.000000000 -0600
3475 +++ nfs-utils-1.0.10/utils/gssd/svcgssd.h 2006-12-15 15:12:23.000000000 -0700
3477 #include <sys/queue.h>
3478 #include <gssapi/gssapi.h>
3480 -void handle_nullreq(FILE *f);
3481 -void gssd_run(void);
3482 +int handle_nullreq(FILE *f);
3483 +void svcgssd_run(void);
3484 +int gssd_prepare_creds(int must_srv_mds, int must_srv_oss);
3485 +gss_cred_id_t gssd_select_svc_cred(int lustre_svc);
3487 -#define GSSD_SERVICE_NAME "nfs"
3488 +extern char *mds_local_realm;
3489 +extern char *oss_local_realm;
3491 +#define GSSD_SERVICE_NAME "lustre"
3494 +#define GSSD_SERVICE_MDS "lustre_mds"
3495 +#define GSSD_SERVICE_OSS "lustre_oss"
3496 +#define LUSTRE_ROOT_NAME "lustre_root"
3497 +#define LUSTRE_ROOT_NAMELEN 11
3499 #endif /* _RPC_SVCGSSD_H_ */
3500 diff -rup nfs-utils-1.0.10.orig/utils/gssd/svcgssd_main_loop.c nfs-utils-1.0.10/utils/gssd/svcgssd_main_loop.c
3501 --- nfs-utils-1.0.10.orig/utils/gssd/svcgssd_main_loop.c 2006-08-07 00:40:50.000000000 -0600
3502 +++ nfs-utils-1.0.10/utils/gssd/svcgssd_main_loop.c 2006-12-15 15:12:23.000000000 -0700
3504 #include "svcgssd.h"
3505 #include "err_util.h"
3508 + * nfs4 in-kernel cache implementation make upcall failed directly
3509 + * if there's no listener detected. so here we should keep the init
3510 + * channel file open as possible as we can.
3512 + * unfortunately the proc doesn't support dir change notification.
3513 + * and when an entry get unlinked, we only got POLLIN event once,
3514 + * it's the only oppotunity we can close the file and startover.
3523 struct pollfd pollfd;
3524 + struct timespec halfsec = { .tv_sec = 0, .tv_nsec = 500000000 };
3526 -#define NULLRPC_FILE "/proc/net/rpc/auth.rpcsec.init/channel"
3527 +#define NULLRPC_FILE "/proc/net/rpc/auth.ptlrpcs.init/channel"
3529 - f = fopen(NULLRPC_FILE, "rw");
3532 - printerr(0, "failed to open %s: %s\n",
3533 - NULLRPC_FILE, strerror(errno));
3536 - pollfd.fd = fileno(f);
3537 - pollfd.events = POLLIN;
3541 + while (f == NULL) {
3542 + f = fopen(NULLRPC_FILE, "rw");
3544 + printerr(4, "failed to open %s: %s\n",
3545 + NULLRPC_FILE, strerror(errno));
3546 + nanosleep(&halfsec, NULL);
3548 + printerr(1, "successfully open %s\n",
3553 + pollfd.fd = fileno(f);
3554 + pollfd.events = POLLIN;
3557 - printerr(1, "entering poll\n");
3558 - ret = poll(&pollfd, 1, -1);
3559 + ret = poll(&pollfd, 1, 1000);
3561 - printerr(1, "leaving poll\n");
3564 - if (save_err != EINTR)
3565 - printerr(0, "error return from poll: %s\n",
3566 - strerror(save_err));
3567 + printerr(0, "error return from poll: %s\n",
3568 + strerror(save_err));
3571 } else if (ret == 0) {
3572 - /* timeout; shouldn't happen. */
3573 + printerr(3, "poll timeout\n");
3576 printerr(0, "bug: unexpected poll return %d\n",
3580 - if (pollfd.revents & POLLIN)
3581 - handle_nullreq(f);
3582 + if (pollfd.revents & POLLIN) {
3583 + if (handle_nullreq(f) < 0) {
3591 diff -rup nfs-utils-1.0.10.orig/utils/gssd/svcgssd_proc.c nfs-utils-1.0.10/utils/gssd/svcgssd_proc.c
3592 --- nfs-utils-1.0.10.orig/utils/gssd/svcgssd_proc.c 2006-08-07 00:40:50.000000000 -0600
3593 +++ nfs-utils-1.0.10/utils/gssd/svcgssd_proc.c 2006-12-15 15:12:23.000000000 -0700
3596 #include <sys/param.h>
3597 #include <sys/stat.h>
3598 -#include <rpc/rpc.h>
3606 -#include <nfsidmap.h>
3609 #include "svcgssd.h"
3610 #include "gss_util.h"
3611 #include "err_util.h"
3612 #include "context.h"
3613 #include "cacheio.h"
3614 +#include "lsupport.h"
3616 extern char * mech2file(gss_OID mech);
3617 -#define SVCGSSD_CONTEXT_CHANNEL "/proc/net/rpc/auth.rpcsec.context/channel"
3618 -#define SVCGSSD_INIT_CHANNEL "/proc/net/rpc/auth.rpcsec.init/channel"
3619 +#define SVCGSSD_CONTEXT_CHANNEL "/proc/net/rpc/auth.ptlrpcs.context/channel"
3620 +#define SVCGSSD_INIT_CHANNEL "/proc/net/rpc/auth.ptlrpcs.init/channel"
3622 #define TOKEN_BUF_SIZE 8192
3628 - gid_t cr_groups[NGROUPS];
3629 + uint32_t cr_remote;
3630 + uint32_t cr_usr_root;
3631 + uint32_t cr_usr_mds;
3633 + uid_t cr_mapped_uid;
3638 @@ -70,10 +72,9 @@ do_svc_downcall(gss_buffer_desc *out_han
3639 gss_OID mech, gss_buffer_desc *context_token)
3645 - printerr(1, "doing downcall\n");
3646 + printerr(2, "doing downcall\n");
3647 if ((fname = mech2file(mech)) == NULL)
3649 f = fopen(SVCGSSD_CONTEXT_CHANNEL, "w");
3650 @@ -86,11 +87,12 @@ do_svc_downcall(gss_buffer_desc *out_han
3651 qword_printhex(f, out_handle->value, out_handle->length);
3652 /* XXX are types OK for the rest of this? */
3653 qword_printint(f, 0x7fffffff); /*XXX need a better timeout */
3654 + qword_printint(f, cred->cr_remote);
3655 + qword_printint(f, cred->cr_usr_root);
3656 + qword_printint(f, cred->cr_usr_mds);
3657 + qword_printint(f, cred->cr_mapped_uid);
3658 qword_printint(f, cred->cr_uid);
3659 qword_printint(f, cred->cr_gid);
3660 - qword_printint(f, cred->cr_ngroups);
3661 - for (i=0; i < cred->cr_ngroups; i++)
3662 - qword_printint(f, cred->cr_groups[i]);
3663 qword_print(f, fname);
3664 qword_printhex(f, context_token->value, context_token->length);
3666 @@ -119,7 +121,7 @@ send_response(FILE *f, gss_buffer_desc *
3670 - printerr(1, "sending null reply\n");
3671 + printerr(2, "sending null reply\n");
3673 qword_addhex(&bp, &blen, in_handle->value, in_handle->length);
3674 qword_addhex(&bp, &blen, in_token->value, in_token->length);
3675 @@ -159,6 +161,7 @@ send_response(FILE *f, gss_buffer_desc *
3676 #define rpcsec_gsserr_credproblem 13
3677 #define rpcsec_gsserr_ctxproblem 14
3681 add_supplementary_groups(char *secname, char *name, struct svc_cred *cred)
3683 @@ -182,7 +185,9 @@ add_supplementary_groups(char *secname,
3691 get_ids(gss_name_t client_name, gss_OID mech, struct svc_cred *cred)
3693 @@ -248,7 +253,9 @@ out_free:
3701 print_hexl(int pri, unsigned char *cp, int length)
3703 @@ -285,12 +292,121 @@ print_hexl(int pri, unsigned char *cp, i
3711 +get_ids(gss_name_t client_name, gss_OID mech, struct svc_cred *cred,
3712 + lnet_nid_t nid, uint32_t lustre_svc)
3714 + u_int32_t maj_stat, min_stat;
3715 + gss_buffer_desc name;
3716 + char *sname, *realm, *slash;
3718 + gss_OID name_type = GSS_C_NO_OID;
3719 + struct passwd *pw;
3721 + cred->cr_remote = cred->cr_usr_root = cred->cr_usr_mds = 0;
3722 + cred->cr_uid = cred->cr_mapped_uid = cred->cr_gid = -1;
3724 + maj_stat = gss_display_name(&min_stat, client_name, &name, &name_type);
3725 + if (maj_stat != GSS_S_COMPLETE) {
3726 + pgsserr("get_ids: gss_display_name",
3727 + maj_stat, min_stat, mech);
3730 + if (name.length >= 0xffff || /* be certain name.length+1 doesn't overflow */
3731 + !(sname = calloc(name.length + 1, 1))) {
3732 + printerr(0, "WARNING: get_ids: error allocating %d bytes "
3733 + "for sname\n", name.length + 1);
3734 + gss_release_buffer(&min_stat, &name);
3737 + memcpy(sname, name.value, name.length);
3738 + printerr(1, "authenticated %s from %016llx\n", sname, nid);
3739 + gss_release_buffer(&min_stat, &name);
3741 + if (lustre_svc == LUSTRE_GSS_SVC_MDS)
3742 + lookup_mapping(sname, nid, &cred->cr_mapped_uid);
3744 + cred->cr_mapped_uid = -1;
3746 + realm = strchr(sname, '@');
3748 + printerr(0, "WARNNING: principal %s contains no realm name\n",
3750 + cred->cr_remote = (mds_local_realm != NULL);
3753 + if (!mds_local_realm)
3754 + cred->cr_remote = 1;
3757 + (strcasecmp(mds_local_realm, realm) != 0);
3760 + if (cred->cr_remote) {
3761 + if (cred->cr_mapped_uid != -1)
3763 + else if (lustre_svc == LUSTRE_GSS_SVC_OSS &&
3764 + strcmp(sname, "lustre_root") == 0)
3767 + printerr(0, "principal %s is remote without mapping\n",
3772 + slash = strchr(sname, '/');
3776 + if (!(pw = getpwnam(sname))) {
3777 + /* If client use machine credential, we map it to root, which
3778 + * will subject to further mapping by root-squash in kernel.
3780 + * MDS service keytab is treated as special user, also mapped
3781 + * to root. OSS service keytab can't be used as a user.
3783 + if (!strcmp(sname, LUSTRE_ROOT_NAME)) {
3784 + printerr(2, "lustre_root principal, resolve to uid 0\n");
3786 + cred->cr_usr_root = 1;
3787 + } else if (!strcmp(sname, GSSD_SERVICE_MDS)) {
3788 + printerr(2, "mds service principal, resolve to uid 0\n");
3790 + cred->cr_usr_mds = 1;
3792 + cred->cr_uid = -1;
3793 + if (cred->cr_mapped_uid == -1) {
3794 + printerr(0, "invalid user %s\n", sname);
3797 + printerr(2, "user %s mapped to %u\n",
3798 + sname, cred->cr_mapped_uid);
3801 + cred->cr_uid = pw->pw_uid;
3802 + printerr(2, "%s resolve to uid %u\n", sname, cred->cr_uid);
3811 +typedef struct gss_union_ctx_id_t {
3812 + gss_OID mech_type;
3813 + gss_ctx_id_t internal_ctx_id;
3814 +} gss_union_ctx_id_desc, *gss_union_ctx_id_t;
3817 + * return -1 only if we detect error during reading from upcall channel,
3818 + * all other cases return 0.
3821 handle_nullreq(FILE *f) {
3822 - /* XXX initialize to a random integer to reduce chances of unnecessary
3823 - * invalidation of existing ctx's on restarting svcgssd. */
3824 - static u_int32_t handle_seq = 0;
3825 + uint64_t handle_seq;
3826 char in_tok_buf[TOKEN_BUF_SIZE];
3827 char in_handle_buf[15];
3828 char out_handle_buf[15];
3829 @@ -302,10 +418,13 @@ handle_nullreq(FILE *f) {
3830 ignore_out_tok = {.value = NULL},
3831 /* XXX isn't there a define for this?: */
3832 null_token = {.value = NULL};
3833 + uint32_t lustre_svc;
3835 u_int32_t ret_flags;
3836 gss_ctx_id_t ctx = GSS_C_NO_CONTEXT;
3837 gss_name_t client_name;
3838 gss_OID mech = GSS_C_NO_OID;
3839 + gss_cred_id_t svc_cred;
3840 u_int32_t maj_stat = GSS_S_FAILURE, min_stat = 0;
3841 u_int32_t ignore_min_stat;
3842 struct svc_cred cred;
3843 @@ -313,25 +432,31 @@ handle_nullreq(FILE *f) {
3844 static int lbuflen = 0;
3847 - printerr(1, "handling null request\n");
3848 + printerr(2, "handling null request\n");
3850 if (readline(fileno(f), &lbuf, &lbuflen) != 1) {
3851 printerr(0, "WARNING: handle_nullreq: "
3852 "failed reading request\n");
3859 + qword_get(&cp, (char *) &lustre_svc, sizeof(lustre_svc));
3860 + qword_get(&cp, (char *) &nid, sizeof(nid));
3861 + qword_get(&cp, (char *) &handle_seq, sizeof(handle_seq));
3862 + printerr(1, "handling req: svc %u, nid %016llx, idx %llx\n",
3863 + lustre_svc, nid, handle_seq);
3865 in_handle.length = (size_t) qword_get(&cp, in_handle.value,
3866 sizeof(in_handle_buf));
3867 - printerr(2, "in_handle: \n");
3868 - print_hexl(2, in_handle.value, in_handle.length);
3869 + printerr(3, "in_handle: \n");
3870 + print_hexl(3, in_handle.value, in_handle.length);
3872 in_tok.length = (size_t) qword_get(&cp, in_tok.value,
3873 sizeof(in_tok_buf));
3874 - printerr(2, "in_tok: \n");
3875 - print_hexl(2, in_tok.value, in_tok.length);
3876 + printerr(3, "in_tok: \n");
3877 + print_hexl(3, in_tok.value, in_tok.length);
3879 if (in_tok.length < 0) {
3880 printerr(0, "WARNING: handle_nullreq: "
3881 @@ -351,7 +476,13 @@ handle_nullreq(FILE *f) {
3882 memcpy(&ctx, in_handle.value, in_handle.length);
3885 - maj_stat = gss_accept_sec_context(&min_stat, &ctx, gssd_creds,
3886 + svc_cred = gssd_select_svc_cred(lustre_svc);
3888 + printerr(0, "no service credential for svc %u\n", lustre_svc);
3892 + maj_stat = gss_accept_sec_context(&min_stat, &ctx, svc_cred,
3893 &in_tok, GSS_C_NO_CHANNEL_BINDINGS, &client_name,
3894 &mech, &out_tok, &ret_flags, NULL, NULL);
3896 @@ -369,7 +500,8 @@ handle_nullreq(FILE *f) {
3897 maj_stat, min_stat, mech);
3900 - if (get_ids(client_name, mech, &cred)) {
3902 + if (get_ids(client_name, mech, &cred, nid, lustre_svc)) {
3903 /* get_ids() prints error msg */
3904 maj_stat = GSS_S_BAD_NAME; /* XXX ? */
3905 gss_release_name(&ignore_min_stat, &client_name);
3906 @@ -377,10 +509,8 @@ handle_nullreq(FILE *f) {
3908 gss_release_name(&ignore_min_stat, &client_name);
3911 /* Context complete. Pass handle_seq in out_handle to use
3912 * for context lookup in the kernel. */
3914 out_handle.length = sizeof(handle_seq);
3915 memcpy(out_handle.value, &handle_seq, sizeof(handle_seq));
3917 @@ -404,8 +534,7 @@ out:
3918 free(ctx_token.value);
3919 if (out_tok.value != NULL)
3920 gss_release_buffer(&ignore_min_stat, &out_tok);
3921 - printerr(1, "finished handling null request\n");
3926 if (ctx != GSS_C_NO_CONTEXT)
3927 diff -rup nfs-utils-1.0.10.orig/utils/Makefile.am nfs-utils-1.0.10/utils/Makefile.am
3928 --- nfs-utils-1.0.10.orig/utils/Makefile.am 2006-08-07 00:40:50.000000000 -0600
3929 +++ nfs-utils-1.0.10/utils/Makefile.am 2006-12-15 15:11:52.000000000 -0700
3962 MAINTAINERCLEANFILES = Makefile.in