]>
Commit | Line | Data |
---|---|---|
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> |
0bb1ca53 | 22 | #include <krb5.h> |
de56407f | 23 | |
7ac48069 | 24 | RCSID("$Header$"); |
de56407f | 25 | |
85330553 | 26 | extern des_cblock session; |
8ae70e8f | 27 | extern char *whoami; |
0bb1ca53 | 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 */ | |
b0464d46 | 48 | krb5_free_data_contents(context, &auth); |
0bb1ca53 | 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 | { | |
b0464d46 | 59 | krb5_free_data_contents(context, &auth); |
0bb1ca53 | 60 | return response; |
61 | } | |
62 | ||
63 | return MR_SUCCESS; | |
64 | ||
65 | out: | |
b0464d46 | 66 | krb5_free_data_contents(context, &auth); |
0bb1ca53 | 67 | return code; |
68 | } | |
de56407f | 69 | |
4e3b3c65 | 70 | int mr_send_auth(int conn, char *host_name) |
de56407f | 71 | { |
5eaef520 | 72 | KTEXT_ST ticket_st; |
85330553 | 73 | int code, auth_version = 2; |
74 | long response; | |
5eaef520 | 75 | |
85330553 | 76 | code = get_mr_update_ticket(host_name, &ticket_st); |
5eaef520 | 77 | if (code) |
78 | return code; | |
85330553 | 79 | code = send_string(conn, "AUTH_002", 9); |
5eaef520 | 80 | if (code) |
85330553 | 81 | return code; |
82 | code = recv_int(conn, &response); | |
5eaef520 | 83 | if (code) |
85330553 | 84 | return code; |
5eaef520 | 85 | if (response) |
86 | { | |
85330553 | 87 | code = send_string(conn, "AUTH_001", 9); |
5eaef520 | 88 | if (code) |
85330553 | 89 | return code; |
90 | code = recv_int(conn, &response); | |
5eaef520 | 91 | if (code) |
85330553 | 92 | return code; |
5eaef520 | 93 | if (response) |
94 | return response; | |
95 | auth_version = 1; | |
de56407f | 96 | } |
85330553 | 97 | code = send_string(conn, (char *)ticket_st.dat, ticket_st.length); |
5eaef520 | 98 | if (code) |
85330553 | 99 | return code; |
100 | code = recv_int(conn, &response); | |
5eaef520 | 101 | if (code) |
85330553 | 102 | return code; |
5eaef520 | 103 | if (response) |
104 | return response; | |
105 | ||
106 | if (auth_version == 2) | |
107 | { | |
108 | des_key_schedule sched; | |
109 | C_Block enonce; | |
85330553 | 110 | char *data; |
111 | size_t size; | |
5eaef520 | 112 | |
85330553 | 113 | code = recv_string(conn, &data, &size); |
5eaef520 | 114 | if (code) |
85330553 | 115 | return code; |
5eaef520 | 116 | des_key_sched(session, sched); |
85330553 | 117 | des_ecb_encrypt(data, enonce, sched, 1); |
118 | free(data); | |
119 | code = send_string(conn, (char *)enonce, sizeof(enonce)); | |
5eaef520 | 120 | if (code) |
85330553 | 121 | return code; |
122 | code = recv_int(conn, &response); | |
5eaef520 | 123 | if (code) |
85330553 | 124 | return code; |
5eaef520 | 125 | if (response) |
126 | return response; | |
be86b0c2 | 127 | } |
128 | ||
5eaef520 | 129 | return MR_SUCCESS; |
de56407f | 130 | } |
131 | ||
4e3b3c65 | 132 | int mr_execute(int conn, char *path) |
de56407f | 133 | { |
85330553 | 134 | long response; |
135 | char *data; | |
44d12d58 | 136 | int code; |
5eaef520 | 137 | |
85330553 | 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); | |
5eaef520 | 144 | if (code) |
85330553 | 145 | return code; |
146 | code = recv_int(conn, &response); | |
5eaef520 | 147 | if (code) |
85330553 | 148 | return code; |
5eaef520 | 149 | if (response) |
150 | return response; | |
85330553 | 151 | |
5eaef520 | 152 | return MR_SUCCESS; |
de56407f | 153 | } |
154 | ||
4e3b3c65 | 155 | void mr_send_quit(int conn) |
85330553 | 156 | { |
157 | send_string(conn, "quit", 5); | |
158 | } | |
159 | ||
160 | void fail(int conn, int err, char *msg) | |
de56407f | 161 | { |
8ae70e8f | 162 | com_err(whoami, err, msg); |
85330553 | 163 | return; |
de56407f | 164 | } |