]>
Commit | Line | Data |
---|---|---|
8ed18d22 | 1 | /* |
2 | * Verify that all SMS updates are successful | |
3 | * | |
4 | * Copyright 1988 by the Massachusetts Institute of Technology. For copying | |
5 | * and distribution information, see the file "mit-copyright.h". | |
6 | * | |
7 | * $Source$ | |
8 | * $Header$ | |
9 | * $Author$ | |
10 | */ | |
11 | ||
12 | #ifndef lint | |
13 | static char *rcsid_chsh_c = "$Header$"; | |
14 | #endif lint | |
15 | ||
16 | #include <stdio.h> | |
17 | #include <sms.h> | |
18 | #include <sms_app.h> | |
19 | #include "mit-copyright.h" | |
20 | ||
21 | char *malloc(), *rindex(), *strsave(); | |
22 | ||
23 | static int status; | |
24 | static char *whoami; | |
25 | ||
26 | ||
27 | char *atot(itime) | |
28 | char *itime; | |
29 | { | |
30 | int time; | |
31 | char *ct, *ctime(); | |
32 | ||
33 | time = atoi(itime); | |
34 | ct = ctime(&time); | |
35 | ct[24] = 0; | |
36 | return(&ct[4]); | |
37 | } | |
38 | ||
39 | gserv(argc, argv, sq) | |
40 | int argc; | |
41 | char **argv; | |
42 | struct save_queue *sq; | |
43 | { | |
44 | char *tmp; | |
45 | ||
46 | tmp = strsave(atot(argv[4])); | |
47 | printf("Service %s, error %s: %s\n\tlast success %s, last try %s\n", | |
48 | argv[0], argv[9], argv[10], tmp, atot(argv[5])); | |
49 | free(tmp); | |
50 | return(SMS_CONT); | |
51 | } | |
52 | ||
53 | ghost(argc, argv, sq) | |
54 | int argc; | |
55 | char **argv; | |
56 | struct save_queue *sq; | |
57 | { | |
58 | char *tmp; | |
59 | ||
60 | tmp = strsave(atot(argv[9])); | |
61 | printf("Host %s:%s, error %s: %s\n\tlast success %s, last try %s\n", | |
62 | argv[0], argv[1], argv[6], argv[7], tmp, atot(argv[8])); | |
63 | free(tmp); | |
64 | return(SMS_CONT); | |
65 | } | |
66 | ||
67 | save_args(argc, argv, sq) | |
68 | int argc; | |
69 | char **argv; | |
70 | struct save_queue *sq; | |
71 | { | |
72 | sq_save_args(argc, argv, sq); | |
73 | return(SMS_CONT); | |
74 | } | |
75 | ||
76 | main(argc, argv) | |
77 | char *argv[]; | |
78 | ||
79 | { | |
80 | char *args[6], buf[BUFSIZ], **service, **host; | |
81 | struct save_queue *services, *hosts; | |
82 | int count = 0, scream(); | |
83 | ||
84 | init_sms_err_tbl(); | |
85 | init_krb_err_tbl(); | |
86 | ||
87 | if ((whoami = rindex(argv[0], '/')) == NULL) | |
88 | whoami = argv[0]; | |
89 | else | |
90 | whoami++; | |
91 | ||
92 | if (argc > 1) { | |
93 | usage(); | |
94 | } | |
95 | ||
96 | status = sms_connect(SMS_SERVER); | |
97 | if (status) { | |
98 | (void) sprintf(buf, "\nConnection to the SMS server failed."); | |
99 | goto punt; | |
100 | } | |
101 | ||
102 | status = sms_auth("smscheck"); | |
103 | if (status) { | |
104 | (void) sprintf(buf, "\nAuthorization failure -- run \"kinit\" \ | |
105 | and try again"); | |
106 | goto punt; | |
107 | } | |
108 | ||
109 | services = sq_create(); | |
110 | args[0] = args[2] = "TRUE"; | |
111 | args[1] = "DONTCARE"; | |
112 | if ((status = sms_query("qualified_get_server", 3, args, save_args, | |
113 | (char *)services)) && | |
114 | status != SMS_NO_MATCH) | |
115 | com_err(whoami, status, " while getting servers"); | |
116 | ||
117 | hosts = sq_create(); | |
118 | args[0] = "*"; | |
119 | args[1] = args[5] = "TRUE"; | |
120 | args[2] = args[3] = args[4] = "DONTCARE"; | |
121 | if ((status = sms_query("qualified_get_server_host", 6, args, save_args, | |
122 | (char *)hosts)) && | |
123 | status != SMS_NO_MATCH) | |
124 | com_err(whoami, status, " while getting server/hosts"); | |
125 | ||
126 | while (sq_get_data(services, &service)) { | |
127 | count++; | |
128 | if (status = sms_query("get_server_info", 1, service, gserv, NULL)) | |
129 | com_err(whoami, status, " while getting info about service %s", | |
130 | service[0]); | |
131 | } | |
132 | ||
133 | while (sq_get_data(hosts, &host)) { | |
134 | count++; | |
135 | if (status = sms_query("get_server_host_info", 2, host, ghost, NULL)) | |
136 | com_err(whoami, status, " while getting info about host %s:%s", | |
137 | host[0], host[1]); | |
138 | } | |
139 | ||
140 | if (!count) | |
141 | strcpy(buf, "Nothing has failed at this time"); | |
142 | else | |
143 | sprintf(buf, "%d thing%s ha%s failed at this time", count, | |
144 | count == 1 ? "" : "s", count == 1 ? "s" : "ve"); | |
145 | puts(buf); | |
146 | ||
147 | sms_disconnect(); | |
148 | exit(0); | |
149 | ||
150 | punt: | |
151 | com_err(whoami, status, buf); | |
152 | sms_disconnect(); | |
153 | exit(1); | |
154 | } | |
155 | ||
156 | ||
157 | scream() | |
158 | { | |
159 | com_err(whoami, status, "Update to SMS returned a value -- \ | |
160 | programmer botch.\n"); | |
161 | sms_disconnect(); | |
162 | exit(1); | |
163 | } | |
164 | ||
165 | usage() | |
166 | { | |
167 | fprintf(stderr, "Usage: %s\n", whoami); | |
168 | exit(1); | |
169 | } |