]> andersk Git - moira.git/blob - update/client.c
Initial cut of krb5 support.
[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   code = get_mr_krb5_update_ticket(host_name, &auth);
37   if (code)
38     goto out;
39   code = send_string(conn, "AUTH_003", 9);
40   if (code)
41     goto out;
42   code = recv_int(conn, &response);
43   if (code)
44     goto out;
45   if (response)
46     {
47       /* Talking to a server that doesn't do AUTH_003 */
48       if (auth.data)
49         krb5_free_data_contents(context, &auth);
50       return response;
51     }
52   code = send_string(conn, (char *)auth.data, auth.length);
53   if (code)
54     goto out;
55   code = recv_int(conn, &response);
56   if (code)
57     goto out;
58   if (response)
59     {
60       if (auth.data)
61         krb5_free_data_contents(context, &auth);
62       return response;
63     }
64
65   return MR_SUCCESS;
66
67  out:
68   if (auth.data)
69     krb5_free_data_contents(context, &auth);
70   return code;
71 }
72
73 int mr_send_auth(int conn, char *host_name)
74 {
75   KTEXT_ST ticket_st;
76   int code, auth_version = 2;
77   long response;
78
79   code = get_mr_update_ticket(host_name, &ticket_st);
80   if (code)
81     return code;
82   code = send_string(conn, "AUTH_002", 9);
83   if (code)
84     return code;
85   code = recv_int(conn, &response);
86   if (code)
87     return code;
88   if (response)
89     {
90       code = send_string(conn, "AUTH_001", 9);
91       if (code)
92         return code;
93       code = recv_int(conn, &response);
94       if (code)
95         return code;
96       if (response)
97         return response;
98       auth_version = 1;
99     }
100   code = send_string(conn, (char *)ticket_st.dat, ticket_st.length);
101   if (code)
102     return code;
103   code = recv_int(conn, &response);
104   if (code)
105     return code;
106   if (response)
107     return response;
108
109   if (auth_version == 2)
110     {
111       des_key_schedule sched;
112       C_Block enonce;
113       char *data;
114       size_t size;
115
116       code = recv_string(conn, &data, &size);
117       if (code)
118         return code;
119       des_key_sched(session, sched);
120       des_ecb_encrypt(data, enonce, sched, 1);
121       free(data);
122       code = send_string(conn, (char *)enonce, sizeof(enonce));
123       if (code)
124         return code;
125       code = recv_int(conn, &response);
126       if (code)
127         return code;
128       if (response)
129         return response;
130     }
131
132   return MR_SUCCESS;
133 }
134
135 int mr_execute(int conn, char *path)
136 {
137   long response;
138   char *data;
139   int code;
140
141   data = malloc(10 + strlen(path));
142   if (!data)
143     return ENOMEM;
144   sprintf(data, "EXEC_002 %s", path);
145   code = send_string(conn, data, strlen(data) + 1);
146   free(data);
147   if (code)
148     return code;
149   code = recv_int(conn, &response);
150   if (code)
151     return code;
152   if (response)
153     return response;
154
155   return MR_SUCCESS;
156 }
157
158 void mr_send_quit(int conn)
159 {
160   send_string(conn, "quit", 5);
161 }
162
163 void fail(int conn, int err, char *msg)
164 {
165   com_err(whoami, err, msg);
166   return;
167 }
This page took 0.047136 seconds and 5 git commands to generate.