]> andersk Git - moira.git/blob - update/client.c
1f6bbdb0ddd3d6475d677f501a0ed89cf7d52f64
[moira.git] / update / client.c
1 /* $Id$
2  *
3  * This code handles the actual distribution of data files
4  * to servers in the Moira server-update program.
5  *
6  * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology.
7  * For copying and distribution information, please see the file
8  * <mit-copyright.h>.
9  */
10
11 #include <mit-copyright.h>
12 #include <moira.h>
13 #include "update.h"
14
15 #include <errno.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include <des.h>
21 #include <krb.h>
22 #include <krb5.h>
23
24 RCSID("$Header$");
25
26 extern des_cblock session;
27 extern char *whoami;
28 extern krb5_context context;
29
30 int mr_send_krb5_auth(int conn, char *host_name)
31 {
32   krb5_data auth;
33   int code;
34   long response;
35
36   memset(&auth, 0, sizeof(auth));
37
38   code = get_mr_krb5_update_ticket(host_name, &auth);
39   if (code)
40     goto out;
41   code = send_string(conn, "AUTH_003", 9);
42   if (code)
43     goto out;
44   code = recv_int(conn, &response);
45   if (code)
46     goto out;
47   if (response)
48     {
49       /* Talking to a server that doesn't do AUTH_003 */
50       krb5_free_data_contents(context, &auth);
51       return response;
52     }
53   code = send_string(conn, (char *)auth.data, auth.length);
54   if (code)
55     goto out;
56   code = recv_int(conn, &response);
57   if (code)
58     goto out;
59   if (response)
60     {
61       krb5_free_data_contents(context, &auth);
62       return response;
63     }
64
65   return MR_SUCCESS;
66
67  out:
68   krb5_free_data_contents(context, &auth);
69   return code;
70 }
71
72 int mr_send_auth(int conn, char *host_name)
73 {
74   KTEXT_ST ticket_st;
75   int code, auth_version = 2;
76   long response;
77
78   code = get_mr_update_ticket(host_name, &ticket_st);
79   if (code)
80     return code;
81   code = send_string(conn, "AUTH_002", 9);
82   if (code)
83     return code;
84   code = recv_int(conn, &response);
85   if (code)
86     return code;
87   if (response)
88     {
89       code = send_string(conn, "AUTH_001", 9);
90       if (code)
91         return code;
92       code = recv_int(conn, &response);
93       if (code)
94         return code;
95       if (response)
96         return response;
97       auth_version = 1;
98     }
99   code = send_string(conn, (char *)ticket_st.dat, ticket_st.length);
100   if (code)
101     return code;
102   code = recv_int(conn, &response);
103   if (code)
104     return code;
105   if (response)
106     return response;
107
108   if (auth_version == 2)
109     {
110       des_key_schedule sched;
111       C_Block enonce;
112       char *data;
113       size_t size;
114
115       code = recv_string(conn, &data, &size);
116       if (code)
117         return code;
118       des_key_sched(session, sched);
119       des_ecb_encrypt(data, enonce, sched, 1);
120       free(data);
121       code = send_string(conn, (char *)enonce, sizeof(enonce));
122       if (code)
123         return code;
124       code = recv_int(conn, &response);
125       if (code)
126         return code;
127       if (response)
128         return response;
129     }
130
131   return MR_SUCCESS;
132 }
133
134 int mr_execute(int conn, char *path)
135 {
136   long response;
137   char *data;
138   int code;
139
140   data = malloc(10 + strlen(path));
141   if (!data)
142     return ENOMEM;
143   sprintf(data, "EXEC_002 %s", path);
144   code = send_string(conn, data, strlen(data) + 1);
145   free(data);
146   if (code)
147     return code;
148   code = recv_int(conn, &response);
149   if (code)
150     return code;
151   if (response)
152     return response;
153
154   return MR_SUCCESS;
155 }
156
157 void mr_send_quit(int conn)
158 {
159   send_string(conn, "quit", 5);
160 }
161
162 void fail(int conn, int err, char *msg)
163 {
164   com_err(whoami, err, msg);
165   return;
166 }
This page took 0.034181 seconds and 3 git commands to generate.