]> andersk Git - moira.git/blobdiff - update/client.c
Build without krb4 if it's unavailable.
[moira.git] / update / client.c
index 1d88e0c116fe485d1c72c7936462858d9f2c9ad2..5b86b0c5676a8f9f91cab5470badc8b06922ab42 100644 (file)
-/*
- *     $Source$
- *     $Header$
- */
-
-#ifndef lint
-static char *rcsid_client2_c = "$Header$";
-#endif lint
-
-/*
- * MODULE IDENTIFICATION:
- *     $Header$
- *     Copyright 1987, 1988 by the Massachusetts Institute of Technology.
- *     For copying and distribution information, please see the file
- *     <mit-copyright.h>.
- * DESCRIPTION:
- *     This code handles the actual distribution of data files
- *     to servers in the MOIRA server-update program.
- * AUTHOR:
- *     Ken Raeburn (spook@athena.MIT.EDU),
- *             MIT Project Athena/MIT Information Systems.
- * DEFINED VALUES:
- *     conn
- *     mr_update_server
+/* $Id$
+ *
+ * This code handles the actual distribution of data files
+ * to servers in the Moira server-update program.
+ *
+ * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  */
 
 #include <mit-copyright.h>
+#include <moira.h>
+#include "update.h"
+
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <gdb.h>
-#include <sys/param.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <update.h>
-#include <errno.h>
-#include <moira.h>
-#include <moira_site.h>
-#include <krb.h>
 
-extern int errno, dbg;
-extern C_Block session;
-
-static char buf[BUFSIZ];
-static int code;
+#ifdef HAVE_KRB4
+#include <des.h>
+#include <krb.h>
+#endif
+#include <krb5.h>
 
-CONNECTION conn;
+RCSID("$Header$");
 
+#ifdef HAVE_KRB4
+extern des_cblock session;
+#endif
+extern char *whoami;
+extern krb5_context context;
 
