if (confirm("This list is an in-line list\nThis program is unable to modify in-line lists\nDo you want to send a request to change this ?") == TRUE)
m_alterInLine(list);
dl_free(list);
return NOTOK;
}
/* if (listOnLocal(list -> dl_listname, hostname) == FALSE) {
printf("List '%s' is expanded on machine '%s'\n",name,hostname);
if (isModerator(list) == TRUE) {
if (confirm("do you wish to mail a request to change the expansion point ?") == TRUE)
m_alterExpansion(list);
} else
printf("This tool can not modify remotely expanded lists\n");
dl_free(list);
return NOTOK;
}*/
if (stat(list->dl_file, &statbuf) < 0) {
if (isModerator(list) == FALSE) {
sprintf(buf, "File for list '%s' can only be created by a moderator\nDo you wish to send a message to the list moderator ?",name);
if (confirm(buf) == TRUE)
m_createListFile(list);
dl_free(list);
return NOTOK;
}
/* work out modes for creation of file */
printf("Creating file for list '%s'\n",name);
printf("Do you want other users to be able to add / remove their own names ?");
if (confirm (NULLCP) == TRUE) {
printf("Do you want them to be able to add / remove anyone else's name ?");
if (confirm(NULLCP) == TRUE)
curmode = FREEMODE;
else
curmode = PUBMODE;
} else {
printf("Do you want others to be able to see who is on the list ?");
if (confirm (NULLCP))
curmode = PRIVMODE;
else
curmode = SECRMODE;
}
printf ("Creating file '%s' with list mode ", list->dl_file);
switch (curmode) {
case FREEMODE:
printf("free\n");
break;
case PUBMODE:
printf("public\n");
break;
case PRIVMODE:
printf("private\n");
break;
case SECRMODE:
printf("secret\n");
break;
}
if ((fd = creat(list->dl_file, curmode)) < 0) {
printf("Unable to create file '%s'\n",list->dl_file);
dl_free(list);
return NOTOK;
}
(void) fchmod(fd, curmode);
} else {
curmode = (int) statbuf.st_mode;
curmode = curmode & 0777;
if (!(isModerator(list)
|| curmode == PUBMODE
|| curmode == FREEMODE)) {
printf ("list '%s' can only be updated by it's moderators\n",name);
if (curmode != SECRMODE) {
printf("Do you want to see who is on the list ? ");
if (confirm (NULLCP))
display(name);
}
if (inList(pwd -> pw_name, list -> dl_list, &inListname) == TRUE) {
printf("You (%s) are already in this list\nDo you wish to mail a request to be removed",inListname);
if (confirm(NULLCP) == TRUE)
m_delReq(list);
} else {
printf ("Do you wish to mail a request to be added");
if (confirm(NULLCP) == TRUE)
m_addReq(list);
}
dl_free(list);
return NOTOK;
}
}
/* all prelimarys done */
printf("Modifying list '%s'\n",name);
if (isModerator(list) || curmode == FREEMODE)
master_modify(list);
else
restrict_modify(list);
return OK;
}
static int modify_menu()
{
int quit = FALSE;
char buf[BUFSIZ],
*margv[20],
ch;
int margc;
while (quit == FALSE) {
printf("\n> ");
fflush (stdout);
if (gets (buf) == NULL)
exit(OK);
compress (buf, buf);
if (buf[0] == NULL || strlen(buf) == 0) {
printf("\nType 'h' or '?' for help\n");
continue;
}
margc = sstr2arg(buf, 20, margv, " \t");
if ((int)strlen(margv[0]) > 1)
ch = 'A';
else if (margv[0][0] == '?')
ch = '?';
else
ch = uptolow(margv[0][0]);
switch (ch)
{
case '\0':
case '\n':
printf("\nType 'h' or '?' for help\n");
continue;
case 'h':
case '?':
printf("\nOptions are:\n'l' ist the lists,\n'c' reate a list,\n");
printf("'p' rint 'listname' to view a list,\n'q' uit,\n't'ype - change type of addresses you're inputing,\n\nor the name of the list you wish to modify\n");
continue;
case 'q':
printf("\nBye...\n");
quit = TRUE;
continue;
case 't':
changeAdrType(margv[1]);
continue;
case 'l':
listLists();
continue;
case 'c':
m_createList();
continue;
case 'p':
if (margc > 1)
display(margv[1]);
continue;
default:
break;
}
if (modify(margv[0]) == NOTOK)
printf("\nType 'h' or '?' for help\n");
}
}
/* */
/* routines to send messages to postmaster or moderators */
if ((curfp = flckopen(list->dl_file, "r+")) == NULL) {
fprintf (stderr, "Can't open %s: %s\n",
list -> dl_file, sys_errname (errno));
return;
}
flckclose(curfp);
while (quit == FALSE) {
fprintf(stdout, "\n%s%s",
list->dl_listname,
(menudriven == TRUE) ? ">> " : "> ");
fflush(stdout);
if (gets(tmpbuf) == NULL) {
exit(0);
}
compress (tmpbuf, tmpbuf);
ix = &(tmpbuf[0]);
switch (tmpbuf[0])
{
case '\0':
case '\n':
printf("\nType 'h' or '?' for help\n");
continue;
case 't':
case 'T':
tix = &(tmpbuf[0]);
while (*tix != '\0'
&& !isspace(*tix))
tix ++;
while (*tix != '\0'
&& isspace(*tix))
tix++;
if (tix == tmpbuf)
tix++;
changeAdrType(tix);
continue;
case 'p':
case 'P':
if (tmpbuf[1] == '\0'
|| isspace(tmpbuf[1])) {
ix = &(tmpbuf[1]);
while (*ix != '\0'
&& isspace(*ix)) ix++;
display(list -> dl_listname);
continue;
}
case 'v':
case 'V':
if (tmpbuf[1] == '\0'
|| isspace(tmpbuf[1])) {
ix = &(tmpbuf[1]);
while (*ix != '\0'
&& isspace(*ix)) ix ++;
verifyList(list);
continue;
}
case 'h':
case 'H':
case '?':
if (tmpbuf[1] == '\0'
|| isspace(tmpbuf[1])) {
fprintf(stdout,
"\nOptions are:\n'p' rint list,\n'v' erify list,\n'a' dd user,\n'f' ind user,\n'r' emove users,\n'l' ist the lists,\n'c' reate a new list,\n't'ype - change type of addresses you're inputting,\n");
if (menudriven == TRUE)
fprintf(stdout, "'q' uit and return to top menu.\n\n");
else
fprintf(stdout, "'q' uit.\n\n");
fprintf(stdout, "If the input is none of the above options,\nit is assumed to be a user name to be added\n");
fflush (stdout);
continue;
}
case 'l':
case 'L':
if (tmpbuf[1] == '\0'
|| isspace(tmpbuf[1])) {
listLists();
continue;
}
case 'c':
case 'C':
if (tmpbuf[1] == '\0'
|| isspace(tmpbuf[1])) {
ix = &(tmpbuf[1]);
while (*ix != '\0' &&
isspace(*ix)) ix++;
m_createList();
continue;
}
case 'q':
case 'Q':
if (tmpbuf[1] == '\0'
|| isspace(tmpbuf[1])) {
ix = &(tmpbuf[1]);
while (*ix != '\0'
&& isspace(*ix)) ix ++;
if (*ix == '\0') {
quit = TRUE;
continue;
}
ix = &(tmpbuf[0]);
break;
}
case 'r':
case 'R':
if (tmpbuf[1] == '\0'
|| isspace(tmpbuf[1])) {
ix = &(tmpbuf[1]);
while (*ix != '\0'
&& isspace(*ix)) ix++;
if (*ix == '\0') {
printf ("give username to be removed (regex): ");
(void) fflush (stdout);
if (gets(tmpbuf) == NULL)
exit(0);
compress (tmpbuf, tmpbuf);
ix = &(tmpbuf[0]);
}
removeUser(ix, list);
continue;
}
case 'f':
case 'F':
if (tmpbuf[1] == '\0'
|| isspace(tmpbuf[1])) {
ix = &(tmpbuf[1]);
while (*ix != '\0'
&& isspace(*ix)) ix++;
if (*ix == '\0') {
printf ("give username to search for (regex): ");
if (gets(tmpbuf) == NULL)
exit(0);
compress (tmpbuf, tmpbuf);
ix = &(tmpbuf[0]);
}
findUser(ix, list);
continue;
}
case 'a':
case 'A':
if (tmpbuf[1] == '\0'
|| isspace(tmpbuf[1])) {
ix = &(tmpbuf[1]);
while (*ix != '\0'
&& isspace (*ix)) ix++;
if (*ix == '\0') {
printf("give username to be added: ");
if (gets(tmpbuf) == NULL)
exit(0);
compress (tmpbuf, tmpbuf);
ix = &(tmpbuf[0]);
}
}
default:
break;
}
done = FALSE;
while (done == FALSE) {
orig_line = ix;
if (ap_pinit(getbufchar) == BADAP) {
printf("Cannot parse '%s'\n",
orig_line);
done = FALSE;
} else {
switch (ap_1adr()) {
case DONE:
done = TRUE;
break;
case NOTOK:
break;
default:
if (ap_t2s(ap_pstrt, &adrstr) != BADAP) {
if (rp_isbad(verifyUser(adrstr, buf)))
printf("Illegal address '%s'\n",
adrstr);
else {
if (inList(adrstr, list -> dl_list, &inListname) == TRUE) {
printf("User '%s' already in list",
adrstr);
if (lexequ(inListname, adrstr) != 0)
printf(" as '%s'", inListname);
printf("\n");
} else
addUser(adrstr, list);
}
free(adrstr);
ap_pstrt = NULLAP;
}
break;
}
}
}
}
if (menudriven == FALSE)
printf("\nBye...\n");
}
static void restrict_modify(list)
dl *list;
{
char buf[LINESIZE],
adr[BUFSIZ],
*nameinlist;
printf("Would you like to see who's in the list ?");
if (confirm(NULLCP) == TRUE)
display(list -> dl_listname);
if (!rp_isbad(verifyUser(pwd->pw_name, adr))) {
if (inList(adr, list -> dl_list, &nameinlist) == TRUE) {
printf("You (%s) are already in this list\nDo you wish to be removed ?",pwd -> pw_name);
if (confirm(NULLCP) == TRUE) {
sprintf(buf, "^%s$",adr);
removeUser(buf, list);
} else
printf("You only have permission to add or remove yourself from this list\n");
} else {
printf ("You (%s) are not in this list\nDo you wish to be added ?", pwd -> pw_name);
if (confirm(NULLCP) == TRUE)
addUser(adr, list);
else
printf("You only have permission to add or remove yourself from this list\n");
}
}
}
/* */
/* checking routines */
static int verifyUser(name, addr)
char *name,
*addr;
{
RP_Buf rp;
ADDR *temp;
int ret,
type;
temp = adr_new(name, adrType, 0);
if (rp_isbad(ret = ad_parse(temp, &rp, dmnorder)))
fprintf(stderr, "Failed to parse '%s' (%s)\n",
name,
rp.rp_line);
if (temp -> ad_r400adr != NULL
&& temp->ad_type == AD_X400_TYPE)
sprintf(addr, "%s", temp->ad_r400adr);
else if (temp -> ad_r822adr != NULL)
sprintf(addr, "%s", temp->ad_r822adr);
adr_free(temp);
return ret;
}
static int verifyList(list)
dl *list;
{
char *name,
buf[BUFSIZ];
Name *ix = list -> dl_list;
while (ix != NULL) {
printf("Checking '%s'...",ix -> name);
if (!rp_isbad(verifyUser(ix -> name, buf))) {
printf("ok\n");
ix = ix -> next;
} else {
name = strdup(ix -> name);
ix = ix -> next;
removeUser(name,list);
free(name);
}
/* if (temp != NULL) *temp = '@';*/
}
}
static int inList(name, list, plistname)
char *name;
Name *list;
char **plistname;
{
while (list != NULL
&& ap_equ(list -> name, name) != TRUE)
list = list -> next;
if (list != NULL)
*plistname = list->name;
return (list != NULL) ? TRUE : FALSE;
}
/* */
/* list maintaince routines */
extern char *re_comp();
extern int re_exec();
static int findUser (name, list)
char *name;
dl *list;
{
char *diag;
Name *ix;
if ((diag = re_comp(name)) != 0) {
fprintf(stderr,
"re_comp error for '%s' [%s]\n", name, diag);
return;
}
ix = list -> dl_list;
openpager();
while (ix != NULL && pipeopen) {
if (re_exec(lowerfy(ix -> name)) == 1) {
fprintf(out, "%s\n", ix -> name);
fflush(stdout);
}
ix = ix -> next;
}
closepager();
}
static int removeUser(name, list)
char *name;
dl *list;
{
char *diag;
Name *ix,
*temp;
char buf[BUFSIZ];
int len = 0,
found;
FILE *curfp;
if ((diag = re_comp(name)) != 0) {
fprintf (stderr,
"re_comp error for '%s' [%s]\n",name,diag);
return;
}
if ((curfp = flckopen (list->dl_file, "r+")) == NULL) {