|
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 q
Length: 11502 (0x2cee) Types: TextFile Names: »qmgrDisable.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« └─⟦e5a54fb17⟧ └─⟦this⟧ »pp-5.0/Tools/qmgrDisable/qmgrDisable.c«
/* qmgrDisable.c: terminal based tool for emergency control of qmgr */ # ifndef lint static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Tools/qmgrDisable/RCS/qmgrDisable.c,v 5.0 90/09/20 16:30:42 pp Exp Locker: pp $"; # endif /* * $Header: /cs/research/pp/hubris/pp-beta/Tools/qmgrDisable/RCS/qmgrDisable.c,v 5.0 90/09/20 16:30:42 pp Exp Locker: pp $ * * $Log: qmgrDisable.c,v $ * Revision 5.0 90/09/20 16:30:42 pp * rcsforce : 5.0 public release * */ #include <stdio.h> #include <varargs.h> #include <isode/rosy.h> #include "util.h" #include "chan.h" #include <isode/cmd_srch.h> #include "Qmgr-types.h" #include "Qmgr-ops.h" #include <isode/tsap.h> static struct client_dispatch { char *ds_name; int ds_operation; IFP ds_argument; IFP ds_free; IFP ds_result; IFP ds_error; char *ds_help; } Client_dispatch; static struct client_dispatch *quecontrol_op; static int do_quecontrol(), quecontrol_result(), general_error(), Connect(); #define quecontrol_error general_error struct client_dispatch client_dispatches[] = { { "quecontrol", operation_Qmgr_qmgrControl, do_quecontrol, free_Qmgr_qmgrControl_argument, quecontrol_result, quecontrol_error, "control the qmgr" }, { NULL } }; static char *myservice = "pp qmgr"; static char *mycontext = "pp qmgr interface"; static char *mypci = "pp qmgr interface pci"; static char *myname = "qmgrDisable"; static void invoke(), do_operation(); static int sd; void adios (), advise (); void acs_adios (), acs_advise (); void ros_adios (), ros_advise (); /* \f */ main(argc, argv) int argc; char **argv; { int opt; char *hostname, *username = NULL, *password = NULL, *myname, buf[BUFSIZ]; extern int optind; extern char *optarg; if (myname = rindex(argv[0], '/')) myname++; if (myname == NULL || *myname == NULL) myname = argv[0]; sys_init(myname); gethostname(buf, BUFSIZ); hostname = strdup(buf); while ((opt = getopt (argc, argv, "H:h:U:u:P:p:")) != EOF) { switch (opt) { case 'h': case 'H': hostname = strdup(optarg); break; case 'u': case 'U': username = strdup(optarg); break; case 'p': case 'P': password = strdup(optarg); break; default: printf("Usage : %s [-h mtaname] [-u username] [-p password]\n", myname); exit(1); break; } } if (optind >= argc) { printf("No operation given..bye\n"); exit(0); } if (username == NULL) { printf("\nPP user name -> "); fflush(stdout); if (gets(buf) == NULL) exit(0); username = strdup(buf); } if (password == NULL) password = getpassword("\nPP password -> "); quecontrol_op = &client_dispatches[0]; printf("Connecting to %s...",hostname); fflush(stdout); if (Connect(myname, hostname, username, password) == OK) { printf("connected\n"); fflush(stdout); for (;optind < argc; optind++) do_operation(argv[optind]); } free(username); free(password); free(hostname); } /* \f */ PE passwdpeps[1], *passwdpep = passwdpeps; fillin_passwdpep(user, passwd) char *user, *passwd; { struct type_Qmgr_BindArgument *ba; if (*passwdpep != NULL) { pe_free(*passwdpep); *passwdpep = NULL; } ba = (struct type_Qmgr_BindArgument *) smalloc (sizeof *ba); if (passwd == NULL) { /* no authentication */ ba -> offset = type_Qmgr_BindArgument_noAuthentication; } else { ba -> offset = type_Qmgr_BindArgument_weakAuthentication; ba -> un.weakAuthentication = (struct type_Qmgr_WeakAuthentication *) smalloc(sizeof(struct type_Qmgr_WeakAuthentication)); ba -> un.weakAuthentication->username = str2qb(user, strlen(user), 1); ba -> un.weakAuthentication->passwd = str2qb(passwd, strlen(passwd), 1); } if (encode_Qmgr_BindArgument(passwdpep, 1, NULLCP, 0, ba) == NOTOK) { PP_LOG(LLOG_EXCEPTIONS, ("failed to encode BindArgument [%s]", PY_pepy)); *passwdpep = NULLPE; free_Qmgr_BindArgument(ba); exit(1); } (*passwdpep)->pe_context = 3; } static int Connect(name, host, user, password) char *name, *host, *user, *password; { struct SSAPref sfs; register struct SSAPref *sf; register struct PSAPaddr *pa; struct AcSAPconnect accs; register struct AcSAPconnect *acc = &accs; struct AcSAPindication acis; register struct AcSAPindication *aci = &acis; register struct AcSAPabort *aca = &aci -> aci_abort; AEI aei; OID ctx, tmppci; struct PSAPctxlist pcs; register struct PSAPctxlist *pc = &pcs; struct RoSAPindication rois; register struct RoSAPindication *roi = &rois; register struct RoSAPpreject *rop = &roi -> roi_preject; struct type_Qmgr_BindResult *br; fillin_passwdpep(user, password); if ((aei = str2aei(host, myservice)) == NULLAEI && (aei = str2aei (host, "pp-qmgr")) == NULLAEI) { printf("%s-%s: unknown application-entity", host, myservice); return NOTOK; } if ((pa = aei2addr (aei)) == NULLPA) { advise(NULLCP, "address translation failed"); return NOTOK; } if ((ctx = ode2oid(mycontext)) == NULLOID) { advise(NULLCP, "%s: unknown ISO object descriptor",mycontext); return NOTOK; } if ((ctx = oid_cpy(ctx)) == NULLOID) { advise(NULLCP, "out of memory"); return NOTOK; } if ((tmppci = ode2oid (mypci)) == NULLOID) { advise (NULLCP, "%s: unknown ISO object descriptor", mypci); return NOTOK; } if ((tmppci = oid_cpy (tmppci)) == NULLOID) { advise (NULLCP, "out of memory"); return NOTOK; } pc -> pc_nctx = 1; pc -> pc_ctx[0].pc_id = 1; pc -> pc_ctx[0].pc_asn = tmppci; pc -> pc_ctx[0].pc_atn = NULLOID; if ((sf = addr2ref (PLocalHostName ())) == NULL) { sf = &sfs; (void) bzero ((char *) sf, sizeof *sf); } if (AcAssocRequest (ctx, NULLAEI, aei, NULLPA, pa, pc, NULLOID, 0, ROS_MYREQUIRE, SERIAL_NONE, 0, sf, passwdpep, 1, NULLQOS, acc, aci) == NOTOK) acs_adios (aca, "A-ASSOCIATE.REQUEST"); if (acc->acc_result != ACS_ACCEPT) { advise (NULLCP, "Association rejected: [%s]", AcErrString(acc->acc_result)); return NOTOK; } sd = acc->acc_sd; br = NULL; if (acc->acc_ninfo >= 1 && decode_Qmgr_BindResult(acc->acc_info[0], 1, NULLVP, NULLIP, &br) == NOTOK) { advise(NULLCP, "failed to parse connect data [%s]",PY_pepy); br = NULL; } if (!(acc->acc_ninfo >= 1 && br != NULL && br -> result == int_Qmgr_result_acceptedFullAccess)) { advise(NULLCP, "failed to gain full access to qmgr"); return NOTOK; } if (br != NULL) free_Qmgr_BindResult(br); ACCFREE(acc); if (RoSetService(sd, RoPService, roi) == NOTOK) ros_adios (rop, "set RO/PS fails"); return OK; } /* \f */ CMD_TABLE tbl_args [] = {/* arguments that can be passed in */ "abort", int_Qmgr_QMGROp_abort, "gracefulTerminate", int_Qmgr_QMGROp_gracefulTerminate, "restart", int_Qmgr_QMGROp_restart, "rereadQueue", int_Qmgr_QMGROp_rereadQueue, "disableSubmission", int_Qmgr_QMGROp_disableSubmission, "enableSubmission", int_Qmgr_QMGROp_enableSubmission, "disableAll", int_Qmgr_QMGROp_disableAll, "enableAll", int_Qmgr_QMGROp_enableAll, 0, -1, }; static void do_operation(name) char *name; { int op; if ((op = cmd_srch(name, tbl_args)) == -1) advise(NULLCP, "Unknown qmgr control argument '%s'", name); else { printf("Doing operation '%s'\n",name); fflush(stdout); invoke(sd, table_Qmgr_Operations, quecontrol_op, op); } } static void invoke (ad, ops, ds, args) int ad; struct RyOperation ops[]; register struct client_dispatch *ds; char **args; { int result; caddr_t in; struct RoSAPindication rois; register struct RoSAPindication *roi = &rois; register struct RoSAPpreject *rop = &roi -> roi_preject; in = NULL; if (ds -> ds_argument && (*ds -> ds_argument) (ad, ds, args, &in) == NOTOK) return; switch (result = RyStub (ad, ops, ds -> ds_operation, RyGenID (ad), NULLIP, in, ds -> ds_result, ds -> ds_error, ROS_SYNC, roi)) { case NOTOK: /* failure */ if (ROS_FATAL (rop -> rop_reason)) ros_adios (rop, "STUB"); ros_advise (rop, "STUB"); break; case OK: /* got a result/error response */ break; case DONE: /* got RO-END? */ adios (NULLCP, "got RO-END.INDICATION"); /* NOTREACHED */ default: adios (NULLCP, "unknown return from RyStub=%d", result); /* NOTREACHED */ } if (ds -> ds_free && in) (void) (*ds -> ds_free) (in); } /* ARGSUSED */ static int do_quecontrol(ad, ds, op, arg) int ad; struct client_dispatch *ds; int op; struct type_Qmgr_QMGROp **arg; { *arg = (struct type_Qmgr_QMGROp *) malloc(sizeof(**arg)); (*arg)->parm = op; return OK; } /* ARGSUSED */ static int quecontrol_result (sd, id, dummy, result, roi) int sd, id, dummy; struct type_Qmgr_Pseudo__newmessage *result; struct RoSAPindication *roi; { return OK; } /* \f */ /* ERROR routine */ /* ARGSUSED */ static general_error (ad, id, error, parameter, roi) int ad, 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 */ void ros_adios (rop, event) register struct RoSAPpreject *rop; char *event; { ros_advise (rop, event); _exit (1); } void ros_advise (rop, event) register struct RoSAPpreject *rop; char *event; { char buffer[BUFSIZ]; if (rop -> rop_cc > 0) (void) sprintf (buffer, "[%s] %*.*s", RoErrString (rop -> rop_reason), rop -> rop_cc, rop -> rop_cc, rop -> rop_data); else (void) sprintf (buffer, "[%s]", RoErrString (rop -> rop_reason)); advise (NULLCP, "%s: %s", event, buffer); } /* \f */ void acs_adios (aca, event) register struct AcSAPabort *aca; char *event; { acs_advise (aca, event); _exit (1); } void acs_advise (aca, event) register struct AcSAPabort *aca; char *event; { char buffer[BUFSIZ]; if (aca -> aca_cc > 0) (void) sprintf (buffer, "[%s] %*.*s", AcErrString (aca -> aca_reason), aca -> aca_cc, aca -> aca_cc, aca -> aca_data); else (void) sprintf (buffer, "[%s]", AcErrString (aca -> aca_reason)); advise (NULLCP, "%s: %s (source %d)", event, buffer, aca -> aca_source); } /* \f */ #ifndef lint static void _advise (); void adios (va_alist) va_dcl { va_list ap; va_start (ap); _advise (ap); va_end (ap); _exit (1); } #else /* VARARGS */ void adios (what, fmt) char *what, *fmt; { adios (what, fmt); } #endif #ifndef lint void advise (va_alist) va_dcl { va_list ap; va_start (ap); _advise (ap); va_end (ap); } static void _advise (ap) va_list ap; { char buffer[BUFSIZ]; asprintf (buffer, ap); (void) fflush (stdout); fprintf (stderr, "%s: ", myname); (void) fputs (buffer, stderr); (void) fputc ('\n', stderr); (void) fflush (stderr); } #else /* VARARGS */ void advise (what, fmt) char *what, *fmt; { advise (what, fmt); } #endif #ifndef lint void ryr_advise (va_alist) va_dcl { char *what; va_list ap; va_start (ap); _advise (ap); va_end (ap); } #else /* VARARGS */ void ryr_advise (what, fmt) char *what, *fmt; { ryr_advise (what, fmt); } #endif