+ if (strcasecmp(auth_header_type, "Negotiate") == 0) {
+ auth_type = "Negotiate";
+
+ auth_header_value = ap_getword_white(req->pool, &auth_header);
+ if (!auth_header_value) goto done;
+ input.length = apr_base64_decode_len(auth_header_value) + 1;
+ input.value = apr_pcalloc(req->pool, input.length);
+ if (!input.value) goto done;
+ input.length = apr_base64_decode(input.value, auth_header_value);
+ } else if ((strcasecmp(auth_header_type, "Basic") == 0) &&
+ (cfg->use_basic_auth == true)) {
+ auth_type = "Basic";
+ is_basic = true;
+
+ gss_buffer_desc ba_user;
+ gss_buffer_desc ba_pwd;
+
+ ba_pwd.value = ap_pbase64decode(req->pool, auth_header);
+ if (!ba_pwd.value) goto done;
+ ba_user.value = ap_getword_nulls_nc(req->pool,
+ (char **)&ba_pwd.value, ':');
+ if (!ba_user.value) goto done;
+ if (((char *)ba_user.value)[0] == '\0' ||
+ ((char *)ba_pwd.value)[0] == '\0') {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, req,
+ "Invalid empty user or password for Basic Auth");
+ goto done;
+ }
+ ba_user.length = strlen(ba_user.value);
+ ba_pwd.length = strlen(ba_pwd.value);
+ maj = gss_import_name(&min, &ba_user, GSS_C_NT_USER_NAME, &client);
+ if (GSS_ERROR(maj)) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, req,
+ "In Basic Auth, %s",
+ mag_error(req, "gss_import_name() failed",
+ maj, min));
+ goto done;
+ }
+#ifdef HAVE_GSS_KRB5_CCACHE_NAME
+ /* Set a per-thread ccache in case we are using kerberos,
+ * it is not elegant but avoids interference between threads */
+ long long unsigned int rndname;
+ apr_status_t rs;
+ rs = apr_generate_random_bytes((unsigned char *)(&rndname),
+ sizeof(long long unsigned int));
+ if (rs != APR_SUCCESS) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, req,
+ "Failed to generate random ccache name");
+ goto done;
+ }
+ user_ccache = apr_psprintf(req->pool, "MEMORY:user_%qu", rndname);
+ maj = gss_krb5_ccache_name(&min, user_ccache, &orig_ccache);
+ if (GSS_ERROR(maj)) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, req,
+ "In Basic Auth, %s",
+ mag_error(req, "gss_krb5_ccache_name() "
+ "failed", maj, min));
+ goto done;
+ }
+#endif
+ maj = gss_acquire_cred_with_password(&min, client, &ba_pwd,
+ GSS_C_INDEFINITE,
+ GSS_C_NO_OID_SET,
+ GSS_C_INITIATE,
+ &user_cred, NULL, NULL);
+ if (GSS_ERROR(maj)) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, req,
+ "In Basic Auth, %s",
+ mag_error(req, "gss_acquire_cred_with_password() "
+ "failed", maj, min));
+ goto done;
+ }
+ gss_release_name(&min, &client);
+ } else {
+ goto done;
+ }