]> andersk Git - moira.git/blob - update/client.c
add missing #include <string.h> (for strlen)
[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
23 RCSID("$Header$");
24
25 extern des_cblock session;
26
27 int send_auth(int conn, char *host_name)
28 {
29   KTEXT_ST ticket_st;
30   int code, auth_version = 2;
31   long response;
32
33   code = get_mr_update_ticket(host_name, &ticket_st);
34   if (code)
35     return code;
36   code = send_string(conn, "AUTH_002", 9);
37   if (code)
38     return code;
39   code = recv_int(conn, &response);
40   if (code)
41     return code;
42   if (response)
43     {
44       code = send_string(conn, "AUTH_001", 9);
45       if (code)
46         return code;
47       code = recv_int(conn, &response);
48       if (code)
49         return code;
50       if (response)
51         return response;
52       auth_version = 1;
53     }
54   code = send_string(conn, (char *)ticket_st.dat, ticket_st.length);
55   if (code)
56     return code;
57   code = recv_int(conn, &response);
58   if (code)
59     return code;
60   if (response)
61     return response;
62
63   if (auth_version == 2)
64     {
65       des_key_schedule sched;
66       C_Block enonce;
67       char *data;
68       size_t size;
69
70       code = recv_string(conn, &data, &size);
71       if (code)
72         return code;
73       des_key_sched(session, sched);
74       des_ecb_encrypt(data, enonce, sched, 1);
75       free(data);
76       code = send_string(conn, (char *)enonce, sizeof(enonce));
77       if (code)
78         return code;
79       code = recv_int(conn, &response);
80       if (code)
81         return code;
82       if (response)
83         return response;
84     }
85
86   return MR_SUCCESS;
87 }
88
89 int execute(int conn, char *path)
90 {
91   long response;
92   char *data;
93   int code;
94
95   data = malloc(10 + strlen(path));
96   if (!data)
97     return ENOMEM;
98   sprintf(data, "EXEC_002 %s", path);
99   code = send_string(conn, data, strlen(data) + 1);
100   free(data);
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   return MR_SUCCESS;
110 }
111
112 void send_quit(int conn)
113 {
114   send_string(conn, "quit", 5);
115 }
116
117 void fail(int conn, int err, char *msg)
118 {
119   return;
120 }
This page took 0.059996 seconds and 5 git commands to generate.