X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fgssd%2Fsvcgssd_proc.c;h=4ab4b2e48a261c01f797ae7687559963e5ce3c10;hp=fd1076efc6fc0b894f95d01b1aa01441d4269e24;hb=acae444246635ec2ca8990d53e685c9062d73091;hpb=2ca793c93c09d0bc180b8eed9819206fd42aff21 diff --git a/utils/gssd/svcgssd_proc.c b/utils/gssd/svcgssd_proc.c index fd1076e..4ab4b2e 100644 --- a/utils/gssd/svcgssd_proc.c +++ b/utils/gssd/svcgssd_proc.c @@ -140,7 +140,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 +193,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 +200,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 +220,21 @@ 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 (res == -ENOENT) { + cred->cr_uid = -2; /* XXX */ + cred->cr_gid = -2; /* XXX */ + cred->cr_groups[0] = -2;/* XXX */ + cred->cr_ngroups = 1; + 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; @@ -282,6 +297,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 +305,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; @@ -353,8 +370,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 +390,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 +400,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;