Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 libpam-krb5 (4.7-3astra5) unstable; urgency=low
 .
   * Setup environment variable USER_DOMAIN_LOGIN for Parsec compatibility
Author: Alexander Levdonsky <alevdonsky@astralinux.ru>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2020-06-29

--- libpam-krb5-4.7.orig/auth.c
+++ libpam-krb5-4.7/auth.c
@@ -1081,6 +1081,35 @@ pamk5_authenticate(struct pam_args *args
         pam_syslog(args->pamh, LOG_INFO, "user %s authenticated as UNKNOWN",
                    ctx->name);
     } else {
+        /* parsec setenv section start */
+        const char *env_var_name = "USER_DOMAIN_LOGIN";
+//        fprintf( stderr, "Astra: user \"%s\" as \"%s\"\n", ctx->name, principal);
+        char *p = strchr( principal, '@');
+        if( p) {
+            p++;
+//            fprintf( stderr, "Astra: %s=\"%s\"\n", env_var_name, p);
+        }
+        if( setenv( env_var_name, p, 1)) {
+            pam_syslog(args->pamh, LOG_ERR, "setenv failed");
+            pamret = PAM_BUF_ERR;
+            goto done;
+        }
+        char *buf = NULL;
+        if( asprintf( &buf, "%s=%s", env_var_name, p) > 0) {
+            int r = pam_putenv( args->pamh, buf);
+            free( buf);
+            if( r != PAM_SUCCESS) {
+                pam_syslog(args->pamh, LOG_ERR, "pam_putenv failed");
+                pamret = r;
+                goto done;
+            }
+        }
+        else {
+            pam_syslog(args->pamh, LOG_ERR, "no memory");
+            pamret = PAM_BUF_ERR;
+            goto done;
+        }
+        /* parsec setenv section end */
         pam_syslog(args->pamh, LOG_INFO, "user %s authenticated as %s%s",
                    ctx->name, principal, ctx->expired ? " (expired)" : "");
         krb5_free_unparsed_name(ctx->context, principal);