-/*
- * FUNCTION:
- *     initialize()
- * DESCRIPTION:
- *     Insures that various libraries have a chance to get
- *     initialized.
- * INPUT:
- * OUTPUT:
- * RETURN VALUE:
- *     void
- * SIDE EFFECTS:
- *     Initializes GDB library.
- * PROBLEMS:
- *
- */
-static void
-initialize()
+int mr_send_krb5_auth(int conn, char *host_name)
 {
-    static int initialized = 0;
+  krb5_data auth;
+  int code;
+  long response;
 
-    if (!initialized) {
-       gdb_init();
-       initialized++;
+  memset(&auth, 0, sizeof(auth));
+
+  code = get_mr_krb5_update_ticket(host_name, &auth);
+  if (code)
+    goto out;
+  code = send_string(conn, "AUTH_003", 9);
+  if (code)
+    goto out;
+  code = recv_int(conn, &response);
+  if (code)
+    goto out;
+  if (response)
+    {
+      /* Talking to a server that doesn't do AUTH_003 */
+      krb5_free_data_contents(context, &auth);
+      return response;
+    }
+  code = send_string(conn, (char *)auth.data, auth.length);
+  if (code)
+    goto out;
+  code = recv_int(conn, &response);
+  if (code)
+    goto out;
+  if (response)
+    {
+      krb5_free_data_contents(context, &auth);
+      return response;
     }
+
+  return MR_SUCCESS;
+
+ out:
+  krb5_free_data_contents(context, &auth);
+  return code;
 }
 
-send_auth(host_name)
-char *host_name;
+int mr_send_auth(int conn, char *host_name)
 {
-    KTEXT_ST ticket_st;
-    KTEXT ticket = &ticket_st;
-    STRING data;
-    register int code;
-    int response;
-    int auth_version = 2;
-    
-    code = get_mr_update_ticket(host_name, ticket);
-    if (code) {
-       return(code);
-    }
-    STRING_DATA(data) = "AUTH_002";
-    MAX_STRING_SIZE(data) = 9;
-    code = send_object(conn, (char *)&data, STRING_T);
-    if (code) {
-       return(connection_errno(conn));
-    }
-    code = receive_object(conn, (char *)&response, INTEGER_T);
-    if (code) {
-       return(connection_errno(conn));
-    }
-    if (response) {
-       STRING_DATA(data) = "AUTH_001";
-       MAX_STRING_SIZE(data) = 9;
-       code = send_object(conn, (char *)&data, STRING_T);
-       if (code) {
-           return(connection_errno(conn));
-       }
-       code = receive_object(conn, (char *)&response, INTEGER_T);
-       if (code) {
-           return(connection_errno(conn));
-       }
-       if (response) {
-           return(response);
-       }
-       auth_version = 1;
-    }
-    STRING_DATA(data) = (char *)ticket->dat;
-    MAX_STRING_SIZE(data) = ticket->length;
-    code = send_object(conn, (char *)&data, STRING_T);
-    if (code) {
-       return(connection_errno(conn));
-    }
-    code = receive_object(conn, (char *)&response, INTEGER_T);
-    if (code) {
-       return(connection_errno(conn));
-    }
-    if (response) {
-       return(response);
+#ifdef HAVE_KRB4
+  KTEXT_ST ticket_st;
+  int code, auth_version = 2;
+  long response;
+
+  code = get_mr_update_ticket(host_name, &ticket_st);
+  if (code)
+    return code;
+  code = send_string(conn, "AUTH_002", 9);
+  if (code)
+    return code;
+  code = recv_int(conn, &response);
+  if (code)
+    return code;
+  if (response)
+    {
+      code = send_string(conn, "AUTH_001", 9);
+      if (code)
+       return code;
+      code = recv_int(conn, &response);
+      if (code)
+       return code;
+      if (response)
+       return response;
+      auth_version = 1;
     }
-    
-    if (auth_version == 2) {
-       des_key_schedule sched;
-       C_Block enonce;
-
-       code = receive_object(conn, (char *)&data, STRING_T);
-       if (code) {
-           return(connection_errno(conn));
-       }
-       des_key_sched(session, sched);
-       des_ecb_encrypt(STRING_DATA(data), enonce, sched, 1);
-       STRING_DATA(data) = enonce;
-       code = send_object(conn, (char *)&data, STRING_T);
-       if (code) {
-           return(connection_errno(conn));
-       }
-       code = receive_object(conn, (char *)&response, INTEGER_T);
-       if (code) {
-           return(connection_errno(conn));
-       }
-       if (response) {
-           return(response);
-       }
+  code = send_string(conn, (char *)ticket_st.dat, ticket_st.length);
+  if (code)
+    return code;
+  code = recv_int(conn, &response);
+  if (code)
+    return code;
+  if (response)
+    return response;
+
+  if (auth_version == 2)
+    {
+      des_key_schedule sched;
+      C_Block enonce;
+      char *data;
+      size_t size;
+
+      code = recv_string(conn, &data, &size);
+      if (code)
+       return code;
+      des_key_sched(session, sched);
+      des_ecb_encrypt(data, enonce, sched, 1);
+      free(data);
+      code = send_string(conn, (char *)enonce, sizeof(enonce));
+      if (code)
+       return code;
+      code = recv_int(conn, &response);
+      if (code)
+       return code;
+      if (response)
+       return response;
     }
 
-    return(MR_SUCCESS);
+  return MR_SUCCESS;
+#else
+  return MR_NO_KRB4;
+#endif
+}
+
+int mr_execute(int conn, char *path)
+{
+  long response;
+  char *data;
+  int code;
+
+  data = malloc(10 + strlen(path));
+  if (!data)
+    return ENOMEM;
+  sprintf(data, "EXEC_002 %s", path);
+  code = send_string(conn, data, strlen(data) + 1);
+  free(data);
+  if (code)
+    return code;
+  code = recv_int(conn, &response);
+  if (code)
+    return code;
+  if (response)
+    return response;
+
+  return MR_SUCCESS;
 }
 
-execute(path)
-    char *path;
+void mr_send_quit(int conn)
 {
-    int response;
-    STRING data;
-    register int code;
-    
-    string_alloc(&data, BUFSIZ);
-    sprintf(STRING_DATA(data), "EXEC_002 %s", path);
-    code = send_object(conn, (char *)&data, STRING_T);
-    if (code)
-       return(connection_errno(conn));
-    code = receive_object(conn, (char *)&response, INTEGER_T);
-    if (code)
-       return(connection_errno(conn));
-    if (response)
-      return(response);
-    return(MR_SUCCESS);
+  send_string(conn, "quit", 5);
 }
 
-send_quit()
+void fail(int conn, int err, char *msg)
 {
-    STRING str;
-    if (!conn)
-       return;
-    string_alloc(&str, 5);
-    (void) strcpy(STRING_DATA(str), "quit");
-    (void) send_object(conn, (char *)&str, STRING_T);
-    string_free(&str);
+  com_err(whoami, err, msg);
+  return;
 }
This page took 0.041956 seconds and 4 git commands to generate.