]>
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> |
22 | ||
7ac48069 | 23 | RCSID("$Header$"); |
de56407f | 24 | |
85330553 | 25 | extern des_cblock session; |
8ae70e8f | 26 | extern char *whoami; |
de56407f | 27 | |
4e3b3c65 | 28 | int mr_send_auth(int conn, char *host_name) |
de56407f | 29 | { |
5eaef520 | 30 | KTEXT_ST ticket_st; |
85330553 | 31 | int code, auth_version = 2; |
32 | long response; | |
5eaef520 | 33 | |
85330553 | 34 | code = get_mr_update_ticket(host_name, &ticket_st); |
5eaef520 | 35 | if (code) |
36 | return code; | |
85330553 | 37 | code = send_string(conn, "AUTH_002", 9); |
5eaef520 | 38 | if (code) |
85330553 | 39 | return code; |
40 | code = recv_int(conn, &response); | |
5eaef520 | 41 | if (code) |
85330553 | 42 | return code; |
5eaef520 | 43 | if (response) |
44 | { | |
85330553 | 45 | code = send_string(conn, "AUTH_001", 9); |
5eaef520 | 46 | if (code) |
85330553 | 47 | return code; |
48 | code = recv_int(conn, &response); | |
5eaef520 | 49 | if (code) |
85330553 | 50 | return code; |
5eaef520 | 51 | if (response) |
52 | return response; | |
53 | auth_version = 1; | |
de56407f | 54 | } |
85330553 | 55 | code = send_string(conn, (char *)ticket_st.dat, ticket_st.length); |
5eaef520 | 56 | if (code) |
85330553 | 57 | return code; |
58 | code = recv_int(conn, &response); | |
5eaef520 | 59 | if (code) |
85330553 | 60 | return code; |
5eaef520 | 61 | if (response) |
62 | return response; | |
63 | ||
64 | if (auth_version == 2) | |
65 | { | |
66 | des_key_schedule sched; | |
67 | C_Block enonce; | |
85330553 | 68 | char *data; |
69 | size_t size; | |
5eaef520 | 70 | |
85330553 | 71 | code = recv_string(conn, &data, &size); |
5eaef520 | 72 | if (code) |
85330553 | 73 | return code; |
5eaef520 | 74 | des_key_sched(session, sched); |
85330553 | 75 | des_ecb_encrypt(data, enonce, sched, 1); |
76 | free(data); | |
77 | code = send_string(conn, (char *)enonce, sizeof(enonce)); | |
5eaef520 | 78 | if (code) |
85330553 | 79 | return code; |
80 | code = recv_int(conn, &response); | |
5eaef520 | 81 | if (code) |
85330553 | 82 | return code; |
5eaef520 | 83 | if (response) |
84 | return response; | |
be86b0c2 | 85 | } |
86 | ||
5eaef520 | 87 | return MR_SUCCESS; |
de56407f | 88 | } |
89 | ||
4e3b3c65 | 90 | int mr_execute(int conn, char *path) |
de56407f | 91 | { |
85330553 | 92 | long response; |
93 | char *data; | |
44d12d58 | 94 | int code; |
5eaef520 | 95 | |
85330553 | 96 | data = malloc(10 + strlen(path)); |
97 | if (!data) | |
98 | return ENOMEM; | |
99 | sprintf(data, "EXEC_002 %s", path); | |
100 | code = send_string(conn, data, strlen(data) + 1); | |
101 | free(data); | |
5eaef520 | 102 | if (code) |
85330553 | 103 | return code; |
104 | code = recv_int(conn, &response); | |
5eaef520 | 105 | if (code) |
85330553 | 106 | return code; |
5eaef520 | 107 | if (response) |
108 | return response; | |
85330553 | 109 | |
5eaef520 | 110 | return MR_SUCCESS; |
de56407f | 111 | } |
112 | ||
4e3b3c65 | 113 | void mr_send_quit(int conn) |
85330553 | 114 | { |
115 | send_string(conn, "quit", 5); | |
116 | } | |
117 | ||
118 | void fail(int conn, int err, char *msg) | |
de56407f | 119 | { |
8ae70e8f | 120 | com_err(whoami, err, msg); |
85330553 | 121 | return; |
de56407f | 122 | } |