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>
33 #include <sys/socket.h>
40 extern char *malloc();
41 extern int errno, dbg;
43 static char buf[BUFSIZ];
53 * Insures that various libraries have a chance to get
60 * Initializes GDB library.
67 static int initialized = 0;
78 * sms_update_server(service, machine, target_path)
80 * Attempts to perform an update to the named machine
81 * of the named service. The file SMS_DIR/dcm/service.out
82 * will be sent, then the file SMS_DIR/bin/service.sh,
83 * the the shell script will be executed.
86 * Name of service to be updated; used to find
87 * the source data file in the SMS data directory.
90 * Location to install the file.
93 * Error code, or zero if no error was detected
94 * in the data supplied to this routine.
96 * May write information to logs.
102 sms_update_server(service, machine, target_path, instructions)
108 #define ASSERT(condition,stat,amsg) \
109 if (!(condition)) { com_err(whoami, stat, amsg); return(stat); }
110 #define ASSERT2(condition,stat,amsg,arg1) \
111 if (!(condition)) { com_err(whoami, stat, amsg, arg1); return(stat); }
112 #define NONNULL(str) \
113 (((str) != (char *)NULL) && (strlen(str) != 0))
115 char *service_address, *service_updated, *pathname;
118 /* some sanity checking of arguments while we build data */
119 ASSERT(NONNULL(machine), SMS_INTERNAL, " null host name");
120 ASSERT(NONNULL(service), SMS_INTERNAL, " null service name");
121 ASSERT((strlen(machine) + strlen(service) + 2 < BUFSIZ), SMS_ARG_TOO_LONG,
122 " machine and service names");
123 sprintf(buf, "%s:%s", machine, service);
124 service_updated = strsave(buf);
125 ASSERT(NONNULL(service_updated), SMS_NO_MEM, " for service name");
126 ASSERT((strlen(machine)+strlen(SERVICE_NAME)+2 < BUFSIZ), SMS_ARG_TOO_LONG,
127 " machine and update service name");
128 sprintf(buf, "%s:%s", machine, SERVICE_NAME);
129 service_address = strsave(buf);
130 ASSERT(NONNULL(service_address), SMS_NO_MEM, " for service address");
131 ASSERT(NONNULL(target_path), SMS_INTERNAL, " null target pathname");
132 ASSERT((strlen(target_path) < MAXPATHLEN), SMS_ARG_TOO_LONG,
134 ASSERT2(target_path[0] == '/', SMS_NOT_UNIQUE,
135 " non-absolute pathname supplied \"%s\"", target_path);
136 sprintf(buf, "%s/dcm/%s.out", SMS_DIR, service);
137 pathname = strsave(buf);
138 ASSERT(NONNULL(pathname), SMS_NO_MEM, " for pathname");
139 ASSERT(NONNULL(instructions), SMS_NO_MEM, " for instructions");
140 ASSERT((strlen(instructions) < MAXPATHLEN), SMS_ARG_TOO_LONG,
141 " instruction pathname");
144 com_err(whoami, 0, "starting update for %s", service_updated);
146 /* open connection */
147 conn = start_server_connection(service_address, 0);
148 if (!conn || (connection_status(conn) == CON_STOPPED)) {
149 com_err(whoami, connection_errno(conn),
150 " can't connect to update %s", service_address);
151 return(SMS_CANT_CONNECT);
154 setsockopt(conn->in.fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
156 /* send authenticators */
157 code = send_auth(machine);
159 com_err(whoami, code, " authorization attempt to %s failed",
164 code = send_file(pathname, target_path);
168 /* send instructions for installation */
169 strcpy(buf, "/tmp/sms-update.XXXXXX");
171 code = send_file(instructions, buf);
175 /* perform installation */
178 com_err(whoami, code, " installation of %s failed, code = %d",
179 service_updated, code);
183 /* finished updates */
188 conn = sever_connection(conn);
201 KTEXT ticket = &ticket_st;
206 code = get_sms_update_ticket(host_name, ticket);
210 STRING_DATA(data) = "AUTH_001";
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));
223 STRING_DATA(data) = (char *)ticket->dat;
224 MAX_STRING_SIZE(data) = ticket->length;
225 code = send_object(conn, (char *)&data, STRING_T);
227 return(connection_errno(conn));
229 code = receive_object(conn, (char *)&response, INTEGER_T);
231 return(connection_errno(conn));
247 string_alloc(&data, BUFSIZ);
248 sprintf(STRING_DATA(data), "EXEC_002 %s", path);
249 code = send_object(conn, (char *)&data, STRING_T);
251 return(connection_errno(conn));
252 code = receive_object(conn, (char *)&response, INTEGER_T);
254 return(connection_errno(conn));
256 com_err(whoami, response, "execute returned %d", response);
267 string_alloc(&str, 5);
268 (void) strcpy(STRING_DATA(str), "quit");
269 (void) send_object(conn, (char *)&str, STRING_T);