+ /*
+ * If the application has provided an authentication identity, parse it.
+ */
+ if (text->client_name == GSS_C_NO_NAME && oparams->authid != NULL) {
+ gss_buffer_desc name_buf;
+
+ name_buf.length = strlen(oparams->authid);
+ name_buf.value = (void *)oparams->authid;
+
+ maj_stat = gss_import_name(&min_stat,
+ &name_buf,
+ GSS_C_NT_USER_NAME,
+ &text->client_name);
+ if (GSS_ERROR(maj_stat))
+ goto cleanup;
+ }
+
+ /*
+ * Armed with the authentication identity, try to get a credential without
+ * a password.
+ */
+ if (!GOT_CREDS(text, params) && text->client_name != GSS_C_NO_NAME) {
+ maj_stat = gss_acquire_cred(&min_stat,
+ text->client_name,
+ GSS_C_INDEFINITE,
+ &mechs,
+ GSS_C_INITIATE,
+ &text->client_creds,
+ NULL,
+ &text->lifetime);
+ if (maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CRED_UNAVAIL)
+ goto cleanup;
+ }
+
+ /*
+ * If that failed, try to get a credential with a password.
+ */
+ if (!GOT_CREDS(text, params)) {
+ if (text->password == NULL) {
+ pass_result = _plug_get_password(params->utils, &text->password,
+ &text->free_password, prompt_need);
+ if (pass_result != SASL_OK && pass_result != SASL_INTERACT) {
+ result = pass_result;
+ goto cleanup;
+ }
+ }
+
+ if (text->password != NULL) {
+ gss_buffer_desc password_buf;
+
+ password_buf.length = text->password->len;
+ password_buf.value = text->password->data;
+
+ maj_stat = gss_acquire_cred_with_password(&min_stat,
+ text->client_name,
+ &password_buf,
+ GSS_C_INDEFINITE,
+ &mechs,
+ GSS_C_INITIATE,
+ &text->client_creds,
+ NULL,
+ &text->lifetime);
+ if (GSS_ERROR(maj_stat))
+ goto cleanup;
+ }
+ }
+
+ maj_stat = GSS_S_COMPLETE;
+