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