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