7 static char *rcsid_client2_c = "$Header$";
11 * MODULE IDENTIFICATION:
13 * Copyright 1987, 1988 by the Massachusetts Institute of Technology.
14 * For copying and distribution information, please see the file
17 * This code handles the actual distribution of data files
18 * to servers in the MOIRA server-update program.
20 * Ken Raeburn (spook@athena.MIT.EDU),
21 * MIT Project Athena/MIT Information Systems.
27 #include <mit-copyright.h>
32 #include <sys/param.h>
34 #include <sys/socket.h>
39 #include <moira_site.h>
42 extern int errno, dbg;
43 extern C_Block session;
45 static char buf[BUFSIZ];
55 * Insures that various libraries have a chance to get
62 * Initializes GDB library.
69 static int initialized = 0;
80 * mr_update_server(service, machine, target_path)
82 * Attempts to perform an update to the named machine
83 * of the named service. The file DCM_DIR/service.out
84 * will be sent, then the file SMS_DIR/bin/service.sh,
85 * the the shell script will be executed.
88 * Name of service to be updated; used to find
89 * the source data file in the MR data directory.
92 * Location to install the file.
95 * Error code, or zero if no error was detected
96 * in the data supplied to this routine.
98 * May write information to logs.
104 mr_update_server(service, machine, target_path, instructions)
110 #define ASSERT(condition,stat,amsg) \
111 if (!(condition)) { com_err(whoami, stat, amsg); return(stat); }
112 #define ASSERT2(condition,stat,amsg,arg1) \
113 if (!(condition)) { com_err(whoami, stat, amsg, arg1); return(stat); }
114 #define NONNULL(str) \
115 (((str) != (char *)NULL) && (strlen(str) != 0))
117 char *service_address, *service_updated, *pathname;
120 /* some sanity checking of arguments while we build data */
121 ASSERT(NONNULL(machine), MR_INTERNAL, " null host name");
122 ASSERT(NONNULL(service), MR_INTERNAL, " null service name");
123 ASSERT((strlen(machine) + strlen(service) + 2 < BUFSIZ), MR_ARG_TOO_LONG,
124 " machine and service names");
125 sprintf(buf, "%s:%s", machine, service);
126 service_updated = strsave(buf);
127 ASSERT(NONNULL(service_updated), MR_NO_MEM, " for service name");
128 ASSERT((strlen(machine)+strlen(SERVICE_NAME)+2 < BUFSIZ), MR_ARG_TOO_LONG,
129 " machine and update service name");
130 sprintf(buf, "%s:%s", machine, SERVICE_NAME);
131 service_address = strsave(buf);
132 ASSERT(NONNULL(service_address), MR_NO_MEM, " for service address");
133 ASSERT(NONNULL(target_path), MR_INTERNAL, " null target pathname");
134 ASSERT((strlen(target_path) < MAXPATHLEN), MR_ARG_TOO_LONG,
136 ASSERT2(target_path[0] == '/', MR_NOT_UNIQUE,
137 " non-absolute pathname supplied \"%s\"", target_path);
138 sprintf(buf, "%s/%s.out", DCM_DIR, service);
139 pathname = strsave(buf);
140 ASSERT(NONNULL(pathname), MR_NO_MEM, " for pathname");
141 ASSERT(NONNULL(instructions), MR_NO_MEM, " for instructions");
142 ASSERT((strlen(instructions) < MAXPATHLEN), MR_ARG_TOO_LONG,
143 " instruction pathname");
146 com_err(whoami, 0, "starting update for %s", service_updated);
148 /* open connection */
149 gdb_Options |= GDB_OPT_KEEPALIVE;
150 conn = start_server_connection(service_address, "");
151 if (!conn || (connection_status(conn) == CON_STOPPED)) {
152 com_err(whoami, connection_errno(conn),
153 " can't connect to update %s", service_address);
154 return(MR_CANT_CONNECT);
157 /* send authenticators */
158 code = send_auth(machine);
160 com_err(whoami, code, " authorization attempt to %s failed",
165 code = send_file(pathname, target_path, 1);
169 /* send instructions for installation */
170 strcpy(buf, "/tmp/moira-update.XXXXXX");
172 code = send_file(instructions, buf, 0);
176 /* perform installation */
179 com_err(whoami, code, " installation of %s failed, code = %d",
180 service_updated, code);
184 /* finished updates */
189 conn = sever_connection(conn);
200 KTEXT ticket = &ticket_st;
204 int auth_version = 2;
206 code = get_mr_update_ticket(host_name, ticket);
210 STRING_DATA(data) = "AUTH_002";
211 MAX_STRING_SIZE(data) = 9;
212 code = send_object(conn, (char *)&data, STRING_T);
214 return(connection_errno(conn));
216 code = receive_object(conn, (char *)&response, INTEGER_T);
218 return(connection_errno(conn));
221 STRING_DATA(data) = "AUTH_001";
222 MAX_STRING_SIZE(data) = 9;
223 code = send_object(conn, (char *)&data, STRING_T);
225 return(connection_errno(conn));
227 code = receive_object(conn, (char *)&response, INTEGER_T);
229 return(connection_errno(conn));
236 STRING_DATA(data) = (char *)ticket->dat;
237 MAX_STRING_SIZE(data) = ticket->length;
238 code = send_object(conn, (char *)&data, STRING_T);
240 return(connection_errno(conn));
242 code = receive_object(conn, (char *)&response, INTEGER_T);
244 return(connection_errno(conn));
250 if (auth_version == 2) {
251 des_key_schedule sched;
254 code = receive_object(conn, (char *)&data, STRING_T);
256 return(connection_errno(conn));
258 des_key_sched(&session, &sched);
259 des_ecb_encrypt(STRING_DATA(data), enonce, sched, 1);
260 STRING_DATA(data) = enonce;
261 code = send_object(conn, (char *)&data, STRING_T);
263 return(connection_errno(conn));
265 code = receive_object(conn, (char *)&response, INTEGER_T);
267 return(connection_errno(conn));
284 string_alloc(&data, BUFSIZ);
285 sprintf(STRING_DATA(data), "EXEC_002 %s", path);
286 code = send_object(conn, (char *)&data, STRING_T);
288 return(connection_errno(conn));
289 code = receive_object(conn, (char *)&response, INTEGER_T);
291 return(connection_errno(conn));
302 string_alloc(&str, 5);
303 (void) strcpy(STRING_DATA(str), "quit");
304 (void) send_object(conn, (char *)&str, STRING_T);