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