X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fgssd%2Fsvcgssd_proc.c;h=2dffa83b195f82526acddab3eb085314ac354442;hp=fd1076efc6fc0b894f95d01b1aa01441d4269e24;hb=44f7f2f92038572663acf22b4fd8dc34640c8c81;hpb=2ca793c93c09d0bc180b8eed9819206fd42aff21 diff --git a/utils/gssd/svcgssd_proc.c b/utils/gssd/svcgssd_proc.c index fd1076e..2dffa83 100644 --- a/utils/gssd/svcgssd_proc.c +++ b/utils/gssd/svcgssd_proc.c @@ -72,6 +72,7 @@ do_svc_downcall(gss_buffer_desc *out_handle, struct svc_cred *cred, FILE *f; int i; char *fname = NULL; + int err; printerr(1, "doing downcall\n"); if ((fname = mech2file(mech)) == NULL) @@ -89,13 +90,19 @@ do_svc_downcall(gss_buffer_desc *out_handle, struct svc_cred *cred, 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, " + "uid: %d, gid: %d, num aux grps: %d:\n", + fname, out_handle->length, context_token->length, 0x7fffffff, + 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); fclose(f); - return 0; + return err; out_err: printerr(0, "WARNING: downcall failed\n"); return -1; @@ -124,8 +131,8 @@ 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); + 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); @@ -140,7 +147,7 @@ send_response(FILE *f, gss_buffer_desc *in_handle, gss_buffer_desc *in_token, return -1; } *bp = '\0'; - printerr(1, "writing message: %s", buf); + printerr(3, "writing message: %s", buf); if (write(g, buf, bp - buf) == -1) { printerr(0, "WARNING: failed to write message\n"); close(g); @@ -193,7 +200,6 @@ get_ids(gss_name_t client_name, gss_OID mech, struct svc_cred *cred) uid_t uid, gid; gss_OID name_type = GSS_C_NO_OID; char *secname; - gid_t *groups; maj_stat = gss_display_name(&min_stat, client_name, &name, &name_type); if (maj_stat != GSS_S_COMPLETE) { @@ -201,13 +207,16 @@ get_ids(gss_name_t client_name, gss_OID mech, struct svc_cred *cred) maj_stat, min_stat, mech); goto out; } - if (!(sname = calloc(name.length + 1, 1))) { + if (name.length >= 0xffff || /* be certain name.length+1 doesn't overflow */ + !(sname = calloc(name.length + 1, 1))) { printerr(0, "WARNING: get_ids: error allocating %d bytes " "for sname\n", name.length + 1); + gss_release_buffer(&min_stat, &name); goto out; } memcpy(sname, name.value, name.length); printerr(1, "sname = %s\n", sname); + gss_release_buffer(&min_stat, &name); res = -EINVAL; if ((secname = mech2file(mech)) == NULL) { @@ -218,8 +227,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(0, "WARNING: get_ids: failed to map name '%s' " + "to uid/gid: %s\n", sname, strerror(-res)); goto out_free; } cred->cr_uid = uid; @@ -232,42 +256,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) { @@ -282,6 +307,7 @@ handle_nullreq(FILE *f) { in_handle = {.value = in_handle_buf}, out_handle = {.value = out_handle_buf}, ctx_token = {.value = NULL}, + ignore_out_tok = {.value = NULL}, /* XXX isn't there a define for this?: */ null_token = {.value = NULL}; u_int32_t ret_flags; @@ -289,6 +315,7 @@ handle_nullreq(FILE *f) { gss_name_t client_name; gss_OID mech = GSS_C_NO_OID; u_int32_t maj_stat = GSS_S_FAILURE, min_stat = 0; + u_int32_t ignore_min_stat; struct svc_cred cred; static char *lbuf = NULL; static int lbuflen = 0; @@ -306,13 +333,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: " @@ -353,8 +382,10 @@ handle_nullreq(FILE *f) { if (get_ids(client_name, mech, &cred)) { /* get_ids() prints error msg */ maj_stat = GSS_S_BAD_NAME; /* XXX ? */ + gss_release_name(&ignore_min_stat, &client_name); goto out_err; } + gss_release_name(&ignore_min_stat, &client_name); /* Context complete. Pass handle_seq in out_handle to use @@ -371,6 +402,9 @@ handle_nullreq(FILE *f) { maj_stat = GSS_S_FAILURE; goto out_err; } + /* 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); continue_needed: send_response(f, &in_handle, &in_tok, maj_stat, min_stat, @@ -378,10 +412,14 @@ continue_needed: out: if (ctx_token.value != NULL) free(ctx_token.value); + if (out_tok.value != NULL) + gss_release_buffer(&ignore_min_stat, &out_tok); printerr(1, "finished handling null request\n"); return; out_err: + if (ctx != GSS_C_NO_CONTEXT) + gss_delete_sec_context(&ignore_min_stat, &ctx, &ignore_out_tok); send_response(f, &in_handle, &in_tok, maj_stat, min_stat, &null_token, &null_token); goto out;