]> andersk Git - moira.git/blame - update/client.c
detect TIMEOUT errors to the kerberos server
[moira.git] / update / client.c
CommitLineData
de56407f 1/*
2 * $Source$
3 * $Header$
4 */
5
6#ifndef lint
7static char *rcsid_client2_c = "$Header$";
8#endif lint
9
10/*
11 * MODULE IDENTIFICATION:
12 * $Header$
546bc43b 13 * Copyright 1987, 1988 by the Massachusetts Institute of Technology.
14 * For copying and distribution information, please see the file
15 * <mit-copyright.h>.
de56407f 16 * DESCRIPTION:
17 * This code handles the actual distribution of data files
18 * to servers in the SMS server-update program.
19 * AUTHOR:
20 * Ken Raeburn (spook@athena.MIT.EDU),
21 * MIT Project Athena/MIT Information Systems.
22 * DEFINED VALUES:
23 * conn
de56407f 24 * sms_update_server
de56407f 25 */
26
546bc43b 27#include <mit-copyright.h>
de56407f 28#include <stdio.h>
29#include <strings.h>
7bd50861 30#include <gdb.h>
de56407f 31#include <sys/param.h>
7bd50861 32#include <sys/wait.h>
f5b9994a 33#include <sys/socket.h>
7bd50861 34#include <update.h>
de56407f 35#include <errno.h>
7bd50861 36#include <dcm.h>
37#include <sms.h>
de56407f 38#include <krb.h>
39
7bd50861 40extern char *malloc();
bc6cbc65 41extern int errno, dbg;
de56407f 42
de56407f 43static char buf[BUFSIZ];
7bd50861 44static int code;
de56407f 45
46CONNECTION conn;
de56407f 47
de56407f 48
49/*
50 * FUNCTION:
51 * initialize()
52 * DESCRIPTION:
53 * Insures that various libraries have a chance to get
54 * initialized.
55 * INPUT:
56 * OUTPUT:
57 * RETURN VALUE:
58 * void
59 * SIDE EFFECTS:
756e2c48 60 * Initializes GDB library.
de56407f 61 * PROBLEMS:
62 *
63 */
7bd50861 64static void
de56407f 65initialize()
66{
67 static int initialized = 0;
7bd50861 68
de56407f 69 if (!initialized) {
70 gdb_init();
de56407f 71 initialized++;
72 }
73}
74
7bd50861 75
de56407f 76/*
77 * FUNCTION:
7bd50861 78 * sms_update_server(service, machine, target_path)
de56407f 79 * DESCRIPTION:
7bd50861 80 * Attempts to perform an update to the named machine
81 * of the named service. The file SMS_DIR/dcm/service.out
82 * will be sent, then the file SMS_DIR/bin/service.sh,
83 * the the shell script will be executed.
de56407f 84 * INPUT:
7bd50861 85 * service
de56407f 86 * Name of service to be updated; used to find
87 * the source data file in the SMS data directory.
7bd50861 88 * machine
89 * target_path
de56407f 90 * Location to install the file.
de56407f 91 * RETURN VALUE:
92 * int:
93 * Error code, or zero if no error was detected
94 * in the data supplied to this routine.
95 * SIDE EFFECTS:
96 * May write information to logs.
97 * PROBLEMS:
98 *
99 */
100
101int
7bd50861 102sms_update_server(service, machine, target_path, instructions)
103char *service;
104char *machine;
105char *target_path;
106char *instructions;
de56407f 107{
7bd50861 108#define ASSERT(condition,stat,amsg) \
109 if (!(condition)) { com_err(whoami, stat, amsg); return(stat); }
110#define ASSERT2(condition,stat,amsg,arg1) \
111 if (!(condition)) { com_err(whoami, stat, amsg, arg1); return(stat); }
de56407f 112#define NONNULL(str) \
7bd50861 113 (((str) != (char *)NULL) && (strlen(str) != 0))
de56407f 114
7bd50861 115 char *service_address, *service_updated, *pathname;
f5b9994a 116 int on;
de56407f 117
de56407f 118 /* some sanity checking of arguments while we build data */
7bd50861 119 ASSERT(NONNULL(machine), SMS_INTERNAL, " null host name");
120 ASSERT(NONNULL(service), SMS_INTERNAL, " null service name");
121 ASSERT((strlen(machine) + strlen(service) + 2 < BUFSIZ), SMS_ARG_TOO_LONG,
122 " machine and service names");
123 sprintf(buf, "%s:%s", machine, service);
124 service_updated = strsave(buf);
125 ASSERT(NONNULL(service_updated), SMS_NO_MEM, " for service name");
126 ASSERT((strlen(machine)+strlen(SERVICE_NAME)+2 < BUFSIZ), SMS_ARG_TOO_LONG,
127 " machine and update service name");
128 sprintf(buf, "%s:%s", machine, SERVICE_NAME);
129 service_address = strsave(buf);
130 ASSERT(NONNULL(service_address), SMS_NO_MEM, " for service address");
131 ASSERT(NONNULL(target_path), SMS_INTERNAL, " null target pathname");
132 ASSERT((strlen(target_path) < MAXPATHLEN), SMS_ARG_TOO_LONG,
133 " target pathname");
134 ASSERT2(target_path[0] == '/', SMS_NOT_UNIQUE,
135 " non-absolute pathname supplied \"%s\"", target_path);
136 sprintf(buf, "%s/dcm/%s.out", SMS_DIR, service);
137 pathname = strsave(buf);
138 ASSERT(NONNULL(pathname), SMS_NO_MEM, " for pathname");
139 ASSERT(NONNULL(instructions), SMS_NO_MEM, " for instructions");
140 ASSERT((strlen(instructions) < MAXPATHLEN), SMS_ARG_TOO_LONG,
141 " instruction pathname");
de56407f 142
143 initialize();
7bd50861 144 com_err(whoami, 0, "starting update for %s", service_updated);
de56407f 145
146 /* open connection */
147 conn = start_server_connection(service_address, 0);
7bd50861 148 if (!conn || (connection_status(conn) == CON_STOPPED)) {
149 com_err(whoami, connection_errno(conn),
150 " can't connect to update %s", service_address);
151 return(SMS_CANT_CONNECT);
de56407f 152 }
f5b9994a 153 on = 1;
154 setsockopt(conn->in.fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
de56407f 155
156 /* send authenticators */
7bd50861 157 code = send_auth(machine);
de56407f 158 if (code) {
7bd50861 159 com_err(whoami, code, " authorization attempt to %s failed",
160 service_updated);
de56407f 161 goto update_failed;
162 }
163
7bd50861 164 code = send_file(pathname, target_path);
de56407f 165 if (code)
7bd50861 166 goto update_failed;
167
de56407f 168 /* send instructions for installation */
169 strcpy(buf, "/tmp/sms-update.XXXXXX");
170 mktemp(buf);
7bd50861 171 code = send_file(instructions, buf);
de56407f 172 if (code)
7bd50861 173 goto update_failed;
174
de56407f 175 /* perform installation */
176 code = execute(buf);
177 if (code) {
7bd50861 178 com_err(whoami, code, " installation of %s failed, code = %d",
179 service_updated, code);
180 goto update_failed;
de56407f 181 }
182
de56407f 183 /* finished updates */
7bd50861 184 code = SMS_SUCCESS;
185
186 update_failed:
de56407f 187 send_quit();
de56407f 188 conn = sever_connection(conn);
189 return(code);
7bd50861 190
de56407f 191#undef NONNULL
192#undef ASSERT
193}
194
7bd50861 195
de56407f 196static
7bd50861 197send_auth(host_name)
198char *host_name;
de56407f 199{
200 KTEXT_ST ticket_st;
201 KTEXT ticket = &ticket_st;
202 STRING data;
203 register int code;
204 int response;
205
7bd50861 206 code = get_sms_update_ticket(host_name, ticket);
de56407f 207 if (code) {
208 return(code);
209 }
210 STRING_DATA(data) = "AUTH_001";
211 MAX_STRING_SIZE(data) = 9;
212 code = send_object(conn, (char *)&data, STRING_T);
213 if (code) {
214 return(connection_errno(conn));
215 }
216 code = receive_object(conn, (char *)&response, INTEGER_T);
217 if (code) {
218 return(connection_errno(conn));
219 }
220 if (response) {
221 return(response);
222 }
223 STRING_DATA(data) = (char *)ticket->dat;
224 MAX_STRING_SIZE(data) = ticket->length;
225 code = send_object(conn, (char *)&data, STRING_T);
226 if (code) {
227 return(connection_errno(conn));
228 }
229 code = receive_object(conn, (char *)&response, INTEGER_T);
230 if (code) {
231 return(connection_errno(conn));
232 }
233 if (response) {
234 return(response);
235 }
7bd50861 236 return(SMS_SUCCESS);
de56407f 237}
238
239static
240execute(path)
241 char *path;
242{
1e447eb1 243 int response;
de56407f 244 STRING data;
245 register int code;
246
247 string_alloc(&data, BUFSIZ);
248 sprintf(STRING_DATA(data), "EXEC_002 %s", path);
249 code = send_object(conn, (char *)&data, STRING_T);
250 if (code)
251 return(connection_errno(conn));
252 code = receive_object(conn, (char *)&response, INTEGER_T);
253 if (code)
254 return(connection_errno(conn));
bc6cbc65 255 if (dbg & DBG_TRACE)
1e447eb1 256 com_err(whoami, response, "execute returned %d", response);
257 if (response)
258 return(response);
7bd50861 259 return(SMS_SUCCESS);
de56407f 260}
261
262send_quit()
263{
264 STRING str;
265 if (!conn)
266 return;
267 string_alloc(&str, 5);
268 (void) strcpy(STRING_DATA(str), "quit");
269 (void) send_object(conn, (char *)&str, STRING_T);
270 string_free(&str);
271}
This page took 0.590897 seconds and 5 git commands to generate.