+ if (is_basic) {
+ if (!acquired_cred) {
+ /* Try to acquire default creds */
+ maj = gss_acquire_cred(&min, GSS_C_NO_NAME, GSS_C_INDEFINITE,
+ GSS_C_NO_OID_SET, cred_usage,
+ &acquired_cred, NULL, NULL);
+ if (GSS_ERROR(maj)) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
+ "%s", mag_error(req, "gss_acquire_cred_from()"
+ " failed", maj, min));
+ goto done;
+ }
+ }
+ if (cred_usage == GSS_C_BOTH) {
+ /* If GSS_C_BOTH is used then inquire_cred will return the client
+ * name instead of the SPN of the server credentials. Therefore we
+ * need to acquire a different set of credential setting
+ * GSS_C_ACCEPT explicitly */
+ if (cfg->cred_store) {
+ maj = gss_acquire_cred_from(&min, GSS_C_NO_NAME,
+ GSS_C_INDEFINITE, GSS_C_NO_OID_SET,
+ GSS_C_ACCEPT, cfg->cred_store,
+ &server_cred, NULL, NULL);
+ } else {
+ /* Try to acquire default creds */
+ maj = gss_acquire_cred(&min, GSS_C_NO_NAME, GSS_C_INDEFINITE,
+ GSS_C_NO_OID_SET, GSS_C_ACCEPT,
+ &server_cred, NULL, NULL);
+ }
+ if (GSS_ERROR(maj)) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req, "%s",
+ mag_error(req, "gss_acquire_cred[_from]() "
+ "failed to get server creds",
+ maj, min));
+ goto done;
+ }
+ } else {
+ server_cred = acquired_cred;
+ }
+ maj = gss_inquire_cred(&min, server_cred, &server,
+ NULL, NULL, NULL);
+ if (GSS_ERROR(maj)) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
+ "%s", mag_error(req, "gss_inquired_cred_() "
+ "failed", maj, min));
+ goto done;
+ }
+ if (server_cred != acquired_cred) {
+ gss_release_cred(&min, &server_cred);
+ }
+
+ if (cfg->deleg_ccache_dir) {
+ /* delegate ourselves credentials so we store them as requested */
+ init_flags |= GSS_C_DELEG_FLAG;
+ }
+
+ /* output and input are inverted here, this is intentional */
+ maj = gss_init_sec_context(&min, user_cred, &user_ctx, server,
+ GSS_C_NO_OID, init_flags, 300,
+ GSS_C_NO_CHANNEL_BINDINGS, &output,
+ NULL, &input, NULL, NULL);
+ if (GSS_ERROR(maj)) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
+ "%s", mag_error(req, "gss_init_sec_context() "
+ "failed", maj, min));
+ goto done;
+ }
+ }
+
+ maj = gss_accept_sec_context(&min, pctx, acquired_cred,