diff options
author | Peter Wemm <peter@FreeBSD.org> | 1999-11-30 02:43:11 +0000 |
---|---|---|
committer | Peter Wemm <peter@FreeBSD.org> | 1999-11-30 02:43:11 +0000 |
commit | 6b6ac9438f352903fe405daefaf6a3c9a2b63093 (patch) | |
tree | 7828b08c74ef918938b1b853c98f0cb41edac52c /contrib/bind/tests/irs_testirpd.c | |
parent | 15f7f569921160e3818633b964623b12cd9179d7 (diff) | |
download | src-test2-6b6ac9438f352903fe405daefaf6a3c9a2b63093.tar.gz src-test2-6b6ac9438f352903fe405daefaf6a3c9a2b63093.zip |
Notes
Diffstat (limited to 'contrib/bind/tests/irs_testirpd.c')
-rw-r--r-- | contrib/bind/tests/irs_testirpd.c | 366 |
1 files changed, 366 insertions, 0 deletions
diff --git a/contrib/bind/tests/irs_testirpd.c b/contrib/bind/tests/irs_testirpd.c new file mode 100644 index 000000000000..2b5a3c450a71 --- /dev/null +++ b/contrib/bind/tests/irs_testirpd.c @@ -0,0 +1,366 @@ +#include <stdio.h> +#include <unistd.h> +#include <pwd.h> +#include <irp.h> +#include <grp.h> +#include <netdb.h> +#include <arpa/inet.h> +#include <sys/socket.h> + +#include <irp.h> +#include <irs.h> +#include <isc/irpmarshall.h> + +void print_passwd(const char *name, struct passwd *pw, FILE *fp); +void print_group(const char *name, struct group *gr, FILE *fp); +void print_servent(const char *name, struct servent *sv, FILE *fp); +void print_host(const char *name, struct hostent *ho, FILE *fp); +void print_netent(const char *name, struct netent *ne, FILE *fp); +void print_proto(const char *name, struct protoent *pr, FILE *fp); + +int +main(int argc, char **argv) { + struct passwd *pw; + struct group *gr; + struct servent *sv; + struct hostent *ho; + struct netent *ne; + struct protoent *pr; + int ch ; + char *groupname = NULL; + + while ((ch = getopt(argc, argv, "u:s:p:g:h:n:g:a:z:")) != -1) { + switch (ch) { + case 'u': + if (strlen (optarg) == 0) { + do { + pw = getpwent(); + print_passwd(optarg, pw, stdout); + printf("\n\n"); + } while (pw != NULL); + sleep(1); + setpwent(); + do { + pw = getpwent(); + print_passwd(optarg, pw, stdout); + printf("\n\n"); + } while (pw != NULL); + sleep(1); + } else { + if (strspn(optarg, "0123456789") == + strlen(optarg)) + pw = getpwuid(atoi(optarg)); + else + pw = getpwnam(optarg); + print_passwd(optarg, pw, stdout); + } + + break; + + case 'g': + if (strlen (optarg) == 0) { + do { + gr = getgrent(); + print_group(optarg, gr, stdout); + printf("\n\n"); + } while (gr != NULL); + sleep(1); + setgrent(); + do { + gr = getgrent(); + print_group(optarg, gr, stdout); + printf("\n\n"); + } while (gr != NULL); + sleep(1); + } else { + if (strspn(optarg, "0123456789") == + strlen(optarg)) + gr = getgrgid(atoi(optarg)); + else + gr = getgrnam(optarg); + print_group(optarg, gr, stdout); + } + break; + + case 's': + if (strlen (optarg) == 0) { + do { + sv = getservent(); + print_servent(optarg, sv, stdout); + printf("\n\n"); + } while (sv != NULL); + sleep(1); + setservent(1); + do { + sv = getservent(); + print_servent(optarg, sv, stdout); + printf("\n\n"); + } while (sv != NULL); + sleep(1); + } else { + if (strspn(optarg, "0123456789") == + strlen(optarg)) + sv = getservbyport(htons(atoi(optarg)), + "tcp"); + else + sv = getservbyname(optarg,"tcp"); + print_servent(optarg, sv, stdout); + } + break; + + case 'h': + if (strlen (optarg) == 0) { + do { + ho = gethostent(); + print_host(optarg, ho, stdout); + printf("\n\n"); + } while (ho != NULL); + sleep(1); + sethostent(1); + do { + ho = gethostent(); + print_host(optarg, ho, stdout); + printf("\n\n"); + } while (ho != NULL); + sleep(1); + } else { + if (strspn(optarg, "0123456789.") == + strlen(optarg)) { + long naddr; + inet_pton(AF_INET, optarg, &naddr); + ho = gethostbyaddr((const char *) + &naddr, + sizeof naddr, + AF_INET); + } else + ho = gethostbyname(optarg); + print_host(optarg, ho, stdout); + } + break; + + case 'n': + if (strlen (optarg) == 0) { + do { + ne = getnetent(); + print_netent(optarg, ne, stdout); + printf("\n\n"); + } while (ne != NULL); + sleep(1); + setnetent(1); + do { + ne = getnetent(); + print_netent(optarg, ne, stdout); + printf("\n\n"); + } while (ne != NULL); + sleep(1); + } else { + if (strspn(optarg, "0123456789./") == + strlen(optarg)) { + long naddr; + inet_pton(AF_INET, optarg, &naddr); + ne = getnetbyaddr(naddr, AF_INET); + } else + ne = getnetbyname(optarg); + print_netent(optarg, ne, stdout); + } + break; + + case 'p': + if (strlen (optarg) == 0) { + do { + pr = getprotoent(); + print_proto(optarg, pr, stdout); + printf("\n\n"); + } while (pr != NULL); + sleep(1); + setprotoent(1); + do { + pr = getprotoent(); + print_proto(optarg, pr, stdout); + printf("\n\n"); + } while (pr != NULL); + sleep(1); + } else { + if (strspn(optarg, "0123456789") == + strlen(optarg)) + pr = getprotobynumber(atoi(optarg)); + else + pr = getprotobyname(optarg); + print_proto(optarg, pr, stdout); + } + + break; + + case 'z': { + char *host, *user, *domain ; + + groupname = optarg; + setnetgrent(groupname); + while (getnetgrent(&host,&user,&domain) == 1) { + fprintf(stdout, "++++\n"); + fprintf(stdout, "Host: \"%s\"\n", + (host == NULL ? "(null)" : host)); + fprintf(stdout, "User: \"%s\"\n", + (user == NULL ? "(null)" : user)); + fprintf(stdout, "Domain: \"%s\"\n", + (domain == NULL ? "(null)" : domain)); + fprintf(stdout, "----\n\n"); + } + break; + } + + default: + printf("Huh?\n"); + exit (1); + } + } + return (0); +} + +void +print_passwd(const char *name, struct passwd *pw, FILE *fp) { + if (pw == NULL) { + fprintf(fp, "%s -- NONE\n",name) ; + return ; + } + + fprintf(fp, "++++\n"); + fprintf(fp, "Name: \"%s\"\n", pw->pw_name); + fprintf(fp, "Uid: %d\n", pw->pw_uid); + fprintf(fp, "Gid: %d\n", pw->pw_gid); + fprintf(fp, "Password: \"%s\"\n", pw->pw_passwd); + fprintf(fp, "Change: %s", ctime(&pw->pw_change)); + fprintf(fp, "Class: \"%s\"\n", pw->pw_class); + fprintf(fp, "Gecos: \"%s\"\n", pw->pw_gecos); + fprintf(fp, "Dir: \"%s\"\n", pw->pw_dir); + fprintf(fp, "Shell: \"%s\"\n", pw->pw_shell); + fprintf(fp, "Expire: %s", ctime(&pw->pw_expire)); + fprintf(fp, "----\n"); +} + + + +void print_group(const char *name, struct group *gr, FILE *fp) { + char **p ; + + if (gr == NULL) { + fprintf(fp, "%s -- NONE\n", name); + return; + } + + fprintf(fp, "++++\n"); + fprintf(fp, "Name: \"%s\"\n", gr->gr_name); + fprintf(fp, "Password: \"%s\"\n", gr->gr_passwd); + fprintf(fp, "Gid: %d\n", gr->gr_gid); + fprintf(fp, "Members:\n") ; + for (p = gr->gr_mem ; p != NULL && *p != NULL ; p++) { + fprintf(fp, "\t\t%s\n",*p); + } + fprintf(fp, "----\n"); +} + + + +void print_servent(const char *name, struct servent *sv, FILE *fp) { + char **p ; + + if (sv == NULL) { + fprintf(fp, "%s -- NONE\n", name); + return; + } + + fprintf(fp, "++++\n"); + fprintf(fp, "Name: \"%s\"\n", sv->s_name); + fprintf(fp, "Aliases:\n") ; + for (p = sv->s_aliases ; p != NULL && *p != NULL ; p++) { + fprintf(fp, "\t\t%s\n",*p); + } + + fprintf(fp, "Port: %d\n", ntohs((short)sv->s_port)); + fprintf(fp, "Protocol: \"%s\"\n", sv->s_proto); + fprintf(fp, "----\n"); +} + + +void print_host(const char *name, struct hostent *ho, FILE *fp) { + char **p ; + char addr[24]; + + if (ho == NULL) { + fprintf(fp, "%s -- NONE\n", name); + return; + } + + fprintf(fp, "++++\n"); + fprintf(fp, "Name: \"%s\"\n", ho->h_name); + fprintf(fp, "Aliases:\n") ; + for (p = ho->h_aliases ; p != NULL && *p != NULL ; p++) { + fprintf(fp, "\t\t%s\n",*p); + } + + + fprintf(fp, "Address Type: %s\n", ADDR_T_STR(ho->h_addrtype)); + fprintf(fp, "Addresses:\n"); + for (p = ho->h_addr_list ; p != NULL && *p ; p++) { + addr[0] = '\0'; + inet_ntop(ho->h_addrtype, *p, addr, sizeof addr); + fprintf(fp, "\t\t%s\n",addr); + } + fprintf(fp, "----\n"); +} + + +void print_netent(const char *name, struct netent *ne, FILE *fp) { + char **p ; + char addr[24]; + long taddr; + + if (ne == NULL) { + fprintf(fp, "%s -- NONE\n", name); + return; + } + + fprintf(fp, "++++\n"); + fprintf(fp, "Name: \"%s\"\n", ne->n_name); + fprintf(fp, "Aliases:\n") ; + for (p = ne->n_aliases ; p != NULL && *p != NULL ; p++) { + fprintf(fp, "\t\t%s\n",*p); + } + + + fprintf(fp, "Address Type: %s\n", ADDR_T_STR(ne->n_addrtype)); + taddr = htonl(ne->n_net); + inet_ntop(ne->n_addrtype, &taddr, addr, sizeof addr); + fprintf(fp, "Net number: %s\n", addr); + fprintf(fp, "----\n"); +} + + +void print_proto(const char *name, struct protoent *pr, FILE *fp) { + char **p ; + char addr[24]; + long taddr; + + if (pr == NULL) { + fprintf(fp, "%s -- NONE\n", name); + return; + } + + fprintf(fp, "++++\n"); + fprintf(fp, "Name: \"%s\"\n", pr->p_name); + fprintf(fp, "Aliases:\n") ; + for (p = pr->p_aliases ; p != NULL && *p != NULL ; p++) { + fprintf(fp, "\t\t%s\n",*p); + } + + + fprintf(fp, "Protocol Number: %d\n", pr->p_proto); + fprintf(fp, "----\n"); +} + +/* + Local Variables: + compile-command: "gcc -g -I../../include -L.. -o testirpd testirpd.c ../libbind.a" + End: +*/ + |