X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fgssd%2Fsvcgssd_proc.c;h=6f2ba61e31edfc62c5b60bf379c80b0631690299;hp=2251d9ab84a1feee03b7a4a8bd88f62262fbd157;hb=7de6c8c54ac195d659c8ac2d2ac01ef47c6c3ecd;hpb=1f1b05a65ef3dc6597c7bc1e2a38f38ae95bf230 diff --git a/utils/gssd/svcgssd_proc.c b/utils/gssd/svcgssd_proc.c index 2251d9a..6f2ba61 100644 --- a/utils/gssd/svcgssd_proc.c +++ b/utils/gssd/svcgssd_proc.c @@ -33,6 +33,10 @@ */ +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + #include #include #include @@ -45,12 +49,13 @@ #include #include #include +#include +#include #include "svcgssd.h" #include "gss_util.h" #include "err_util.h" #include "context.h" -#include "cacheio.h" extern char * mech2file(gss_OID mech); #define SVCGSSD_CONTEXT_CHANNEL "/proc/net/rpc/auth.rpcsec.context/channel" @@ -67,11 +72,13 @@ struct svc_cred { static int do_svc_downcall(gss_buffer_desc *out_handle, struct svc_cred *cred, - gss_OID mech, gss_buffer_desc *context_token) + gss_OID mech, gss_buffer_desc *context_token, + int32_t endtime) { FILE *f; int i; char *fname = NULL; + int err; printerr(1, "doing downcall\n"); if ((fname = mech2file(mech)) == NULL) @@ -85,19 +92,31 @@ do_svc_downcall(gss_buffer_desc *out_handle, struct svc_cred *cred, } qword_printhex(f, out_handle->value, out_handle->length); /* XXX are types OK for the rest of this? */ - qword_printint(f, 0x7fffffff); /*XXX need a better timeout */ + /* For context cache, use the actual context endtime */ + qword_printint(f, endtime); qword_printint(f, cred->cr_uid); qword_printint(f, cred->cr_gid); qword_printint(f, cred->cr_ngroups); - for (i=0; i < cred->cr_ngroups; i++) + printerr(2, "mech: %s, hndl len: %d, ctx len %d, timeout: %d (%d from now), " + "uid: %d, gid: %d, num aux grps: %d:\n", + fname, out_handle->length, context_token->length, + endtime, endtime - time(0), + cred->cr_uid, cred->cr_gid, cred->cr_ngroups); + for (i=0; i < cred->cr_ngroups; i++) { qword_printint(f, cred->cr_groups[i]); + printerr(2, " (%4d) %d\n", i+1, cred->cr_groups[i]); + } qword_print(f, fname); qword_printhex(f, context_token->value, context_token->length); - qword_eol(f); + err = qword_eol(f); + if (err) { + printerr(1, "WARNING: error writing to downcall channel " + "%s: %s\n", SVCGSSD_CONTEXT_CHANNEL, strerror(errno)); + } fclose(f); - return 0; + return err; out_err: - printerr(0, "WARNING: downcall failed\n"); + printerr(1, "WARNING: downcall failed\n"); return -1; } @@ -123,9 +142,10 @@ send_response(FILE *f, gss_buffer_desc *in_handle, gss_buffer_desc *in_token, qword_addhex(&bp, &blen, in_handle->value, in_handle->length); qword_addhex(&bp, &blen, in_token->value, in_token->length); - qword_addint(&bp, &blen, 0x7fffffff); /*XXX need a better timeout */ - qword_addint(&bp, &blen, maj_stat); - qword_addint(&bp, &blen, min_stat); + /* For init cache, only needed for a short time */ + qword_addint(&bp, &blen, time(0) + 60); + qword_adduint(&bp, &blen, maj_stat); + qword_adduint(&bp, &blen, min_stat); qword_addhex(&bp, &blen, out_handle->value, out_handle->length); qword_addhex(&bp, &blen, out_token->value, out_token->length); qword_addeol(&bp, &blen); @@ -220,8 +240,23 @@ get_ids(gss_name_t client_name, gss_OID mech, struct svc_cred *cred) nfs4_init_name_mapping(NULL); /* XXX: should only do this once */ res = nfs4_gss_princ_to_ids(secname, sname, &uid, &gid); if (res < 0) { - printerr(0, "WARNING: get_ids: unable to map " - "name '%s' to a uid\n", sname); + /* + * -ENOENT means there was no mapping, any other error + * value means there was an error trying to do the + * mapping. + * If there was no mapping, we send down the value -1 + * to indicate that the anonuid/anongid for the export + * should be used. + */ + if (res == -ENOENT) { + cred->cr_uid = -1; + cred->cr_gid = -1; + cred->cr_ngroups = 0; + res = 0; + goto out_free; + } + printerr(1, "WARNING: get_ids: failed to map name '%s' " + "to uid/gid: %s\n", sname, strerror(-res)); goto out_free; } cred->cr_uid = uid; @@ -234,42 +269,43 @@ out: return res; } +#ifdef DEBUG void -print_hexl(int pri, unsigned char *cp, int length) +print_hexl(const char *description, unsigned char *cp, int length) { int i, j, jm; unsigned char c; - printerr(pri, "length %d\n",length); - printerr(pri, "\n"); + printf("%s (length %d)\n", description, length); for (i = 0; i < length; i += 0x10) { - printerr(pri, " %04x: ", (u_int)i); + printf(" %04x: ", (u_int)i); jm = length - i; jm = jm > 16 ? 16 : jm; for (j = 0; j < jm; j++) { if ((j % 2) == 1) - printerr(pri,"%02x ", (u_int)cp[i+j]); + printf("%02x ", (u_int)cp[i+j]); else - printerr(pri,"%02x", (u_int)cp[i+j]); + printf("%02x", (u_int)cp[i+j]); } for (; j < 16; j++) { if ((j % 2) == 1) - printerr(pri," "); + printf(" "); else - printerr(pri," "); + printf(" "); } - printerr(pri," "); + printf(" "); for (j = 0; j < jm; j++) { c = cp[i+j]; c = isprint(c) ? c : '.'; - printerr(pri,"%c", c); + printf("%c", c); } - printerr(pri,"\n"); + printf("\n"); } } +#endif void handle_nullreq(FILE *f) { @@ -297,6 +333,7 @@ handle_nullreq(FILE *f) { static char *lbuf = NULL; static int lbuflen = 0; static char *cp; + int32_t ctx_endtime; printerr(1, "handling null request\n"); @@ -310,13 +347,15 @@ handle_nullreq(FILE *f) { in_handle.length = (size_t) qword_get(&cp, in_handle.value, sizeof(in_handle_buf)); - printerr(2, "in_handle: \n"); - print_hexl(2, in_handle.value, in_handle.length); +#ifdef DEBUG + print_hexl("in_handle", in_handle.value, in_handle.length); +#endif in_tok.length = (size_t) qword_get(&cp, in_tok.value, sizeof(in_tok_buf)); - printerr(2, "in_tok: \n"); - print_hexl(2, in_tok.value, in_tok.length); +#ifdef DEBUG + print_hexl("in_tok", in_tok.value, in_tok.length); +#endif if (in_tok.length < 0) { printerr(0, "WARNING: handle_nullreq: " @@ -349,7 +388,7 @@ handle_nullreq(FILE *f) { goto continue_needed; } else if (maj_stat != GSS_S_COMPLETE) { - printerr(0, "WARNING: gss_accept_sec_context failed\n"); + printerr(1, "WARNING: gss_accept_sec_context failed\n"); pgsserr("handle_nullreq: gss_accept_sec_context", maj_stat, min_stat, mech); goto out_err; @@ -371,7 +410,7 @@ handle_nullreq(FILE *f) { /* kernel needs ctx to calculate verifier on null response, so * must give it context before doing null call: */ - if (serialize_context_for_kernel(ctx, &ctx_token, mech)) { + if (serialize_context_for_kernel(ctx, &ctx_token, mech, &ctx_endtime)) { printerr(0, "WARNING: handle_nullreq: " "serialize_context_for_kernel failed\n"); maj_stat = GSS_S_FAILURE; @@ -380,7 +419,7 @@ handle_nullreq(FILE *f) { /* We no longer need the gss context */ gss_delete_sec_context(&ignore_min_stat, &ctx, &ignore_out_tok); - do_svc_downcall(&out_handle, &cred, mech, &ctx_token); + do_svc_downcall(&out_handle, &cred, mech, &ctx_token, ctx_endtime); continue_needed: send_response(f, &in_handle, &in_tok, maj_stat, min_stat, &out_handle, &out_tok);