[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.3

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