4 * Copyright (c) 2000 The Regents of the University of Michigan.
7 * Copyright (c) 2002 Bruce Fields <bfields@UMICH.EDU>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/param.h>
61 #define SVCGSSD_CONTEXT_CHANNEL "/proc/net/rpc/auth.sptlrpc.context/channel"
62 #define SVCGSSD_INIT_CHANNEL "/proc/net/rpc/auth.sptlrpc.init/channel"
64 #define TOKEN_BUF_SIZE 8192
76 struct svc_nego_data {
81 char nm_name[LUSTRE_NODEMAP_NAME_LENGTH + 1];
82 gss_buffer_desc in_tok;
83 gss_buffer_desc out_tok;
84 gss_buffer_desc in_handle;
85 gss_buffer_desc out_handle;
92 gss_buffer_desc ctx_token;
96 do_svc_downcall(gss_buffer_desc *out_handle, struct svc_cred *cred,
97 gss_OID mechoid, gss_buffer_desc *context_token)
100 const char *mechname;
103 printerr(2, "doing downcall\n");
104 mechname = gss_OID_mech_name(mechoid);
105 if (mechname == NULL)
107 f = fopen(SVCGSSD_CONTEXT_CHANNEL, "w");
109 printerr(0, "WARNING: unable to open downcall channel "
111 SVCGSSD_CONTEXT_CHANNEL, strerror(errno));
114 qword_printhex(f, out_handle->value, out_handle->length);
115 /* XXX are types OK for the rest of this? */
116 qword_printint(f, time(NULL) + 3600); /* 1 hour should be ok */
117 qword_printint(f, cred->cr_remote);
118 qword_printint(f, cred->cr_usr_root);
119 qword_printint(f, cred->cr_usr_mds);
120 qword_printint(f, cred->cr_usr_oss);
121 qword_printint(f, cred->cr_mapped_uid);
122 qword_printint(f, cred->cr_uid);
123 qword_printint(f, cred->cr_gid);
124 qword_print(f, mechname);
125 qword_printhex(f, context_token->value, context_token->length);
130 printerr(0, "WARNING: downcall failed\n");
134 struct gss_verifier {
136 gss_buffer_desc body;
139 #define RPCSEC_GSS_SEQ_WIN 5
142 send_response(FILE *f, gss_buffer_desc *in_handle, gss_buffer_desc *in_token,
143 u_int32_t maj_stat, u_int32_t min_stat,
144 gss_buffer_desc *out_handle, gss_buffer_desc *out_token)
146 char buf[2 * TOKEN_BUF_SIZE];
148 int blen = sizeof(buf);
152 printerr(2, "sending reply\n");
153 qword_addhex(&bp, &blen, in_handle->value, in_handle->length);
154 qword_addhex(&bp, &blen, in_token->value, in_token->length);
155 qword_addint(&bp, &blen, time(NULL) + 3600); /* 1 hour should be ok */
156 qword_adduint(&bp, &blen, maj_stat);
157 qword_adduint(&bp, &blen, min_stat);
158 qword_addhex(&bp, &blen, out_handle->value, out_handle->length);
159 qword_addhex(&bp, &blen, out_token->value, out_token->length);
160 qword_addeol(&bp, &blen);
162 printerr(0, "WARNING: send_response: message too long\n");
165 g = open(SVCGSSD_INIT_CHANNEL, O_WRONLY);
167 printerr(0, "WARNING: open %s failed: %s\n",
168 SVCGSSD_INIT_CHANNEL, strerror(errno));
172 printerr(3, "writing message: %s", buf);
173 if (write(g, buf, bp - buf) == -1) {
174 printerr(0, "WARNING: failed to write message\n");
182 #define rpc_auth_ok 0
183 #define rpc_autherr_badcred 1
184 #define rpc_autherr_rejectedcred 2
185 #define rpc_autherr_badverf 3
186 #define rpc_autherr_rejectedverf 4
187 #define rpc_autherr_tooweak 5
188 #define rpcsec_gsserr_credproblem 13
189 #define rpcsec_gsserr_ctxproblem 14
192 get_ids(gss_name_t client_name, gss_OID mech, struct svc_cred *cred,
193 lnet_nid_t nid, uint32_t lustre_svc)
195 u_int32_t maj_stat, min_stat;
196 gss_buffer_desc name;
197 char *sname, *host, *realm;
198 const int namebuf_size = 512;
199 char namebuf[namebuf_size];
201 gss_OID name_type = GSS_C_NO_OID;
205 cred->cr_usr_root = cred->cr_usr_mds = cred->cr_usr_oss = 0;
206 cred->cr_uid = cred->cr_mapped_uid = cred->cr_gid = -1;
208 maj_stat = gss_display_name(&min_stat, client_name, &name, &name_type);
209 if (maj_stat != GSS_S_COMPLETE) {
210 pgsserr("get_ids: gss_display_name",
211 maj_stat, min_stat, mech);
214 if (name.length >= 0xffff || /* be certain name.length+1 doesn't overflow */
215 !(sname = calloc(name.length + 1, 1))) {
216 printerr(0, "WARNING: get_ids: error allocating %zu bytes "
217 "for sname\n", name.length + 1);
218 gss_release_buffer(&min_stat, &name);
221 memcpy(sname, name.value, name.length);
222 sname[name.length] = '\0';
223 gss_release_buffer(&min_stat, &name);
225 if (lustre_svc == LUSTRE_GSS_SVC_MDS)
226 lookup_mapping(sname, nid, &cred->cr_mapped_uid);
228 cred->cr_mapped_uid = -1;
230 realm = strchr(sname, '@');
234 printerr(0, "ERROR: %s has no realm name\n", sname);
238 host = strchr(sname, '/');
242 if (strcmp(sname, GSSD_SERVICE_MGS) == 0) {
243 printerr(0, "forbid %s as a user name\n", sname);
247 /* 1. check host part */
249 if (lnet_nid2hostname(nid, namebuf, namebuf_size)) {
250 printerr(0, "ERROR: failed to resolve hostname for "
251 "%s/%s@%s from %016llx\n",
252 sname, host, realm, nid);
256 if (strcasecmp(host, namebuf)) {
257 printerr(0, "ERROR: %s/%s@%s claimed hostname doesn't "
258 "match %s, nid %016llx\n", sname, host, realm,
263 if (!strcmp(sname, GSSD_SERVICE_MDS) ||
264 !strcmp(sname, GSSD_SERVICE_OSS)) {
265 printerr(0, "ERROR: %s@%s from %016llx doesn't "
266 "bind with hostname\n", sname, realm, nid);
271 /* 2. check realm and user */
272 switch (lustre_svc) {
273 case LUSTRE_GSS_SVC_MDS:
274 if (strcasecmp(mds_local_realm, realm)) {
277 /* only allow mapped user from remote realm */
278 if (cred->cr_mapped_uid == -1) {
279 printerr(0, "ERROR: %s%s%s@%s from %016llx "
280 "is remote but without mapping\n",
281 sname, host ? "/" : "",
282 host ? host : "", realm, nid);
286 if (!strcmp(sname, LUSTRE_ROOT_NAME)) {
288 cred->cr_usr_root = 1;
289 } else if (!strcmp(sname, GSSD_SERVICE_MDS)) {
291 cred->cr_usr_mds = 1;
292 } else if (!strcmp(sname, GSSD_SERVICE_OSS)) {
294 cred->cr_usr_oss = 1;
296 pw = getpwnam(sname);
298 cred->cr_uid = pw->pw_uid;
299 printerr(2, "%s resolve to uid %u\n",
300 sname, cred->cr_uid);
301 } else if (cred->cr_mapped_uid != -1) {
302 printerr(2, "user %s from %016llx is "
303 "mapped to %u\n", sname, nid,
304 cred->cr_mapped_uid);
306 printerr(0, "ERROR: invalid user, "
307 "%s/%s@%s from %016llx\n",
308 sname, host, realm, nid);
316 case LUSTRE_GSS_SVC_MGS:
317 if (!strcmp(sname, GSSD_SERVICE_OSS)) {
319 cred->cr_usr_oss = 1;
322 case LUSTRE_GSS_SVC_OSS:
323 if (!strcmp(sname, LUSTRE_ROOT_NAME)) {
325 cred->cr_usr_root = 1;
326 } else if (!strcmp(sname, GSSD_SERVICE_MDS)) {
328 cred->cr_usr_mds = 1;
330 if (cred->cr_uid == -1) {
331 printerr(0, "ERROR: svc %d doesn't accept user %s "
332 "from %016llx\n", lustre_svc, sname, nid);
343 printerr(1, "%s: authenticated %s%s%s@%s from %016llx\n",
344 lustre_svc_name[lustre_svc], sname,
345 host ? "/" : "", host ? host : "", realm, nid);
350 typedef struct gss_union_ctx_id_t {
352 gss_ctx_id_t internal_ctx_id;
353 } gss_union_ctx_id_desc, *gss_union_ctx_id_t;
355 int handle_sk(struct svc_nego_data *snd)
357 #ifdef HAVE_OPENSSL_SSK
358 struct sk_cred *skc = NULL;
359 struct svc_cred cred;
360 gss_buffer_desc bufs[SK_INIT_BUFFERS];
361 gss_buffer_desc remote_pub_key = GSS_C_EMPTY_BUFFER;
363 uint32_t rc = GSS_S_DEFECTIVE_TOKEN;
369 printerr(3, "Handling sk request\n");
370 memset(bufs, 0, sizeof(gss_buffer_desc) * SK_INIT_BUFFERS);
372 /* See lgss_sk_using_cred() for client side token formation.
373 * Decoding initiator buffers */
374 i = sk_decode_netstring(bufs, SK_INIT_BUFFERS, &snd->in_tok);
375 if (i < SK_INIT_BUFFERS) {
376 printerr(0, "Invalid netstring token received from peer\n");
377 goto cleanup_buffers;
380 /* Allowing for a larger length first buffer in the future */
381 if (bufs[SK_INIT_VERSION].length < sizeof(version)) {
382 printerr(0, "Invalid version received (wrong size)\n");
383 goto cleanup_buffers;
385 memcpy(&version, bufs[SK_INIT_VERSION].value, sizeof(version));
386 version = be32toh(version);
387 if (version != SK_MSG_VERSION) {
388 printerr(0, "Invalid version received: %d\n", version);
389 goto cleanup_buffers;
394 /* target must be a null terminated string */
395 i = bufs[SK_INIT_TARGET].length - 1;
396 target = bufs[SK_INIT_TARGET].value;
397 if (i >= 0 && target[i] != '\0') {
398 printerr(0, "Invalid target from netstring\n");
399 goto cleanup_buffers;
402 if (bufs[SK_INIT_FLAGS].length != sizeof(flags)) {
403 printerr(0, "Invalid flags from netstring\n");
404 goto cleanup_buffers;
406 memcpy(&flags, bufs[SK_INIT_FLAGS].value, sizeof(flags));
408 skc = sk_create_cred(target, snd->nm_name, be32toh(flags));
410 printerr(0, "Failed to create sk credentials\n");
411 goto cleanup_buffers;
414 /* Verify that the peer has used a prime size greater or equal to
415 * the size specified in the key file which may contain only zero
416 * fill but the size specifies the mimimum supported size on
418 if (skc->sc_flags & LGSS_SVC_PRIV &&
419 bufs[SK_INIT_P].length < skc->sc_p.length) {
420 printerr(0, "Peer DHKE prime does not meet the size required "
421 "by keyfile: %zd bits\n", skc->sc_p.length * 8);
422 goto cleanup_buffers;
425 /* Throw out the p from the server and use the wire data */
426 free(skc->sc_p.value);
427 skc->sc_p.value = NULL;
428 skc->sc_p.length = 0;
430 /* Take control of all the allocated buffers from decoding */
431 if (bufs[SK_INIT_RANDOM].length !=
432 sizeof(skc->sc_kctx.skc_peer_random)) {
433 printerr(0, "Invalid size for client random\n");
434 goto cleanup_buffers;
437 memcpy(&skc->sc_kctx.skc_peer_random, bufs[SK_INIT_RANDOM].value,
438 sizeof(skc->sc_kctx.skc_peer_random));
439 skc->sc_p = bufs[SK_INIT_P];
440 remote_pub_key = bufs[SK_INIT_PUB_KEY];
441 skc->sc_nodemap_hash = bufs[SK_INIT_NODEMAP];
442 skc->sc_hmac = bufs[SK_INIT_HMAC];
444 /* Verify HMAC from peer. Ideally this would happen before anything
445 * else but we don't have enough information to lookup key without the
446 * token (fsname and cluster_hash) so it's done after. */
447 rc = sk_verify_hmac(skc, bufs, SK_INIT_BUFFERS - 1, EVP_sha256(),
449 if (rc != GSS_S_COMPLETE) {
450 printerr(0, "HMAC verification error: 0x%x from peer %s\n",
451 rc, libcfs_nid2str((lnet_nid_t)snd->nid));
452 goto cleanup_partial;
455 /* Check that the cluster hash matches the hash of nodemap name */
456 rc = sk_verify_hash(snd->nm_name, EVP_sha256(), &skc->sc_nodemap_hash);
457 if (rc != GSS_S_COMPLETE) {
458 printerr(0, "Cluster hash failed validation: 0x%x\n", rc);
459 goto cleanup_partial;
463 rc = sk_gen_params(skc);
464 if (rc != GSS_S_COMPLETE) {
465 printerr(0, "Failed to generate DH params for responder\n");
466 goto cleanup_partial;
468 rc = sk_compute_dh_key(skc, &remote_pub_key);
469 if (rc == GSS_S_BAD_QOP && attempts < 2) {
470 /* GSS_S_BAD_QOP means the generated shared key was shorter
471 * than expected. Just retry twice before giving up.
474 if (skc->sc_params) {
475 DH_free(skc->sc_params);
476 skc->sc_params = NULL;
478 if (skc->sc_pub_key.value) {
479 free(skc->sc_pub_key.value);
480 skc->sc_pub_key.value = NULL;
482 skc->sc_pub_key.length = 0;
483 if (skc->sc_dh_shared_key.value) {
484 free(skc->sc_dh_shared_key.value);
485 skc->sc_dh_shared_key.value = NULL;
487 skc->sc_dh_shared_key.length = 0;
489 } else if (rc != GSS_S_COMPLETE) {
490 printerr(0, "Failed to compute session key from DH params\n");
491 goto cleanup_partial;
494 /* Cleanup init buffers we have copied or don't need anymore */
495 free(bufs[SK_INIT_VERSION].value);
496 free(bufs[SK_INIT_RANDOM].value);
497 free(bufs[SK_INIT_TARGET].value);
498 free(bufs[SK_INIT_FLAGS].value);
500 /* Server reply contains the servers public key, random, and HMAC */
501 version = htobe32(SK_MSG_VERSION);
502 bufs[SK_RESP_VERSION].value = &version;
503 bufs[SK_RESP_VERSION].length = sizeof(version);
504 bufs[SK_RESP_RANDOM].value = &skc->sc_kctx.skc_host_random;
505 bufs[SK_RESP_RANDOM].length = sizeof(skc->sc_kctx.skc_host_random);
506 bufs[SK_RESP_PUB_KEY] = skc->sc_pub_key;
507 if (sk_sign_bufs(&skc->sc_kctx.skc_shared_key, bufs,
508 SK_RESP_BUFFERS - 1, EVP_sha256(),
510 printerr(0, "Failed to sign parameters\n");
513 bufs[SK_RESP_HMAC] = skc->sc_hmac;
514 if (sk_encode_netstring(bufs, SK_RESP_BUFFERS, &snd->out_tok)) {
515 printerr(0, "Failed to encode netstring for token\n");
518 printerr(2, "Created netstring of %zd bytes\n", snd->out_tok.length);
520 if (sk_session_kdf(skc, snd->nid, &snd->in_tok, &snd->out_tok)) {
521 printerr(0, "Failed to calulate derviced session key\n");
524 if (sk_compute_keys(skc)) {
525 printerr(0, "Failed to compute HMAC and encryption keys\n");
528 if (sk_serialize_kctx(skc, &snd->ctx_token)) {
529 printerr(0, "Failed to serialize context for kernel\n");
533 snd->out_handle.length = sizeof(snd->handle_seq);
534 memcpy(snd->out_handle.value, &snd->handle_seq,
535 sizeof(snd->handle_seq));
536 snd->maj_stat = GSS_S_COMPLETE;
538 /* fix credentials */
539 memset(&cred, 0, sizeof(cred));
540 cred.cr_mapped_uid = -1;
542 if (skc->sc_flags & LGSS_ROOT_CRED_ROOT)
543 cred.cr_usr_root = 1;
544 if (skc->sc_flags & LGSS_ROOT_CRED_MDT)
546 if (skc->sc_flags & LGSS_ROOT_CRED_OST)
549 do_svc_downcall(&snd->out_handle, &cred, snd->mech, &snd->ctx_token);
551 /* cleanup ctx_token, out_tok is cleaned up in handle_channel_req */
552 free(remote_pub_key.value);
553 free(snd->ctx_token.value);
554 snd->ctx_token.length = 0;
556 printerr(3, "sk returning success\n");
560 for (i = 0; i < SK_INIT_BUFFERS; i++)
567 free(bufs[SK_INIT_VERSION].value);
568 free(bufs[SK_INIT_RANDOM].value);
569 free(bufs[SK_INIT_TARGET].value);
570 free(bufs[SK_INIT_FLAGS].value);
571 free(remote_pub_key.value);
578 if (snd->ctx_token.value) {
579 free(snd->ctx_token.value);
580 snd->ctx_token.value = 0;
581 snd->ctx_token.length = 0;
583 free(remote_pub_key.value);
585 printerr(3, "sk returning failure\n");
586 #else /* !HAVE_OPENSSL_SSK */
587 printerr(0, "ERROR: shared key subflavour is not enabled\n");
588 #endif /* HAVE_OPENSSL_SSK */
592 int handle_null(struct svc_nego_data *snd)
594 struct svc_cred cred;
598 /* null just uses the same token as the return token and for
599 * for sending to the kernel. It is a single uint64_t. */
600 if (snd->in_tok.length != sizeof(uint64_t)) {
601 snd->maj_stat = GSS_S_DEFECTIVE_TOKEN;
602 printerr(0, "Invalid token size (%zd) received\n",
606 snd->out_tok.length = snd->in_tok.length;
607 snd->out_tok.value = malloc(snd->out_tok.length);
608 if (!snd->out_tok.value) {
609 snd->maj_stat = GSS_S_FAILURE;
610 printerr(0, "Failed to allocate out_tok\n");
614 snd->ctx_token.length = snd->in_tok.length;
615 snd->ctx_token.value = malloc(snd->ctx_token.length);
616 if (!snd->ctx_token.value) {
617 snd->maj_stat = GSS_S_FAILURE;
618 printerr(0, "Failed to allocate ctx_token\n");
622 snd->out_handle.length = sizeof(snd->handle_seq);
623 memcpy(snd->out_handle.value, &snd->handle_seq,
624 sizeof(snd->handle_seq));
625 snd->maj_stat = GSS_S_COMPLETE;
627 memcpy(&tmp, snd->in_tok.value, sizeof(tmp));
629 flags = (uint32_t)(tmp & 0x00000000ffffffff);
630 memset(&cred, 0, sizeof(cred));
631 cred.cr_mapped_uid = -1;
633 if (flags & LGSS_ROOT_CRED_ROOT)
634 cred.cr_usr_root = 1;
635 if (flags & LGSS_ROOT_CRED_MDT)
637 if (flags & LGSS_ROOT_CRED_OST)
640 do_svc_downcall(&snd->out_handle, &cred, snd->mech, &snd->ctx_token);
642 /* cleanup ctx_token, out_tok is cleaned up in handle_channel_req */
643 free(snd->ctx_token.value);
644 snd->ctx_token.length = 0;
649 static int handle_krb(struct svc_nego_data *snd)
652 gss_name_t client_name;
653 gss_buffer_desc ignore_out_tok = {.value = NULL};
654 gss_OID mech = GSS_C_NO_OID;
655 gss_cred_id_t svc_cred;
656 u_int32_t ignore_min_stat;
657 struct svc_cred cred;
659 svc_cred = gssd_select_svc_cred(snd->lustre_svc);
661 printerr(0, "no service credential for svc %u\n",
666 snd->maj_stat = gss_accept_sec_context(&snd->min_stat, &snd->ctx,
667 svc_cred, &snd->in_tok,
668 GSS_C_NO_CHANNEL_BINDINGS,
670 &snd->out_tok, &ret_flags, NULL,
673 if (snd->maj_stat == GSS_S_CONTINUE_NEEDED) {
674 printerr(1, "gss_accept_sec_context GSS_S_CONTINUE_NEEDED\n");
676 /* Save the context handle for future calls */
677 snd->out_handle.length = sizeof(snd->ctx);
678 memcpy(snd->out_handle.value, &snd->ctx, sizeof(snd->ctx));
680 } else if (snd->maj_stat != GSS_S_COMPLETE) {
681 printerr(0, "WARNING: gss_accept_sec_context failed\n");
682 pgsserr("handle_krb: gss_accept_sec_context",
683 snd->maj_stat, snd->min_stat, mech);
687 if (get_ids(client_name, mech, &cred, snd->nid, snd->lustre_svc)) {
688 /* get_ids() prints error msg */
689 snd->maj_stat = GSS_S_BAD_NAME; /* XXX ? */
690 gss_release_name(&ignore_min_stat, &client_name);
693 gss_release_name(&ignore_min_stat, &client_name);
695 /* Context complete. Pass handle_seq in out_handle to use
696 * for context lookup in the kernel. */
697 snd->out_handle.length = sizeof(snd->handle_seq);
698 memcpy(snd->out_handle.value, &snd->handle_seq,
699 sizeof(snd->handle_seq));
701 /* kernel needs ctx to calculate verifier on null response, so
702 * must give it context before doing null call: */
703 if (serialize_context_for_kernel(snd->ctx, &snd->ctx_token, mech)) {
704 printerr(0, "WARNING: handle_krb: "
705 "serialize_context_for_kernel failed\n");
706 snd->maj_stat = GSS_S_FAILURE;
709 /* We no longer need the gss context */
710 gss_delete_sec_context(&ignore_min_stat, &snd->ctx, &ignore_out_tok);
711 do_svc_downcall(&snd->out_handle, &cred, mech, &snd->ctx_token);
716 if (snd->ctx != GSS_C_NO_CONTEXT)
717 gss_delete_sec_context(&ignore_min_stat, &snd->ctx,
724 * return -1 only if we detect error during reading from upcall channel,
725 * all other cases return 0.
727 int handle_channel_request(FILE *f)
729 char in_tok_buf[TOKEN_BUF_SIZE];
730 char in_handle_buf[15];
731 char out_handle_buf[15];
732 gss_buffer_desc ctx_token = {.value = NULL},
733 null_token = {.value = NULL};
734 uint32_t lustre_mech;
740 u_int32_t ignore_min_stat;
741 struct svc_nego_data snd = {
742 .in_tok.value = in_tok_buf,
743 .in_handle.value = in_handle_buf,
744 .out_handle.value = out_handle_buf,
745 .maj_stat = GSS_S_FAILURE,
746 .ctx = GSS_C_NO_CONTEXT,
749 printerr(2, "handling request\n");
750 if (readline(fileno(f), &lbuf, &lbuflen) != 1) {
751 printerr(0, "WARNING: failed reading request\n");
757 /* see rsi_request() for the format of data being input here */
758 qword_get(&cp, (char *)&snd.lustre_svc, sizeof(snd.lustre_svc));
760 /* lustre_svc is the svc and gss subflavor */
761 lustre_mech = (snd.lustre_svc & LUSTRE_GSS_MECH_MASK) >>
762 LUSTRE_GSS_MECH_SHIFT;
763 snd.lustre_svc = snd.lustre_svc & LUSTRE_GSS_SVC_MASK;
764 switch (lustre_mech) {
767 static time_t next_krb;
769 if (time(NULL) > next_krb) {
770 printerr(1, "warning: Request for kerberos but "
771 "service support not enabled\n");
772 next_krb = time(NULL) + 3600;
780 static time_t next_null;
782 if (time(NULL) > next_null) {
783 printerr(1, "warning: Request for gssnull but "
784 "service support not enabled\n");
785 next_null = time(NULL) + 3600;
793 static time_t next_ssk;
795 if (time(NULL) > next_ssk) {
796 printerr(1, "warning: Request for SSK but "
797 "service support not %s\n",
798 #ifdef HAVE_OPENSSL_SSK
804 next_ssk = time(NULL) + 3600;
812 printerr(0, "WARNING: invalid mechanism recevied: %d\n",
818 qword_get(&cp, (char *)&snd.nid, sizeof(snd.nid));
819 qword_get(&cp, (char *)&snd.handle_seq, sizeof(snd.handle_seq));
820 qword_get(&cp, snd.nm_name, sizeof(snd.nm_name));
821 printerr(2, "handling req: svc %u, nid %016llx, idx %"PRIx64" nodemap "
822 "%s\n", snd.lustre_svc, snd.nid, snd.handle_seq, snd.nm_name);
824 get_len = qword_get(&cp, snd.in_handle.value, sizeof(in_handle_buf));
826 printerr(0, "WARNING: failed parsing request\n");
829 snd.in_handle.length = (size_t)get_len;
831 printerr(3, "in_handle:\n");
832 print_hexl(3, snd.in_handle.value, snd.in_handle.length);
834 get_len = qword_get(&cp, snd.in_tok.value, sizeof(in_tok_buf));
836 printerr(0, "WARNING: failed parsing request\n");
839 snd.in_tok.length = (size_t)get_len;
841 printerr(3, "in_tok:\n");
842 print_hexl(3, snd.in_tok.value, snd.in_tok.length);
844 if (snd.in_handle.length != 0) { /* CONTINUE_INIT case */
845 if (snd.in_handle.length != sizeof(snd.ctx)) {
846 printerr(0, "WARNING: input handle has unexpected "
847 "length %zu\n", snd.in_handle.length);
850 /* in_handle is the context id stored in the out_handle
851 * for the GSS_S_CONTINUE_NEEDED case below. */
852 memcpy(&snd.ctx, snd.in_handle.value, snd.in_handle.length);
855 if (lustre_mech == LGSS_MECH_KRB5)
856 rc = handle_krb(&snd);
857 else if (lustre_mech == LGSS_MECH_SK)
858 rc = handle_sk(&snd);
859 else if (lustre_mech == LGSS_MECH_NULL)
860 rc = handle_null(&snd);
863 "WARNING: Received or request for subflavor that is not enabled: %d\n",
867 /* Failures send a null token */
869 send_response(f, &snd.in_handle, &snd.in_tok, snd.maj_stat,
870 snd.min_stat, &snd.out_handle, &snd.out_tok);
872 send_response(f, &snd.in_handle, &snd.in_tok, snd.maj_stat,
873 snd.min_stat, &null_token, &null_token);
875 /* cleanup buffers */
876 if (snd.ctx_token.value != NULL)
877 free(ctx_token.value);
878 if (snd.out_tok.value != NULL)
879 gss_release_buffer(&ignore_min_stat, &snd.out_tok);
881 /* For junk wire data just ignore */