+ assert(text->client_name == GSS_C_NO_NAME);
+
+ if (!GOT_CREDS(text, params)) {
+ maj_stat = gss_acquire_cred(&min_stat,
+ GSS_C_NO_NAME,
+ GSS_C_INDEFINITE,
+ &mechs,
+ GSS_C_INITIATE,
+ &text->client_creds,
+ NULL,
+ &text->lifetime);
+ } else
+ maj_stat = GSS_S_COMPLETE;
+
+ if (maj_stat == GSS_S_COMPLETE) {
+ maj_stat = gss_inquire_cred(&min_stat,
+ params->gss_creds
+ ? (gss_cred_id_t)params->gss_creds
+ : text->client_creds,
+ &text->client_name,
+ NULL,
+ NULL,
+ NULL);
+ if (GSS_ERROR(maj_stat))
+ goto cleanup;
+ } else if (maj_stat != GSS_S_CRED_UNAVAIL)
+ goto cleanup;
+
+ if (text->client_name != GSS_C_NO_NAME) {
+ maj_stat = gss_display_name(&min_stat,
+ text->client_name,
+ &cred_authid,
+ NULL);
+ if (GSS_ERROR(maj_stat))
+ goto cleanup;
+
+ authid = cred_authid.value;
+ } else {
+ auth_result = _plug_get_authid(params->utils, &authid, prompt_need);
+ if (auth_result != SASL_OK && auth_result != SASL_INTERACT) {
+ result = auth_result;
+ goto cleanup;
+ }
+ }
+ }
+
+ /*
+ * If the application has provided an authentication identity, parse it.
+ */
+ if (text->client_name == GSS_C_NO_NAME) {
+ gss_buffer_desc name_buf;
+
+ if (oparams->authid != NULL) {
+ name_buf.length = strlen(oparams->authid);
+ name_buf.value = (void *)oparams->authid;
+ } else {
+ name_buf.length = strlen(authid);
+ name_buf.value = (void *)authid;
+ }