3 * This is the file misc.c for the Moira Client, which allows a naieve
4 * to quickly and easily maintain most parts of the Moira database.
10 * Created: 5 October 1988
11 * By: Mark A. Rosenstein
13 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
14 * For copying and distribution information, please see the file
18 #include <mit-copyright.h>
20 #include <moira_site.h>
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
37 void PrintStats(char **info);
38 void PrintClients(char **info);
39 void PrintValue(char **info);
40 void PrintAlias(char **info);
42 /* Function Name: PrintStats
43 * Description: print statistics from argv
44 * Arguments: info: statistics tuple
48 void PrintStats(char **info)
52 sprintf(buf, "Table: %-30s Modified: %s", info[0], info[5]);
54 sprintf(buf, " %s appends, %s updates, %s deletes",
55 info[2], info[3], info[4]);
60 /* Function Name: TableStats
61 * Description: display the Moira table statistics
66 int TableStats(int argc, char **argv)
69 struct qelem *elem = NULL;
71 if ((status = do_mr_query("get_all_table_stats", 0, NULL, StoreInfo, &elem)))
73 com_err(program_name, status, " in TableStats");
76 Loop(QueueTop(elem), PrintStats);
82 /* Function Name: PrintClients
83 * Description: print info from client tuple
87 void PrintClients(char **info)
90 unsigned long host_address;
91 struct hostent *host_entry;
93 host_address = inet_addr(info[1]);
96 host_entry = gethostbyaddr((char *) &host_address, 4, AF_INET);
100 info[1] = strdup(host_entry->h_name);
103 sprintf(buf, "Principal %s on %s (%s)", info[0], info[1], info[2]);
105 sprintf(buf, " Connected at %s, client %s", info[3], info[4]);
110 /* Function Name: ShowClients
111 * Description: show clients actively using MR
116 int ShowClients(int argc, char **argv)
119 struct qelem *elem = NULL;
121 if ((status = do_mr_query("_list_users", 0, NULL, StoreInfo, &elem)))
123 com_err(program_name, status, " in ShowClients");
126 Loop(QueueTop(elem), PrintClients);
132 /* Function Name: PrintValue
133 * Description: displays variable values
137 void PrintValue(char **info)
141 sprintf(buf, "Value: %s", info[0]);
146 /* Function Name: ShowValue
147 * Description: get a variable value from MR
148 * Arguments: variable name
152 int ShowValue(int argc, char **argv)
155 struct qelem *elem = NULL;
157 if ((status = do_mr_query("get_value", 1, &argv[1], StoreInfo, &elem)))
159 com_err(program_name, status, " in ShowValue");
162 Loop(elem, PrintValue);
168 /* Function Name: PrintAlias
169 * Description: print an alias relation
173 void PrintAlias(char **info)
177 sprintf(buf, "Name: %-20s Type: %-12s Value: %s",
178 info[0], info[1], info[2]);
183 /* Function Name: ShowAlias
184 * Description: display an alias relation
185 * Arguments: name & type of alias
189 int ShowAlias(int argc, char **argv)
193 struct qelem *elem = NULL;
198 if ((status = do_mr_query("get_alias", 3, info, StoreInfo, &elem)))
200 com_err(program_name, status, " in ShowAlias");
203 Loop(QueueTop(elem), PrintAlias);