home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / PROCWRKB.ZIP / BENCH1.ZIP / SRC / PASSWD.C
Encoding:
C/C++ Source or Header  |  1990-08-24  |  26.6 KB  |  1,037 lines

  1. /* ---( src/passwd.c )---------------------------- */
  2. /* Pro-C - Copyright (C) 1988, 1989 Vestronix Inc. */
  3. /* Modification to this source is not supported    */
  4. /* by Vestronix Inc.                               */
  5. /*            All Rights Reserved                  */
  6. /* ----------------------------------------------- */
  7. /* Written   JZ       Jan-90                       */
  8. /* Modified  Nig   29-Jan-90                       */
  9. /* ----------------------------------------------- */
  10. /* %W%  (%H% %T%) */
  11.  
  12. /*
  13.  *  Modifications
  14.  *
  15.  *  27-Mar-90  NVS - Condense code
  16.  *  30-Jan-90  Nig - Rename Command using help/renfile
  17.  *  29-Jan-90  Nig - Enhancements using dll.....
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <bench.h>
  22. #include <time.h>
  23. #include <errno.h>
  24. #include <proc.io>
  25. #include <field.h>
  26.  
  27. #include <passwd.h>
  28.  
  29. #include "../hdr/fileio.h"
  30. #include "../hdr/dllist.h"
  31.  
  32. /* These 2 lines need to be removed and taken care of externally */
  33. # define MYVER "2.0"
  34. # define MAXLOCKTRYS 10
  35.  
  36. # ifdef UNIX
  37. # undef BLINK
  38. # define BLINK NORMAL
  39. # else
  40. # undef USRCOL4
  41. # define USRCOL4 NORMAL
  42. # endif
  43.  
  44. /*
  45.  * GLOBAL DEFINES
  46. */
  47. #define HELP_FILE       "pass"
  48. #define WRITEMSG        "Write Changes back to File ? "
  49. #define PRJFILE         "test"
  50. #define USER 0
  51. #define MODULE 1
  52.  
  53. extern FIELD modfield;
  54. extern FIELD userfield;
  55. extern FIELD pwdfield;
  56. extern int uhand;
  57. extern int mhand;
  58. extern USER_ENT tmpuser;
  59. extern MOD_ENT tmpmod;
  60. extern USER_ENT *tmpuptr;
  61. extern MOD_ENT *tmpmptr;
  62. extern char buffer[];
  63. extern char pwdfile[];
  64. extern char pwdtmpf[];
  65. extern char pswdfile_path[];
  66. extern int tempfd;
  67.  
  68. extern PERMS pperms[];
  69. extern int  ichar;         /* Global INPUT_W Return Value - 0 for CR */
  70.  
  71. # ifdef MSDOS                 /* Set up tables monitor types */
  72. extern char xmonitor;
  73. extern unsigned char colour[];
  74. static unsigned char dcolour[] =
  75. { 0x00, 0x17, 0x30, 0x47, 0x17, 0x1f, 0x30, 0x4f,
  76.   0x1f, 0x19, 0x1f, 0x2f, 0x3f, 0x4f, 0x5f, 0x6f};
  77. static unsigned char dmono[] =
  78. { 0x00, 0x07, 0x70, 0x01, 0x07, 0x0f, 0x70, 0x09,
  79.   0x0f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07};
  80. # endif
  81.  
  82. /*
  83.  * Set keywords used by library routines
  84. */
  85. char accept_prompt[] = "Accept";
  86. char cancel_prompt[] = "Cancel";
  87. char exit_prompt[] = "Exit";
  88. char help_prompt[] = "Help";
  89. char menu_prompt[] = "Menu";
  90. char no_prompt[] = "No";
  91. char ok_prompt[] = "Ok";
  92. char popup_prompt[] = "Popup";
  93. char select_prompt[] = "Select";
  94. char toggle_prompt[] = "Toggle";
  95. char yes_prompt[] = "Yes";
  96. char res_prompt[] = "Resize";
  97. char move_prompt[] = "Move";
  98. char choice_prompt[] = "Choices";
  99. char scroll_prompt[] = "Scroll";
  100. char rescan_prompt[] = "Rescan";
  101. char invoke_prompt[] = "Invoke";
  102. char cont_prompt[] = "Continue";
  103.  
  104. int main_win;
  105. static int keymatch = USER;
  106.  
  107. static PROTO (int op_type, (void));
  108.  
  109. /*
  110.  * Main Module for Password Administration
  111. */
  112. main(argc, argv)
  113. int argc;
  114. char *argv[];
  115. {
  116.     initpwdscreen (argc > 1 ? argv[1] : PRJFILE);
  117.     if (openpwdfile() == PERM_INIT) 
  118.     {
  119.         pwdscreenmaint(); 
  120.         writefile();
  121.         dll_close(uhand);
  122.         dll_close(mhand);
  123.     }
  124.     chain("", NULL);
  125. }
  126.  
  127. /*
  128.  * Display the First Screen and Initialize Variables
  129. */
  130. void initpwdscreen(prjname)
  131. char *prjname;
  132. {
  133.    open_help(HELP_FILE);
  134.    init_w(24, 80);
  135.  
  136. # ifdef MSDOS
  137.    /* Set up the colour array (AFTER the first create_w) */
  138.    if (xmonitor == MONO)
  139.       bytecpy(colour, dmono, 16);
  140.    else
  141.       bytecpy(colour, dcolour, 16);
  142. # endif
  143.  
  144.    /* Initialize global variables */
  145.    setvars(prjname);
  146.  
  147.    /* Create a Window For The Screen */
  148.    main_win = 0;
  149.    ncreate_w( 1, 1, w_nrows, w_ncols, &main_win);
  150.  
  151.    /* Now display the Text */
  152.  
  153.    fill_w( 6, 2, BLINK, 14, 20, ' ' );
  154.    fill_w( 9, 23, USRCOL4, 7, 35, ' ' );
  155.    fill_w( 7, 60, BLINK, 14, 20, ' ' );
  156.    boxset = 0;
  157.    box_w( 1, 1, GRAPHIC | BLINK, 23, 80 );
  158.    box_w( 6, 22, GRAPHIC | USRCOL4, 14, 37 );
  159.    disp_w( 2, 24, BOLDBLINK, "Password Administration - ");
  160.    strupr(prjname);
  161.    disp_w( 2, 50, BOLDBLINK, prjname);
  162.  
  163.    rephoriz_w( 3, 2, GRAPHIC | BLINK, 78, BHORIZ(0));
  164.    rephoriz_w( 8, 23, GRAPHIC | USRCOL4, 35, BHORIZ(0));
  165.    rephoriz_w( 16, 23, GRAPHIC | USRCOL4, 35, BHORIZ(0));
  166.    rephoriz_w( 2, 2, BOLDBLINK, 22, ' ');
  167.     fill_w( 4, 2, BLINK, 2, 78, ' ' );
  168.    rephoriz_w( 20, 2, BLINK, 21, ' ');
  169.     fill_w( 21, 2, BLINK, 2, 78, ' ' );
  170.    rephoriz_w( 7, 23, USRCOL4, 35, ' ');
  171.    rephoriz_w( 2, 50 + strlen(prjname), BOLDBLINK, 30-strlen(prjname), ' ');
  172.    rephoriz_w( 6, 59, BLINK, 21, ' ');
  173.     fill_w( 17, 23, USRCOL4, 2, 35, ' ' );
  174.    poke_w( 3, 1, GRAPHIC | BLINK, BLEFTT(0));
  175.    poke_w( 3, 80, GRAPHIC | BLINK, BRIGHTT(0));
  176.    poke_w( 8, 22, GRAPHIC | USRCOL4, BLEFTT(0));
  177.    poke_w( 8, 58, GRAPHIC | USRCOL4, BRIGHTT(0));
  178.    poke_w( 16, 22, GRAPHIC | USRCOL4, BLEFTT(0));
  179.    poke_w( 16, 58, GRAPHIC | USRCOL4, BRIGHTT(0));
  180.    poke_w( 17, 57, USRCOL4, ' ');
  181.    disp_w(2, 2, BOLDBLINK, "Date" );
  182.    disp_w(2, 70, USRCOL2, "Time" );
  183. }
  184.  
  185.  
  186.  
  187. /*
  188.  * Open the Password file and Read it into user and module lists for processing
  189. */
  190. int openpwdfile()
  191. {
  192.     unsigned int stat = PERM_INIT;
  193.     int fd;
  194.  
  195.     statmsg("Opening File ... Please Wait");
  196.  
  197.     switch (stat = readfile()) 
  198.     {
  199.     case PERM_NOTMPFILE:
  200.         errmsg("Couldn't create temporary password file (%s).", pwdtmpf);
  201.         break;
  202.     case PERM_LOCKED:
  203.         errmsg("Password file (%s) is locked.  Try again later.", pwdfile);
  204.         break;
  205.     case PERM_NOACC:
  206.         errmsg("Password file (%s) is not accessible.", pwdfile);
  207.         break;
  208.     case PERM_INVFILE:
  209.         errmsg("Password file (%s) is invalid.  Delete and rebuild.", pwdfile);
  210.         break;
  211.     case PERM_NOFILE:
  212.         fd = PCRT_FILE(pwdfile);
  213.         if (fd < 0) 
  214.         {
  215.             errmsg("Password file (%s) could not be created.", pwdfile);
  216.             unlink(pwdtmpf);
  217.             close(tempfd);
  218.         } else {
  219.             stat = PERM_INIT;
  220.             uhand = dll_open(usercmp, sizeof(USER_ENT));
  221.             mhand = dll_open(modcmp, sizeof(MOD_ENT));
  222.         }
  223.     }
  224.     return(stat);
  225. }
  226.  
  227. /*
  228.  * MENU STRUCTURES
  229. */
  230. struct optab menu0_bar[] =
  231. {
  232.    {   7,  23,  "Add" },
  233.    {   7,  27,  "Change" },
  234.    {   7,  34,  "Delete" },
  235.    {   7,  41,  "Inquire" },
  236.    {   7,  49,  "Keys" },
  237.    {   7,  54,  "eXit" },
  238.    {  NORMAL, REVVID, NULL }
  239. };
  240.  
  241. void pwdscreenmaint()
  242. {
  243. int choice = 0;
  244.  
  245.     while (TRUE) 
  246.     {
  247.         display_extras_passwd();
  248.         choice = do_options(menu0_bar, choice, 25);
  249.         switch(choice) 
  250.         {
  251.         case 0  :
  252.             switch (keymatch) 
  253.             {
  254.             case 0:     add_user();
  255.                     break;
  256.             default: add_module();
  257.                     break;
  258.             }
  259.                break;
  260.         case 1  :
  261.             chg_user();
  262.             break;
  263.         case 2  :
  264.             switch (keymatch) 
  265.             {
  266.             case 0: del_user();
  267.                     break;
  268.             default: del_module();
  269.                     break;
  270.             }
  271.             break;
  272.         case 3  :
  273.             switch (keymatch) 
  274.             {
  275.             case 0:    inq_user();
  276.                     break;
  277.             case 1:    inq_module();
  278.                     break;
  279.             }
  280.             break;
  281.         case 4 :
  282.             op_type();
  283.             break;
  284.         case 5 :
  285.         case -1  : /* <Esc> */
  286.             return;
  287.         }
  288.         clear_window();
  289.     }
  290. }
  291.  
  292. /*
  293.  * This routine permits the user to select the type of modification 
  294.  * they would like to make.
  295. */
  296. static int op_type()
  297. {
  298.     static struct optab options[] =
  299.     {
  300.        {2, 2, "User    "},
  301.        {3, 2, "Module  "},
  302.        {NORMAL, REVVID, NULL}
  303.     };
  304.     static int rcurfunc = 0;
  305.     
  306.     disp_w(17, 24, USRCOL4, "Select type of modification to be");
  307.     disp_w(18, 24, USRCOL4, "made to password file.");
  308.     create_w(10, 35, 4, 10);
  309.     border_w(boxset, BOLD);
  310.  
  311.     rcurfunc = do_options(options, rcurfunc, 16);
  312.     delete_w();
  313.     sel_w(&main_win);
  314.  
  315.     fill_w( 17, 24, USRCOL4, 2, 34, ' ');
  316.     if (rcurfunc != -1)         /* User made a selection */
  317.     {     
  318.         keymatch = rcurfunc;
  319.         return(TRUE);
  320.     } else {                         /* Escape pressed */
  321.         rcurfunc = 0;
  322.         return(FALSE);
  323.    }
  324. }
  325.  
  326.  
  327. /* 
  328.  * Add a new unique user to the password file and give the user permissions 
  329.  * in one or more modules.
  330. */
  331. void add_user() 
  332. {
  333.     char password2[PWDARLEN];
  334.     int conspwd = FALSE;
  335.     int cont = TRUE;
  336.  
  337.     while (ichar != K_ESC) 
  338.     {         /* Continue adding users until ESC is hit */
  339.         keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  340.  
  341.         disp_w(10, 24, USRCOL4, "User Name:");
  342.         disp_w(12, 24, USRCOL4, "Password:");
  343.         disp_w(13, 24, USRCOL4, "Password:");
  344.         disp_w(17, 24, USRCOL4, "Enter information for new user.");
  345.  
  346.         cont = TRUE;
  347.         conspwd = FALSE;
  348.  
  349.         /* Input a nonempty nonexisting user */
  350.         *tmpuser.user = 0;
  351.         while (ichar != K_ESC && !strlen(tmpuser.user))
  352.         {
  353.             userfield.fbuff = tmpuser.user;
  354.             strcpy(userfield.fmask, repchr( MASK_C, userfield.fieldlen));
  355.             userfield.frow = 10;
  356.             userfield.fcol = 36;
  357.             userfield.fhelp = 1;
  358.             input_wx(&userfield, K_ESC, 0);
  359.             if (ichar != K_ESC && *tmpuser.user && (USER_ENT *)dll_find(uhand, &tmpuser) != (USER_ENT *)0) 
  360.             {
  361.                 errmsg("User name ^%s^ already exists!  Please input unique userid.", tmpuser.user);
  362.                 *tmpuser.user = 0;
  363.             }
  364.         }
  365.  
  366.         /* Input 2 passwords until they are consistent. Passwords are not 
  367.          *    shown on the screen.
  368.          */
  369.         while (ichar != K_ESC && !conspwd) 
  370.         {
  371.             *tmpuser.pwd = *password2 = '\0';
  372.             fill_w( 12, 36, USRCOL4, 2, 10, ' ' );
  373.             get_pwd(12, 36, 1, tmpuser.pwd);
  374.             if (ichar != K_ESC)
  375.                 get_pwd(13, 36, 1, password2);
  376.             if (ichar != K_ESC) 
  377.             {
  378.                 conspwd = (!bytecmp(tmpuser.pwd, password2, PWDLEN));
  379.                 if (!conspwd)
  380.                     errmsg("Passwords were not consistent.  Please re-enter.");
  381.             }
  382.         }
  383.         encrypt(tmpuser.pwd, PASSKEY);
  384.         /* Add the user line to the password file */
  385.         if (ichar != K_ESC && dll_add(uhand, &tmpuser, ADD_SORT)) 
  386.             errmsg("Couldn't add new user (%s).", tmpuser.user);
  387.  
  388.         fill_w( 9, 24, USRCOL4, 6, 34, ' ' );
  389.  
  390.         if (ichar != K_ESC)
  391.         {    /* Create a new screen for giving perms in modules */
  392.             disp_w(11, 24, USRCOL4, "Module:");
  393.             disp_w(13, 24, USRCOL4, "Permissions:");
  394.             disp_w(17, 24, USRCOL4, "Enter permissions for");
  395.             disp_w(18, 24, REVVID, tmpuser.user);
  396.             disp_w(18, 24+strlen(tmpuser.user), USRCOL4, ".");
  397.  
  398.             while (ichar != K_ESC && cont) 
  399.             {
  400.                 strcpy(tmpmod.user, tmpuser.user);
  401.  
  402.                 /*
  403.                  * input a nonempty module for which the user does not already
  404.                  * have perms (otherwise change mode should be used)
  405.                 */
  406.                 *tmpmod.mod = 0;
  407.                 while (ichar != K_ESC && !strlen(tmpmod.mod))
  408.                 {
  409.                     keys_w(K_F1, help_prompt, K_F2, choice_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  410.                     get_module_from_list( 11, 38, 2, 7, 0 );
  411.                     disp_w( 11, 38, NORMAL, tmpmod.mod);
  412.                     if ((ichar != K_ESC) && *tmpmod.mod) 
  413.                     {
  414.                         for(tmpmptr = (MOD_ENT *)dll_find(mhand, &tmpmod);(!strcmp(tmpmod.mod, tmpmptr->mod)); tmpmptr = (MOD_ENT *)dll_next(mhand)) 
  415.                         {
  416.                             if (!strcmp(tmpmod.user, tmpmptr->user)) 
  417.                             {
  418.                                 errmsg("User %s already has permissions in %s.", tmpmod.user, tmpmod.mod);
  419.                                 *tmpmod.mod = 0;
  420.                                 break;
  421.                             }
  422.                         }
  423.                     }
  424.                 }
  425.  
  426.                 /* input a nonempty perms string */
  427.                 *tmpmod.perm = 0;
  428.                 keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  429.                 while (ichar != K_ESC && !strlen(tmpmod.perm))
  430.                     getperms(13, 38, tmpmod.perm, 2); 
  431.  
  432.                 /* add the module line and inquire about continuing */
  433.                 if (ichar != K_ESC) 
  434.                 {
  435.                     tmpmod.writeflag = FALSE;
  436.                     dll_add(mhand, &tmpmod, ADD_SORT);
  437.                     disp_w(15, 24, USRCOL4, "Give more permissions to user?");
  438.                     cont = yn_w(15, 55, REVVID, 10, cont, K_ESC, 0);
  439.                     rephoriz_w(11, 38, USRCOL4, MODLEN, ' ');
  440.                     rephoriz_w(13, 38, USRCOL4, PERMLEN, ' ');
  441.                     rephoriz_w(15, 24, USRCOL4, 34, ' ');
  442.                 }
  443.             }
  444.            clear_window();
  445.         }
  446.     }
  447. }
  448.  
  449.  
  450. /* 
  451.  * Adds a module to the password file with as many associated users and 
  452.  * permissions as desired
  453. */
  454. void add_module()
  455. {
  456.     int cont = TRUE;
  457.  
  458.     /* set up the screen */
  459.  
  460.     disp_w(10, 24, USRCOL4, "Module:");
  461.     disp_w(12, 24, USRCOL4, "User Name:");
  462.     disp_w(13, 24, USRCOL4, "Permissions:");
  463.     disp_w(17, 24, USRCOL4, "Enter information for new module.");
  464.  
  465.     while (ichar != K_ESC) 
  466.     {
  467.         cont = TRUE;
  468.  
  469.         /* input a nonempty nonexisting module */
  470.         *tmpmod.mod = 0;
  471.         while (ichar != K_ESC && !strlen(tmpmod.mod)) 
  472.         {
  473.             keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  474.             modfield.fbuff = tmpmod.mod;
  475.             modfield.frow = 10;
  476.             modfield.fcol = 38;
  477.             modfield.fhelp = 3;
  478.             input_wx(&modfield, K_ESC, 0);
  479.             if ((ichar != K_ESC) && *tmpmod.mod && ((MOD_ENT *)dll_find(mhand, &tmpmod) != (MOD_ENT *)0)) 
  480.             {
  481.                 errmsg("Module `%s' already exists!  Please input unique module.", tmpmod.mod);
  482.                 *tmpmod.mod = 0;
  483.             }
  484.         }
  485.  
  486.         while (ichar != K_ESC && cont) 
  487.         {
  488.             keys_w(K_F1, help_prompt, K_F2, choice_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  489.             get_user_from_list( 12, 38, 3, 18, 0 );
  490.             strcpy(tmpmod.user, tmpuser.user);
  491.             disp_w( 12, 38, NORMAL, tmpuser.user);
  492.  
  493.             /* input a nonempty perms string */
  494.             *tmpmod.perm = 0;
  495.             keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  496.             while (ichar != K_ESC && !strlen(tmpmod.perm))
  497.                 getperms(13, 38, tmpmod.perm, 3);
  498.  
  499.             /* add the module and inquire about continuing */
  500.             if (ichar != K_ESC) 
  501.             {
  502.                 tmpmod.writeflag = FALSE;
  503.                 dll_add(mhand, &tmpmod, ADD_SORT);
  504.                 disp_w(15, 24, USRCOL4, "Give more users permissions?");
  505.                 cont = yn_w(15, 54, REVVID, 11, cont, K_ESC, 0);
  506.                 rephoriz_w(12, 38, USRCOL4, NAMELEN, ' ');
  507.                 rephoriz_w(13, 38, USRCOL4, PERMLEN, ' ');
  508.                 rephoriz_w(15, 24, USRCOL4, 34, ' ');
  509.             }
  510.         }
  511.     }
  512. }
  513.  
  514.  
  515. /* 
  516.  * Change a user's permissions in a module 
  517. */
  518. void chg_user()
  519. {
  520.     /* set up the screen */
  521.  
  522.     disp_w(9, 24, USRCOL4, "User Name:");
  523.     disp_w(11, 24, USRCOL4, "Module:");
  524.     disp_w(13, 24, USRCOL4, "Old Permissions:");
  525.     disp_w(14, 24, USRCOL4, "New Permissions:");
  526.     disp_w(17, 24, USRCOL4, "Enter detail to change user's");
  527.     disp_w(18, 24, USRCOL4, "permissions in a module.");
  528.  
  529.     while (ichar != K_ESC) 
  530.     {
  531.         keys_w(K_F1, help_prompt, K_F2, choice_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  532.         get_user_from_list( 9, 42, 4, 9, 0 );
  533.         disp_w(9, 42, NORMAL, tmpuser.user);
  534.         get_module_from_list( 11, 42, 4, 7, 0 );
  535.         strcpy(tmpmod.user, tmpuser.user);
  536.         disp_w( 11, 42, NORMAL, tmpmod.mod);
  537.  
  538.         /* 
  539.          * display the user's current perms in the module
  540.         */
  541.         if (ichar != K_ESC) 
  542.         {
  543.             for(tmpmptr = (MOD_ENT *)dll_find(mhand, &tmpmod); tmpmptr != NULL; tmpmptr = (MOD_ENT *)dll_next(mhand)) 
  544.             {
  545.                 if (!strcmp(tmpmptr->user, tmpmod.user)) 
  546.                 {
  547.                     disp_w(13, 42, USRCOL4, tmpmptr->perm);
  548.                     break;
  549.                 }
  550.             }
  551.         }
  552.  
  553.         /* 
  554.          * input a (possibly empty) perm string 
  555.         */
  556.         keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  557.         *tmpmod.perm = 0;
  558.         if (ichar != K_ESC)
  559.             getperms(14, 42, tmpmod.perm, 4);
  560.     
  561.         /* confirm the changes before making them */
  562.         if (ichar != K_ESC && warning(4, WRITEMSG)) 
  563.         { 
  564.             tmpmod.writeflag = FALSE;
  565.             if (tmpmptr == (MOD_ENT *)NULL) 
  566.             { 
  567.                 /* if user doesn't already have perms in module */
  568.                 if (*tmpmod.perm)
  569.                     dll_add(mhand, &tmpmod, ADD_SORT);
  570.             } else {
  571.                 if (cmpperms(tmpmptr->perm, tmpmod.perm)) 
  572.                 {
  573.                     dll_del(mhand);
  574.                     if (*tmpmod.perm) 
  575.                         dll_add(mhand, &tmpmod, ADD_SORT);
  576.                 }
  577.             }
  578.         }
  579.         fill_w( 9,42, USRCOL4, 6, 14, ' ' );
  580.     }
  581. }
  582.  
  583.  
  584. /* Delete a user from the password file */
  585. void del_user() 
  586. {
  587.     /* set up the screen */
  588.  
  589.     disp_w(12, 24, USRCOL4, "User Name:");
  590.     disp_w(17, 24, USRCOL4, "Enter a user to be deleted.");
  591.  
  592.     while (ichar != K_ESC) 
  593.     {
  594.         keys_w(K_F1, help_prompt, K_F2, choice_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  595.         get_user_from_list( 12, 36, 5, 18, 0 );
  596.         disp_w( 12, 36, NORMAL, tmpuser.user);
  597.         /*
  598.          * confirm the deletion
  599.         */
  600.         if (ichar != K_ESC && warning(4, "Really Delete This User ? ")) 
  601.         {
  602.             strcpy(tmpmod.user, tmpuser.user);
  603.             dll_del(uhand);        /* Delete user from list of users */
  604.  
  605.             /*
  606.              * delete every occurence of the user in module lines 
  607.             */
  608.             for (tmpmptr = (MOD_ENT *)dll_seek(mhand, 0, SEEK_SET); tmpmptr != NULL; tmpmptr = (MOD_ENT *)dll_next(mhand)) 
  609.             {
  610.                 if (!strcmp(tmpmod.user, tmpmptr->user)) 
  611.                     dll_del(mhand);
  612.             }
  613.         }
  614.         rephoriz_w(12, 36, USRCOL4, NAMELEN, ' ');
  615.     }
  616. }
  617.  
  618.  
  619. /* 
  620.  * Delete a module from the password file 
  621. */
  622. void del_module()
  623. {
  624.     /* set up the screen */
  625.     keys_w(K_F1, help_prompt, K_F2, choice_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  626.  
  627.     disp_w(12, 24, USRCOL4, "Module:");
  628.     disp_w(17, 24, USRCOL4, "Enter a module to be deleted.");
  629.  
  630.     while (ichar != K_ESC) 
  631.     {
  632.         *tmpmod.mod = 0;
  633.         while (ichar != K_ESC && !strlen(tmpmod.mod)) 
  634.         {
  635.             get_module_from_list( 12, 33, 6, 12, 0 );
  636.             disp_w( 12, 33, NORMAL, tmpmod.mod);
  637.             if ((ichar != K_ESC) && (*tmpmod.mod) && (!dll_find(mhand, &tmpmod))) 
  638.             {
  639.                 errmsg("Module %s doesn't exist.", tmpmod.mod);
  640.                 *tmpmod.mod = 0;
  641.             }
  642.         }
  643.         /* 
  644.          * confirm the deletion 
  645.         */
  646.         if (ichar != K_ESC && warning(4, "Really Delete This Module ? ")) 
  647.         {
  648.             /* delete this node ie. the first line that the module was found in */
  649.             dll_del(mhand);
  650.  
  651.             /* delete all other lines that the module is found in */
  652.             while ((tmpmptr = (MOD_ENT *)dll_next(mhand)) != (MOD_ENT *)0) 
  653.             {
  654.                 if (!strcmp(tmpmptr->mod, tmpmod.mod))
  655.                     dll_del(mhand);
  656.                 else
  657.                     break;
  658.             }
  659.         }
  660.         rephoriz_w(12, 33, USRCOL4, MODLEN, ' ');
  661.     }
  662. }
  663.  
  664. /* 
  665.  * Inquire about a user's perms according to the user 
  666. */
  667. void inq_user() 
  668. {
  669.     int selwin = 0;
  670.     int selhand;
  671.  
  672.     keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  673.  
  674.     while (ichar != K_ESC) 
  675.     {
  676.         disp_w(17, 24, USRCOL4, "Select a user.  The user's");
  677.         disp_w(18, 24, USRCOL4, "permissions will be displayed.");
  678.  
  679.         /* Get the user from a user window */
  680.         get_user_from_list( 9, 30, 13, 13, 1 );
  681.         fill_w( 17, 24, USRCOL4, 2, 34, ' ' );
  682.         if( ichar != K_ESC ) 
  683.         {
  684.             strcpy(buffer, tmpuptr->user);
  685.             disp_w(17, 24, USRCOL4, "This list displays all of");
  686.             disp_w(18, 24, USRCOL4, "%s's permissions.", tmpuptr->user);
  687.  
  688.             ncreate_w(9, 40-(MODARLEN + PERMARLEN + 5)/2, 7, MODARLEN + PERMARLEN + 5, &selwin);
  689.             border_w(0, BOLD);
  690.             /* Display a list of modules and permissions for the selected user */
  691.             dll_seek(mhand, 0, SEEK_SET);
  692.             selhand = dll_scroll(2, 2, 5, MODARLEN + PERMARLEN + 3, &selwin, mhand, modperm_dsp, SEL_SINGLE, 14, 0, 0, 0);
  693.             dll_scroll_close(&selwin);
  694.             if ((selhand == -1) && (ichar == K_ESC))
  695.                 ichar = K_CR;
  696.             sel_w(&selwin);
  697.             delete_w();
  698.             if (selhand == -2)
  699.                 errmsg("No Entries Found!");
  700.             sel_w(&main_win);
  701.             fill_w( 17, 24, USRCOL4, 2, 34, ' ' );
  702.         }
  703.     }
  704. }
  705.  
  706.  
  707. /* 
  708.  * Inquire about a user's perms according to the module 
  709. */
  710. void inq_module() 
  711. {
  712.     int selwin = 0;
  713.     int selhand;
  714.  
  715.     keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
  716.  
  717.     while (ichar != K_ESC) 
  718.     {
  719.         disp_w(17, 24, USRCOL4, "Select a module.  All users in the");
  720.         disp_w(18, 24, USRCOL4, "module will be displayed.");
  721.  
  722.         /* Get the module from a module window */
  723.         get_module_from_list( 9, 30, 15, 15, 1 );
  724.         if( ichar != K_ESC ) 
  725.         {
  726.             strcpy(buffer, tmpmptr->mod);
  727.             ndisp_w(17, 24, USRCOL4, 34, "This list displays all users with");
  728.             ndisp_w(18, 24, USRCOL4, 34, "permissions in");
  729.             disp_w(18, 39, USRCOL4, "%s.", tmpmptr->mod);
  730.  
  731.             selwin = 0;
  732.             ncreate_w(9, 40 - (NAMEARLEN + PERMARLEN + 5)/2, 7, NAMEARLEN + PERMARLEN + 5, &selwin);
  733.             border_w(0, BOLD);
  734.             /* Display a list of users and permissions for the selected module */
  735.             dll_seek(mhand, 0, SEEK_SET);
  736.             selhand = dll_scroll(2, 2, 5, NAMEARLEN + PERMARLEN + 3, &selwin, mhand, userperm_dsp, SEL_SINGLE, 17, 0, 0, 0);
  737.             dll_scroll_close(&selwin);
  738.             if ((selhand == -1) && (ichar == K_ESC))
  739.                 ichar = K_CR;
  740.             sel_w(&selwin);
  741.             delete_w();
  742.             if (selhand == -2)
  743.                 errmsg("No Entries Found!");
  744.             sel_w(&main_win);
  745.             fill_w( 17, 24, USRCOL4, 2, 34, ' ' );
  746.         }
  747.     }
  748. }
  749.  
  750.  
  751. /* 
  752.  * Get permissions - the perms are displayed  - only valid perms are 
  753.  * accepted as input
  754. */
  755. void getperms(winline, wincol, perms, helpnum)
  756. int winline, wincol, helpnum;
  757. char *perms;
  758. {
  759.     int c, j, k, valid, repeat, curstate;
  760.     int scrpos = 0;        /* keeps track of position on screen */
  761.     int permpos = 0;        /* keeps track of position of input in perm string */
  762.  
  763.     rephoriz_w(winline, wincol, REVVID, PERMLEN, ' ');
  764.     moveto_w(winline, wincol);
  765.     curstate = cursor(ON);
  766.     for (c = inchar(); c != K_ESC && c != K_CR && scrpos < PERMLEN;) 
  767.     {
  768.         if (c == K_HELP) 
  769.         {
  770.             help_msg(helpnum); 
  771.             moveto_w(winline, wincol + scrpos);
  772.             c = inchar();
  773.             continue;
  774.         }
  775.         if (c == K_BS) 
  776.         {
  777.             if (scrpos > 0) 
  778.             {
  779.                 scrpos--;
  780.                 permpos--;
  781.                 poke_w(winline, wincol+scrpos, REVVID, ' ');
  782.                 moveto_w(winline, wincol + scrpos);
  783.                 *(perms + permpos) = 0;
  784.             }
  785.             c = inchar();
  786.             continue;
  787.         }
  788.         valid = FALSE;
  789.         poke_w(winline, wincol+scrpos, REVVID, c);
  790.         c = isupper(c) ? tolower(c) : c;
  791.  
  792.         /* check validity of perm entered */
  793.         for (j = 0; !valid && pperms[j].code; j++) 
  794.         {
  795.             if (pperms[j].code == (char) c) 
  796.             {
  797.                 valid = TRUE;
  798.                 repeat = FALSE;
  799.                 /* check perm was not already input */
  800.                 for (k = 0; !repeat && k < permpos; k++) 
  801.                     if (*(perms + k) == (char) c)
  802.                         repeat = TRUE;
  803.                 if (!repeat) 
  804.                 {
  805.                     *(perms + permpos) = (char) c;
  806.                     permpos++;
  807.                 }
  808.                 scrpos++;
  809.             }
  810.         }
  811.         if (!valid) 
  812.         {
  813.             cursor(OFF);
  814.             errmsg("Only valid characters are a,A,c,C,d,D,i,I !!");
  815.             poke_w(winline, wincol+scrpos, REVVID, ' ');
  816.             cursor(ON);
  817.         }
  818.         if (scrpos != PERMLEN) 
  819.         {
  820.             moveto_w(winline, wincol + scrpos);
  821.             c = inchar();
  822.         }
  823.     }
  824.     *(perms + permpos) = (char) NULL;
  825.     if (c == K_ESC)
  826.         ichar = K_ESC;
  827.     cursor(curstate);
  828.     disp_w(winline, wincol, NORMAL, perms);
  829.     for (j = strlen(perms); j < PERMLEN; j++)
  830.         poke_w(winline, wincol + j, NORMAL, ' ');
  831. }
  832.  
  833. /* 
  834.  * Display a user - for scrolling window 
  835. */
  836. char *user_dsp(ueptr)
  837. USER_ENT *ueptr;
  838. {
  839.     return(ueptr->user);
  840. }
  841.  
  842. /* 
  843.  * Display a module - for scrolling window 
  844. */
  845. char *mod_dsp(meptr)
  846. MOD_ENT *meptr;
  847. {
  848.     struct dll_entry *curpos; 
  849.  
  850.     curpos = dll_getpos(mhand);
  851.     tmpmptr = (MOD_ENT *)dll_find(mhand, meptr);
  852.     dll_setpos(mhand, curpos);
  853.     if (!strcmp(meptr->user, tmpmptr->user)) 
  854.         return(meptr->mod);
  855.     else 
  856.         return(NULL);
  857. }
  858.  
  859. /* 
  860.  * Display a user and its perms for a given module - for scrolling window 
  861. */
  862. char *userperm_dsp(meptr)
  863. MOD_ENT *meptr;
  864. {
  865.     static char userperm_str[NAMEARLEN + PERMARLEN];
  866.  
  867.     /* user and perms are only displayed if they match the module found in 
  868.      * buffer
  869.      */
  870.     if (!strcmp(meptr->mod, buffer)) 
  871.     {
  872.         sprintf(userperm_str, "%s %s", meptr->user, meptr->perm);
  873.         return(userperm_str);
  874.     } else
  875.         return(NULL);
  876. }
  877.  
  878. /* 
  879.  * Display a module and perms for a given user - for scrolling window 
  880. */
  881. char *modperm_dsp(meptr)
  882. MOD_ENT *meptr;
  883. {
  884.     static char modperm_str[MODARLEN + PERMARLEN];
  885.  
  886.     /* module and perms are only displayed if they match the user found in 
  887.      * buffer
  888.      */
  889.     if (!strcmp(meptr->user, buffer)) 
  890.     {
  891.         sprintf(modperm_str, "%s %s", meptr->mod, meptr->perm);
  892.         return(modperm_str);
  893.     } else
  894.         return(NULL);
  895. }
  896.  
  897. /*
  898.  * input a nonempty existing user with F2 to select from list
  899. */
  900. void get_user_from_list( input_row, input_col, input_help, popup_help, mode )
  901. int input_row, input_col, input_help, popup_help, mode;
  902. {
  903.     int uwin = 0;
  904.     int seluhand = -1;
  905.     struct sel_entry *useptr;
  906.     *tmpuser.user = 0;
  907.     if (mode) ichar = K_F2;
  908.     while (ichar != K_ESC && !strlen(tmpuser.user)) 
  909.     {
  910.         userfield.fbuff = tmpuser.user;
  911.         strcpy(userfield.fmask, repchr( MASK_C, userfield.fieldlen));
  912.         userfield.frow = input_row;
  913.         userfield.fcol = input_col;
  914.         userfield.fhelp = input_help;
  915.         if (!mode) input_wx(&userfield, K_F2, K_ESC, 0);
  916.         if (ichar == K_F2)         /* pop-up window request */
  917.         {
  918.             ncreate_w(input_row, input_col, 7, NAMEARLEN + 5, &uwin);
  919.             border_w(0, BOLD);
  920.             dll_seek(uhand, 0, SEEK_SET);
  921.             seluhand = dll_scroll(2, 2, 5, NAMEARLEN + 3, &uwin, uhand, user_dsp, SEL_SINGLE, popup_help, 0, 0, 0);
  922.             dll_scroll_close(&uwin);
  923.             sel_w(&uwin);
  924.             delete_w();
  925.             sel_w(&main_win);
  926.             if ((seluhand < 0) || ((useptr = (struct sel_entry *)dll_seek(seluhand, 0, SEEK_SET)) == (struct sel_entry *)0)) 
  927.             {
  928.                 if (!mode) ichar = K_CR;
  929.                 else ichar = K_ESC;
  930.                 *tmpuser.user = 0;
  931.             } else {
  932.                 tmpuptr = (USER_ENT *)useptr->sel_data;
  933.                 strcpy(tmpuser.user, tmpuptr->user);
  934.             }    
  935.         }
  936.         /* does user exist? */
  937.         if ((ichar != K_ESC) && *tmpuser.user && ((USER_ENT *)dll_find(uhand, &tmpuser) == (USER_ENT *)0)) 
  938.         {
  939.             errmsg("User %s does not exist!", tmpuser.user);
  940.             *tmpuser.user = 0;
  941.         } 
  942.     }
  943. }
  944.  
  945. /* 
  946.  * input a nonempty module with F2 to select from list
  947. */
  948. void get_module_from_list( input_row, input_col, input_help, popup_help, mode )
  949. int input_row, input_col, input_help, popup_help, mode;
  950. {
  951.     int mwin = 0;
  952.     int selmhand = -1;
  953.     struct sel_entry *mseptr;
  954.     *tmpmod.mod = 0;
  955.  
  956.     if (mode) ichar = K_F2;
  957.     while (ichar != K_ESC && !strlen(tmpmod.mod)) 
  958.     {
  959.         modfield.fbuff = tmpmod.mod;
  960.         modfield.frow = input_row;
  961.         modfield.fcol = input_col;
  962.         modfield.fhelp = input_help;
  963.         if (!mode) input_wx(&modfield, K_F2, K_ESC, 0);
  964.         if (ichar == K_F2)         /* pop-up window request */
  965.         {
  966.             ncreate_w(input_row, input_col, 7, MODARLEN + 5, &mwin);
  967.             border_w(0, BOLD);
  968.             dll_seek(mhand, 0, SEEK_SET);
  969.             selmhand = dll_scroll(2, 2, 5, MODARLEN + 3, &mwin, mhand, mod_dsp, SEL_SINGLE, popup_help, 0, 0, 0);
  970.             dll_scroll_close(&mwin);
  971.             sel_w(&mwin);
  972.             delete_w();
  973.             sel_w(&main_win);
  974.             if ((selmhand < 0) || ((mseptr = (struct sel_entry *)dll_seek(selmhand, 0, SEEK_SET)) == (struct sel_entry *)0)) 
  975.             {
  976.                 if (!mode) ichar = K_CR;
  977.                 else ichar = K_ESC;
  978.                 *tmpmod.mod = 0;
  979.             } else {
  980.                 tmpmptr = (MOD_ENT *)mseptr->sel_data;
  981.                 strcpy(tmpmod.mod, tmpmptr->mod);
  982.             }    
  983.         }
  984.     }
  985. }
  986.  
  987. void clear_window()
  988. {
  989.     fill_w( 9, 24, USRCOL4, 7, 34, ' ' );
  990.     fill_w( 17, 24, USRCOL4, 2, 34, ' ' );
  991. }
  992.  
  993. void get_pwd( input_row, input_col, input_help, pswd )
  994. int input_row, input_col, input_help;
  995. char *pswd;
  996. {
  997.     ichar = K_CR;
  998.     pwdfield.frow = input_row;
  999.     pwdfield.fcol = input_col;
  1000.     pwdfield.fhelp = input_help;
  1001.     pwdfield.fbuff = pswd; 
  1002.     while( ichar != K_ESC && !strlen(pswd) ) 
  1003.         input_wx(&pwdfield, K_ESC, 0);
  1004. }
  1005.  
  1006. /*
  1007.  * extras buffer
  1008. */
  1009. char tmpinput[20];
  1010.  
  1011. char passwd_Date_mask[] = "MM-DD-YYYY";
  1012. FIELD f_passwd_Date = 
  1013. {
  1014.    2  , 7  , 1, tmpinput, passwd_Date_mask, 0,
  1015.    10, F_DATE, USRCOL2, REVVID, CONFIRM_NEEDED | NO_BLANK,
  1016.    NULL, NULL, NULL, NULL
  1017. };
  1018.  
  1019. char passwd_Time_mask[] = "HH:NN";
  1020. FIELD f_passwd_Time = 
  1021. {
  1022.    2  , 75 , 1, tmpinput, passwd_Time_mask, 0,
  1023.    5, F_DATE, USRCOL2, REVVID, CONFIRM_NEEDED | NO_BLANK,
  1024.    NULL, NULL, NULL, NULL
  1025. };
  1026.  
  1027. /*
  1028.  * display date and/or time
  1029. */
  1030. void display_extras_passwd()
  1031. {
  1032.    strcpy(f_passwd_Date.fbuff, ltocon(today(), f_passwd_Date.fmask, 1));
  1033.    disp_text(&f_passwd_Date, f_passwd_Date.fattrib_on);
  1034.    strcpy(f_passwd_Time.fbuff, ltocon(today(), f_passwd_Time.fmask, 1));
  1035.    disp_text(&f_passwd_Time, f_passwd_Time.fattrib_on);
  1036. }
  1037.