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