]> andersk Git - moira.git/blob - update/client.c
second code style cleanup: void/void * usage, proper #includes. try to
[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 <stdio.h>
16
17 #include <des.h>
18 #include <gdb.h>
19 #include <krb.h>
20
21 RCSID("$Header$");
22
23 extern int dbg;
24 extern C_Block session;
25
26 CONNECTION conn;
27
28 int send_auth(char *host_name)
29 {
30   KTEXT_ST ticket_st;
31   KTEXT ticket = &ticket_st;
32   STRING data;
33   int code;
34   int response;
35   int auth_version = 2;
36
37   code = get_mr_update_ticket(host_name, ticket);
38   if (code)
39     return code;
40   STRING_DATA(data) = "AUTH_002";
41   MAX_STRING_SIZE(data) = 9;
42   code = send_object(conn, (char *)&data, STRING_T);
43   if (code)
44     return connection_errno(conn);
45   code = receive_object(conn, (char *)&response, INTEGER_T);
46   if (code)
47     return connection_errno(conn);
48   if (response)
49     {
50       STRING_DATA(data) = "AUTH_001";
51       MAX_STRING_SIZE(data) = 9;
52       code = send_object(conn, (char *)&data, STRING_T);
53       if (code)
54         return connection_errno(conn);
55       code = receive_object(conn, (char *)&response, INTEGER_T);
56       if (code)
57         return connection_errno(conn);
58       if (response)
59         return response;
60       auth_version = 1;
61     }
62   STRING_DATA(data) = (char *)ticket->dat;
63   MAX_STRING_SIZE(data) = ticket->length;
64   code = send_object(conn, (char *)&data, STRING_T);
65   if (code)
66     return connection_errno(conn);
67   code = receive_object(conn, (char *)&response, INTEGER_T);
68   if (code)
69     return connection_errno(conn);
70   if (response)
71     return response;
72
73   if (auth_version == 2)
74     {
75       des_key_schedule sched;
76       C_Block enonce;
77
78       code = receive_object(conn, (char *)&data, STRING_T);
79       if (code)
80         return connection_errno(conn);
81       des_key_sched(session, sched);
82       des_ecb_encrypt(STRING_DATA(data), enonce, sched, 1);
83       STRING_DATA(data) = enonce;
84       code = send_object(conn, (char *)&data, STRING_T);
85       if (code)
86         return connection_errno(conn);
87       code = receive_object(conn, (char *)&response, INTEGER_T);
88       if (code)
89         return connection_errno(conn);
90       if (response)
91         return response;
92     }
93
94   return MR_SUCCESS;
95 }
96
97 int execute(char *path)
98 {
99   int response;
100   STRING data;
101   int code;
102
103   string_alloc(&data, BUFSIZ);
104   sprintf(STRING_DATA(data), "EXEC_002 %s", path);
105   code = send_object(conn, (char *)&data, STRING_T);
106   if (code)
107     return connection_errno(conn);
108   code = receive_object(conn, (char *)&response, INTEGER_T);
109   if (code)
110     return connection_errno(conn);
111   if (response)
112     return response;
113   return MR_SUCCESS;
114 }
115
116 void send_quit(void)
117 {
118   STRING str;
119   if (!conn)
120     return;
121   string_alloc(&str, 5);
122   strcpy(STRING_DATA(str), "quit");
123   send_object(conn, (char *)&str, STRING_T);
124   string_free(&str);
125 }
This page took 0.04795 seconds and 5 git commands to generate.