[BACK]Return to krcmd.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rsh

Annotation of src/usr.bin/rsh/krcmd.c, Revision 1.2

1.2     ! deraadt     1: /*     $OpenBSD: krcmd.c,v 1.1 2002/05/06 22:23:53 deraadt Exp $       */
1.1       deraadt     2: /*     $NetBSD: krcmd.c,v 1.2 1995/03/21 07:58:36 cgd Exp $    */
                      3:
                      4: /*
                      5:  * Copyright (c) 1989, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *     This product includes software developed by the University of
                     19:  *     California, Berkeley and its contributors.
                     20:  * 4. Neither the name of the University nor the names of its contributors
                     21:  *    may be used to endorse or promote products derived from this software
                     22:  *    without specific prior written permission.
                     23:  *
                     24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     34:  * SUCH DAMAGE.
                     35:  */
                     36:
                     37: #ifndef lint
                     38: #if 0
                     39: static char sccsid[] = "@(#)krcmd.c    8.1 (Berkeley) 6/6/93";
                     40: #else
1.2     ! deraadt    41: static char rcsid[] = "$OpenBSD: krcmd.c,v 1.1 2002/05/06 22:23:53 deraadt Exp $";
1.1       deraadt    42: #endif
                     43: #endif /* not lint */
                     44:
                     45: /*
                     46:  *     $Header: /mit/kerberos/ucb/mit/kcmd/RCS/krcmd.c,v 5.1
                     47:  *             89/07/25 15:38:44 kfall Exp Locker: kfall
                     48:  */
                     49:
                     50: #ifdef KERBEROS
                     51: #include <sys/types.h>
                     52: #include <sys/socket.h>
                     53:
                     54: #include <netinet/in.h>
                     55:
                     56: #include <des.h>
                     57: #include <kerberosIV/krb.h>
                     58:
                     59: #include <stdio.h>
                     60:
                     61: #define        SERVICE_NAME    "rcmd"
                     62:
                     63: int    kcmd(int *, char **, u_short, char *, char *, char *, int *,
                     64:            KTEXT, char *, char *, CREDENTIALS *, Key_schedule, MSG_DAT *,
                     65:            struct sockaddr_in *, struct sockaddr_in *, long);
                     66: int    krcmd(char **, u_short, char *, char *, int *, char *);
                     67: int    krcmd_mutual(char **, u_short, char *, char *, int *, char *,
                     68:            CREDENTIALS *, Key_schedule);
                     69:
                     70: /*
                     71:  * krcmd: simplified version of Athena's "kcmd"
                     72:  *     returns a socket attached to the destination, -1 or krb error on error
                     73:  *     if fd2p is non-NULL, another socket is filled in for it
                     74:  */
                     75: int
1.2     ! deraadt    76: krcmd(char **ahost, u_short rport, char *remuser, char *cmd, int *fd2p,
        !            77:     char *realm)
1.1       deraadt    78: {
1.2     ! deraadt    79:        int sock = -1, err = 0;
1.1       deraadt    80:        char myrealm[REALM_SZ];
1.2     ! deraadt    81:        long authopts = 0L;
        !            82:        KTEXT_ST ticket;
1.1       deraadt    83:
1.2     ! deraadt    84:        err = kcmd(&sock, ahost, rport, NULL, remuser, cmd, fd2p,
        !            85:            &ticket, SERVICE_NAME, realm, (CREDENTIALS *) NULL,
        !            86:            (void *) NULL, (MSG_DAT *) NULL, (struct sockaddr_in *) NULL,
        !            87:            (struct sockaddr_in *) NULL, authopts);
1.1       deraadt    88:
                     89:        if (err > KSUCCESS && err < MAX_KRB_ERRORS) {
                     90:                if (krb_get_lrealm(myrealm, 0) == KSUCCESS)
                     91:                        fprintf(stderr, "krcmd: %s\n", krb_err_txt[err]);
                     92:                return(-1);
                     93:        }
                     94:        if (err < 0)
                     95:                return(-1);
                     96:        return(sock);
                     97: }
                     98:
                     99: int
1.2     ! deraadt   100: krcmd_mutual(char **ahost, u_short rport, char *remuser, char *cmd, int *fd2p,
        !           101:     char *realm, CREDENTIALS *cred, Key_schedule sched)
1.1       deraadt   102: {
1.2     ! deraadt   103:        struct sockaddr_in laddr, faddr;
1.1       deraadt   104:        long authopts = KOPT_DO_MUTUAL;
                    105:        char myrealm[REALM_SZ];
1.2     ! deraadt   106:        KTEXT_ST ticket;
        !           107:        MSG_DAT msg_dat;
        !           108:        int sock, err;
        !           109:
        !           110:        err = kcmd(&sock, ahost, rport, NULL, remuser, cmd, fd2p,
        !           111:            &ticket, SERVICE_NAME, realm, cred, sched, &msg_dat,
        !           112:            &laddr, &faddr, authopts);
1.1       deraadt   113:
                    114:        if (err > KSUCCESS && err < MAX_KRB_ERRORS) {
                    115:                if (krb_get_lrealm(myrealm, 0) == KSUCCESS)
                    116:                        fprintf(stderr, "krcmd_mutual: %s\n", krb_err_txt[err]);
                    117:                return(-1);
                    118:        }
                    119:
                    120:        if (err < 0)
                    121:                return (-1);
                    122:        return(sock);
                    123: }
                    124: #endif /* KERBEROS */