diff -uNr torque-2.5.12/src/resmom/catch_child.c torque-2.5.12psr/src/resmom/catch_child.c
--- torque-2.5.12/src/resmom/catch_child.c	2011-12-20 19:54:56.000000000 +0400
+++ torque-2.5.12psr/src/resmom/catch_child.c	2012-07-27 12:25:16.546974190 +0400
@@ -318,6 +318,12 @@
 
   int NumSisters;
 
+#ifdef    PSR
+  long  sheppid;
+  FILE   *pfile;
+  char  pidfile[PATH_MAX];
+#endif /* PSR */
+
   /*
   ** Look through the jobs.  Each one has it's tasks examined
   ** and if the job is EXITING, it meets it's fate depending
@@ -478,6 +484,34 @@
           }
         }    /* END if (ptask->ti_qs.ti_parenttask == TM_NULL_TASK) */
 
+#ifdef    PSR
+      /*
+      ** Killing the auth_shepherd
+      */
+
+      if (strlen(pjob->ji_qs.ji_jobid) + 9 <= PATH_MAX) {
+        strcpy(pidfile, pjob->ji_qs.ji_jobid);
+        strcat(pidfile, ".authpid");
+        if ((pfile = fopen(pidfile, "r")) != NULL) {
+          while(!feof(pfile)) {
+            fscanf(pfile, "%li", &sheppid);
+            if (sheppid > 1) {
+              (void)kill((pid_t)sheppid,SIGKILL);
+              if (LOGLEVEL >= 2) {
+                LOG_EVENT(
+                  PBSEVENT_JOB,
+                  PBS_EVENTCLASS_JOB,
+                  pjob->ji_qs.ji_jobid,
+                  "kill dauth_shepherd");
+              }
+            }
+          }
+          (void)fclose(pfile);
+          (void)unlink(pidfile);
+        }
+      }
+#endif /* PSR */
+
       /*
       ** process any TM client obits waiting.
       */
diff -uNr torque-2.5.12/src/resmom/Makefile.am torque-2.5.12psr/src/resmom/Makefile.am
--- torque-2.5.12/src/resmom/Makefile.am	2011-07-25 21:08:49.000000000 +0400
+++ torque-2.5.12psr/src/resmom/Makefile.am	2012-07-27 12:15:02.626964380 +0400
@@ -4,7 +4,7 @@
 DIST_SUBDIRS = aix4 aix5 cygwin darwin digitalunix freebsd freebsd5 fujitsu hpux10 hpux11 \
 	irix5 irix6 irix6array linux netbsd solaris5 solaris7 sunos4 unicos8 unicosmk2
 
-AM_CPPFLAGS += -I$(top_srcdir)/src/resmom/@PBS_MACH@ -DPBS_MOM \
+AM_CPPFLAGS += -I$(top_srcdir)/src/resmom/@PBS_MACH@ -DPBS_MOM -DPSR \
 	       -DDEMUX=\"$(program_prefix)$(DEMUX_PATH)$(program_suffix)\" \
 	       -DRCP_PATH=\"$(program_prefix)$(RCP_PATH)$(program_suffix)\" \
 	       -DRCP_ARGS=\"$(RCP_ARGS)\" \
@@ -12,13 +12,13 @@
 
 PBS_LIBS = ../lib/Libattr/libattr.a \
 	   ../lib/Libsite/libsite.a \
-		 ../lib/Libutils/libutils.a \
+	   ../lib/Libutils/libutils.a \
 	   ../lib/Libpbs/libtorque.la
 
 EXTRA_DIST = rm_dep.h
 sbin_PROGRAMS = pbs_mom pbs_demux
 
-LDADD = @PBS_MACH@/libmommach.a $(PBS_LIBS) $(MOMLIBS) 
+LDADD = @PBS_MACH@/libmommach.a $(PBS_LIBS) $(MOMLIBS) -lpsr_afs -lkrb5
 
 pbs_mom_SOURCES = catch_child.c mom_comm.c mom_inter.c mom_main.c \
 		   mom_server.c prolog.c requests.c start_exec.c \
