|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T c
Length: 10943 (0x2abf) Types: TextFile Names: »ckmail.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« └─⟦e5a54fb17⟧ └─⟦this⟧ »pp-5.0/Tools/ckmail/ckmail.c«
/* ckmail.c: tool to allow user to query status of users msgs */ # ifndef lint static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Tools/ckmail/RCS/ckmail.c,v 5.0 90/09/20 16:25:22 pp Exp Locker: pp $"; # endif /* * $Header: /cs/research/pp/hubris/pp-beta/Tools/ckmail/RCS/ckmail.c,v 5.0 90/09/20 16:25:22 pp Exp Locker: pp $ * * $Log: ckmail.c,v $ * Revision 5.0 90/09/20 16:25:22 pp * rcsforce : 5.0 public release * */ #include "ryinitiator.h" /* for generic interactive initiators */ #include "Qmgr-ops.h" /* operation definitions */ #include "Qmgr-types.h" /* type definitions */ #include "util.h" #include "retcode.h" #include <isode/cmd_srch.h> #include "adr.h" #include "alias.h" #include "ap.h" #include "or.h" #include <pwd.h> /* \f */ extern CMD_TABLE atbl_ctrl_addrs[/* Env-crl-address */]; extern char *loc_dom_site, *pplogin, *postmaster; extern UTC utclocalise(); /* DATA */ static char *myservice = "pp qmgr"; /* OPERATIONS */ static int do_readmsginfo(), do_quit(), p_msg(), p_msginfo(), p_recip(), do_alias_check(), do_user_check(), isPP(); /* RESULTS */ int readmsginfo_result(); /* ERRORS */ int general_error (); #define readmsginfo_error general_error static struct client_dispatch dispatches[] = { { "readmsginfo", operation_Qmgr_readmsginfo, do_readmsginfo, free_Qmgr_readmsginfo_argument, readmsginfo_result, readmsginfo_error, "Read set of messages" }, { "quit", 0, do_quit, NULLIFP, NULLIFP, NULLIFP, "terminate the association and exit", }, { NULL } }; char *qhost; /* host to query */ int first; int all = FALSE; int verbose = FALSE; int time_out, first, do_loop = FALSE; int haveUid, userId; char *userAlias; ADDR *ad; struct passwd *pwd; extern char *qmgr_hostname; /* \f */ main(argc, argv) int argc; char **argv; { char *myname; int opt; extern char *optarg; extern int optind; if (myname = rindex (argv[0], '/')) myname++; if (myname == NULL || *myname == NULL) myname = argv[0]; sys_init(myname); or_myinit(); qhost = strdup(qmgr_hostname); all = FALSE; verbose = FALSE; do_loop = FALSE; first = 0; haveUid = NOTOK; userAlias = NULLCP; while ((opt = getopt(argc, argv, "vVaAh:H:l:L:u:U:i:I:")) != EOF) { switch (opt) { case 'a': case 'A': all = TRUE; break; case 'v': case 'V': verbose = TRUE; break; case 'h': case 'H': if (optarg[0] == '-') { printf("Illegal host '%s' (starts with a '-')\n", optarg); exit(0); } qhost = optarg; break; case 'l': case 'L': if (optarg[0] =='-') { printf ("Expecting time in minutes got '%s'", optarg); exit(0); } time_out = atoi(optarg); do_loop = TRUE; break; case 'u': case 'U': if (isPP() == NOTOK) { printf("You are not a mail superuser and so cannot use the '-u' flag\n"); exit(0); } userAlias = optarg; break; case 'i': case 'I': if (isPP() == NOTOK) { printf("You are not a mail superuser and so cannot use the '-i' flag\n"); exit(0); } userId = atoi(optarg); haveUid = OK; break; default: printf("usage: %s [-v] [-a] [-h host] [-l time] [-u user] [-i uid]\n",argv[0]); exit(0); } } fillinaddr(); if (verbose == TRUE) { printf("Please wait while attempt to connect to %s....",qhost); fflush(stdout); } if (do_loop == TRUE) { while (TRUE) { (void) ryinitiator (myname, qhost, argc, argv, myservice, table_Qmgr_Operations, dispatches, do_quit); first++; sleep (time_out*60); } } else (void) ryinitiator (myname, qhost, argc, argv, myservice, table_Qmgr_Operations, dispatches, do_quit); exit(0); } /* \f */ /* OPERATIONS */ /* ARGSUSED */ static int do_quit (sd, ds, args) int sd; struct client_dispatch *ds; char **args; { struct AcSAPrelease acrs; register struct AcSAPrelease *acr = &acrs; struct AcSAPindication acis; register struct AcSAPindication *aci = &acis; register struct AcSAPabort *aca = &aci -> aci_abort; #ifdef CONNECTING_1 if (AcRelRequest (sd, ACF_NORMAL, NULLPEP, 0, NOTOK, acr, aci) == NOTOK) #else if (AcRelRequest (sd, ACF_NORMAL, NULLPEP, 0, acr, aci) == NOTOK) #endif acs_adios (aca, "A-RELEASE.REQUEST"); if (!acr -> acr_affirmative) { (void) AcUAbortRequest (sd, NULLPEP, 0, aci); adios (NULLCP, "Release rejected by peer: %d", acr -> acr_reason); } ACRFREE (acr); /* exit (0);*/ } static struct type_Qmgr_Filter *fillin_1_to(name) char *name; { struct type_Qmgr_Filter *ret = (struct type_Qmgr_Filter *) calloc(1, sizeof(*ret)); ret->recipient = str2qb(name, strlen(name), 1); return ret; } static struct type_Qmgr_Filter *fillin_1_from(name) char *name; { struct type_Qmgr_Filter *ret = (struct type_Qmgr_Filter *) calloc(1, sizeof(*ret)); ret->originator = str2qb(name, strlen(name), 1); return ret; } static struct type_Qmgr_FilterList *fillinfilters(args) char **args; { struct type_Qmgr_FilterList *head = NULL, *tail = NULL, *ix; ix = (struct type_Qmgr_FilterList *) calloc(1, sizeof(*ix)); ix->Filter = fillin_1_from(ad->ad_r822adr); if (head == NULL) head = tail = ix; else { tail->next = ix; tail = ix; } ix = (struct type_Qmgr_FilterList *) calloc(1, sizeof(*ix)); ix->Filter = fillin_1_from(ad->ad_r400adr); if (head == NULL) head = tail = ix; else { tail->next = ix; tail =ix; } if (all == FALSE) return head; ix->Filter = fillin_1_to(ad->ad_r822adr); if (head == NULL) head = tail = ix; else { tail->next = ix; tail = ix; } ix = (struct type_Qmgr_FilterList *) calloc(1, sizeof(*ix)); ix->Filter = fillin_1_to(ad->ad_r400adr); if (head == NULL) head = tail = ix; else { tail->next = ix; tail =ix; } return head; } /* ARGSUSED */ static do_readmsginfo (sd, ds, args, arg) int sd; struct client_dispatch *ds; char **args; /* contains various filters */ struct type_Qmgr_ReadMessageArgument **arg; { char *str; UTC utc; *arg = (struct type_Qmgr_ReadMessageArgument *) malloc(sizeof(**arg)); /* fillin time */ utc = (UTC) malloc (sizeof(struct UTCtime)); utc->ut_flags = UT_SEC; utc->ut_sec = 0; str = utct2str(utc); (*arg)->interval = str2qb(str, strlen(str), 1); (*arg)->filters = fillinfilters(args); return OK; } /* \f */ /* RESULTS */ /* ARGSUSED */ int readmsginfo_result (sd, id, dummy, result, roi) int sd, id, dummy; register struct type_Qmgr_MsgList *result; struct RoSAPindication *roi; { struct type_Qmgr_MsgStructList *ix; if (result == NULL || result->msgs == NULL) { if (do_loop == FALSE || first == 0) printf("There are no messages %s %s at %s\n", (all == TRUE) ? "to or from" : "from", pwd->pw_name, qhost); } else { printf("The messages %s %s on %s are as follows:\n", (all == TRUE) ? "to or from" : "from", pwd->pw_name, qhost); ix = result->msgs; while (ix != NULL) { p_msg(ix->MsgStruct); ix = ix->next; } } return OK; } static int p_msg(msg) struct type_Qmgr_MsgStruct *msg; { char *orig; struct type_Qmgr_RecipientList *ix; int len; orig = qb2str(msg->recipientlist->RecipientInfo->user); first = 1; if (all == TRUE && strcmp(orig, ad->ad_r822adr) != 0 && strcmp(orig, ad->ad_r400adr) != 0) { /* to user */ len = p_msginfo(msg->messageinfo); printf(" is from"); len += strlen(" is from") +1; p_recip(msg->recipientlist->RecipientInfo, len); printf("\n"); } else if (strcmp(orig, ad->ad_r822adr) == 0 || strcmp(orig, ad->ad_r400adr) == 0) { ix = msg->recipientlist; ix = ix -> next; len = p_msginfo(msg->messageinfo); if (ix != NULL) { printf(" is pending delivery to"); len += strlen(" is pending delivery to") +1; while (ix != NULL) { p_recip(ix->RecipientInfo, len); ix = ix -> next; } } else printf(" is waiting for notification/deletion"); printf("\n"); } /* else given wrong info */ free(orig); } static int p_msginfo(info) struct type_Qmgr_PerMessageInfo *info; { char *id, buf[BUFSIZ]; int retval; UTC ut, lut; id = qb2str(info->queueid); retval = strlen(id); printf("%s",id); free(id); if (info -> uaContentId != NULL) { id = qb2str (info -> uaContentId); printf (" with content id '%s'\n%*s", id, retval, " "); free(id); } if (info -> age != NULL) { id = qb2str(info -> age); ut = str2utct(id, strlen(id)); lut = utclocalise (ut); if (UTC2rfc (lut, buf) != NOTOK) printf (" submitted at %s\n%*s", buf, retval, " "); if (lut) free ((char *) lut); free(id); } if (verbose == TRUE && info -> expiryTime != NULL) { id = qb2str (info -> expiryTime); ut = str2utct(id, strlen(id)); lut = utclocalise(ut); if (UTC2rfc (lut, buf) != NOTOK) printf (" will expire at %s\n%*s", buf, retval, " "); if (lut) free ((char *) lut); free(id); } return retval; } static int p_recip(recip, tab) struct type_Qmgr_RecipientInfo *recip; int tab; { char *usr; if (first != 1) printf(",\n%*s", tab, " "); else printf(" "); first = 0; usr = qb2str(recip->user); printf("%s",usr); free(usr); } /* \f */ /* ERRORS */ /* ARGSUSED */ general_error (sd, id, error, parameter, roi) int sd, id, error; caddr_t parameter; struct RoSAPindication *roi; { register struct RyError *rye; if (error == RY_REJECT) { advise (NULLCP, "%s", RoErrString ((int) parameter)); return OK; } if (rye = finderrbyerr (table_Qmgr_Errors, error)) advise (NULLCP, "%s", rye -> rye_name); else advise (NULLCP, "Error %d", error); return OK; } /* \f */ /* fillin an ADDR struct for person running this program */ fillinaddr() { RP_Buf rp; if (userAlias != NULLCP) { if ((pwd = getpwnam(userAlias)) == NULL) adios (NULLCP, "Cannot get passwd entry for user '%s'", userAlias); } else if (haveUid == OK) { if ((pwd = getpwuid(userId)) == NULL) adios (NULLCP, "Cannot get passwd entry for uid '%d'", userId); } else { if ((pwd = getpwuid(getuid())) == NULL) adios(NULLCP,"Cannot get your password entry"); } ad = adr_new(pwd->pw_name, AD_ANY_TYPE, 0); if (rp_isbad(ad_parse(ad, &rp, CH_UK_PREF))) adios(NULLCP, "Address parse failed\nReason : %s\n",rp.rp_line); } static int isPP() { RP_Buf rp; int uid; struct passwd *tmp; ADDR *tmpadr; if ((uid = getuid()) == 0) /* super user */ return OK; if ((tmp = getpwuid(uid)) == NULL) { printf("Cannot get your passwd entry\n"); exit(0); } tmpadr = adr_new(tmp->pw_name, AD_ANY_TYPE, 0); if (rp_isbad(ad_parse(tmpadr, &rp, CH_UK_PREF))) { printf("Cannot parse your mail address\nReason : %s\n",rp.rp_line); exit(1); } if ((strcmp(tmp->pw_name, pplogin) == 0) || (strcmp(tmpadr->ad_r822adr, postmaster) == 0)) { adr_free(tmpadr); return OK; } adr_free(tmpadr); return NOTOK; }