source: trunk/third/moira/update/client.c @ 24319

Revision 24319, 3.5 KB checked in by broder, 15 years ago (diff)
New Moira snapshot from SVN.
Line 
1/* $Id: client.c 3956 2010-01-05 20:56:56Z zacheiss $
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 <errno.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
20#ifdef HAVE_KRB4
21#include <des.h>
22#include <krb.h>
23#endif
24#include <krb5.h>
25
26RCSID("$HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/update/client.c $ $Id: client.c 3956 2010-01-05 20:56:56Z zacheiss $");
27
28#ifdef HAVE_KRB4
29extern des_cblock session;
30#endif
31extern char *whoami;
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}
75
76int mr_send_auth(int conn, char *host_name)
77{
78#ifdef HAVE_KRB4
79  KTEXT_ST ticket_st;
80  int code, auth_version = 2;
81  long response;
82
83  code = get_mr_update_ticket(host_name, &ticket_st);
84  if (code)
85    return code;
86  code = send_string(conn, "AUTH_002", 9);
87  if (code)
88    return code;
89  code = recv_int(conn, &response);
90  if (code)
91    return code;
92  if (response)
93    {
94      code = send_string(conn, "AUTH_001", 9);
95      if (code)
96        return code;
97      code = recv_int(conn, &response);
98      if (code)
99        return code;
100      if (response)
101        return response;
102      auth_version = 1;
103    }
104  code = send_string(conn, (char *)ticket_st.dat, ticket_st.length);
105  if (code)
106    return code;
107  code = recv_int(conn, &response);
108  if (code)
109    return code;
110  if (response)
111    return response;
112
113  if (auth_version == 2)
114    {
115      des_key_schedule sched;
116      C_Block enonce;
117      char *data;
118      size_t size;
119
120      code = recv_string(conn, &data, &size);
121      if (code)
122        return code;
123      des_key_sched(session, sched);
124      des_ecb_encrypt((des_cblock *)data, &enonce, sched, 1);
125      free(data);
126      code = send_string(conn, (char *)enonce, sizeof(enonce));
127      if (code)
128        return code;
129      code = recv_int(conn, &response);
130      if (code)
131        return code;
132      if (response)
133        return response;
134    }
135
136  return MR_SUCCESS;
137#else
138  return MR_NO_KRB4;
139#endif
140}
141
142int mr_execute(int conn, char *path)
143{
144  long response;
145  char *data;
146  int code;
147
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);
154  if (code)
155    return code;
156  code = recv_int(conn, &response);
157  if (code)
158    return code;
159  if (response)
160    return response;
161
162  return MR_SUCCESS;
163}
164
165void mr_send_quit(int conn)
166{
167  send_string(conn, "quit", 5);
168}
169
170void fail(int conn, int err, char *msg)
171{
172  com_err(whoami, err, msg);
173  return;
174}
Note: See TracBrowser for help on using the repository browser.