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>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
39 void PrintStats(char **info);
40 void PrintClients(char **info);
41 void PrintValue(char **info);
42 void PrintAlias(char **info);
44 /* Function Name: PrintStats
45 * Description: print statistics from argv
46 * Arguments: info: statistics tuple
50 void PrintStats(char **info)
54 sprintf(buf, "Table: %-30s Modified: %s", info[0], info[4]);
56 sprintf(buf, " %s appends, %s updates, %s deletes",
57 info[1], info[2], info[3]);
62 /* Function Name: TableStats
63 * Description: display the Moira table statistics
68 int TableStats(int argc, char **argv)
71 struct mqelem *elem = NULL;
73 if ((status = do_mr_query("get_all_table_stats", 0, NULL, StoreInfo, &elem)))
75 com_err(program_name, status, " in TableStats");
78 Loop(QueueTop(elem), PrintStats);
84 /* Function Name: PrintClients
85 * Description: print info from client tuple
89 void PrintClients(char **info)
92 unsigned long host_address;
93 struct hostent *host_entry;
95 host_address = inet_addr(info[1]);
98 host_entry = gethostbyaddr((char *) &host_address, 4, AF_INET);
102 info[1] = strdup(host_entry->h_name);
105 sprintf(buf, "Principal %s on %s (%s)", info[0], info[1], info[2]);
107 sprintf(buf, " Connected at %s, client %s", info[3], info[4]);
112 /* Function Name: ShowClients
113 * Description: show clients actively using MR
118 int ShowClients(int argc, char **argv)
121 struct mqelem *elem = NULL;
123 if ((status = do_mr_query("_list_users", 0, NULL, StoreInfo, &elem)))
125 com_err(program_name, status, " in ShowClients");
128 Loop(QueueTop(elem), PrintClients);
134 /* Function Name: PrintValue
135 * Description: displays variable values
139 void PrintValue(char **info)
143 sprintf(buf, "Value: %s", info[0]);
148 /* Function Name: ShowValue
149 * Description: get a variable value from MR
150 * Arguments: variable name
154 int ShowValue(int argc, char **argv)
157 struct mqelem *elem = NULL;
159 if ((status = do_mr_query("get_value", 1, &argv[1], StoreInfo, &elem)))
161 com_err(program_name, status, " in ShowValue");
164 Loop(elem, PrintValue);
170 /* Function Name: PrintAlias
171 * Description: print an alias relation
175 void PrintAlias(char **info)
179 sprintf(buf, "Name: %-20s Type: %-12s Value: %s",
180 info[0], info[1], info[2]);
185 /* Function Name: ShowAlias
186 * Description: display an alias relation
187 * Arguments: name & type of alias
191 int ShowAlias(int argc, char **argv)
195 struct mqelem *elem = NULL;
200 if ((status = do_mr_query("get_alias", 3, info, StoreInfo, &elem)))
202 com_err(program_name, status, " in ShowAlias");
205 Loop(QueueTop(elem), PrintAlias);