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();
37 extern int errno, dbg;
39 static char buf[BUFSIZ];
49 * Insures that various libraries have a chance to get
56 * Initializes GDB library.
63 static int initialized = 0;
74 * sms_update_server(service, machine, target_path)
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.
82 * Name of service to be updated; used to find
83 * the source data file in the SMS data directory.
86 * Location to install the file.
89 * Error code, or zero if no error was detected
90 * in the data supplied to this routine.
92 * May write information to logs.
98 sms_update_server(service, machine, target_path, instructions)
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); }
108 #define NONNULL(str) \
109 (((str) != (char *)NULL) && (strlen(str) != 0))
111 char *service_address, *service_updated, *pathname;
113 /* some sanity checking of arguments while we build data */
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,
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");
139 com_err(whoami, 0, "starting update for %s", service_updated);
141 /* open connection */
142 conn = start_server_connection(service_address, 0);
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);
149 /* send authenticators */
150 code = send_auth(machine);
152 com_err(whoami, code, " authorization attempt to %s failed",
157 code = send_file(pathname, target_path);
161 /* send instructions for installation */
162 strcpy(buf, "/tmp/sms-update.XXXXXX");
164 code = send_file(instructions, buf);
168 /* perform installation */
171 com_err(whoami, code, " installation of %s failed, code = %d",
172 service_updated, code);
176 /* finished updates */
181 conn = sever_connection(conn);
194 KTEXT ticket = &ticket_st;
199 code = get_sms_update_ticket(host_name, ticket);
203 STRING_DATA(data) = "AUTH_001";
204 MAX_STRING_SIZE(data) = 9;
205 code = send_object(conn, (char *)&data, STRING_T);
207 return(connection_errno(conn));
209 code = receive_object(conn, (char *)&response, INTEGER_T);
211 return(connection_errno(conn));
216 STRING_DATA(data) = (char *)ticket->dat;
217 MAX_STRING_SIZE(data) = ticket->length;
218 code = send_object(conn, (char *)&data, STRING_T);
220 return(connection_errno(conn));
222 code = receive_object(conn, (char *)&response, INTEGER_T);
224 return(connection_errno(conn));
240 string_alloc(&data, BUFSIZ);
241 sprintf(STRING_DATA(data), "EXEC_002 %s", path);
242 code = send_object(conn, (char *)&data, STRING_T);
244 return(connection_errno(conn));
245 code = receive_object(conn, (char *)&response, INTEGER_T);
247 return(connection_errno(conn));
249 com_err(whoami, response, "execute returned %d", response);
260 string_alloc(&str, 5);
261 (void) strcpy(STRING_DATA(str), "quit");
262 (void) send_object(conn, (char *)&str, STRING_T);