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>
31 #include <sys/param.h>
33 #include <sys/socket.h>
38 #include <moira_site.h>
41 extern char *malloc();
42 extern int errno, dbg;
44 static char buf[BUFSIZ];
54 * Insures that various libraries have a chance to get
61 * Initializes GDB library.
68 static int initialized = 0;
79 * mr_update_server(service, machine, target_path)
81 * Attempts to perform an update to the named machine
82 * of the named service. The file DCM_DIR/service.out
83 * will be sent, then the file SMS_DIR/bin/service.sh,
84 * the the shell script will be executed.
87 * Name of service to be updated; used to find
88 * the source data file in the MR data directory.
91 * Location to install the file.
94 * Error code, or zero if no error was detected
95 * in the data supplied to this routine.
97 * May write information to logs.
103 mr_update_server(service, machine, target_path, instructions)
109 #define ASSERT(condition,stat,amsg) \
110 if (!(condition)) { com_err(whoami, stat, amsg); return(stat); }
111 #define ASSERT2(condition,stat,amsg,arg1) \
112 if (!(condition)) { com_err(whoami, stat, amsg, arg1); return(stat); }
113 #define NONNULL(str) \
114 (((str) != (char *)NULL) && (strlen(str) != 0))
116 char *service_address, *service_updated, *pathname;
119 /* some sanity checking of arguments while we build data */
120 ASSERT(NONNULL(machine), MR_INTERNAL, " null host name");
121 ASSERT(NONNULL(service), MR_INTERNAL, " null service name");
122 ASSERT((strlen(machine) + strlen(service) + 2 < BUFSIZ), MR_ARG_TOO_LONG,
123 " machine and service names");
124 sprintf(buf, "%s:%s", machine, service);
125 service_updated = strsave(buf);
126 ASSERT(NONNULL(service_updated), MR_NO_MEM, " for service name");
127 ASSERT((strlen(machine)+strlen(SERVICE_NAME)+2 < BUFSIZ), MR_ARG_TOO_LONG,
128 " machine and update service name");
129 sprintf(buf, "%s:%s", machine, SERVICE_NAME);
130 service_address = strsave(buf);
131 ASSERT(NONNULL(service_address), MR_NO_MEM, " for service address");
132 ASSERT(NONNULL(target_path), MR_INTERNAL, " null target pathname");
133 ASSERT((strlen(target_path) < MAXPATHLEN), MR_ARG_TOO_LONG,
135 ASSERT2(target_path[0] == '/', MR_NOT_UNIQUE,
136 " non-absolute pathname supplied \"%s\"", target_path);
137 sprintf(buf, "%s/%s.out", DCM_DIR, service);
138 pathname = strsave(buf);
139 ASSERT(NONNULL(pathname), MR_NO_MEM, " for pathname");
140 ASSERT(NONNULL(instructions), MR_NO_MEM, " for instructions");
141 ASSERT((strlen(instructions) < MAXPATHLEN), MR_ARG_TOO_LONG,
142 " instruction pathname");
145 com_err(whoami, 0, "starting update for %s", service_updated);
147 /* open connection */
148 conn = start_server_connection(service_address, 0);
149 if (!conn || (connection_status(conn) == CON_STOPPED)) {
150 com_err(whoami, connection_errno(conn),
151 " can't connect to update %s", service_address);
152 return(MR_CANT_CONNECT);
155 setsockopt(conn->in.fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
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);
169 /* send instructions for installation */
170 strcpy(buf, "/tmp/moira-update.XXXXXX");
172 code = send_file(instructions, buf);
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);
202 KTEXT ticket = &ticket_st;
207 code = get_mr_update_ticket(host_name, ticket);
211 STRING_DATA(data) = "AUTH_001";
212 MAX_STRING_SIZE(data) = 9;
213 code = send_object(conn, (char *)&data, STRING_T);
215 return(connection_errno(conn));
217 code = receive_object(conn, (char *)&response, INTEGER_T);
219 return(connection_errno(conn));
224 STRING_DATA(data) = (char *)ticket->dat;
225 MAX_STRING_SIZE(data) = ticket->length;
226 code = send_object(conn, (char *)&data, STRING_T);
228 return(connection_errno(conn));
230 code = receive_object(conn, (char *)&response, INTEGER_T);
232 return(connection_errno(conn));
248 string_alloc(&data, BUFSIZ);
249 sprintf(STRING_DATA(data), "EXEC_002 %s", path);
250 code = send_object(conn, (char *)&data, STRING_T);
252 return(connection_errno(conn));
253 code = receive_object(conn, (char *)&response, INTEGER_T);
255 return(connection_errno(conn));
257 com_err(whoami, response, "execute returned %d", response);
268 string_alloc(&str, 5);
269 (void) strcpy(STRING_DATA(str), "quit");
270 (void) send_object(conn, (char *)&str, STRING_T);