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 SMS 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>
39 extern char *malloc();
40 extern int errno, dbg;
42 static char buf[BUFSIZ];
52 * Insures that various libraries have a chance to get
59 * Initializes GDB library.
66 static int initialized = 0;
77 * sms_update_server(service, machine, target_path)
79 * Attempts to perform an update to the named machine
80 * of the named service. The file SMS_DIR/dcm/service.out
81 * will be sent, then the file SMS_DIR/bin/service.sh,
82 * the the shell script will be executed.
85 * Name of service to be updated; used to find
86 * the source data file in the SMS data directory.
89 * Location to install the file.
92 * Error code, or zero if no error was detected
93 * in the data supplied to this routine.
95 * May write information to logs.
101 sms_update_server(service, machine, target_path, instructions)
107 #define ASSERT(condition,stat,amsg) \
108 if (!(condition)) { com_err(whoami, stat, amsg); return(stat); }
109 #define ASSERT2(condition,stat,amsg,arg1) \
110 if (!(condition)) { com_err(whoami, stat, amsg, arg1); return(stat); }
111 #define NONNULL(str) \
112 (((str) != (char *)NULL) && (strlen(str) != 0))
114 char *service_address, *service_updated, *pathname;
116 /* some sanity checking of arguments while we build data */
117 ASSERT(NONNULL(machine), SMS_INTERNAL, " null host name");
118 ASSERT(NONNULL(service), SMS_INTERNAL, " null service name");
119 ASSERT((strlen(machine) + strlen(service) + 2 < BUFSIZ), SMS_ARG_TOO_LONG,
120 " machine and service names");
121 sprintf(buf, "%s:%s", machine, service);
122 service_updated = strsave(buf);
123 ASSERT(NONNULL(service_updated), SMS_NO_MEM, " for service name");
124 ASSERT((strlen(machine)+strlen(SERVICE_NAME)+2 < BUFSIZ), SMS_ARG_TOO_LONG,
125 " machine and update service name");
126 sprintf(buf, "%s:%s", machine, SERVICE_NAME);
127 service_address = strsave(buf);
128 ASSERT(NONNULL(service_address), SMS_NO_MEM, " for service address");
129 ASSERT(NONNULL(target_path), SMS_INTERNAL, " null target pathname");
130 ASSERT((strlen(target_path) < MAXPATHLEN), SMS_ARG_TOO_LONG,
132 ASSERT2(target_path[0] == '/', SMS_NOT_UNIQUE,
133 " non-absolute pathname supplied \"%s\"", target_path);
134 sprintf(buf, "%s/dcm/%s.out", SMS_DIR, service);
135 pathname = strsave(buf);
136 ASSERT(NONNULL(pathname), SMS_NO_MEM, " for pathname");
137 ASSERT(NONNULL(instructions), SMS_NO_MEM, " for instructions");
138 ASSERT((strlen(instructions) < MAXPATHLEN), SMS_ARG_TOO_LONG,
139 " instruction pathname");
142 com_err(whoami, 0, "starting update for %s", service_updated);
144 /* open connection */
145 conn = start_server_connection(service_address, 0);
146 if (!conn || (connection_status(conn) == CON_STOPPED)) {
147 com_err(whoami, connection_errno(conn),
148 " can't connect to update %s", service_address);
149 return(SMS_CANT_CONNECT);
152 /* send authenticators */
153 code = send_auth(machine);
155 com_err(whoami, code, " authorization attempt to %s failed",
160 code = send_file(pathname, target_path);
164 /* send instructions for installation */
165 strcpy(buf, "/tmp/sms-update.XXXXXX");
167 code = send_file(instructions, buf);
171 /* perform installation */
174 com_err(whoami, code, " installation of %s failed, code = %d",
175 service_updated, code);
179 /* finished updates */
184 conn = sever_connection(conn);
197 KTEXT ticket = &ticket_st;
202 code = get_sms_update_ticket(host_name, ticket);
206 STRING_DATA(data) = "AUTH_001";
207 MAX_STRING_SIZE(data) = 9;
208 code = send_object(conn, (char *)&data, STRING_T);
210 return(connection_errno(conn));
212 code = receive_object(conn, (char *)&response, INTEGER_T);
214 return(connection_errno(conn));
219 STRING_DATA(data) = (char *)ticket->dat;
220 MAX_STRING_SIZE(data) = ticket->length;
221 code = send_object(conn, (char *)&data, STRING_T);
223 return(connection_errno(conn));
225 code = receive_object(conn, (char *)&response, INTEGER_T);
227 return(connection_errno(conn));
243 string_alloc(&data, BUFSIZ);
244 sprintf(STRING_DATA(data), "EXEC_002 %s", path);
245 code = send_object(conn, (char *)&data, STRING_T);
247 return(connection_errno(conn));
248 code = receive_object(conn, (char *)&response, INTEGER_T);
250 return(connection_errno(conn));
252 com_err(whoami, response, "execute returned %d", response);
263 string_alloc(&str, 5);
264 (void) strcpy(STRING_DATA(str), "quit");
265 (void) send_object(conn, (char *)&str, STRING_T);