home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / passwd+ / passwd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  7.9 KB  |  241 lines

  1. /*
  2.  * passwd -- a super dooper password changer
  3.  * it checks for specifically bad passwords and refuses
  4.  * to change a password to them
  5.  *
  6.  * this is the header file
  7.  */
  8. #include <stdio.h>
  9. #include <ctype.h>
  10. #include <grp.h>
  11. #include <pwd.h>
  12. #include <sys/types.h>
  13. #include "sys.h"
  14. #ifdef SYSLOG
  15. #    include <syslog.h>
  16. #endif
  17.  
  18. /*
  19.  * the following should be reset to those parameters
  20.  * that fit best with your system
  21.  */
  22. #define DEFPWFILE    "./passwd.data"        /* password file */
  23. #define PWTESTFILE    "./passwd.test"        /* password test file */
  24. #define DEFAULTTEST                /* default test if needed */
  25. #define LG_DEFAULT    LG_NONE            /* default logging */
  26. #define LG_OUTDEF    "> ./passwd.log"        /* default logging location */
  27. #define LG_INIT        " "            /* initial logging */
  28.  
  29. /*
  30.  * the following may be changed but odds are you won't want to
  31.  */
  32. #define ROOTID        0        /* the UID of the superuser */
  33. #define PWSIGCHARS    8        /* significant characters */
  34. #define MAXLOGTO    10        /* max number of open logs */
  35. #define GECOSSIZE    100        /* max size of gecos fields */
  36.  
  37. /*
  38.  * the following should NEVER be changed (unless you're suicidal!)
  39.  */
  40. #ifndef NUVAR
  41.     /**** WARNING -- IF YOU CHANGE THIS REMEMBER TO DELETE THE ****/
  42.     /****          APPROPRIATE ESCAPES IN VERIFY.C           ****/
  43. #    define NUVAR        10    /* number of user definable escapes */
  44. #endif
  45.  
  46. /*
  47.  *========== L O G G I N G  M A C R O S ==========
  48.  *
  49.  * We allow the user to log a number of ways
  50.  * The macros below indicate his choices
  51.  */
  52. #define LG_FILE        0x01        /* to a file */
  53. #define LG_PIPE        0x02        /* to a pipe */
  54. #define LG_STDERR    0x04        /* to stderr */
  55.                     /* if no syslog, write to error */
  56. #ifdef SYSLOG
  57. #define    LG_SYSLOG    0x08        /* syslog; may not be valid */
  58. #else
  59. #define    LG_SYSLOG    LG_STDERR    /* no syslog: send to stderr */
  60. #endif
  61.  
  62. /*
  63.  * he can log several sorts of things:
  64.  */
  65. #define    LG_NONE        0x00        /* log nothing */
  66. #define    LG_SYNTAX    0x01        /* log syntax errors */
  67. #define LG_USE        0x02        /* log use of program */
  68. #define LG_RESULT    0x04        /* log result of run */
  69. #define LG_ITEM        0x08        /* log why test failed */
  70. #define LG_DEBUG    0x10        /* log debugging information */
  71. #define LG_SYSTEM    0x20        /* log system problems */
  72. #define LG_ALL        0x3f        /* log everything */
  73. /*
  74.  * a convenience to make excluding components easy
  75.  */
  76. #define LG_NEG        '!'        /* negation character */
  77. /*
  78.  * some generally useful macros
  79.  */
  80.                     /* ends log keyword */
  81. #define log_end(x)    (ispunct((x))||isspace((x))||((x)=='\0'))
  82. #define log_set(x,y)    ((x)|=((y)&LG_ALL))    /* set one bit for logging */
  83. #define log_reset(x,y)    ((x)&=((~(y))&LG_ALL))    /* clear one bit for logging */
  84. #define    log_test(x,y)    (((x)&(y))==(y))    /* 1 if to log y */
  85. /*
  86.  * these macros do the actual logging
  87.  * and are here to keep the logging functions simple
  88.  * they are named LOGn, where n is the number of arguments to sprintf
  89.  */
  90. #define LOG0(y, z)    logfunc(y, z)
  91. #define LOG1(y, z, a)    {                    \
  92.             char tbuf[BUFSIZ];            \
  93.             SPRINTF(tbuf, z, a);            \
  94.             logfunc(y, tbuf);            \
  95.         }
  96. #define LOG2(y, z, a, b)    {                \
  97.             char tbuf[BUFSIZ];            \
  98.             SPRINTF(tbuf, z, a, b);            \
  99.             logfunc(y, tbuf);            \
  100.         }
  101. #define LOG3(y, z, a, b, c)    {                \
  102.             char tbuf[BUFSIZ];            \
  103.             SPRINTF(tbuf, z, a, b, c);        \
  104.             logfunc(y, tbuf);            \
  105.         }
  106.  
  107. /*
  108.  *========== E S C A P E   S E Q U E N C E S   F O R   T E S T S ==========
  109.  *
  110.  * these tell how to access escape sequences
  111.  */
  112. #define    F_ASIS        0    /* insert the string as is */
  113. #define F_NUMBER    1    /* insert the length of the string */
  114. #define F_UPPER        2    /* insert the string in upper case */
  115. #define F_LOWER        3    /* insert the string in lower case */
  116. #define F_FIRST        4    /* insert the string first capitalized */
  117.  
  118. /*
  119.  * a number or a string?
  120.  */
  121. #define    TY_STR        0    /* string */
  122. #define    TY_NUM        1    /* number */
  123.  
  124. /*
  125.  * map upper case to lower case
  126.  */
  127. #define lowcase(x)    (isupper((x)) ? tolower((x)) : (x))
  128. #define upcase(x)    (islower((x)) ? toupper((x)) : (x))
  129.  
  130. /*
  131.  * structure to hold "%" and "#" escapes (ie, internal variables)
  132.  */
  133. struct intvar {
  134.     char name;        /* internal variable name to the user */
  135.     int nstype;        /* 1 if a number, 0 if a string */
  136.     char *string;        /* string value */
  137.     char *length;        /* length (as a string) */
  138.     int userset;        /* 1 if this can be reset */
  139.     char *prompt;        /* a prompt, if needed */
  140. };
  141.             /* quick assignment macros */
  142. #define    IVSASSIGN(x, y)    {                        \
  143.         register struct intvar *ipx = findiv(x);        \
  144.         ipx->string = strsave((y));                \
  145.         if ((y) == CH_NULL)    ipx->length = strsave(CH_NULL);    \
  146.         else            ipx->length = tonum(strlen(y));    \
  147.     }
  148. #define    IVSPASSIGN(x, y)    {                    \
  149.         (x)->string = strsave((y));                \
  150.         if ((y) == CH_NULL)    (x)->length = strsave(CH_NULL);    \
  151.         else            (x)->length = tonum(strlen(y));    \
  152.     }
  153. #define    IVNASSIGN(x, y, z) {                        \
  154.         register struct intvar *ipx = findiv(x);        \
  155.         ipx->string = tonum((y));                \
  156.         ipx->length = tonum((z));                \
  157.     }
  158.  
  159. /*
  160.  *========== N U L L   P O I N T E R S ==========
  161.  *
  162.  * NULL pointers -- these are used to shut lint up
  163.  */
  164. #define CH_NULL    ((char *) NULL)        /* NULL character pointer */
  165. #define FI_NULL ((FILE *) NULL)        /* NULL file pointer */
  166. #define GR_NULL ((struct group *) NULL)    /* NULL group structure pointer */
  167. #define IV_NULL ((struct intvar *) NULL)/* NULL escape structure pointer */
  168. #define PW_NULL ((struct passwd *) NULL)/* NULL password structure pointer */
  169. #define TI_NULL ((time_t *) NULL)    /* NULL time pointer */
  170.  
  171. /*
  172.  *========== D E C L A R A T I O N S ==========
  173.  *
  174.  * globals
  175.  */
  176. extern char runner[];        /* who is running this program */
  177. extern char user[];        /* name of user */
  178. extern char password[];        /* new password */
  179. extern char oldpassword[];    /* current password */
  180. extern struct passwd *pwinfo;    /* associated password structure */
  181. extern char *progname;        /* program name */
  182. extern char *pwdfile;        /* password file */
  183. extern char pwtest[];        /* password test file */
  184. extern int pwsig;        /* number of significant chars in password */
  185. extern unsigned int logging;    /* logging level */
  186. extern int linect;        /* line number of test file */
  187. extern struct intvar iv[];    /* internal variables */
  188. extern int pf_errno;        /* system error from update_pwd() */
  189.  
  190. /*
  191.  * system variables
  192.  */
  193. extern int errno;        /* system error number */
  194. extern int sys_nerr;        /* number of system errors */
  195. extern char *sys_errlist[];    /* descriptions of system errors */
  196.  
  197. /*
  198.  * internal (forward) declarations
  199.  */
  200. extern struct intvar *findiv();    /* find entry for internal variable */
  201. extern int fmgets();        /* like mgets but folds to lower case */
  202. extern char *getcstring();    /* read a string in C syntax */
  203. extern int mgets();        /* like fgets but clobbers trailing newline */
  204. extern struct passwd *mgpwnam();/* password structure lookup on name */
  205. extern struct passwd *mgpwuid();/* password structure lookup on uid */
  206. extern char *nfmt();        /* formats a number */
  207. extern char *sfmt();        /* formats a string */
  208. extern char *strsave();        /* copy a string into allocated memory */
  209. extern char *tonum();        /* convert inter to char string */
  210.  
  211. /*
  212.  * library functions
  213.  */
  214. extern char *crypt();        /* encrypt a password */
  215. extern int fclose();        /* closes a file */
  216. extern FILE *fopen();        /* opens a file, returns pointer */
  217. extern int fprintf();        /* formatted print to file */
  218. extern struct group *getgrgid();/* get group information */
  219. extern char *getpass();        /* grab a password */
  220. #ifdef GETUSERSHELL
  221. extern char *GETUSERSHELL();    /* return legal user shells */
  222. #endif
  223. extern char *index();        /* find first occurrance of char */
  224. extern char *malloc();        /* allocate memory */
  225. extern int pclose();        /* closes a pipe */
  226. extern FILE *popen();        /* opens a pipe, returns pointer */
  227. extern int printf();        /* formatted print to standard output */
  228. extern char *sprintf();        /* formatted print to memory */
  229. extern char *strcat();        /* append to a string */
  230. extern int strcmp();        /* string comparison function */
  231. extern char *strcpy();        /* copy a string */
  232. extern char *strncpy();        /* copy part of a string */
  233. extern time_t time();        /* return internal time */
  234.  
  235. /*
  236.  * lint stuff
  237.  */
  238. #define FPRINTF    (void) fprintf    /* return value of fprintf NEVER used */
  239. #define PRINTF    (void) printf    /* return value of printf NEVER used */
  240. #define SPRINTF    (void) sprintf    /* return value of sprintf NEVER used */
  241.