[BACK]Return to ypmatch.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.bin / ypmatch

Annotation of src/usr.bin/ypmatch/ypmatch.c, Revision 1.10

1.10    ! thorpej     1: /*     $NetBSD: ypmatch.c,v 1.9 1996/05/07 18:27:46 jtc Exp $  */
1.5       cgd         2:
1.2       deraadt     3: /*
1.4       deraadt     4:  * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
1.2       deraadt     5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
1.4       deraadt    15:  * 3. All advertising materials mentioning features or use of this software
                     16:  *    must display the following acknowledgement:
                     17:  *     This product includes software developed by Theo de Raadt.
                     18:  * 4. The name of the author may not be used to endorse or promote
1.2       deraadt    19:  *    products derived from this software without specific prior written
                     20:  *    permission.
                     21:  *
                     22:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
                     23:  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                     24:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     25:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
                     26:  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     27:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     28:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     29:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     30:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     31:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     32:  * SUCH DAMAGE.
                     33:  */
                     34:
1.10    ! thorpej    35: #include <sys/cdefs.h>
        !            36: #ifndef lint
        !            37: __RCSID("$NetBSD: ypmatch.c,v 1.9 1996/05/07 18:27:46 jtc Exp $");
1.2       deraadt    38: #endif
                     39:
1.1       deraadt    40: #include <sys/param.h>
                     41: #include <sys/types.h>
                     42: #include <sys/socket.h>
1.10    ! thorpej    43: #include <ctype.h>
        !            44: #include <err.h>
1.1       deraadt    45: #include <stdio.h>
1.5       cgd        46: #include <string.h>
1.10    ! thorpej    47: #include <unistd.h>
1.1       deraadt    48:
                     49: #include <rpc/rpc.h>
                     50: #include <rpc/xdr.h>
                     51: #include <rpcsvc/yp_prot.h>
                     52: #include <rpcsvc/ypclnt.h>
                     53:
1.10    ! thorpej    54: const struct ypalias {
1.1       deraadt    55:        char *alias, *name;
                     56: } ypaliases[] = {
                     57:        { "passwd", "passwd.byname" },
                     58:        { "group", "group.byname" },
                     59:        { "networks", "networks.byaddr" },
1.3       deraadt    60:        { "hosts", "hosts.byname" },
1.1       deraadt    61:        { "protocols", "protocols.bynumber" },
                     62:        { "services", "services.byname" },
                     63:        { "aliases", "mail.aliases" },
                     64:        { "ethers", "ethers.byname" },
                     65: };
                     66:
1.10    ! thorpej    67: int    main __P((int, char *[]));
        !            68: void   usage __P((void));
        !            69:
        !            70: extern char *__progname;
1.1       deraadt    71:
                     72: int
                     73: main(argc, argv)
1.10    ! thorpej    74:        int argc;
        !            75:        char *argv[];
1.1       deraadt    76: {
                     77:        char *domainname;
                     78:        char *inkey, *inmap, *outbuf;
                     79:        extern char *optarg;
                     80:        extern int optind;
                     81:        int outbuflen, key, notrans;
                     82:        int c, r, i;
1.8       jtc        83:        int rval;
1.1       deraadt    84:
1.9       jtc        85:        domainname = NULL;
1.1       deraadt    86:        notrans = key = 0;
1.10    ! thorpej    87:        while ((c = getopt(argc, argv, "xd:kt")) != -1) {
        !            88:                switch (c) {
1.1       deraadt    89:                case 'x':
1.10    ! thorpej    90:                        for(i = 0;
        !            91:                            i < sizeof(ypaliases)/sizeof(ypaliases[0]); i++)
1.1       deraadt    92:                                printf("Use \"%s\" for \"%s\"\n",
                     93:                                        ypaliases[i].alias,
                     94:                                        ypaliases[i].name);
                     95:                        exit(0);
1.10    ! thorpej    96:
1.1       deraadt    97:                case 'd':
                     98:                        domainname = optarg;
                     99:                        break;
1.10    ! thorpej   100:
1.1       deraadt   101:                case 't':
                    102:                        notrans++;
                    103:                        break;
1.10    ! thorpej   104:
1.1       deraadt   105:                case 'k':
                    106:                        key++;
                    107:                        break;
1.10    ! thorpej   108:
1.1       deraadt   109:                default:
                    110:                        usage();
                    111:                }
1.10    ! thorpej   112:        }
        !           113:
        !           114:        argc -= optind;
        !           115:        argv += optind;
1.1       deraadt   116:
1.10    ! thorpej   117:        if (argc < 2)
1.1       deraadt   118:                usage();
1.9       jtc       119:
1.10    ! thorpej   120:        if (domainname == NULL)
1.9       jtc       121:                yp_get_default_domain(&domainname);
1.1       deraadt   122:
1.10    ! thorpej   123:        inmap = argv[argc - 1];
        !           124:        if (notrans == 0) {
        !           125:                for (i = 0 ; i < sizeof(ypaliases)/sizeof(ypaliases[0]); i++)
        !           126:                        if (strcmp(inmap, ypaliases[i].alias) == 0)
1.6       jtc       127:                                inmap = ypaliases[i].name;
                    128:        }
1.8       jtc       129:
                    130:        rval = 0;
1.10    ! thorpej   131:        for(i = 0; i < (argc - 1); i++) {
        !           132:                inkey = argv[i];
1.1       deraadt   133:
1.10    ! thorpej   134:                r = yp_match(domainname, inmap, inkey, strlen(inkey),
        !           135:                    &outbuf, &outbuflen);
        !           136:                switch (r) {
1.1       deraadt   137:                case 0:
1.10    ! thorpej   138:                        if (key)
1.7       jtc       139:                                printf("%s: ", inkey);
1.1       deraadt   140:                        printf("%*.*s\n", outbuflen, outbuflen, outbuf);
                    141:                        break;
1.10    ! thorpej   142:
1.1       deraadt   143:                case YPERR_YPBIND:
1.10    ! thorpej   144:                        errx(1, "not running ypbind");
        !           145:
1.1       deraadt   146:                default:
1.10    ! thorpej   147:                        warnx("can't match key %s in map %s.  Reason: %s",
        !           148:                            inkey, inmap, yperr_string(r));
1.8       jtc       149:                        rval = 1;
1.1       deraadt   150:                        break;
                    151:                }
                    152:        }
1.8       jtc       153:
                    154:        exit(rval);
1.10    ! thorpej   155: }
        !           156:
        !           157: void
        !           158: usage()
        !           159: {
        !           160:
        !           161:        fprintf(stderr, "usage: %s [-d domain] [-t] [-k] key [key ...] "
        !           162:            "mapname\n", __progname);
        !           163:        fprintf(stderr, "       %s -x\n", __progname);
        !           164:        exit(1);
1.1       deraadt   165: }

CVSweb <webmaster@jp.NetBSD.org>