]> andersk Git - moira.git/blame - update/client.c
re-write to use krb_get_phost instead of local routine;
[moira.git] / update / client.c
CommitLineData
de56407f 1/*
2 * $Source$
3 * $Header$
4 */
5
6#ifndef lint
7static char *rcsid_client2_c = "$Header$";
8#endif lint
9
10/*
11 * MODULE IDENTIFICATION:
12 * $Header$
546bc43b 13 * Copyright 1987, 1988 by the Massachusetts Institute of Technology.
14 * For copying and distribution information, please see the file
15 * <mit-copyright.h>.
de56407f 16 * DESCRIPTION:
17 * This code handles the actual distribution of data files
2ad0a777 18 * to servers in the MOIRA server-update program.
de56407f 19 * AUTHOR:
20 * Ken Raeburn (spook@athena.MIT.EDU),
21 * MIT Project Athena/MIT Information Systems.
22 * DEFINED VALUES:
23 * conn
2ad0a777 24 * mr_update_server
de56407f 25 */
26
546bc43b 27#include <mit-copyright.h>
de56407f 28#include <stdio.h>
29#include <strings.h>
7bd50861 30#include <gdb.h>
de56407f 31#include <sys/param.h>
7bd50861 32#include <sys/wait.h>
f5b9994a 33#include <sys/socket.h>
7bd50861 34#include <update.h>
de56407f 35#include <errno.h>
7bd50861 36#include <dcm.h>
2ad0a777 37#include <moira.h>
38#include <moira_site.h>
de56407f 39#include <krb.h>
40
7bd50861 41extern char *malloc();
bc6cbc65 42extern int errno, dbg;
de56407f 43
de56407f 44static char buf[BUFSIZ];
7bd50861 45static int code;
de56407f 46
47CONNECTION conn;
de56407f 48
de56407f 49
50/*
51 * FUNCTION:
52 * initialize()
53 * DESCRIPTION:
54 * Insures that various libraries have a chance to get
55 * initialized.
56 * INPUT:
57 * OUTPUT:
58 * RETURN VALUE:
59 * void
60 * SIDE EFFECTS:
756e2c48 61 * Initializes GDB library.
de56407f 62 * PROBLEMS:
63 *
64 */
7bd50861 65static void
de56407f 66initialize()
67{
68 static int initialized = 0;
7bd50861 69
de56407f 70 if (!initialized) {
71 gdb_init();
de56407f 72 initialized++;
73 }
74}
75
7bd50861 76
de56407f 77/*
78 * FUNCTION:
2ad0a777 79 * mr_update_server(service, machine, target_path)
de56407f 80 * DESCRIPTION:
7bd50861 81 * Attempts to perform an update to the named machine
a6be2cf4 82 * of the named service. The file DCM_DIR/service.out
7bd50861 83 * will be sent, then the file SMS_DIR/bin/service.sh,
84 * the the shell script will be executed.
de56407f 85 * INPUT:
7bd50861 86 * service
de56407f 87 * Name of service to be updated; used to find
2ad0a777 88 * the source data file in the MR data directory.
7bd50861 89 * machine
90 * target_path
de56407f 91 * Location to install the file.
de56407f 92 * RETURN VALUE:
93 * int:
94 * Error code, or zero if no error was detected
95 * in the data supplied to this routine.
96 * SIDE EFFECTS:
97 * May write information to logs.
98 * PROBLEMS:
99 *
100 */
101
102int
2ad0a777 103mr_update_server(service, machine, target_path, instructions)
7bd50861 104char *service;
105char *machine;
106char *target_path;
107char *instructions;
de56407f 108{
7bd50861 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); }
de56407f 113#define NONNULL(str) \
7bd50861 114 (((str) != (char *)NULL) && (strlen(str) != 0))
de56407f 115
7bd50861 116 char *service_address, *service_updated, *pathname;
f5b9994a 117 int on;
de56407f 118
de56407f 119 /* some sanity checking of arguments while we build data */
2ad0a777 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,
7bd50861 123 " machine and service names");
124 sprintf(buf, "%s:%s", machine, service);
125 service_updated = strsave(buf);
2ad0a777 126 ASSERT(NONNULL(service_updated), MR_NO_MEM, " for service name");
127 ASSERT((strlen(machine)+strlen(SERVICE_NAME)+2 < BUFSIZ), MR_ARG_TOO_LONG,
7bd50861 128 " machine and update service name");
129 sprintf(buf, "%s:%s", machine, SERVICE_NAME);
130 service_address = strsave(buf);
2ad0a777 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,
7bd50861 134 " target pathname");
2ad0a777 135 ASSERT2(target_path[0] == '/', MR_NOT_UNIQUE,
7bd50861 136 " non-absolute pathname supplied \"%s\"", target_path);
a6be2cf4 137 sprintf(buf, "%s/%s.out", DCM_DIR, service);
7bd50861 138 pathname = strsave(buf);
2ad0a777 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,
7bd50861 142 " instruction pathname");
de56407f 143
144 initialize();
7bd50861 145 com_err(whoami, 0, "starting update for %s", service_updated);
de56407f 146
147 /* open connection */
5dabdff4 148 conn = start_server_connection(service_address, "");
7bd50861 149 if (!conn || (connection_status(conn) == CON_STOPPED)) {
150 com_err(whoami, connection_errno(conn),
151 " can't connect to update %s", service_address);
2ad0a777 152 return(MR_CANT_CONNECT);
de56407f 153 }
f5b9994a 154 on = 1;
155 setsockopt(conn->in.fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
de56407f 156
157 /* send authenticators */
7bd50861 158 code = send_auth(machine);
de56407f 159 if (code) {
7bd50861 160 com_err(whoami, code, " authorization attempt to %s failed",
161 service_updated);
de56407f 162 goto update_failed;
163 }
164
7bd50861 165 code = send_file(pathname, target_path);
de56407f 166 if (code)
7bd50861 167 goto update_failed;
168
de56407f 169 /* send instructions for installation */
2ad0a777 170 strcpy(buf, "/tmp/moira-update.XXXXXX");
de56407f 171 mktemp(buf);
7bd50861 172 code = send_file(instructions, buf);
de56407f 173 if (code)
7bd50861 174 goto update_failed;
175
de56407f 176 /* perform installation */
177 code = execute(buf);
178 if (code) {
7bd50861 179 com_err(whoami, code, " installation of %s failed, code = %d",
180 service_updated, code);
181 goto update_failed;
de56407f 182 }
183
de56407f 184 /* finished updates */
2ad0a777 185 code = MR_SUCCESS;
7bd50861 186
187 update_failed:
de56407f 188 send_quit();
de56407f 189 conn = sever_connection(conn);
190 return(code);
7bd50861 191
de56407f 192#undef NONNULL
193#undef ASSERT
194}
195
7bd50861 196
de56407f 197static
7bd50861 198send_auth(host_name)
199char *host_name;
de56407f 200{
201 KTEXT_ST ticket_st;
202 KTEXT ticket = &ticket_st;
203 STRING data;
204 register int code;
205 int response;
206
2ad0a777 207 code = get_mr_update_ticket(host_name, ticket);
de56407f 208 if (code) {
209 return(code);
210 }
211 STRING_DATA(data) = "AUTH_001";
212 MAX_STRING_SIZE(data) = 9;
213 code = send_object(conn, (char *)&data, STRING_T);
214 if (code) {
215 return(connection_errno(conn));
216 }
217 code = receive_object(conn, (char *)&response, INTEGER_T);
218 if (code) {
219 return(connection_errno(conn));
220 }
221 if (response) {
222 return(response);
223 }
224 STRING_DATA(data) = (char *)ticket->dat;
225 MAX_STRING_SIZE(data) = ticket->length;
226 code = send_object(conn, (char *)&data, STRING_T);
227 if (code) {
228 return(connection_errno(conn));
229 }
230 code = receive_object(conn, (char *)&response, INTEGER_T);
231 if (code) {
232 return(connection_errno(conn));
233 }
234 if (response) {
235 return(response);
236 }
2ad0a777 237 return(MR_SUCCESS);
de56407f 238}
239
240static
241execute(path)
242 char *path;
243{
1e447eb1 244 int response;
de56407f 245 STRING data;
246 register int code;
247
248 string_alloc(&data, BUFSIZ);
249 sprintf(STRING_DATA(data), "EXEC_002 %s", path);
250 code = send_object(conn, (char *)&data, STRING_T);
251 if (code)
252 return(connection_errno(conn));
253 code = receive_object(conn, (char *)&response, INTEGER_T);
254 if (code)
255 return(connection_errno(conn));
bc6cbc65 256 if (dbg & DBG_TRACE)
1e447eb1 257 com_err(whoami, response, "execute returned %d", response);
258 if (response)
259 return(response);
2ad0a777 260 return(MR_SUCCESS);
de56407f 261}
262
263send_quit()
264{
265 STRING str;
266 if (!conn)
267 return;
268 string_alloc(&str, 5);
269 (void) strcpy(STRING_DATA(str), "quit");
270 (void) send_object(conn, (char *)&str, STRING_T);
271 string_free(&str);
272}
This page took 0.353794 seconds and 5 git commands to generate.