7 static char *rcsid_client2_c = "$Header$";
11 * MODULE IDENTIFICATION:
13 * Copyright 1987 MIT Project Athena.
15 * This code handles the actual distribution of data files
16 * to servers in the SMS server-update program.
18 * Ken Raeburn (spook@athena.MIT.EDU),
19 * MIT Project Athena/MIT Information Systems.
28 #include <sys/param.h>
36 extern char *malloc();
39 static char buf[BUFSIZ];
49 * Insures that various libraries have a chance to get
56 * Initializes GDB library and SMSU error table.
63 static int initialized = 0;
75 * sms_update_server(service, machine, target_path)
77 * Attempts to perform an update to the named machine
78 * of the named service. The file SMS_DIR/dcm/service.out
79 * will be sent, then the file SMS_DIR/bin/service.sh,
80 * the the shell script will be executed.
83 * Name of service to be updated; used to find
84 * the source data file in the SMS data directory.
87 * Location to install the file.
90 * Error code, or zero if no error was detected
91 * in the data supplied to this routine.
93 * May write information to logs.
99 sms_update_server(service, machine, target_path, instructions)
105 #define ASSERT(condition,stat,amsg) \
106 if (!(condition)) { com_err(whoami, stat, amsg); return(stat); }
107 #define ASSERT2(condition,stat,amsg,arg1) \
108 if (!(condition)) { com_err(whoami, stat, amsg, arg1); return(stat); }
109 #define NONNULL(str) \
110 (((str) != (char *)NULL) && (strlen(str) != 0))
112 char *service_address, *service_updated, *pathname;
114 /* some sanity checking of arguments while we build data */
115 ASSERT(NONNULL(machine), SMS_INTERNAL, " null host name");
116 ASSERT(NONNULL(service), SMS_INTERNAL, " null service name");
117 ASSERT((strlen(machine) + strlen(service) + 2 < BUFSIZ), SMS_ARG_TOO_LONG,
118 " machine and service names");
119 sprintf(buf, "%s:%s", machine, service);
120 service_updated = strsave(buf);
121 ASSERT(NONNULL(service_updated), SMS_NO_MEM, " for service name");
122 ASSERT((strlen(machine)+strlen(SERVICE_NAME)+2 < BUFSIZ), SMS_ARG_TOO_LONG,
123 " machine and update service name");
124 sprintf(buf, "%s:%s", machine, SERVICE_NAME);
125 service_address = strsave(buf);
126 ASSERT(NONNULL(service_address), SMS_NO_MEM, " for service address");
127 ASSERT(NONNULL(target_path), SMS_INTERNAL, " null target pathname");
128 ASSERT((strlen(target_path) < MAXPATHLEN), SMS_ARG_TOO_LONG,
130 ASSERT2(target_path[0] == '/', SMS_NOT_UNIQUE,
131 " non-absolute pathname supplied \"%s\"", target_path);
132 sprintf(buf, "%s/dcm/%s.out", SMS_DIR, service);
133 pathname = strsave(buf);
134 ASSERT(NONNULL(pathname), SMS_NO_MEM, " for pathname");
135 ASSERT(NONNULL(instructions), SMS_NO_MEM, " for instructions");
136 ASSERT((strlen(instructions) < MAXPATHLEN), SMS_ARG_TOO_LONG,
137 " instruction pathname");
140 com_err(whoami, 0, "starting update for %s", service_updated);
142 /* open connection */
143 conn = start_server_connection(service_address, 0);
144 if (!conn || (connection_status(conn) == CON_STOPPED)) {
145 com_err(whoami, connection_errno(conn),
146 " can't connect to update %s", service_address);
147 return(SMS_CANT_CONNECT);
150 /* send authenticators */
151 code = send_auth(machine);
153 com_err(whoami, code, " authorization attempt to %s failed",
158 code = send_file(pathname, target_path);
162 /* send instructions for installation */
163 strcpy(buf, "/tmp/sms-update.XXXXXX");
165 code = send_file(instructions, buf);
169 /* perform installation */
172 com_err(whoami, code, " installation of %s failed, code = %d",
173 service_updated, code);
177 /* finished updates */
182 conn = sever_connection(conn);
195 KTEXT ticket = &ticket_st;
200 code = get_sms_update_ticket(host_name, ticket);
204 STRING_DATA(data) = "AUTH_001";
205 MAX_STRING_SIZE(data) = 9;
206 code = send_object(conn, (char *)&data, STRING_T);
208 return(connection_errno(conn));
210 code = receive_object(conn, (char *)&response, INTEGER_T);
212 return(connection_errno(conn));
217 STRING_DATA(data) = (char *)ticket->dat;
218 MAX_STRING_SIZE(data) = ticket->length;
219 code = send_object(conn, (char *)&data, STRING_T);
221 return(connection_errno(conn));
223 code = receive_object(conn, (char *)&response, INTEGER_T);
225 return(connection_errno(conn));
241 string_alloc(&data, BUFSIZ);
242 sprintf(STRING_DATA(data), "EXEC_002 %s", path);
243 code = send_object(conn, (char *)&data, STRING_T);
245 return(connection_errno(conn));
246 code = receive_object(conn, (char *)&response, INTEGER_T);
248 return(connection_errno(conn));
249 if (response.w_retcode) {
250 /****************************************************************
251 * The following line is there because the current update servers
252 * don't return the correct error code when an update fails. Remove
253 * this line when they are fixed. -mar 7/26/88
254 ****************************************************************/
255 return(SMS_INTERNAL);
256 return(response.w_retcode);
266 string_alloc(&str, 5);
267 (void) strcpy(STRING_DATA(str), "quit");
268 (void) send_object(conn, (char *)&str, STRING_T);