version 1.13, 2002/05/16 03:50:42 |
version 1.14, 2002/05/29 15:32:10 |
|
|
#include <unistd.h> |
#include <unistd.h> |
#include <skey.h> |
#include <skey.h> |
|
|
extern char *__progname; |
|
|
|
void notify(struct passwd *, int, int); |
void notify(struct passwd *, int, int); |
FILE *runsendmail(struct passwd *, int *); |
FILE *runsendmail(struct passwd *, int *); |
void usage(void); |
__dead void usage(void); |
|
|
int |
int |
main(argc, argv) |
main(int argc, char **argv) |
int argc; |
|
char **argv; |
|
{ |
{ |
struct passwd *pw; |
struct passwd *pw; |
struct skey key; |
struct skey key; |
int ch, errs = 0, left = 0, aflag = 0, iflag = 0, limit = 12; |
|
char *name; |
char *name; |
|
int ch, left, aflag, iflag, limit; |
|
|
|
left = aflag = iflag = 0; |
|
limit = 12; |
while ((ch = getopt(argc, argv, "ail:")) != -1) |
while ((ch = getopt(argc, argv, "ail:")) != -1) |
switch(ch) { |
switch(ch) { |
case 'a': |
case 'a': |
aflag = 1; |
|
if (getuid() != 0) |
if (getuid() != 0) |
errx(1, "only root may use the -a flag"); |
errx(1, "only root may use the -a flag"); |
|
aflag = 1; |
break; |
break; |
case 'i': |
case 'i': |
iflag = 1; |
iflag = 1; |
|
|
err(1, "cannot allocate memory"); |
err(1, "cannot allocate memory"); |
sevenbit(name); |
sevenbit(name); |
|
|
errs = skeylookup(&key, name); |
switch (skeylookup(&key, name)) { |
switch (errs) { |
|
case 0: /* Success! */ |
case 0: /* Success! */ |
left = key.n - 1; |
left = key.n - 1; |
break; |
break; |
case -1: /* File error */ |
case -1: /* File error */ |
errx(errs, "cannot open %s", _PATH_SKEYDIR); |
errx(1, "cannot open %s/%s", _PATH_SKEYDIR, |
|
name); |
break; |
break; |
case 1: /* Unknown user */ |
case 1: /* Unknown user */ |
warnx("%s is not listed in %s", name, |
errx(1, "user %s is not listed in %s", name, |
_PATH_SKEYDIR); |
_PATH_SKEYDIR); |
} |
} |
(void)fclose(key.keyfile); |
(void)fclose(key.keyfile); |
|
|
if (!errs && left < limit) |
if (left < limit) |
notify(pw, left, iflag); |
notify(pw, left, iflag); |
} |
} |
|
|
exit(errs); |
exit(0); |
} |
} |
|
|
void |
void |
notify(pw, seq, interactive) |
notify(struct passwd *pw, int seq, int interactive) |
struct passwd *pw; |
|
int seq; |
|
int interactive; |
|
{ |
{ |
static char hostname[MAXHOSTNAMELEN]; |
static char hostname[MAXHOSTNAMELEN]; |
int pid; |
pid_t pid; |
FILE *out; |
FILE *out; |
|
|
/* Only set this once */ |
/* Only set this once */ |
|
|
} |
} |
|
|
FILE * |
FILE * |
runsendmail(pw, pidp) |
runsendmail(struct passwd *pw, pid_t *pidp) |
struct passwd *pw; |
|
int *pidp; |
|
{ |
{ |
FILE *fp; |
FILE *fp; |
int pfd[2], pid; |
int pfd[2]; |
|
pid_t pid; |
|
|
if (pipe(pfd) < 0) |
if (pipe(pfd) < 0) |
return(NULL); |
return(NULL); |
|
|
|
|
return(fp); |
return(fp); |
} |
} |
void |
|
usage() |
__dead void |
|
usage(void) |
{ |
{ |
|
extern char *__progname; |
|
|
(void)fprintf(stderr, "Usage: %s [-i] [-l limit]\n", |
(void)fprintf(stderr, "Usage: %s [-i] [-l limit]\n", |
__progname); |
__progname); |
exit(1); |
exit(1); |