diff -uNr torque-2.5.12/src/resmom/Makefile.in torque-2.5.12psr/src/resmom/Makefile.in
--- torque-2.5.12/src/resmom/Makefile.in	2011-11-06 04:46:49.000000000 +0400
+++ torque-2.5.12psr/src/resmom/Makefile.in	2012-07-27 12:18:30.871965876 +0400
@@ -352,7 +352,7 @@
 AUTOMAKE_OPTIONS = foreign
 PBS_MKDIRS = $(SHELL) $(top_builddir)/buildutils/pbs_mkdirs
 AM_CPPFLAGS = -I$(top_srcdir)/src/include \
-	-I$(top_srcdir)/src/resmom/@PBS_MACH@ -DPBS_MOM \
+	-I$(top_srcdir)/src/resmom/@PBS_MACH@ -DPBS_MOM -DPSR \
 	-DDEMUX=\"$(program_prefix)$(DEMUX_PATH)$(program_suffix)\" \
 	-DRCP_PATH=\"$(program_prefix)$(RCP_PATH)$(program_suffix)\" \
 	-DRCP_ARGS=\"$(RCP_ARGS)\" \
@@ -369,11 +369,11 @@
 
 PBS_LIBS = ../lib/Libattr/libattr.a \
 	   ../lib/Libsite/libsite.a \
-		 ../lib/Libutils/libutils.a \
+	   ../lib/Libutils/libutils.a \
 	   ../lib/Libpbs/libtorque.la
 
 EXTRA_DIST = rm_dep.h
-LDADD = @PBS_MACH@/libmommach.a $(PBS_LIBS) $(MOMLIBS) 
+LDADD = @PBS_MACH@/libmommach.a $(PBS_LIBS) $(MOMLIBS) -lpsr_afs -lkrb5
 pbs_mom_SOURCES = catch_child.c mom_comm.c mom_inter.c mom_main.c \
 	mom_server.c prolog.c requests.c start_exec.c checkpoint.c \
 	tmsock_recov.c req_quejob.c job_func.c ../server/attr_recov.c \
diff -uNr torque-2.5.12/src/resmom/prolog.c torque-2.5.12psr/src/resmom/prolog.c
--- torque-2.5.12/src/resmom/prolog.c	2011-12-08 22:16:42.000000000 +0400
+++ torque-2.5.12psr/src/resmom/prolog.c	2012-07-27 12:32:09.493973846 +0400
@@ -102,6 +102,12 @@
 #include "net_connect.h"
 #include "utils.h"
 
+#ifdef    PSR
+#include <string.h>
+#include <limits.h>
+#include <psr_config.h>
+extern void GetNewPAG(void);
+#endif /* PSR */
 
 #define PBS_PROLOG_TIME 300
 
@@ -404,6 +410,10 @@
   int    num_gids = 0;
 
   int    jobtypespecified = 0;
+#ifdef    PSR
+  FILE	*cpass;
+  char	 execute[PATH_MAX];
+#endif /* PSR */
 
   resource      *r;
 
