]> andersk Git - moira.git/blobdiff - update/client.c
Command line printer manipulation client, and build goo.
[moira.git] / update / client.c
index f72746efca863d671e83ffe47917a6203f10d082..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)
+  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)
     {
-      gdb_init();
-      initialized++;
+      /* 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;
 }
 
-int send_auth(char *host_name)
+int mr_send_auth(int conn, char *host_name)
 {
+#ifdef HAVE_KRB4
   KTEXT_ST ticket_st;
-  KTEXT ticket = &ticket_st;
-  STRING data;
-  int code;
-  int response;
-  int auth_version = 2;
+  int code, auth_version = 2;
+  long response;
 
-  code = get_mr_update_ticket(host_name, ticket);
+  code = get_mr_update_ticket(host_name, &ticket_st);
   if (code)
     return code;
-  STRING_DATA(data) = "AUTH_002";
-  MAX_STRING_SIZE(data) = 9;
-  code = send_object(conn, (char *)&data, STRING_T);
+  code = send_string(conn, "AUTH_002", 9);
   if (code)
-    return connection_errno(conn);
-  code = receive_object(conn, (char *)&response, INTEGER_T);
+    return code;
+  code = recv_int(conn, &response);
   if (code)
-    return connection_errno(conn);
+    return code;
   if (response)
     {
-      STRING_DATA(data) = "AUTH_001";
-      MAX_STRING_SIZE(data) = 9;
-      code = send_object(conn, (char *)&data, STRING_T);
+      code = send_string(conn, "AUTH_001", 9);
       if (code)
-       return connection_errno(conn);
-      code = receive_object(conn, (char *)&response, INTEGER_T);
+       return code;
+      code = recv_int(conn, &response);
       if (code)
-       return connection_errno(conn);
+       return code;
       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);
+  code = send_string(conn, (char *)ticket_st.dat, ticket_st.length);
   if (code)
-    return connection_errno(conn);
-  code = receive_object(conn, (char *)&response, INTEGER_T);
+    return code;
+  code = recv_int(conn, &response);
   if (code)
-    return connection_errno(conn);
+    return code;
   if (response)
     return response;
 
@@ -122,52 +114,61 @@ int send_auth(char *host_name)
     {
       des_key_schedule sched;
       C_Block enonce;
+      char *data;
+      size_t size;
 
-      code = receive_object(conn, (char *)&data, STRING_T);
+      code = recv_string(conn, &data, &size);
       if (code)
-       return connection_errno(conn);
+       return code;
       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);
+      des_ecb_encrypt(data, enonce, sched, 1);
+      free(data);
+      code = send_string(conn, (char *)enonce, sizeof(enonce));
       if (code)
-       return connection_errno(conn);
-      code = receive_object(conn, (char *)&response, INTEGER_T);
+       return code;
+      code = recv_int(conn, &response);
       if (code)
-       return connection_errno(conn);
+       return code;
       if (response)
        return response;
     }
 
   return MR_SUCCESS;
+#else
+  return MR_NO_KRB4;
+#endif
 }
 
-int execute(char *path)
+int mr_execute(int conn, char *path)
 {
-  int response;
-  STRING data;
+  long response;
+  char *data;
   int code;
 
-  string_alloc(&data, BUFSIZ);
-  sprintf(STRING_DATA(data), "EXEC_002 %s", path);
-  code = send_object(conn, (char *)&data, STRING_T);
+  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 connection_errno(conn);
-  code = receive_object(conn, (char *)&response, INTEGER_T);
+    return code;
+  code = recv_int(conn, &response);
   if (code)
-    return connection_errno(conn);
+    return code;
   if (response)
     return response;
+
   return MR_SUCCESS;
 }
 
-send_quit(void)
+void mr_send_quit(int conn)
+{
+  send_string(conn, "quit", 5);
+}
+
+void fail(int conn, int err, char *msg)
 {
-  STRING str;
-  if (!conn)
-    return;
-  string_alloc(&str, 5);
-  strcpy(STRING_DATA(str), "quit");
-  send_object(conn, (char *)&str, STRING_T);
-  string_free(&str);
+  com_err(whoami, err, msg);
+  return;
 }
This page took 0.041251 seconds and 4 git commands to generate.