]> andersk Git - moira.git/blob - update/client.c
30aaa1aefb1403b9e3173937d14852544d24a42c
[moira.git] / update / client.c
1 /*
2  *      $Source$
3  *      $Header$
4  */
5
6 #ifndef lint
7 static char *rcsid_client2_c = "$Header$";
8 #endif  lint
9
10 /*
11  * MODULE IDENTIFICATION:
12  *      $Header$
13  *      Copyright 1987, 1988 by the Massachusetts Institute of Technology.
14  *      For copying and distribution information, please see the file
15  *      <mit-copyright.h>.
16  * DESCRIPTION:
17  *      This code handles the actual distribution of data files
18  *      to servers in the MOIRA server-update program.
19  * AUTHOR:
20  *      Ken Raeburn (spook@athena.MIT.EDU),
21  *              MIT Project Athena/MIT Information Systems.
22  * DEFINED VALUES:
23  *      conn
24  *      mr_update_server
25  */
26
27 #include <mit-copyright.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <gdb.h>
32 #include <sys/param.h>
33 #include <sys/wait.h>
34 #include <sys/socket.h>
35 #include <update.h>
36 #include <errno.h>
37 #include <moira.h>
38 #include <moira_site.h>
39 #include <krb.h>
40
41 extern int errno, dbg;
42 extern C_Block session;
43
44 static char buf[BUFSIZ];
45 static int code;
46
47 CONNECTION conn;
48
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:
61  *      Initializes GDB library.
62  * PROBLEMS:
63  *
64  */
65 static void initialize()
66 {
67   static int initialized = 0;
68
69   if (!initialized)
70     {
71       gdb_init();
72       initialized++;
73     }
74 }
75
76 int send_auth(char *host_name)
77 {
78   KTEXT_ST ticket_st;
79   KTEXT ticket = &ticket_st;
80   STRING data;
81   register int code;
82   int response;
83   int auth_version = 2;
84
85   code = get_mr_update_ticket(host_name, ticket);
86   if (code)
87     return code;
88   STRING_DATA(data) = "AUTH_002";
89   MAX_STRING_SIZE(data) = 9;
90   code = send_object(conn, (char *)&data, STRING_T);
91   if (code)
92     return connection_errno(conn);
93   code = receive_object(conn, (char *)&response, INTEGER_T);
94   if (code)
95     return connection_errno(conn);
96   if (response)
97     {
98       STRING_DATA(data) = "AUTH_001";
99       MAX_STRING_SIZE(data) = 9;
100       code = send_object(conn, (char *)&data, STRING_T);
101       if (code)
102         return connection_errno(conn);
103       code = receive_object(conn, (char *)&response, INTEGER_T);
104       if (code)
105         return connection_errno(conn);
106       if (response)
107         return response;
108       auth_version = 1;
109     }
110   STRING_DATA(data) = (char *)ticket->dat;
111   MAX_STRING_SIZE(data) = ticket->length;
112   code = send_object(conn, (char *)&data, STRING_T);
113   if (code)
114     return connection_errno(conn);
115   code = receive_object(conn, (char *)&response, INTEGER_T);
116   if (code)
117     return connection_errno(conn);
118   if (response)
119     return response;
120
121   if (auth_version == 2)
122     {
123       des_key_schedule sched;
124       C_Block enonce;
125
126       code = receive_object(conn, (char *)&data, STRING_T);
127       if (code)
128         return connection_errno(conn);
129       des_key_sched(session, sched);
130       des_ecb_encrypt(STRING_DATA(data), enonce, sched, 1);
131       STRING_DATA(data) = enonce;
132       code = send_object(conn, (char *)&data, STRING_T);
133       if (code)
134         return connection_errno(conn);
135       code = receive_object(conn, (char *)&response, INTEGER_T);
136       if (code)
137         return connection_errno(conn);
138       if (response)
139         return response;
140     }
141
142   return MR_SUCCESS;
143 }
144
145 int execute(char *path)
146 {
147   int response;
148   STRING data;
149   register int code;
150
151   string_alloc(&data, BUFSIZ);
152   sprintf(STRING_DATA(data), "EXEC_002 %s", path);
153   code = send_object(conn, (char *)&data, STRING_T);
154   if (code)
155     return connection_errno(conn);
156   code = receive_object(conn, (char *)&response, INTEGER_T);
157   if (code)
158     return connection_errno(conn);
159   if (response)
160     return response;
161   return MR_SUCCESS;
162 }
163
164 send_quit(void)
165 {
166   STRING str;
167   if (!conn)
168     return;
169   string_alloc(&str, 5);
170   strcpy(STRING_DATA(str), "quit");
171   send_object(conn, (char *)&str, STRING_T);
172   string_free(&str);
173 }
This page took 0.182797 seconds and 3 git commands to generate.