@@ -905,6 +915,31 @@
       {
       /* for epilog only */
 
+#ifdef    PSR
+      /*
+       * If user's HOME is in AFS space then
+       * Use dauthr to get an AFS token
+       */
+      if (strncmp(pjob->ji_grpcache->gc_homedir, "/afs/", 5) == 0) {
+        GetNewPAG();
+        if(strlen(DAUTHR) +
+             strlen(pjob->ji_wattr[(int)JOB_ATR_euser].at_val.at_str)
+             + 2 <= PATH_MAX) {
+          strcpy(execute, DAUTHR);
+          strcat(execute, " ");
+          strcat(execute, pjob->ji_wattr[(int)JOB_ATR_euser].at_val.at_str);
+          if ((cpass = popen(execute,"r")) != NULL)
+            (void)pclose(cpass);
+          else {
+            sprintf(log_buffer,"dauthr exec failed: %s",
+              execute);
+            write(2,log_buffer,strlen(log_buffer));
+            fsync(2);
+          }
+        }
+      }
+#endif /* PSR */
+
       sprintf(sid, "%ld",
               pjob->ji_wattr[(int)JOB_ATR_session_id].at_val.at_long);
       sprintf(exit_stat,"%d",
diff -uNr torque-2.5.12/src/resmom/requests.c torque-2.5.12psr/src/resmom/requests.c
--- torque-2.5.12/src/resmom/requests.c	2012-04-14 01:02:59.000000000 +0400
+++ torque-2.5.12psr/src/resmom/requests.c	2012-07-27 16:23:21.261973366 +0400
@@ -118,6 +118,11 @@
 #ifdef HAVE_WORDEXP
 #include <wordexp.h>
 
+#ifdef    PSR
+#include <psr_config.h>
+extern void GetNewPAG(void);
+#endif /* PSR */
+
 extern struct var_table vtable;      /* see start_exec.c */
 extern char           **environ;
 
@@ -263,6 +268,12 @@
 
   struct stat     sb;
 
+#ifdef    PSR
+  char           *rpwdir;
+  FILE           *cpass;
+  char            execute[PATH_MAX];
+#endif /* PSR */
+
   /* initialize */
 
   if (EMsg != NULL)
@@ -280,6 +291,10 @@
     ngroup  = pjob->ji_grpcache->gc_ngroup;
     groups  = pjob->ji_grpcache->gc_groups;
 
+#ifdef    PSR
+    rpwdir = pjob->ji_grpcache->gc_homedir;
+#endif /* PSR */
+
     if ((idir = get_job_envvar(pjob, "PBS_O_INITDIR")) != NULL)
       {
       hdir = idir;
@@ -309,6 +324,10 @@
 
     useruid = pwdp->pw_uid;
 
+#ifdef    PSR
+    rpwdir = pwdp->pw_dir;
+#endif /* PSR */
+
     if (preq->rq_ind.rq_cpyfile.rq_group[0] == '\0')
       {
       usergid = pwdp->pw_gid;   /* default to login group */
@@ -403,10 +422,19 @@
 
   if (LOGLEVEL >= 1)
     {
+#ifdef    PSR
+    sprintf(log_buffer,"forking to user, uid: %ld  gid: %ld  dir: '%s'  name: '%s'  home: '%s'",
+      (long)useruid,
+      (long)usergid,
+      hdir,
+      preq->rq_ind.rq_cpyfile.rq_user,
+      rpwdir);
+#else
     sprintf(log_buffer, "forking to user, uid: %ld  gid: %ld  homedir: '%s'",
             (long)useruid,
             (long)usergid,
             hdir);
+#endif /* PSR */
 
     log_record(
       PBSEVENT_JOB,
@@ -464,6 +492,33 @@
 
 #endif /* _CRAY */
 
+#ifdef    PSR
+  /*
+   * If user's HOME is in AFS space then
+   * Use dauthr to get an AFS token
+   */
+  if (strncmp(rpwdir, "/afs/", 5) == 0) {
+    GetNewPAG();
+    if(strlen(DAUTHR) + 
+          strlen(preq->rq_ind.rq_cpyfile.rq_user) + 2 <= PATH_MAX) {
+      strcpy(execute, DAUTHR);
+      strcat(execute, " ");
+      strcat(execute, preq->rq_ind.rq_cpyfile.rq_user);
+      if ((cpass = popen(execute,"r")) != NULL) {
+        (void)pclose(cpass);
+      }
+      else {
+        sprintf(log_buffer,"dauthr exec failed: %s",
+           execute);
+        log_err(-1,id,log_buffer);
+        if (EMsg != NULL)
+          strncpy(EMsg,log_buffer,1024);
+        return(-PBSE_SYSTEM);
+      }
+    }
+  }
+#endif /* PSR */
+
   /* NOTE:  only chdir now if SetUID is TRUE */
 
   if (SetUID == TRUE)
diff -uNr torque-2.5.12/src/resmom/start_exec.c torque-2.5.12psr/src/resmom/start_exec.c
--- torque-2.5.12/src/resmom/start_exec.c	2012-06-07 01:36:52.000000000 +0400
+++ torque-2.5.12psr/src/resmom/start_exec.c	2012-07-27 16:36:17.822973290 +0400
@@ -171,6 +171,11 @@
 #endif /* CSAFAKE */
 #endif /* ENABLE_CSA */
 
+#ifdef    PSR
+#include <psr_config.h>
+extern void GetNewPAG(void);
+#endif /* PSR */
+
 #ifdef NOPOSIXMEMLOCK
   #undef _POSIX_MEMLOCK
 #endif /* NOPOSIXMEMLOCK */
@@ -2473,6 +2478,18 @@
   struct passwd         *pwdp;
   char                   EMsg[1024];
 
+#ifdef    PSR
+  long                   sheppid;
+  FILE		        *cpass;
+  FILE                  *pfile;
+  char		         execute[PATH_MAX + 1];
+  char		         pidfile[PATH_MAX + 1];
+  char		         cccache[PATH_MAX + 1];
+  char		         ssheppid[10];
+
+  memset(ssheppid,0,10);
+  memset(cccache,0,PATH_MAX + 1);
+#endif /* PSR */
 
   pjob  = (job *)TJE->pjob;
   ptask = (task *)TJE->ptask;
@@ -2524,6 +2541,63 @@
   if (LOGLEVEL >= 10)
     log_ext(-1, id, "env initialized", LOG_DEBUG);
 
+#ifdef    PSR
+  /*
+   * If user's HOME is in AFS space then
+   * Use dauthr to get an AFS token
+   */
+  if (strncmp(pwdp->pw_dir, "/afs/", 5) == 0) {
+    GetNewPAG();
+    if(strlen(DAUTHR) + strlen(pwdp->pw_name) + 2 <= PATH_MAX) {
+      strcpy(execute, DAUTHR);
+      strcat(execute, " ");
+      strcat(execute, pwdp->pw_name);
+      if ((cpass=popen(execute, "r")) != NULL) {
+        (void)pclose(cpass);
+      }
+      else {
+        sprintf(log_buffer,"dauthr exec failed: %s", execute);
+        log_err(errno,id,log_buffer);
+        starter_return(TJE->upfds,TJE->downfds,JOB_EXEC_FAIL1,&sjr);
+      }
+    }
+    /*
+     * Starting dauth_shepperd
+     */
+    if(strlen(AUTHSHEP) + strlen(pwdp->pw_name) + 2 <= PATH_MAX) {
+      strcpy(execute, AUTHSHEP);
+      strcat(execute, " ");
+      strcat(execute, pwdp->pw_name);
+      if ((cpass = popen(execute, "r")) != NULL) {
+        (void)fgets(ssheppid, 10, cpass);
+        sheppid=atol(ssheppid);
+        if (pclose(cpass) == 0){
+          strcpy(pidfile, pjob->ji_qs.ji_jobid);
+          strcat(pidfile, ".authpid");
+          if ((pfile = fopen(pidfile, "a+")) != NULL) {
+            fprintf(pfile, "%li\n",sheppid);
+            (void)fclose(pfile);
+            /*
+             * Pure hack.
+             * We construct proper file name for cccache from:
+             * - our uid
+             * - pid of our AUTHSHEP.
+             * FIXME: "FILE:/tmp/krb5cc_" should be defined in the "psr_config.h"
+             */
+            snprintf(cccache, sizeof(cccache), "FILE:/tmp/krb5cc_%u_%lu", pwdp->pw_uid, sheppid);
+            bld_env_variables(&vtable,"KRB5CCNAME", cccache);
+          }
+        }
+      }
+      else {
+        sprintf(log_buffer,"dauth_shepperd exec failed: %s", execute);
+        log_err(errno,id,log_buffer);
+        starter_return(TJE->upfds,TJE->downfds,JOB_EXEC_FAIL1,&sjr);
+      }
+    }
+  }
+#endif /* PSR */
+
   /* Create the job's nodefile */
 
   vnodenum = pjob->ji_numvnod;
@@ -4234,6 +4308,19 @@
 
 #endif /* USEJOBCREATE */
 
+#ifdef    PSR
+  long		 sheppid;
+  FILE	        *pfile;
+  char	 	 pidfile[PATH_MAX + 1];
+  FILE	        *cpass;
+  char		 execute[PATH_MAX + 1];
+  struct passwd	*pwdpp;
+  char		 cccache[PATH_MAX + 1];
+  char		 ssheppid[10];
+
+  memset(ssheppid,0,10);
+  memset(cccache,0,PATH_MAX + 1);
+#endif /* PSR */
 
   if (pipe(pipes) == -1)
     {
@@ -4307,13 +4394,73 @@
    * to spawn tasks (ji_grpcache).
    */
 
+#ifdef    PSR
+  if ((pwdpp = check_pwd(pjob)) == NULL)
+#else
   if (!check_pwd(pjob))
+#endif /* PSR */
     {
     log_err(-1, id, log_buffer);
 
     return(-1);
     }
 
+#ifdef    PSR
+  /*
+   * If user's HOME is in AFS space then
+   * Use dauthr to get an AFS token
+   */
+  if (strncmp(pwdpp->pw_dir, "/afs/", 5) == 0) {
+    GetNewPAG();
+    if (strlen(DAUTHR) + strlen(pwdpp->pw_name) + 2 <= PATH_MAX) {
+      strcpy(execute, DAUTHR);
+      strcat(execute, " ");
+      strcat(execute, pwdpp->pw_name);
+      if ((cpass=popen(execute, "r")) != NULL) {
+        (void)pclose(cpass);
+      }
+      else {
+        sprintf(log_buffer,"dauthr exec failed: %s", execute);
+        log_err(-1,id,log_buffer);
+        return(-1);
+      }
+    }
+    /*
+     * Starting dauth_shepperd
+     */
+    if(strlen(AUTHSHEP) + strlen(pwdpp->pw_name) + 2 <= PATH_MAX) {
+      strcpy(execute, AUTHSHEP);
+      strcat(execute, " ");
+      strcat(execute, pwdpp->pw_name);
+      if ((cpass = popen(execute, "r")) != NULL) {
+        (void)fgets(ssheppid, 10, cpass);
+        sheppid=atol(ssheppid);
+        if (pclose(cpass) == 0){
+          strcpy(pidfile, pjob->ji_qs.ji_jobid);
+          strcat(pidfile, ".authpid");
+          if ((pfile = fopen(pidfile, "a+")) != NULL){
+            fprintf(pfile, "%li\n",sheppid);
+            (void)fclose(pfile);
+            /*
+             * Pure hack.
+             * We construct proper file name for cccache from:
+             * - our uid
+             * - pid of our AUTHSHEP.
+             * FIXME: "FILE:/tmp/krb5cc_" should be defined in the "psr_config.h"
+             */
+            snprintf(cccache, sizeof(cccache), "FILE:/tmp/krb5cc_%u_%lu", pwdpp->pw_uid, sheppid);
+          }
+        }
+      }
+      else {
+        sprintf(log_buffer,"dauth_shepperd exec failed: %s", execute);
+        log_err(-1,id,log_buffer);
+        return(-1);
+      }
+    }
+  }
+#endif /* PSR */
+
   /*
   ** Begin a new process for the fledgling task.
   */
@@ -4531,6 +4678,12 @@
   if (LOGLEVEL >= 10)
     log_ext(-1, id, "user env initialized", LOG_DEBUG);
 
+#ifdef    PSR
+  if (*cccache != (char)NULL) {
+    bld_env_variables(&vtable,"KRB5CCNAME", cccache);
+  }
+#endif /* PSR */
+
   if (set_mach_vars(pjob, &vtable) != 0)
     {
     strcpy(log_buffer, "PBS: machine dependent environment variable setup failed\n");
@@ -6773,10 +6926,15 @@
 
 #ifndef __TOLDGROUP
 
-/*
+ /*
   * init_groups - build the group list via an LDAP friendly method
   */
 
+#ifdef    PSR
+#define AFSPAGGMIN 0x3F00
+#define AFSPAGGMAX 0xFEFF
+#endif /* PSR */
+
 int init_groups(
 
   char *pwname,   /* I User's name */
@@ -6885,6 +7043,24 @@
     log_ext(-1, id, "post-initgroups", LOG_DEBUG);
     }
 
+#ifdef    PSR
+  /* remove AFS PAG's groups from the list */
+  if (n > 1 ) {
+    int j;
+    for (j = i = 0; i < n; i++) {
+/* Hack for old openafs w/ two groups for PAG */
+      if (groups[i] < AFSPAGGMIN || groups[i] > AFSPAGGMAX) {
+/* Hack for new openafs w/ one group for PAG */
+         if (((groups[i] >> 24) & 0xff) != 'A') {
+           groups[j] = groups[i];
+           j++;
+         }
+      }
+    } 
+    n = j;
+  }
+#endif /* PSR */
+
   /* restore state */
 
   if (setgroups(nsaved, savedgroups) < 0)
