/*------------------------------------------------------------------------------*/
/* define constants                                                             */
/*------------------------------------------------------------------------------*/

#ifdef VAX
globalvalue     CTL$GL_UAF_FLAGS;
#else
extern char       *CTL$GL_UAF_FLAGS;
#endif

#define UAF$V_DISCTLY                   0
#define        UAF$V_DEFCLI                    1
#define        UAF$V_LOCKPWD                   2
#define        UAF$V_RESTRICTED                3
#define        UAF$V_DISACNT                   4
#define        UAF$V_DISWELCOM                 5
#define        UAF$V_DISMAIL                   6
#define        UAF$V_NOMAIL                    7
#define        UAF$V_GENPWD                    8
#define        UAF$V_PWD_EXPIRED               9
#define        UAF$V_PWD2_EXPIRED              10
#define       UAF$V_AUDIT                     11
#define       UAF$V_DISREPORT                 12
#define       UAF$V_DISRECONNECT              13
#define       UAF$V_AUTOLOGIN                 14
#define       UAF$V_DISFORCE_PWD_CHANGE       15
#define       UAF$V_CAPTIVE                   16
#define       UAF$V_DISIMAGE                  17
#define       UAF$V_DISPWDDIC                 18
#define       UAF$V_DISPWDHIS                 19
#define       UAF$V_DEFCLSVAL                 20

/*------------------------------------------------------------------------------*/
/* include headers                                                              */
/*------------------------------------------------------------------------------*/

#include <ssdef.h>
#include <stdio.h>

/*------------------------------------------------------------------------------*/
/* local variables                                                              */
/*------------------------------------------------------------------------------*/

static long int uaf_flags;

/*------------------------------------------------------------------------------*/
/* local functions                                                              */
/*------------------------------------------------------------------------------*/

static int condition_handler()
{
       sys$unwind(0, 0);
       return SS$_CONTINUE;
}

/*------------------------------------------------------------------------------*/

static int pop_into_kernel()
{
    /* stop kernel mode exceptions - very bad */
    lib$establish(condition_handler);

#ifdef VAX
     /* read the current value */
    uaf_flags = *(int *)CTL$GL_UAF_FLAGS;

   /* set the captive bit */
       *(int *)CTL$GL_UAF_FLAGS |= (1 << UAF$V_CAPTIVE);
#else
  /* read the current value */
    uaf_flags = *(int *)&CTL$GL_UAF_FLAGS;
#endif

    /* finished */
  return(SS$_NORMAL);
}

/*------------------------------------------------------------------------------*/

main()
{
   int     captive_flag;
   int     restrict_flag;
  int     status;


 status = sys$cmkrnl(pop_into_kernel, 0);

        captive_flag = (uaf_flags & (1 << UAF$V_CAPTIVE)) > 0;
  restrict_flag = (uaf_flags & (1 << UAF$V_RESTRICTED)) > 0;

      printf("\n");
   printf("PROCESS UAF FLAGS\n");
  printf("\n");
   printf("\tRESTRICTED     = %s\n", restrict_flag ? "TRUE" : "FALSE");
    printf("\tCAPTIVE        = %s\n", captive_flag ? "TRUE" : "FALSE");

     /* finished */
  return(status);
}

/*------------------------------------------------------------------------------*/

