--- /dev/null
+/* $Header$
+ */
+
+#include <stdio.h>
+#include <strings.h>
+#include <ctype.h>
+#include <sms.h>
+#include <menu.h>
+
+#include "mit-copyright.h"
+#include "defs.h"
+#include "f_defs.h"
+#include "globals.h"
+#include "infodefs.h"
+
+char *whoami;
+
+static char buf[BUFSIZ];
+char *unparse_interval(), *canonicalize_hostname(), *pgets(), *strsave();
+char *atot();
+
+#define DCM_ENABLE_FLAG 0
+
+genable(argc, argv, hint)
+int argc;
+char **argv;
+int *hint;
+{
+ *hint = atoi(argv[0]);
+ return(SMS_CONT);
+}
+
+enabledcm(argc, argv)
+int argc;
+char **argv;
+{
+ char *qargv[2];
+ int value, status;
+
+ qargv[0] = "dcm_enable";
+ if (status = sms_query("get_value", 1, qargv, genable, (char *)&value))
+ com_err(whoami, status, " while getting value of dcm_enable");
+ sprintf(buf, "%d", value);
+ qargv[1] = pgets("Enable value", buf);
+ if (status = sms_query("update_value", 2, qargv, Scream, NULL))
+ com_err(whoami, status, " while updating value of dcm_enable");
+ free(qargv[1]);
+ return(DM_NORMAL);
+}
+
+
+int shserv(argc, argv)
+int argc;
+char **argv;
+{
+ char tmp[64], *dfgen;
+
+ Put_message("Name Type Owner Modified");
+ sprintf(tmp, "%s:%s", argv[11], argv[12]);
+ sprintf(buf, "%-10s %-8s %-14s by %s on %s with %s", argv[0], argv[6],
+ tmp, argv[14], argv[13], argv[15]);
+ Put_message(buf);
+ sprintf(buf, " Interval %s, Target:%s, Script:%s",
+ unparse_interval(atoi(argv[1])), argv[2], argv[3]);
+ Put_message(buf);
+ if (atoi(argv[9]))
+ sprintf(tmp, "Error %d: %s", atoi(argv[9]), argv[10]);
+ else
+ strcpy(tmp, "No error");
+ dfgen = strsave(atot(argv[4]));
+ sprintf(buf, " Generated %s; Last Checked %s", dfgen, atot(argv[5]));
+ free(dfgen);
+ Put_message(buf);
+ sprintf(buf, " %s/%s/%s", atoi(argv[7]) ? "Enabled" : "Disabled",
+ atoi(argv[8]) ? "InProgress" : "Idle", tmp);
+ Put_message(buf);
+ Put_message("");
+ return(SMS_CONT);
+}
+
+
+showserv(argc, argv)
+int argc;
+char **argv;
+{
+ char *qargv[1];
+ int status;
+
+ qargv[0] = argv[1];
+ if (status = sms_query("get_server_info", 1, qargv, shserv, NULL))
+ com_err(whoami, status, " while getting server info");
+ return(DM_NORMAL);
+}
+
+
+char *unparse_interval(i)
+int i;
+{
+ static char uibuf[10];
+
+ sprintf(uibuf, "%02d:%02d:00", i / 60, i % 60);
+ return(uibuf);
+}
+
+addserv(argc, argv)
+int argc;
+char **argv;
+{
+ char *qargv[8], tmp[BUFSIZ];
+ int status;
+
+ qargv[0] = argv[1];
+ qargv[1] = pgets("Interval", "1440");
+ sprintf(tmp, "/tmp/%s.out", argv[1]);
+ qargv[2] = pgets("Target", tmp);
+ sprintf(tmp, "/u1/sms/bin/%s.sh", argv[1]);
+ qargv[3] = pgets("Script", tmp);
+ qargv[4] = pgets("Service type", "UNIQUE");
+ qargv[5] = pgets("Enable", "1");
+ qargv[6] = pgets("ACE type", "list");
+ qargv[7] = pgets("ACE name", "dbadmin");
+ if (status = sms_query("add_server_info", 8, qargv, Scream, NULL))
+ com_err(whoami, status, " while updating server info");
+ return(DM_NORMAL);
+}
+
+
+gserv(argc, argv, cargv)
+int argc;
+char **argv;
+char **cargv;
+{
+ cargv[0] = argv[0];
+ cargv[1] = argv[1];
+ cargv[2] = argv[2];
+ cargv[3] = argv[3];
+ cargv[4] = argv[6];
+ cargv[5] = argv[7];
+ cargv[6] = argv[11];
+ cargv[7] = argv[12];
+ return(SMS_CONT);
+}
+
+
+char *pgets(prompt, def)
+char *prompt;
+char *def;
+{
+ char ibuf[BUFSIZ], pbuf[BUFSIZ];
+
+ sprintf(pbuf, "%s [%s]: ", prompt, def);
+ Prompt_input(pbuf, ibuf, BUFSIZ);
+ if (!strlen(ibuf))
+ return(strsave(def));
+ else
+ return(strsave(ibuf));
+}
+
+
+updateserv(argc, argv)
+int argc;
+char **argv;
+{
+ char *qargv[8];
+ int status;
+
+ qargv[0] = (char *)argv[1];
+ if (status = sms_query("get_server_info", 1, qargv,gserv,(char *)qargv)) {
+ com_err(whoami, status, " while getting server info");
+ return(DM_NORMAL);
+ }
+ qargv[1] = pgets("Interval", qargv[1]);
+ qargv[2] = pgets("Target", qargv[2]);
+ qargv[3] = pgets("Script", qargv[3]);
+ qargv[4] = pgets("Service type", qargv[4]);
+ qargv[5] = pgets("Enable", qargv[5]);
+ qargv[6] = pgets("ACE type", qargv[6]);
+ qargv[7] = pgets("ACE name", qargv[7]);
+ if (status = sms_query("update_server_info", 8, qargv, Scream, NULL))
+ com_err(whoami, status, " while updating server info");
+ return(DM_NORMAL);
+}
+
+
+int shhost(argc, argv)
+int argc;
+char **argv;
+{
+ char tmp[64], *ltt;
+
+ sprintf(buf, "%s:%s mod by %s on %s with %s", argv[1], argv[0],
+ argv[14], argv[13], argv[15]);
+ Put_message(buf);
+ if (atoi(argv[6]))
+ sprintf(tmp, "Error %d: %s", atoi(argv[6]), argv[7]);
+ else
+ strcpy(tmp, "No error");
+ sprintf(buf, " %s/%s/%s/%s/%s",
+ atoi(argv[2]) ? "Enabled" : "Disabled",
+ atoi(argv[4]) ? "Success" : "Failure",
+ atoi(argv[5]) ? "InProgress" : "Idle",
+ atoi(argv[3]) ? "Override" : "Normal", tmp);
+ Put_message(buf);
+ Put_message(" Last Try Last Success Value1 Value2 Value3");
+ ltt = strsave(atot(argv[8]));
+ sprintf(buf, " %-20s %-20s %-9d %-9d %s", ltt, atot(argv[9]),
+ atoi(argv[10]), atoi(argv[11]), argv[12]);
+ free(ltt);
+ Put_message(buf);
+ Put_message("");
+ return(SMS_CONT);
+}
+
+
+showhost(argc, argv)
+int argc;
+char **argv;
+{
+ char *qargv[1];
+ int status;
+
+ qargv[0] = argv[1];
+ qargv[1] = canonicalize_hostname(argv[2]);
+ if (status = sms_query("get_server_host_info", 2, qargv, shhost, NULL))
+ com_err(whoami, status, " getting server/host info");
+ return(DM_NORMAL);
+}
+
+
+resetsrverr(argc, argv)
+int argc;
+char **argv;
+{
+ int status;
+ if (status = sms_query("reset_server_error", 1, &argv[1], Scream, NULL))
+ com_err(whoami, status, " while resetting server error");
+ return(DM_NORMAL);
+}
+
+
+resetsrvc(argc, argv)
+int argc;
+char **argv;
+{
+ int status;
+ char *qargv[5];
+
+ qargv[0] = argv[1];
+ qargv[1] = "0";
+ qargv[2] = "0";
+ qargv[3] = "0";
+ qargv[4] = "0";
+ qargv[5] = "";
+ if (status = sms_query("set_server_internal_flags", 6, qargv, Scream, NULL))
+ com_err(whoami, status, " while resetting server error");
+ return(DM_NORMAL);
+}
+
+
+resethosterr(argc, argv)
+int argc;
+char **argv;
+{
+ int status;
+
+ argv[2] = canonicalize_hostname(argv[2]);
+ if (status = sms_query("reset_server_host_error",2, &argv[1], Scream, NULL))
+ com_err(whoami, status, " while resetting server/host error");
+ return(DM_NORMAL);
+}
+
+
+resethost(argc, argv)
+int argc;
+char **argv;
+{
+ int status;
+ char *qargv[9];
+
+ qargv[0] = argv[1];
+ qargv[1] = canonicalize_hostname(argv[2]);
+ qargv[2] = "0";
+ qargv[3] = "0";
+ qargv[4] = "0";
+ qargv[5] = "0";
+ qargv[6] = "";
+ qargv[7] = "0";
+ qargv[8] = "0";
+ if (status = sms_query("set_server_host_internal", 9, qargv, Scream, NULL))
+ com_err(whoami, status, " while resetting server/host error");
+ return(DM_NORMAL);
+}
+
+
+sethostor(argc, argv)
+int argc;
+char **argv;
+{
+ int status;
+
+ argv[2] = canonicalize_hostname(argv[2]);
+ if (status = sms_query("set_server_host_override",2,&argv[1], Scream, NULL))
+ com_err(whoami, status, " while setting server/host override");
+ return(DM_NORMAL);
+}
+
+
+ghost(argc, argv, cargv)
+int argc;
+char **argv;
+char **cargv;
+{
+ cargv[0] = argv[0];
+ cargv[1] = argv[1];
+ cargv[2] = argv[2];
+ cargv[3] = argv[10];
+ cargv[4] = argv[11];
+ cargv[5] = argv[12];
+ return(SMS_CONT);
+}
+
+
+updatehost(argc, argv)
+int argc;
+char **argv;
+{
+ char *qargv[6];
+ int status;
+
+ qargv[0] = (char *)argv[1];
+ qargv[1] = canonicalize_hostname(argv[2]);
+ if (status = sms_query("get_server_host_info", 2, qargv, ghost,
+ (char *)qargv)) {
+ com_err(whoami, status, " while getting server/host info");
+ return(DM_NORMAL);
+ }
+ qargv[1] = canonicalize_hostname(argv[2]);
+ qargv[2] = pgets("Enable", qargv[2]);
+ qargv[3] = pgets("Value 1", qargv[3]);
+ qargv[4] = pgets("Value 2", qargv[4]);
+ qargv[5] = pgets("Value 3", qargv[5]);
+ if (status = sms_query("update_server_host_info", 6, qargv, Scream, NULL))
+ com_err(whoami, status, " while updating server/host info");
+ return(DM_NORMAL);
+}
+
+
+addhost(argc, argv)
+int argc;
+char **argv;
+{
+ char *qargv[6];
+ int status;
+
+ qargv[0] = argv[1];
+ qargv[1] = canonicalize_hostname(argv[2]);
+ qargv[2] = pgets("Enable", "1");
+ qargv[3] = pgets("Value 1", "0");
+ qargv[4] = pgets("Value 2", "0");
+ qargv[5] = pgets("Value 3", "");
+ if (status = sms_query("add_server_host_info", 6, qargv, Scream, NULL))
+ com_err(whoami, status, " while adding server/host info");
+ return(DM_NORMAL);
+}
+
+
+delserv(argc, argv)
+int argc;
+char **argv;
+{
+ int status;
+
+ if (status = sms_query("delete_server_info", 1, &argv[1], Scream, NULL))
+ com_err(whoami, status, " while deleting server info");
+ return(DM_NORMAL);
+}
+
+
+delhost(argc, argv)
+int argc;
+char **argv;
+{
+ int status;
+
+ argv[2] = canonicalize_hostname(argv[2]);
+ if (status = sms_query("delete_server_host_info",2, &argv[1], Scream, NULL))
+ com_err(whoami, status, " while deleting server/host info");
+ return(DM_NORMAL);
+}
+
+
+pserv(argc, argv, count)
+int argc;
+char **argv;
+int *count;
+{
+ sprintf(buf, "Service %s", argv[0]);
+ Put_message(buf);
+ (*count)++;
+ return(SMS_CONT);
+}
+
+phost(argc, argv, count)
+int argc;
+char **argv;
+int *count;
+{
+ sprintf(buf, "Host %s:%s", argv[0], argv[1]);
+ Put_message(buf);
+ (*count)++;
+ return(SMS_CONT);
+}
+
+
+inprogress()
+{
+ char *argv[6];
+ int status, count = 0;
+
+ argv[0] = argv[2] = "DONTCARE";
+ argv[1] = "TRUE";
+ if ((status = sms_query("qualified_get_server", 3, argv, pserv,
+ (char *)&count)) &&
+ status != SMS_NO_MATCH)
+ com_err(whoami, status, " while getting servers");
+ argv[0] = "*";
+ argv[1] = argv[2] = argv[3] = argv[5] = "DONTCARE";
+ argv[4] = "TRUE";
+ if ((status = sms_query("qualified_get_server_host",6,argv,phost,
+ (char *)&count)) &&
+ status != SMS_NO_MATCH)
+ com_err(whoami, status, " while getting server/hosts");
+ if (!count)
+ strcpy(buf, "Nothing is in progress at this time");
+ else
+ sprintf(buf, "%d update%s in progress at this time", count,
+ count == 1 ? "" : "s");
+ Put_message(buf);
+ return(DM_NORMAL);
+}
+
+failed()
+{
+ char *argv[6];
+ int status, count = 0;
+
+ argv[0] = argv[1] = "DONTCARE";
+ argv[2] = "TRUE";
+ if ((status = sms_query("qualified_get_server", 3, argv, pserv,
+ (char *)&count)) &&
+ status != SMS_NO_MATCH)
+ com_err(whoami, status, " while getting servers");
+ argv[0] = "*";
+ argv[1] = argv[2] = argv[3] = argv[4] = "DONTCARE";
+ argv[5] = "TRUE";
+ if ((status = sms_query("qualified_get_server_host",6,argv,phost,
+ (char *)&count)) &&
+ status != SMS_NO_MATCH)
+ com_err(whoami, status, " while getting server/hosts");
+ if (!count)
+ strcpy(buf, "Nothing has failed at this time");
+ else
+ sprintf(buf, "%d thing%s ha%s failed at this time", count,
+ count == 1 ? "" : "s", count == 1 ? "s" : "ve");
+ Put_message(buf);
+ return(DM_NORMAL);
+}
+
+
+dcm()
+{
+ int status;
+ if (status = sms_do_update())
+ com_err(whoami, status, " while triggering update");
+ return(DM_NORMAL);
+}
+
+
+char *atot(itime)
+char *itime;
+{
+ int time;
+ char *ct, *ctime();
+
+ time = atoi(itime);
+ ct = ctime(&time);
+ ct[24] = 0;
+ return(&ct[4]);
+}
--- /dev/null
+#if (!defined(lint) && !defined(SABER))
+ static char rcsid_module_c[] = "$Header$";
+#endif lint
+
+/* This is the file printer.c for the SMS Client, which allows a nieve
+ * user to quickly and easily maintain most parts of the SMS database.
+ * It Contains: Functions for handling the printers.
+ *
+ * Created: 8/16/88
+ * By: Theodore Y. Ts'o
+ *
+ * $Source$
+ * $Author$
+ * $Header$
+ *
+ * Copyright 1988 by the Massachusetts Institute of Technology.
+ *
+ * For further information on copyright and distribution
+ * see the file mit-copyright.h
+ */
+
+#include <stdio.h>
+#include <strings.h>
+#include <ctype.h>
+#include <sms.h>
+#include <menu.h>
+
+#include "mit-copyright.h"
+#include "defs.h"
+#include "f_defs.h"
+#include "globals.h"
+#include "infodefs.h"
+
+#define PCAP_NAME 0
+#define PCAP_SPOOL_HOST 1
+#define PCAP_SPOOL_DIR 2
+#define PCAP_RPRINTER 3
+#define PCAP_COMMENTS 4
+#define PCAP_MODTIME 5
+#define PCAP_MODBY 6
+#define PCAP_MODWITH 7
+#define PCAP_END 8
+
+#define DEFAULT_MACHINE "E40-PRINT-SERVER-1.MIT.EDU"
+
+/* Function Name: SetDefaults
+ * Description: sets the default values for filesystem additions.
+ * Arguments: info - an array of char pointers to recieve defaults.
+ * Returns: char ** (this array, now filled).
+ */
+
+static char **
+SetDefaults(info, name)
+char ** info;
+char * name;
+{
+ char spool_dir[256];
+
+ strcpy(spool_dir, "/usr/spool/printer/");
+ strcat(spool_dir, name);
+
+ info[PCAP_NAME] = Strsave(name);
+ info[PCAP_SPOOL_HOST] = Strsave(DEFAULT_MACHINE);
+ info[PCAP_SPOOL_DIR] = Strsave(spool_dir);
+ info[PCAP_RPRINTER] = Strsave(name);
+ info[PCAP_COMMENTS] = Strsave("");
+ info[PCAP_MODTIME] = info[PCAP_MODBY] = info[PCAP_MODWITH] = NULL;
+
+ info[PCAP_END] = NULL;
+ return(info);
+}
+
+/* Function Name: GetPcapInfo
+ * Description: Stores the info in a queue.
+ * Arguments: name - name of the item to get information on.
+ * Returns: a pointer to the first element in the queue or null
+ * if printer not found.
+ */
+
+static struct qelem *
+GetPcapInfo(name)
+char *name;
+
+{
+ int stat;
+ struct qelem *elem = NULL;
+
+ if ( (stat = sms_query("get_printcap", 1, &name,
+ StoreInfo, (char *)&elem)) != 0) {
+ com_err(program_name, stat, NULL);
+ return(NULL);
+ }
+ return(QueueTop(elem));
+}
+
+/* Function Name: PrintPcapInfo
+ * Description: Yet another specialized print function.
+ * Arguments: info - all info about this Printer.
+ * Returns: none
+ */
+
+static void
+PrintPcapInfo(info)
+char ** info;
+{
+ char buf[BUFSIZ];
+
+ if (!info) { /* If no informaion */
+ Put_message("PrintPcapInfo called with null info!");
+ return;
+ }
+ sprintf(buf, "Printer: %-35s Spool host: %s", info[PCAP_NAME],
+ info[PCAP_SPOOL_HOST]);
+ Put_message(buf);
+ sprintf(buf, "Spool directory: %-27s Remote Printer Name: %s",
+ info[PCAP_SPOOL_DIR], info[PCAP_RPRINTER]);
+ Put_message(buf);
+ sprintf(buf, "Comments: ", info[PCAP_COMMENTS]);
+ Put_message(buf);
+ sprintf(buf, MOD_FORMAT, info[PCAP_MODBY], info[PCAP_MODTIME],
+ info[PCAP_MODWITH]);
+ Put_message(buf);
+}
+
+/* Function Name: AskPcapInfo.
+ * Description: This function askes the user for information about a
+ * printer and saves it into a structure.
+ * Arguments: info - a pointer the the structure to put the
+ * info into.
+ * Returns: none.
+ */
+
+static char **
+AskPcapInfo(info)
+char ** info;
+{
+ char temp_buf[BUFSIZ], *newname;
+
+ Put_message("");
+ sprintf(temp_buf, "Printcap entry for %s.",
+ info[FS_NAME]);
+ Put_message(temp_buf);
+ Put_message("");
+
+ GetValueFromUser("Printer Server", &info[PCAP_SPOOL_HOST]);
+ strcpy(temp_buf, CanonicalizeHostname(info[PCAP_SPOOL_HOST]));
+ free(info[PCAP_SPOOL_HOST]);
+ info[PCAP_SPOOL_HOST] = Strsave(temp_buf);
+ GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]);
+ GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]);
+ GetValueFromUser("Comments", &info[PCAP_COMMENTS]);
+
+ FreeAndClear(&info[PCAP_MODTIME], TRUE);
+ FreeAndClear(&info[PCAP_MODBY], TRUE);
+ FreeAndClear(&info[PCAP_MODWITH], TRUE);
+
+ return(info);
+}
+
+/* ---------------- Printer Menu ------------------ */
+
+/* Function Name: GetPcap
+ * Description: Get Printcap information
+ * Arguments: argc, argv - name of filsys in argv[1].
+ * Returns: DM_NORMAL.
+ */
+
+/* ARGSUSED */
+int
+GetPcap(argc, argv)
+int argc;
+char **argv;
+{
+ struct qelem *top;
+
+ top = GetPcapInfo(argv[1]); /* get info. */
+ Loop(top, (void *) PrintPcapInfo);
+ FreeQueue(top); /* clean the queue. */
+ return (DM_NORMAL);
+}
+
+/* Function Name: RealDeletePcap
+ * Description: Does the real deletion work.
+ * Arguments: info - array of char *'s containing all useful info.
+ * one_item - a Boolean that is true if only one item
+ * in queue that dumped us here.
+ * Returns: none.
+ */
+
+void
+RealDeletePcap(info, one_item)
+char ** info;
+Bool one_item;
+{
+ int stat;
+ char temp_buf[BUFSIZ];
+
+ if ( (stat = sms_query("delete_printcap", 1,
+ &info[FS_NAME], Scream, NULL)) != 0)
+ com_err(program_name, stat, " printcap entry not deleted.");
+ else
+ Put_message("Printcap entry deleted.");
+}
+
+/* Function Name: DeletePcap
+ * Description: Delete a printcap entry given its name.
+ * Arguments: argc, argv - argv[1] is the name of the printer.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+
+int
+DeletePcap(argc, argv)
+int argc;
+char **argv;
+{
+ struct qelem *elem = GetPcapInfo(argv[1]);
+ QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer");
+
+ FreeQueue(elem);
+ return (DM_NORMAL);
+}
+
+/* Function Name: AddPcap
+ * Description: Add a printcap entry
+ * Arguments: arc, argv - name of printer in argv[1].
+ * Returns: DM_NORMAL.
+ */
+
+/* ARGSUSED */
+int
+AddPcap(argc, argv)
+char **argv;
+int argc;
+{
+ char *info[MAX_ARGS_SIZE], **args;
+ int stat;
+
+ if ( !ValidName(argv[1]) )
+ return(DM_NORMAL);
+
+ if ( (stat = sms_query("get_printcap", 1, argv + 1,
+ NullFunc, NULL)) == 0) {
+ Put_message ("A Printer by that name already exists.");
+ return(DM_NORMAL);
+ } else if (stat != SMS_NO_MATCH) {
+ com_err(program_name, stat, " in AddPcap");
+ return(DM_NORMAL);
+ }
+
+ args = AskPcapInfo(SetDefaults(info, argv[1]));
+
+ if ( (stat = sms_query("add_printcap", CountArgs(args), args,
+ NullFunc, NULL)) != 0)
+ com_err(program_name, stat, " in AddPcap");
+
+ FreeInfo(info);
+ return (DM_NORMAL);
+}
+
+
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-indent-level: 4
+ * c-continued-statement-offset: 4
+ * c-brace-offset: -4
+ * c-argdecl-indent: 4
+ * c-label-offset: -4
+ * End:
+ */
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+