1 /* This is the file misc.c for the Moira Client, which allows a naieve
2 * to quickly and easily maintain most parts of the Moira database.
8 * Created: 5 October 1988
9 * By: Mark A. Rosenstein
15 * Copyright 1988 by the Massachusetts Institute of Technology.
17 * For further information on copyright and distribution
18 * see the file mit-copyright.h
24 #include <moira_site.h>
26 #include <sys/types.h>
28 #include <sys/socket.h>
29 #include <netinet/in.h>
31 #include "mit-copyright.h"
37 /* Function Name: PrintStats
38 * Description: print statistics from argv
39 * Arguments: info: statistics tuple
43 int PrintStats(char **info)
47 sprintf(buf, "Table: %-30s Modified: %s", info[0], info[5]);
49 sprintf(buf, " %s appends, %s updates, %s deletes",
50 info[2], info[3], info[4]);
55 /* Function Name: TableStats
56 * Description: display the Moira table statistics
64 struct qelem *elem = NULL;
66 if ((status = do_mr_query("get_all_table_stats", 0, NULL,
67 StoreInfo, (char *)&elem)))
69 com_err(program_name, status, " in TableStats");
72 Loop(QueueTop(elem), PrintStats);
78 /* Function Name: PrintClients
79 * Description: print info from client tuple
83 int PrintClients(char **info)
86 unsigned long host_address;
87 struct hostent *host_entry;
89 host_address = inet_addr(info[1]);
92 host_entry = gethostbyaddr((char *) &host_address, 4, AF_INET);
96 info[1] = Strsave(host_entry->h_name);
99 sprintf(buf, "Principal %s on %s (%s)", info[0], info[1], info[2]);
101 sprintf(buf, " Connected at %s, client %s", info[3], info[4]);
106 /* Function Name: ShowClients
107 * Description: show clients actively using MR
112 int ShowClients(void)
115 struct qelem *elem = NULL;
117 if ((status = do_mr_query("_list_users", 0, NULL,
118 StoreInfo, (char *) &elem)))
120 com_err(program_name, status, " in ShowClients");
123 Loop(QueueTop(elem), PrintClients);
129 /* Function Name: PrintValue
130 * Description: displays variable values
134 int PrintValue(char **info)
138 sprintf(buf, "Value: %s", info[0]);
143 /* Function Name: ShowValue
144 * Description: get a variable value from MR
145 * Arguments: variable name
149 int ShowValue(int argc, char **argv)
152 struct qelem *elem = NULL;
154 if ((status = do_mr_query("get_value", 1, &argv[1],
155 StoreInfo, (char *) &elem)))
157 com_err(program_name, status, " in ShowValue");
160 Loop(elem, PrintValue);
166 /* Function Name: PrintAlias
167 * Description: print an alias relation
171 int PrintAlias(char **info)
175 sprintf(buf, "Name: %-20s Type: %-12s Value: %s",
176 info[0], info[1], info[2]);
181 /* Function Name: ShowAlias
182 * Description: display an alias relation
183 * Arguments: name & type of alias
187 int ShowAlias(int argc, char **argv)
191 struct qelem *elem = NULL;
196 if ((status = do_mr_query("get_alias", 3, info,
197 StoreInfo, (char *) &elem)))
199 com_err(program_name, status, " in ShowAlias");
202 Loop(QueueTop(elem), PrintAlias);