diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/krb5/os/ChangeLog | 3 | ||||
-rw-r--r-- | src/lib/krb5/os/Makefile.in | 6 | ||||
-rw-r--r-- | src/lib/krb5/os/t_locate_kdc.c | 110 |
3 files changed, 119 insertions, 0 deletions
diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 7e330c91ad..8688b92d4e 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,5 +1,8 @@ 2001-07-19 Ken Raeburn <raeburn@mit.edu> + * t_locate_kdc.c: New file. + * Makefile.in (t_locate_kdc.o, t_locate_kdc): New targets. + * locate_kdc.c: Include fake-addrinfo.h. (FAI_PREFIX, FAI_IMPLEMENTATION): Define macros. (get_port, add_sockaddr_to_list, add_host_to_list): Drop diff --git a/src/lib/krb5/os/Makefile.in b/src/lib/krb5/os/Makefile.in index 70faf78337..417b50d6c4 100644 --- a/src/lib/krb5/os/Makefile.in +++ b/src/lib/krb5/os/Makefile.in @@ -171,6 +171,12 @@ t_mktime: gmt_mktime.c t_localaddr: localaddr.c $(CC) $(ALL_CFLAGS) -DTEST -o t_localaddr $(srcdir)/localaddr.c + +t_locate_kdc: t_locate_kdc.o + $(CC) $(ALL_CFLAGS) -o t_locate_kdc t_locate_kdc.o \ + -static -L../.. -lkrb5 -lk5crypto -lcom_err @GEN_LIB@ $(LIBS) +t_locate_kdc.o: t_locate_kdc.c locate_kdc.c + LCLINT=lclint LCLINTOPTS= -warnposix \ -usedef +charintliteral +ignoresigns -predboolint +boolint \ diff --git a/src/lib/krb5/os/t_locate_kdc.c b/src/lib/krb5/os/t_locate_kdc.c new file mode 100644 index 0000000000..e93b6d8776 --- /dev/null +++ b/src/lib/krb5/os/t_locate_kdc.c @@ -0,0 +1,110 @@ +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> +#include <netinet/in.h> +#include <arpa/inet.h> + +#include <com_err.h> + +#define TEST +#include "locate_kdc.c" + +enum { + LOOKUP_CONF = 3, + LOOKUP_DNS, + LOOKUP_WHATEVER +} how = LOOKUP_WHATEVER; + +const char *prog; + +struct addrlist al; + +void kfatal (krb5_error_code err) +{ + com_err (prog, err, "- exiting"); + exit (1); +} + +void print_addrs () +{ + int i; + + struct sockaddr **addrs = al.addrs; + int naddrs = al.naddrs; + + printf ("%d addresses:\n", naddrs); + for (i = 0; i < naddrs; i++) { + int err; + char hostbuf[NI_MAXHOST], srvbuf[NI_MAXSERV]; + err = getnameinfo (addrs[i], socklen(addrs[i]), + hostbuf, sizeof (hostbuf), + srvbuf, sizeof (srvbuf), + NI_NUMERICHOST | NI_NUMERICSERV); + if (err) + printf ("%2d: getnameinfo returns error %d=%s\n", + i, err, gai_strerror (err)); + else + printf ("%2d: address %s\tport %s\n", i, hostbuf, srvbuf); + } +} + +int main (int argc, char *argv[]) +{ + char *p, *realmname; + krb5_data realm; + krb5_context ctx; + krb5_error_code err; + + p = strrchr (argv[0], '/'); + if (p) + prog = p+1; + else + prog = argv[0]; + + switch (argc) { + case 2: + /* foo $realm */ + realmname = argv[1]; + break; + case 3: + if (!strcmp (argv[1], "-c")) + how = LOOKUP_CONF; + else if (!strcmp (argv[1], "-d")) + how = LOOKUP_DNS; + else + goto usage; + realmname = argv[2]; + break; + default: + usage: + fprintf (stderr, "%s: usage: %s [-c | -d] realm\n", prog, prog); + return 1; + } + + err = krb5_init_context (&ctx); + if (err) + kfatal (err); + + realm.data = realmname; + realm.length = strlen (realmname); + + switch (how) { + case LOOKUP_CONF: + err = krb5_locate_srv_conf (ctx, &realm, "kdc", &al, 0, + htons (88), htons (750)); + break; + + case LOOKUP_DNS: + err = krb5_locate_srv_dns (&realm, "_kerberos", "_udp", &al); + break; + + case LOOKUP_WHATEVER: + err = krb5_locate_kdc (ctx, &realm, &al, 0); + break; + } + if (err) kfatal (err); + print_addrs (); + return 0; +} |