First version
authorBill Sommerfeld <wesommer@mit.edu>
Tue, 30 Jan 1990 00:51:42 +0000 (00:51 +0000)
committerBill Sommerfeld <wesommer@mit.edu>
Tue, 30 Jan 1990 00:51:42 +0000 (00:51 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@193 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/ccache/Imakefile [new file with mode: 0644]
src/lib/krb5/ccache/ccdefault.c [new file with mode: 0644]
src/lib/krb5/os/ccdefname.c [new file with mode: 0644]
src/lib/krb5/os/localaddr.c [new file with mode: 0644]

diff --git a/src/lib/krb5/ccache/Imakefile b/src/lib/krb5/ccache/Imakefile
new file mode 100644 (file)
index 0000000..b592561
--- /dev/null
@@ -0,0 +1,13 @@
+#define IHaveSubdirs
+#define PassCDebugFlags
+
+        SUBDIRS = file
+
+MakeSubdirs($(SUBDIRS))
+
+NormalLibraryObjectRule()
+
+OBJS=  default.o       \
+       destroy.o
+
+NormalLibraryTarget(cred,$(OBJS))
diff --git a/src/lib/krb5/ccache/ccdefault.c b/src/lib/krb5/ccache/ccdefault.c
new file mode 100644 (file)
index 0000000..365086b
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * Find default credential cache
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_default_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+#include <assert.h>
+
+static krb5_ccache default_ccache;
+
+krb5_ccache krb5_cc_default()
+{
+    if (default_ccache == 0) 
+       assert(krb5_cc_resolve (krb5_cc_default_name(), &default_ccache) == 0); /* XXX error handling? */
+
+    return default_ccache;
+}
diff --git a/src/lib/krb5/os/ccdefname.c b/src/lib/krb5/os/ccdefname.c
new file mode 100644 (file)
index 0000000..53719bf
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * Return default cred. cache name.
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_defname_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+char *krb5_cc_default_name()
+{
+    char *name = getenv ("KRB5CCNAME");
+    static char *name_buf;
+    
+    if (name == 0) {
+       if (name_buf == 0)
+           name_buf = malloc (30);
+       
+       sprintf(name_buf, "/tmp/krb5cc_%d", getuid());
+       name = name_buf;
+    }
+    return name;
+}
+    
diff --git a/src/lib/krb5/os/localaddr.c b/src/lib/krb5/os/localaddr.c
new file mode 100644 (file)
index 0000000..1b1acbf
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * Return the protocol addresses supported by this host.
+ *
+ * XNS support is untested, but "Should just work".
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_getaddr_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+#include <krb5/osconf.h>
+
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <sys/errno.h>
+
+/*
+ * The SIOCGIF* ioctls require a socket.
+ * It doesn't matter *what* kind of socket they use, but it has to be
+ * a socket.
+ *
+ * Of course, you can't just ask the kernel for a socket of arbitrary
+ * type; you have to ask for one with a valid type.
+ *
+ */
+#ifdef KRB5_USE_INET
+
+#include <netinet/in.h>
+
+#ifndef USE_AF
+#define USE_AF AF_INET
+#define USE_TYPE SOCK_DGRAM
+#define USE_PROTO 0
+#endif
+
+#endif
+
+#ifdef KRB5_USE_NS
+
+#include <netns/ns.h>
+
+#ifndef USE_AF
+#define USE_AF AF_NS
+#define USE_TYPE SOCK_DGRAM
+#define USE_PROTO 0            /* guess */
+#endif
+
+#endif
+/*
+ * Add more address families here.
+ */
+
+extern int errno;
+
+/*
+ * Return all the protocol addresses of this host.
+ *
+ * We could kludge up something to return all addresses, assuming that
+ * they're valid kerberos protocol addresses, but we wouldn't know the
+ * real size of the sockaddr or know which part of it was actually the
+ * host part.
+ *
+ * This uses the SIOCGIFCONF, SIOCGIFFLAGS, and SIOCGIFADDR ioctl's.
+ */
+
+int krb5_os_localaddr(addr)
+    krb5_address ***addr;
+{
+    struct ifreq *ifr;
+    struct ifconf ifc;
+    int s, code, n, i;
+    char buf[1024];
+    krb5_address *addr_temp [ 1024/sizeof(struct ifreq) ];
+    int n_found;
+    int mem_err = 0;
+    
+    ifc.ifc_len = sizeof(buf);
+    ifc.ifc_buf = buf;
+
+    s = socket (USE_AF, USE_TYPE, USE_PROTO);
+    if (s < 0)
+       return errno;
+
+    code = ioctl (s, SIOCGIFCONF, (char *)&ifc);
+    if (code < 0) {
+       close(s);
+       return errno;
+    }
+    n = ifc.ifc_len / sizeof (struct ifreq);
+    
+    for (n_found=0, i=0; i<n && ! mem_err; i++) {
+       krb5_address *address;
+       ifr = &ifc.ifc_req[i];
+       
+       if (ioctl (s, SIOCGIFFLAGS, (char *)ifr) < 0)
+           continue;
+
+#ifdef IFF_LOOPBACK
+       if (ifr->ifr_flags & IFF_LOOPBACK) 
+           continue;
+#endif
+
+       if (!(ifr->ifr_flags & IFF_UP)) 
+           /* interface is down; skip */
+           continue;
+
+       if (ioctl (s, SIOCGIFADDR, (char *)ifr) < 0)
+           /* can't get address */
+           continue;
+
+       /* ifr->ifr_addr has what we want! */
+       switch (ifr->ifr_addr.sa_family) {
+#ifdef KRB5_USE_INET
+       case AF_INET:
+           {
+               struct sockaddr_in *in =
+                   (struct sockaddr_in *)&ifr->ifr_addr;
+               
+               address = (krb5_address *)
+                   malloc (sizeof(krb5_address) + sizeof(struct in_addr));
+               if (address) {
+                   address->addrtype = ADDRTYPE_INET;
+                   address->length = sizeof(struct in_addr);
+                   memcpy ((char *)address->contents, (char *)&in->sin_addr, 
+                           address->length);
+                   break;
+               } else mem_err++;
+           }
+#endif
+#ifdef KRB5_USE_NS
+           case AF_XNS:
+           {  
+               struct sockaddr_ns *ns =
+                   (struct sockaddr_ns *)&ifr->ifr_addr;                   
+               address = (krb5_address *)
+                   malloc (sizeof (krb5_address) + sizeof (struct ns_addr));
+               if (address) {
+                   address->addrtype = ADDRTYPE_XNS; 
+
+                   /* XXX should we perhaps use ns_host instead? */
+
+                   address->length = sizeof(struct ns_addr);
+                   memcpy ((char *)address->contents, (char *)&ns->sns_addr,
+                           address->length);
+               } else mem_err++;
+               break;
+           }
+#endif
+       /*
+        * Add more address families here..
+        */
+       default:
+           continue;
+       }
+       if (address)
+           addr_temp[n_found++] = address;
+       address = 0;
+    }
+    close(s);
+
+    *addr = (krb5_address **)malloc (sizeof (krb5_address *) * (n_found+1));
+    if (*addr == 0)
+       mem_err++;
+    
+    if (mem_err) {
+       for (i=0; i<n_found; i++) {
+           free((char *)addr_temp[i]);
+           addr_temp[i] = 0;
+       }
+       return ENOMEM;
+    }
+    
+    for (i=0; i<n_found; i++) {
+       (*addr)[i] = addr_temp[i];
+    }
+    (*addr)[n_found] = 0;
+    return 0;
+}