home *** CD-ROM | disk | FTP | other *** search
- /* ---( src/passwd.c )---------------------------- */
- /* Pro-C - Copyright (C) 1988, 1989 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written JZ Jan-90 */
- /* Modified Nig 29-Jan-90 */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- * 27-Mar-90 NVS - Condense code
- * 30-Jan-90 Nig - Rename Command using help/renfile
- * 29-Jan-90 Nig - Enhancements using dll.....
- */
-
- #include <stdio.h>
- #include <bench.h>
- #include <time.h>
- #include <errno.h>
- #include <proc.io>
- #include <field.h>
-
- #include <passwd.h>
-
- #include "../hdr/fileio.h"
- #include "../hdr/dllist.h"
-
- /* These 2 lines need to be removed and taken care of externally */
- # define MYVER "2.0"
- # define MAXLOCKTRYS 10
-
- # ifdef UNIX
- # undef BLINK
- # define BLINK NORMAL
- # else
- # undef USRCOL4
- # define USRCOL4 NORMAL
- # endif
-
- /*
- * GLOBAL DEFINES
- */
- #define HELP_FILE "pass"
- #define WRITEMSG "Write Changes back to File ? "
- #define PRJFILE "test"
- #define USER 0
- #define MODULE 1
-
- extern FIELD modfield;
- extern FIELD userfield;
- extern FIELD pwdfield;
- extern int uhand;
- extern int mhand;
- extern USER_ENT tmpuser;
- extern MOD_ENT tmpmod;
- extern USER_ENT *tmpuptr;
- extern MOD_ENT *tmpmptr;
- extern char buffer[];
- extern char pwdfile[];
- extern char pwdtmpf[];
- extern char pswdfile_path[];
- extern int tempfd;
-
- extern PERMS pperms[];
- extern int ichar; /* Global INPUT_W Return Value - 0 for CR */
-
- # ifdef MSDOS /* Set up tables monitor types */
- extern char xmonitor;
- extern unsigned char colour[];
- static unsigned char dcolour[] =
- { 0x00, 0x17, 0x30, 0x47, 0x17, 0x1f, 0x30, 0x4f,
- 0x1f, 0x19, 0x1f, 0x2f, 0x3f, 0x4f, 0x5f, 0x6f};
- static unsigned char dmono[] =
- { 0x00, 0x07, 0x70, 0x01, 0x07, 0x0f, 0x70, 0x09,
- 0x0f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07};
- # endif
-
- /*
- * Set keywords used by library routines
- */
- char accept_prompt[] = "Accept";
- char cancel_prompt[] = "Cancel";
- char exit_prompt[] = "Exit";
- char help_prompt[] = "Help";
- char menu_prompt[] = "Menu";
- char no_prompt[] = "No";
- char ok_prompt[] = "Ok";
- char popup_prompt[] = "Popup";
- char select_prompt[] = "Select";
- char toggle_prompt[] = "Toggle";
- char yes_prompt[] = "Yes";
- char res_prompt[] = "Resize";
- char move_prompt[] = "Move";
- char choice_prompt[] = "Choices";
- char scroll_prompt[] = "Scroll";
- char rescan_prompt[] = "Rescan";
- char invoke_prompt[] = "Invoke";
- char cont_prompt[] = "Continue";
-
- int main_win;
- static int keymatch = USER;
-
- static PROTO (int op_type, (void));
-
- /*
- * Main Module for Password Administration
- */
- main(argc, argv)
- int argc;
- char *argv[];
- {
- initpwdscreen (argc > 1 ? argv[1] : PRJFILE);
- if (openpwdfile() == PERM_INIT)
- {
- pwdscreenmaint();
- writefile();
- dll_close(uhand);
- dll_close(mhand);
- }
- chain("", NULL);
- }
-
- /*
- * Display the First Screen and Initialize Variables
- */
- void initpwdscreen(prjname)
- char *prjname;
- {
- open_help(HELP_FILE);
- init_w(24, 80);
-
- # ifdef MSDOS
- /* Set up the colour array (AFTER the first create_w) */
- if (xmonitor == MONO)
- bytecpy(colour, dmono, 16);
- else
- bytecpy(colour, dcolour, 16);
- # endif
-
- /* Initialize global variables */
- setvars(prjname);
-
- /* Create a Window For The Screen */
- main_win = 0;
- ncreate_w( 1, 1, w_nrows, w_ncols, &main_win);
-
- /* Now display the Text */
-
- fill_w( 6, 2, BLINK, 14, 20, ' ' );
- fill_w( 9, 23, USRCOL4, 7, 35, ' ' );
- fill_w( 7, 60, BLINK, 14, 20, ' ' );
- boxset = 0;
- box_w( 1, 1, GRAPHIC | BLINK, 23, 80 );
- box_w( 6, 22, GRAPHIC | USRCOL4, 14, 37 );
- disp_w( 2, 24, BOLDBLINK, "Password Administration - ");
- strupr(prjname);
- disp_w( 2, 50, BOLDBLINK, prjname);
-
- rephoriz_w( 3, 2, GRAPHIC | BLINK, 78, BHORIZ(0));
- rephoriz_w( 8, 23, GRAPHIC | USRCOL4, 35, BHORIZ(0));
- rephoriz_w( 16, 23, GRAPHIC | USRCOL4, 35, BHORIZ(0));
- rephoriz_w( 2, 2, BOLDBLINK, 22, ' ');
- fill_w( 4, 2, BLINK, 2, 78, ' ' );
- rephoriz_w( 20, 2, BLINK, 21, ' ');
- fill_w( 21, 2, BLINK, 2, 78, ' ' );
- rephoriz_w( 7, 23, USRCOL4, 35, ' ');
- rephoriz_w( 2, 50 + strlen(prjname), BOLDBLINK, 30-strlen(prjname), ' ');
- rephoriz_w( 6, 59, BLINK, 21, ' ');
- fill_w( 17, 23, USRCOL4, 2, 35, ' ' );
- poke_w( 3, 1, GRAPHIC | BLINK, BLEFTT(0));
- poke_w( 3, 80, GRAPHIC | BLINK, BRIGHTT(0));
- poke_w( 8, 22, GRAPHIC | USRCOL4, BLEFTT(0));
- poke_w( 8, 58, GRAPHIC | USRCOL4, BRIGHTT(0));
- poke_w( 16, 22, GRAPHIC | USRCOL4, BLEFTT(0));
- poke_w( 16, 58, GRAPHIC | USRCOL4, BRIGHTT(0));
- poke_w( 17, 57, USRCOL4, ' ');
- disp_w(2, 2, BOLDBLINK, "Date" );
- disp_w(2, 70, USRCOL2, "Time" );
- }
-
-
-
- /*
- * Open the Password file and Read it into user and module lists for processing
- */
- int openpwdfile()
- {
- unsigned int stat = PERM_INIT;
- int fd;
-
- statmsg("Opening File ... Please Wait");
-
- switch (stat = readfile())
- {
- case PERM_NOTMPFILE:
- errmsg("Couldn't create temporary password file (%s).", pwdtmpf);
- break;
- case PERM_LOCKED:
- errmsg("Password file (%s) is locked. Try again later.", pwdfile);
- break;
- case PERM_NOACC:
- errmsg("Password file (%s) is not accessible.", pwdfile);
- break;
- case PERM_INVFILE:
- errmsg("Password file (%s) is invalid. Delete and rebuild.", pwdfile);
- break;
- case PERM_NOFILE:
- fd = PCRT_FILE(pwdfile);
- if (fd < 0)
- {
- errmsg("Password file (%s) could not be created.", pwdfile);
- unlink(pwdtmpf);
- close(tempfd);
- } else {
- stat = PERM_INIT;
- uhand = dll_open(usercmp, sizeof(USER_ENT));
- mhand = dll_open(modcmp, sizeof(MOD_ENT));
- }
- }
- return(stat);
- }
-
- /*
- * MENU STRUCTURES
- */
- struct optab menu0_bar[] =
- {
- { 7, 23, "Add" },
- { 7, 27, "Change" },
- { 7, 34, "Delete" },
- { 7, 41, "Inquire" },
- { 7, 49, "Keys" },
- { 7, 54, "eXit" },
- { NORMAL, REVVID, NULL }
- };
-
- void pwdscreenmaint()
- {
- int choice = 0;
-
- while (TRUE)
- {
- display_extras_passwd();
- choice = do_options(menu0_bar, choice, 25);
- switch(choice)
- {
- case 0 :
- switch (keymatch)
- {
- case 0: add_user();
- break;
- default: add_module();
- break;
- }
- break;
- case 1 :
- chg_user();
- break;
- case 2 :
- switch (keymatch)
- {
- case 0: del_user();
- break;
- default: del_module();
- break;
- }
- break;
- case 3 :
- switch (keymatch)
- {
- case 0: inq_user();
- break;
- case 1: inq_module();
- break;
- }
- break;
- case 4 :
- op_type();
- break;
- case 5 :
- case -1 : /* <Esc> */
- return;
- }
- clear_window();
- }
- }
-
- /*
- * This routine permits the user to select the type of modification
- * they would like to make.
- */
- static int op_type()
- {
- static struct optab options[] =
- {
- {2, 2, "User "},
- {3, 2, "Module "},
- {NORMAL, REVVID, NULL}
- };
- static int rcurfunc = 0;
-
- disp_w(17, 24, USRCOL4, "Select type of modification to be");
- disp_w(18, 24, USRCOL4, "made to password file.");
- create_w(10, 35, 4, 10);
- border_w(boxset, BOLD);
-
- rcurfunc = do_options(options, rcurfunc, 16);
- delete_w();
- sel_w(&main_win);
-
- fill_w( 17, 24, USRCOL4, 2, 34, ' ');
- if (rcurfunc != -1) /* User made a selection */
- {
- keymatch = rcurfunc;
- return(TRUE);
- } else { /* Escape pressed */
- rcurfunc = 0;
- return(FALSE);
- }
- }
-
-
- /*
- * Add a new unique user to the password file and give the user permissions
- * in one or more modules.
- */
- void add_user()
- {
- char password2[PWDARLEN];
- int conspwd = FALSE;
- int cont = TRUE;
-
- while (ichar != K_ESC)
- { /* Continue adding users until ESC is hit */
- keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
-
- disp_w(10, 24, USRCOL4, "User Name:");
- disp_w(12, 24, USRCOL4, "Password:");
- disp_w(13, 24, USRCOL4, "Password:");
- disp_w(17, 24, USRCOL4, "Enter information for new user.");
-
- cont = TRUE;
- conspwd = FALSE;
-
- /* Input a nonempty nonexisting user */
- *tmpuser.user = 0;
- while (ichar != K_ESC && !strlen(tmpuser.user))
- {
- userfield.fbuff = tmpuser.user;
- strcpy(userfield.fmask, repchr( MASK_C, userfield.fieldlen));
- userfield.frow = 10;
- userfield.fcol = 36;
- userfield.fhelp = 1;
- input_wx(&userfield, K_ESC, 0);
- if (ichar != K_ESC && *tmpuser.user && (USER_ENT *)dll_find(uhand, &tmpuser) != (USER_ENT *)0)
- {
- errmsg("User name ^%s^ already exists! Please input unique userid.", tmpuser.user);
- *tmpuser.user = 0;
- }
- }
-
- /* Input 2 passwords until they are consistent. Passwords are not
- * shown on the screen.
- */
- while (ichar != K_ESC && !conspwd)
- {
- *tmpuser.pwd = *password2 = '\0';
- fill_w( 12, 36, USRCOL4, 2, 10, ' ' );
- get_pwd(12, 36, 1, tmpuser.pwd);
- if (ichar != K_ESC)
- get_pwd(13, 36, 1, password2);
- if (ichar != K_ESC)
- {
- conspwd = (!bytecmp(tmpuser.pwd, password2, PWDLEN));
- if (!conspwd)
- errmsg("Passwords were not consistent. Please re-enter.");
- }
- }
- encrypt(tmpuser.pwd, PASSKEY);
- /* Add the user line to the password file */
- if (ichar != K_ESC && dll_add(uhand, &tmpuser, ADD_SORT))
- errmsg("Couldn't add new user (%s).", tmpuser.user);
-
- fill_w( 9, 24, USRCOL4, 6, 34, ' ' );
-
- if (ichar != K_ESC)
- { /* Create a new screen for giving perms in modules */
- disp_w(11, 24, USRCOL4, "Module:");
- disp_w(13, 24, USRCOL4, "Permissions:");
- disp_w(17, 24, USRCOL4, "Enter permissions for");
- disp_w(18, 24, REVVID, tmpuser.user);
- disp_w(18, 24+strlen(tmpuser.user), USRCOL4, ".");
-
- while (ichar != K_ESC && cont)
- {
- strcpy(tmpmod.user, tmpuser.user);
-
- /*
- * input a nonempty module for which the user does not already
- * have perms (otherwise change mode should be used)
- */
- *tmpmod.mod = 0;
- while (ichar != K_ESC && !strlen(tmpmod.mod))
- {
- keys_w(K_F1, help_prompt, K_F2, choice_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
- get_module_from_list( 11, 38, 2, 7, 0 );
- disp_w( 11, 38, NORMAL, tmpmod.mod);
- if ((ichar != K_ESC) && *tmpmod.mod)
- {
- for(tmpmptr = (MOD_ENT *)dll_find(mhand, &tmpmod);(!strcmp(tmpmod.mod, tmpmptr->mod)); tmpmptr = (MOD_ENT *)dll_next(mhand))
- {
- if (!strcmp(tmpmod.user, tmpmptr->user))
- {
- errmsg("User %s already has permissions in %s.", tmpmod.user, tmpmod.mod);
- *tmpmod.mod = 0;
- break;
- }
- }
- }
- }
-
- /* input a nonempty perms string */
- *tmpmod.perm = 0;
- keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
- while (ichar != K_ESC && !strlen(tmpmod.perm))
- getperms(13, 38, tmpmod.perm, 2);
-
- /* add the module line and inquire about continuing */
- if (ichar != K_ESC)
- {
- tmpmod.writeflag = FALSE;
- dll_add(mhand, &tmpmod, ADD_SORT);
- disp_w(15, 24, USRCOL4, "Give more permissions to user?");
- cont = yn_w(15, 55, REVVID, 10, cont, K_ESC, 0);
- rephoriz_w(11, 38, USRCOL4, MODLEN, ' ');
- rephoriz_w(13, 38, USRCOL4, PERMLEN, ' ');
- rephoriz_w(15, 24, USRCOL4, 34, ' ');
- }
- }
- clear_window();
- }
- }
- }
-
-
- /*
- * Adds a module to the password file with as many associated users and
- * permissions as desired
- */
- void add_module()
- {
- int cont = TRUE;
-
- /* set up the screen */
-
- disp_w(10, 24, USRCOL4, "Module:");
- disp_w(12, 24, USRCOL4, "User Name:");
- disp_w(13, 24, USRCOL4, "Permissions:");
- disp_w(17, 24, USRCOL4, "Enter information for new module.");
-
- while (ichar != K_ESC)
- {
- cont = TRUE;
-
- /* input a nonempty nonexisting module */
- *tmpmod.mod = 0;
- while (ichar != K_ESC && !strlen(tmpmod.mod))
- {
- keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
- modfield.fbuff = tmpmod.mod;
- modfield.frow = 10;
- modfield.fcol = 38;
- modfield.fhelp = 3;
- input_wx(&modfield, K_ESC, 0);
- if ((ichar != K_ESC) && *tmpmod.mod && ((MOD_ENT *)dll_find(mhand, &tmpmod) != (MOD_ENT *)0))
- {
- errmsg("Module `%s' already exists! Please input unique module.", tmpmod.mod);
- *tmpmod.mod = 0;
- }
- }
-
- while (ichar != K_ESC && cont)
- {
- keys_w(K_F1, help_prompt, K_F2, choice_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
- get_user_from_list( 12, 38, 3, 18, 0 );
- strcpy(tmpmod.user, tmpuser.user);
- disp_w( 12, 38, NORMAL, tmpuser.user);
-
- /* input a nonempty perms string */
- *tmpmod.perm = 0;
- keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
- while (ichar != K_ESC && !strlen(tmpmod.perm))
- getperms(13, 38, tmpmod.perm, 3);
-
- /* add the module and inquire about continuing */
- if (ichar != K_ESC)
- {
- tmpmod.writeflag = FALSE;
- dll_add(mhand, &tmpmod, ADD_SORT);
- disp_w(15, 24, USRCOL4, "Give more users permissions?");
- cont = yn_w(15, 54, REVVID, 11, cont, K_ESC, 0);
- rephoriz_w(12, 38, USRCOL4, NAMELEN, ' ');
- rephoriz_w(13, 38, USRCOL4, PERMLEN, ' ');
- rephoriz_w(15, 24, USRCOL4, 34, ' ');
- }
- }
- }
- }
-
-
- /*
- * Change a user's permissions in a module
- */
- void chg_user()
- {
- /* set up the screen */
-
- disp_w(9, 24, USRCOL4, "User Name:");
- disp_w(11, 24, USRCOL4, "Module:");
- disp_w(13, 24, USRCOL4, "Old Permissions:");
- disp_w(14, 24, USRCOL4, "New Permissions:");
- disp_w(17, 24, USRCOL4, "Enter detail to change user's");
- disp_w(18, 24, USRCOL4, "permissions in a module.");
-
- while (ichar != K_ESC)
- {
- keys_w(K_F1, help_prompt, K_F2, choice_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
- get_user_from_list( 9, 42, 4, 9, 0 );
- disp_w(9, 42, NORMAL, tmpuser.user);
- get_module_from_list( 11, 42, 4, 7, 0 );
- strcpy(tmpmod.user, tmpuser.user);
- disp_w( 11, 42, NORMAL, tmpmod.mod);
-
- /*
- * display the user's current perms in the module
- */
- if (ichar != K_ESC)
- {
- for(tmpmptr = (MOD_ENT *)dll_find(mhand, &tmpmod); tmpmptr != NULL; tmpmptr = (MOD_ENT *)dll_next(mhand))
- {
- if (!strcmp(tmpmptr->user, tmpmod.user))
- {
- disp_w(13, 42, USRCOL4, tmpmptr->perm);
- break;
- }
- }
- }
-
- /*
- * input a (possibly empty) perm string
- */
- keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
- *tmpmod.perm = 0;
- if (ichar != K_ESC)
- getperms(14, 42, tmpmod.perm, 4);
-
- /* confirm the changes before making them */
- if (ichar != K_ESC && warning(4, WRITEMSG))
- {
- tmpmod.writeflag = FALSE;
- if (tmpmptr == (MOD_ENT *)NULL)
- {
- /* if user doesn't already have perms in module */
- if (*tmpmod.perm)
- dll_add(mhand, &tmpmod, ADD_SORT);
- } else {
- if (cmpperms(tmpmptr->perm, tmpmod.perm))
- {
- dll_del(mhand);
- if (*tmpmod.perm)
- dll_add(mhand, &tmpmod, ADD_SORT);
- }
- }
- }
- fill_w( 9,42, USRCOL4, 6, 14, ' ' );
- }
- }
-
-
- /* Delete a user from the password file */
- void del_user()
- {
- /* set up the screen */
-
- disp_w(12, 24, USRCOL4, "User Name:");
- disp_w(17, 24, USRCOL4, "Enter a user to be deleted.");
-
- while (ichar != K_ESC)
- {
- keys_w(K_F1, help_prompt, K_F2, choice_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
- get_user_from_list( 12, 36, 5, 18, 0 );
- disp_w( 12, 36, NORMAL, tmpuser.user);
- /*
- * confirm the deletion
- */
- if (ichar != K_ESC && warning(4, "Really Delete This User ? "))
- {
- strcpy(tmpmod.user, tmpuser.user);
- dll_del(uhand); /* Delete user from list of users */
-
- /*
- * delete every occurence of the user in module lines
- */
- for (tmpmptr = (MOD_ENT *)dll_seek(mhand, 0, SEEK_SET); tmpmptr != NULL; tmpmptr = (MOD_ENT *)dll_next(mhand))
- {
- if (!strcmp(tmpmod.user, tmpmptr->user))
- dll_del(mhand);
- }
- }
- rephoriz_w(12, 36, USRCOL4, NAMELEN, ' ');
- }
- }
-
-
- /*
- * Delete a module from the password file
- */
- void del_module()
- {
- /* set up the screen */
- keys_w(K_F1, help_prompt, K_F2, choice_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
-
- disp_w(12, 24, USRCOL4, "Module:");
- disp_w(17, 24, USRCOL4, "Enter a module to be deleted.");
-
- while (ichar != K_ESC)
- {
- *tmpmod.mod = 0;
- while (ichar != K_ESC && !strlen(tmpmod.mod))
- {
- get_module_from_list( 12, 33, 6, 12, 0 );
- disp_w( 12, 33, NORMAL, tmpmod.mod);
- if ((ichar != K_ESC) && (*tmpmod.mod) && (!dll_find(mhand, &tmpmod)))
- {
- errmsg("Module %s doesn't exist.", tmpmod.mod);
- *tmpmod.mod = 0;
- }
- }
- /*
- * confirm the deletion
- */
- if (ichar != K_ESC && warning(4, "Really Delete This Module ? "))
- {
- /* delete this node ie. the first line that the module was found in */
- dll_del(mhand);
-
- /* delete all other lines that the module is found in */
- while ((tmpmptr = (MOD_ENT *)dll_next(mhand)) != (MOD_ENT *)0)
- {
- if (!strcmp(tmpmptr->mod, tmpmod.mod))
- dll_del(mhand);
- else
- break;
- }
- }
- rephoriz_w(12, 33, USRCOL4, MODLEN, ' ');
- }
- }
-
- /*
- * Inquire about a user's perms according to the user
- */
- void inq_user()
- {
- int selwin = 0;
- int selhand;
-
- keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
-
- while (ichar != K_ESC)
- {
- disp_w(17, 24, USRCOL4, "Select a user. The user's");
- disp_w(18, 24, USRCOL4, "permissions will be displayed.");
-
- /* Get the user from a user window */
- get_user_from_list( 9, 30, 13, 13, 1 );
- fill_w( 17, 24, USRCOL4, 2, 34, ' ' );
- if( ichar != K_ESC )
- {
- strcpy(buffer, tmpuptr->user);
- disp_w(17, 24, USRCOL4, "This list displays all of");
- disp_w(18, 24, USRCOL4, "%s's permissions.", tmpuptr->user);
-
- ncreate_w(9, 40-(MODARLEN + PERMARLEN + 5)/2, 7, MODARLEN + PERMARLEN + 5, &selwin);
- border_w(0, BOLD);
- /* Display a list of modules and permissions for the selected user */
- dll_seek(mhand, 0, SEEK_SET);
- selhand = dll_scroll(2, 2, 5, MODARLEN + PERMARLEN + 3, &selwin, mhand, modperm_dsp, SEL_SINGLE, 14, 0, 0, 0);
- dll_scroll_close(&selwin);
- if ((selhand == -1) && (ichar == K_ESC))
- ichar = K_CR;
- sel_w(&selwin);
- delete_w();
- if (selhand == -2)
- errmsg("No Entries Found!");
- sel_w(&main_win);
- fill_w( 17, 24, USRCOL4, 2, 34, ' ' );
- }
- }
- }
-
-
- /*
- * Inquire about a user's perms according to the module
- */
- void inq_module()
- {
- int selwin = 0;
- int selhand;
-
- keys_w(K_F1, help_prompt, K_CR, accept_prompt, K_ESC, exit_prompt, 0);
-
- while (ichar != K_ESC)
- {
- disp_w(17, 24, USRCOL4, "Select a module. All users in the");
- disp_w(18, 24, USRCOL4, "module will be displayed.");
-
- /* Get the module from a module window */
- get_module_from_list( 9, 30, 15, 15, 1 );
- if( ichar != K_ESC )
- {
- strcpy(buffer, tmpmptr->mod);
- ndisp_w(17, 24, USRCOL4, 34, "This list displays all users with");
- ndisp_w(18, 24, USRCOL4, 34, "permissions in");
- disp_w(18, 39, USRCOL4, "%s.", tmpmptr->mod);
-
- selwin = 0;
- ncreate_w(9, 40 - (NAMEARLEN + PERMARLEN + 5)/2, 7, NAMEARLEN + PERMARLEN + 5, &selwin);
- border_w(0, BOLD);
- /* Display a list of users and permissions for the selected module */
- dll_seek(mhand, 0, SEEK_SET);
- selhand = dll_scroll(2, 2, 5, NAMEARLEN + PERMARLEN + 3, &selwin, mhand, userperm_dsp, SEL_SINGLE, 17, 0, 0, 0);
- dll_scroll_close(&selwin);
- if ((selhand == -1) && (ichar == K_ESC))
- ichar = K_CR;
- sel_w(&selwin);
- delete_w();
- if (selhand == -2)
- errmsg("No Entries Found!");
- sel_w(&main_win);
- fill_w( 17, 24, USRCOL4, 2, 34, ' ' );
- }
- }
- }
-
-
- /*
- * Get permissions - the perms are displayed - only valid perms are
- * accepted as input
- */
- void getperms(winline, wincol, perms, helpnum)
- int winline, wincol, helpnum;
- char *perms;
- {
- int c, j, k, valid, repeat, curstate;
- int scrpos = 0; /* keeps track of position on screen */
- int permpos = 0; /* keeps track of position of input in perm string */
-
- rephoriz_w(winline, wincol, REVVID, PERMLEN, ' ');
- moveto_w(winline, wincol);
- curstate = cursor(ON);
- for (c = inchar(); c != K_ESC && c != K_CR && scrpos < PERMLEN;)
- {
- if (c == K_HELP)
- {
- help_msg(helpnum);
- moveto_w(winline, wincol + scrpos);
- c = inchar();
- continue;
- }
- if (c == K_BS)
- {
- if (scrpos > 0)
- {
- scrpos--;
- permpos--;
- poke_w(winline, wincol+scrpos, REVVID, ' ');
- moveto_w(winline, wincol + scrpos);
- *(perms + permpos) = 0;
- }
- c = inchar();
- continue;
- }
- valid = FALSE;
- poke_w(winline, wincol+scrpos, REVVID, c);
- c = isupper(c) ? tolower(c) : c;
-
- /* check validity of perm entered */
- for (j = 0; !valid && pperms[j].code; j++)
- {
- if (pperms[j].code == (char) c)
- {
- valid = TRUE;
- repeat = FALSE;
- /* check perm was not already input */
- for (k = 0; !repeat && k < permpos; k++)
- if (*(perms + k) == (char) c)
- repeat = TRUE;
- if (!repeat)
- {
- *(perms + permpos) = (char) c;
- permpos++;
- }
- scrpos++;
- }
- }
- if (!valid)
- {
- cursor(OFF);
- errmsg("Only valid characters are a,A,c,C,d,D,i,I !!");
- poke_w(winline, wincol+scrpos, REVVID, ' ');
- cursor(ON);
- }
- if (scrpos != PERMLEN)
- {
- moveto_w(winline, wincol + scrpos);
- c = inchar();
- }
- }
- *(perms + permpos) = (char) NULL;
- if (c == K_ESC)
- ichar = K_ESC;
- cursor(curstate);
- disp_w(winline, wincol, NORMAL, perms);
- for (j = strlen(perms); j < PERMLEN; j++)
- poke_w(winline, wincol + j, NORMAL, ' ');
- }
-
- /*
- * Display a user - for scrolling window
- */
- char *user_dsp(ueptr)
- USER_ENT *ueptr;
- {
- return(ueptr->user);
- }
-
- /*
- * Display a module - for scrolling window
- */
- char *mod_dsp(meptr)
- MOD_ENT *meptr;
- {
- struct dll_entry *curpos;
-
- curpos = dll_getpos(mhand);
- tmpmptr = (MOD_ENT *)dll_find(mhand, meptr);
- dll_setpos(mhand, curpos);
- if (!strcmp(meptr->user, tmpmptr->user))
- return(meptr->mod);
- else
- return(NULL);
- }
-
- /*
- * Display a user and its perms for a given module - for scrolling window
- */
- char *userperm_dsp(meptr)
- MOD_ENT *meptr;
- {
- static char userperm_str[NAMEARLEN + PERMARLEN];
-
- /* user and perms are only displayed if they match the module found in
- * buffer
- */
- if (!strcmp(meptr->mod, buffer))
- {
- sprintf(userperm_str, "%s %s", meptr->user, meptr->perm);
- return(userperm_str);
- } else
- return(NULL);
- }
-
- /*
- * Display a module and perms for a given user - for scrolling window
- */
- char *modperm_dsp(meptr)
- MOD_ENT *meptr;
- {
- static char modperm_str[MODARLEN + PERMARLEN];
-
- /* module and perms are only displayed if they match the user found in
- * buffer
- */
- if (!strcmp(meptr->user, buffer))
- {
- sprintf(modperm_str, "%s %s", meptr->mod, meptr->perm);
- return(modperm_str);
- } else
- return(NULL);
- }
-
- /*
- * input a nonempty existing user with F2 to select from list
- */
- void get_user_from_list( input_row, input_col, input_help, popup_help, mode )
- int input_row, input_col, input_help, popup_help, mode;
- {
- int uwin = 0;
- int seluhand = -1;
- struct sel_entry *useptr;
- *tmpuser.user = 0;
- if (mode) ichar = K_F2;
- while (ichar != K_ESC && !strlen(tmpuser.user))
- {
- userfield.fbuff = tmpuser.user;
- strcpy(userfield.fmask, repchr( MASK_C, userfield.fieldlen));
- userfield.frow = input_row;
- userfield.fcol = input_col;
- userfield.fhelp = input_help;
- if (!mode) input_wx(&userfield, K_F2, K_ESC, 0);
- if (ichar == K_F2) /* pop-up window request */
- {
- ncreate_w(input_row, input_col, 7, NAMEARLEN + 5, &uwin);
- border_w(0, BOLD);
- dll_seek(uhand, 0, SEEK_SET);
- seluhand = dll_scroll(2, 2, 5, NAMEARLEN + 3, &uwin, uhand, user_dsp, SEL_SINGLE, popup_help, 0, 0, 0);
- dll_scroll_close(&uwin);
- sel_w(&uwin);
- delete_w();
- sel_w(&main_win);
- if ((seluhand < 0) || ((useptr = (struct sel_entry *)dll_seek(seluhand, 0, SEEK_SET)) == (struct sel_entry *)0))
- {
- if (!mode) ichar = K_CR;
- else ichar = K_ESC;
- *tmpuser.user = 0;
- } else {
- tmpuptr = (USER_ENT *)useptr->sel_data;
- strcpy(tmpuser.user, tmpuptr->user);
- }
- }
- /* does user exist? */
- if ((ichar != K_ESC) && *tmpuser.user && ((USER_ENT *)dll_find(uhand, &tmpuser) == (USER_ENT *)0))
- {
- errmsg("User %s does not exist!", tmpuser.user);
- *tmpuser.user = 0;
- }
- }
- }
-
- /*
- * input a nonempty module with F2 to select from list
- */
- void get_module_from_list( input_row, input_col, input_help, popup_help, mode )
- int input_row, input_col, input_help, popup_help, mode;
- {
- int mwin = 0;
- int selmhand = -1;
- struct sel_entry *mseptr;
- *tmpmod.mod = 0;
-
- if (mode) ichar = K_F2;
- while (ichar != K_ESC && !strlen(tmpmod.mod))
- {
- modfield.fbuff = tmpmod.mod;
- modfield.frow = input_row;
- modfield.fcol = input_col;
- modfield.fhelp = input_help;
- if (!mode) input_wx(&modfield, K_F2, K_ESC, 0);
- if (ichar == K_F2) /* pop-up window request */
- {
- ncreate_w(input_row, input_col, 7, MODARLEN + 5, &mwin);
- border_w(0, BOLD);
- dll_seek(mhand, 0, SEEK_SET);
- selmhand = dll_scroll(2, 2, 5, MODARLEN + 3, &mwin, mhand, mod_dsp, SEL_SINGLE, popup_help, 0, 0, 0);
- dll_scroll_close(&mwin);
- sel_w(&mwin);
- delete_w();
- sel_w(&main_win);
- if ((selmhand < 0) || ((mseptr = (struct sel_entry *)dll_seek(selmhand, 0, SEEK_SET)) == (struct sel_entry *)0))
- {
- if (!mode) ichar = K_CR;
- else ichar = K_ESC;
- *tmpmod.mod = 0;
- } else {
- tmpmptr = (MOD_ENT *)mseptr->sel_data;
- strcpy(tmpmod.mod, tmpmptr->mod);
- }
- }
- }
- }
-
- void clear_window()
- {
- fill_w( 9, 24, USRCOL4, 7, 34, ' ' );
- fill_w( 17, 24, USRCOL4, 2, 34, ' ' );
- }
-
- void get_pwd( input_row, input_col, input_help, pswd )
- int input_row, input_col, input_help;
- char *pswd;
- {
- ichar = K_CR;
- pwdfield.frow = input_row;
- pwdfield.fcol = input_col;
- pwdfield.fhelp = input_help;
- pwdfield.fbuff = pswd;
- while( ichar != K_ESC && !strlen(pswd) )
- input_wx(&pwdfield, K_ESC, 0);
- }
-
- /*
- * extras buffer
- */
- char tmpinput[20];
-
- char passwd_Date_mask[] = "MM-DD-YYYY";
- FIELD f_passwd_Date =
- {
- 2 , 7 , 1, tmpinput, passwd_Date_mask, 0,
- 10, F_DATE, USRCOL2, REVVID, CONFIRM_NEEDED | NO_BLANK,
- NULL, NULL, NULL, NULL
- };
-
- char passwd_Time_mask[] = "HH:NN";
- FIELD f_passwd_Time =
- {
- 2 , 75 , 1, tmpinput, passwd_Time_mask, 0,
- 5, F_DATE, USRCOL2, REVVID, CONFIRM_NEEDED | NO_BLANK,
- NULL, NULL, NULL, NULL
- };
-
- /*
- * display date and/or time
- */
- void display_extras_passwd()
- {
- strcpy(f_passwd_Date.fbuff, ltocon(today(), f_passwd_Date.fmask, 1));
- disp_text(&f_passwd_Date, f_passwd_Date.fattrib_on);
- strcpy(f_passwd_Time.fbuff, ltocon(today(), f_passwd_Time.fmask, 1));
- disp_text(&f_passwd_Time, f_passwd_Time.fattrib_on);
- }
-