158f0484fSRodney W. Grimes /* 258f0484fSRodney W. Grimes * Copyright (c) 1980, 1993 358f0484fSRodney W. Grimes * The Regents of the University of California. All rights reserved. 458f0484fSRodney W. Grimes * 558f0484fSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 658f0484fSRodney W. Grimes * modification, are permitted provided that the following conditions 758f0484fSRodney W. Grimes * are met: 858f0484fSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 958f0484fSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 1058f0484fSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 1158f0484fSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 1258f0484fSRodney W. Grimes * documentation and/or other materials provided with the distribution. 1358f0484fSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 1458f0484fSRodney W. Grimes * may be used to endorse or promote products derived from this software 1558f0484fSRodney W. Grimes * without specific prior written permission. 1658f0484fSRodney W. Grimes * 1758f0484fSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1858f0484fSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1958f0484fSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2058f0484fSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2158f0484fSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2258f0484fSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2358f0484fSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2458f0484fSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2558f0484fSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2658f0484fSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2758f0484fSRodney W. Grimes * SUCH DAMAGE. 289c9c8212SKris Kennaway * 299c9c8212SKris Kennaway * $FreeBSD$ 3058f0484fSRodney W. Grimes */ 3158f0484fSRodney W. Grimes 3258f0484fSRodney W. Grimes #if defined(LIBC_SCCS) && !defined(lint) 3358f0484fSRodney W. Grimes static char sccsid[] = "@(#)rexec.c 8.1 (Berkeley) 6/4/93"; 3458f0484fSRodney W. Grimes #endif /* LIBC_SCCS and not lint */ 3558f0484fSRodney W. Grimes 3658f0484fSRodney W. Grimes #include <sys/types.h> 37f06a5580SPoul-Henning Kamp #include <sys/uio.h> 3858f0484fSRodney W. Grimes #include <sys/socket.h> 39bfb50190SJoerg Wunsch #include <sys/param.h> 40bfb50190SJoerg Wunsch #include <sys/stat.h> 4158f0484fSRodney W. Grimes 4258f0484fSRodney W. Grimes #include <netinet/in.h> 4358f0484fSRodney W. Grimes 4458f0484fSRodney W. Grimes #include <stdio.h> 45f06a5580SPoul-Henning Kamp #include <unistd.h> 46bfb50190SJoerg Wunsch #include <string.h> 4758f0484fSRodney W. Grimes #include <netdb.h> 4858f0484fSRodney W. Grimes #include <errno.h> 49bfb50190SJoerg Wunsch #include <ctype.h> 50bfb50190SJoerg Wunsch #include <err.h> 51bfb50190SJoerg Wunsch #include <stdlib.h> 52bfb50190SJoerg Wunsch #include <unistd.h> 5358f0484fSRodney W. Grimes 5458f0484fSRodney W. Grimes int rexecoptions; 5558f0484fSRodney W. Grimes char *getpass(), *getlogin(); 5658f0484fSRodney W. Grimes 57bfb50190SJoerg Wunsch /* 58bfb50190SJoerg Wunsch * Options and other state info. 59bfb50190SJoerg Wunsch */ 60bfb50190SJoerg Wunsch struct macel { 61bfb50190SJoerg Wunsch char mac_name[9]; /* macro name */ 62bfb50190SJoerg Wunsch char *mac_start; /* start of macro in macbuf */ 63bfb50190SJoerg Wunsch char *mac_end; /* end of macro in macbuf */ 64bfb50190SJoerg Wunsch }; 65bfb50190SJoerg Wunsch 66bfb50190SJoerg Wunsch int macnum; /* number of defined macros */ 67bfb50190SJoerg Wunsch struct macel macros[16]; 68bfb50190SJoerg Wunsch char macbuf[4096]; 69bfb50190SJoerg Wunsch 70bfb50190SJoerg Wunsch static FILE *cfile; 71bfb50190SJoerg Wunsch 72bfb50190SJoerg Wunsch #define DEFAULT 1 73bfb50190SJoerg Wunsch #define LOGIN 2 74bfb50190SJoerg Wunsch #define PASSWD 3 75bfb50190SJoerg Wunsch #define ACCOUNT 4 76bfb50190SJoerg Wunsch #define MACDEF 5 77bfb50190SJoerg Wunsch #define ID 10 78bfb50190SJoerg Wunsch #define MACH 11 79bfb50190SJoerg Wunsch 80bfb50190SJoerg Wunsch static char tokval[100]; 81bfb50190SJoerg Wunsch 82bfb50190SJoerg Wunsch static struct toktab { 83bfb50190SJoerg Wunsch char *tokstr; 84bfb50190SJoerg Wunsch int tval; 85bfb50190SJoerg Wunsch } toktab[]= { 86bfb50190SJoerg Wunsch { "default", DEFAULT }, 87bfb50190SJoerg Wunsch { "login", LOGIN }, 88bfb50190SJoerg Wunsch { "password", PASSWD }, 89bfb50190SJoerg Wunsch { "passwd", PASSWD }, 90bfb50190SJoerg Wunsch { "account", ACCOUNT }, 91bfb50190SJoerg Wunsch { "machine", MACH }, 92bfb50190SJoerg Wunsch { "macdef", MACDEF }, 93bfb50190SJoerg Wunsch { NULL, 0 } 94bfb50190SJoerg Wunsch }; 95bfb50190SJoerg Wunsch 96bfb50190SJoerg Wunsch static int 97bfb50190SJoerg Wunsch token() 98bfb50190SJoerg Wunsch { 99bfb50190SJoerg Wunsch char *cp; 100bfb50190SJoerg Wunsch int c; 101bfb50190SJoerg Wunsch struct toktab *t; 102bfb50190SJoerg Wunsch 103bfb50190SJoerg Wunsch if (feof(cfile) || ferror(cfile)) 104bfb50190SJoerg Wunsch return (0); 105bfb50190SJoerg Wunsch while ((c = getc(cfile)) != EOF && 106bfb50190SJoerg Wunsch (c == '\n' || c == '\t' || c == ' ' || c == ',')) 107bfb50190SJoerg Wunsch continue; 108bfb50190SJoerg Wunsch if (c == EOF) 109bfb50190SJoerg Wunsch return (0); 110bfb50190SJoerg Wunsch cp = tokval; 111bfb50190SJoerg Wunsch if (c == '"') { 112bfb50190SJoerg Wunsch while ((c = getc(cfile)) != EOF && c != '"') { 113bfb50190SJoerg Wunsch if (c == '\\') 114bfb50190SJoerg Wunsch c = getc(cfile); 115bfb50190SJoerg Wunsch *cp++ = c; 116bfb50190SJoerg Wunsch } 117bfb50190SJoerg Wunsch } else { 118bfb50190SJoerg Wunsch *cp++ = c; 119bfb50190SJoerg Wunsch while ((c = getc(cfile)) != EOF 120bfb50190SJoerg Wunsch && c != '\n' && c != '\t' && c != ' ' && c != ',') { 121bfb50190SJoerg Wunsch if (c == '\\') 122bfb50190SJoerg Wunsch c = getc(cfile); 123bfb50190SJoerg Wunsch *cp++ = c; 124bfb50190SJoerg Wunsch } 125bfb50190SJoerg Wunsch } 126bfb50190SJoerg Wunsch *cp = 0; 127bfb50190SJoerg Wunsch if (tokval[0] == 0) 128bfb50190SJoerg Wunsch return (0); 129bfb50190SJoerg Wunsch for (t = toktab; t->tokstr; t++) 130bfb50190SJoerg Wunsch if (!strcmp(t->tokstr, tokval)) 131bfb50190SJoerg Wunsch return (t->tval); 132bfb50190SJoerg Wunsch return (ID); 133bfb50190SJoerg Wunsch } 134bfb50190SJoerg Wunsch 135bfb50190SJoerg Wunsch static int 136bfb50190SJoerg Wunsch ruserpass(host, aname, apass, aacct) 137bfb50190SJoerg Wunsch char *host, **aname, **apass, **aacct; 138bfb50190SJoerg Wunsch { 139bfb50190SJoerg Wunsch char *hdir, buf[BUFSIZ], *tmp; 140bfb50190SJoerg Wunsch char myname[MAXHOSTNAMELEN], *mydomain; 141bfb50190SJoerg Wunsch int t, i, c, usedefault = 0; 142bfb50190SJoerg Wunsch struct stat stb; 143bfb50190SJoerg Wunsch 144bfb50190SJoerg Wunsch hdir = getenv("HOME"); 145bfb50190SJoerg Wunsch if (hdir == NULL) 146bfb50190SJoerg Wunsch hdir = "."; 1479c9c8212SKris Kennaway if (strlen(hdir) + 8 > sizeof(buf)) 1489c9c8212SKris Kennaway return (0); 149bfb50190SJoerg Wunsch (void) sprintf(buf, "%s/.netrc", hdir); 150bfb50190SJoerg Wunsch cfile = fopen(buf, "r"); 151bfb50190SJoerg Wunsch if (cfile == NULL) { 152bfb50190SJoerg Wunsch if (errno != ENOENT) 153bfb50190SJoerg Wunsch warn("%s", buf); 154bfb50190SJoerg Wunsch return (0); 155bfb50190SJoerg Wunsch } 156bfb50190SJoerg Wunsch if (gethostname(myname, sizeof(myname)) < 0) 157bfb50190SJoerg Wunsch myname[0] = '\0'; 158bfb50190SJoerg Wunsch if ((mydomain = strchr(myname, '.')) == NULL) 159bfb50190SJoerg Wunsch mydomain = ""; 160bfb50190SJoerg Wunsch next: 161bfb50190SJoerg Wunsch while ((t = token())) switch(t) { 162bfb50190SJoerg Wunsch 163bfb50190SJoerg Wunsch case DEFAULT: 164bfb50190SJoerg Wunsch usedefault = 1; 165bfb50190SJoerg Wunsch /* FALL THROUGH */ 166bfb50190SJoerg Wunsch 167bfb50190SJoerg Wunsch case MACH: 168bfb50190SJoerg Wunsch if (!usedefault) { 169bfb50190SJoerg Wunsch if (token() != ID) 170bfb50190SJoerg Wunsch continue; 171bfb50190SJoerg Wunsch /* 172bfb50190SJoerg Wunsch * Allow match either for user's input host name 173bfb50190SJoerg Wunsch * or official hostname. Also allow match of 174bfb50190SJoerg Wunsch * incompletely-specified host in local domain. 175bfb50190SJoerg Wunsch */ 176bfb50190SJoerg Wunsch if (strcasecmp(host, tokval) == 0) 177bfb50190SJoerg Wunsch goto match; 178bfb50190SJoerg Wunsch if ((tmp = strchr(host, '.')) != NULL && 179bfb50190SJoerg Wunsch strcasecmp(tmp, mydomain) == 0 && 180bfb50190SJoerg Wunsch strncasecmp(host, tokval, tmp - host) == 0 && 181bfb50190SJoerg Wunsch tokval[tmp - host] == '\0') 182bfb50190SJoerg Wunsch goto match; 183bfb50190SJoerg Wunsch continue; 184bfb50190SJoerg Wunsch } 185bfb50190SJoerg Wunsch match: 186bfb50190SJoerg Wunsch while ((t = token()) && t != MACH && t != DEFAULT) switch(t) { 187bfb50190SJoerg Wunsch 188bfb50190SJoerg Wunsch case LOGIN: 189bfb50190SJoerg Wunsch if (token()) 190*50a7cc95SPedro F. Giffuni if (*aname == NULL) { 191bfb50190SJoerg Wunsch *aname = malloc((unsigned) strlen(tokval) + 1); 192bfb50190SJoerg Wunsch (void) strcpy(*aname, tokval); 193bfb50190SJoerg Wunsch } else { 194bfb50190SJoerg Wunsch if (strcmp(*aname, tokval)) 195bfb50190SJoerg Wunsch goto next; 196bfb50190SJoerg Wunsch } 197bfb50190SJoerg Wunsch break; 198bfb50190SJoerg Wunsch case PASSWD: 199*50a7cc95SPedro F. Giffuni if ((*aname == NULL || strcmp(*aname, "anonymous")) && 200bfb50190SJoerg Wunsch fstat(fileno(cfile), &stb) >= 0 && 201bfb50190SJoerg Wunsch (stb.st_mode & 077) != 0) { 202bfb50190SJoerg Wunsch warnx("Error: .netrc file is readable by others."); 203bfb50190SJoerg Wunsch warnx("Remove password or make file unreadable by others."); 204bfb50190SJoerg Wunsch goto bad; 205bfb50190SJoerg Wunsch } 206*50a7cc95SPedro F. Giffuni if (token() && *apass == NULL) { 207bfb50190SJoerg Wunsch *apass = malloc((unsigned) strlen(tokval) + 1); 208bfb50190SJoerg Wunsch (void) strcpy(*apass, tokval); 209bfb50190SJoerg Wunsch } 210bfb50190SJoerg Wunsch break; 211bfb50190SJoerg Wunsch case ACCOUNT: 212bfb50190SJoerg Wunsch if (fstat(fileno(cfile), &stb) >= 0 213bfb50190SJoerg Wunsch && (stb.st_mode & 077) != 0) { 214bfb50190SJoerg Wunsch warnx("Error: .netrc file is readable by others."); 215bfb50190SJoerg Wunsch warnx("Remove account or make file unreadable by others."); 216bfb50190SJoerg Wunsch goto bad; 217bfb50190SJoerg Wunsch } 218*50a7cc95SPedro F. Giffuni if (token() && *aacct == NULL) { 219bfb50190SJoerg Wunsch *aacct = malloc((unsigned) strlen(tokval) + 1); 220bfb50190SJoerg Wunsch (void) strcpy(*aacct, tokval); 221bfb50190SJoerg Wunsch } 222bfb50190SJoerg Wunsch break; 223bfb50190SJoerg Wunsch case MACDEF: 224bfb50190SJoerg Wunsch while ((c=getc(cfile)) != EOF && 225bfb50190SJoerg Wunsch (c == ' ' || c == '\t')) 226bfb50190SJoerg Wunsch ; 227bfb50190SJoerg Wunsch if (c == EOF || c == '\n') { 228bfb50190SJoerg Wunsch printf("Missing macdef name argument.\n"); 229bfb50190SJoerg Wunsch goto bad; 230bfb50190SJoerg Wunsch } 231bfb50190SJoerg Wunsch if (macnum == 16) { 232bfb50190SJoerg Wunsch printf("Limit of 16 macros have already been defined\n"); 233bfb50190SJoerg Wunsch goto bad; 234bfb50190SJoerg Wunsch } 235bfb50190SJoerg Wunsch tmp = macros[macnum].mac_name; 236bfb50190SJoerg Wunsch *tmp++ = c; 237bfb50190SJoerg Wunsch for (i=0; i < 8 && (c=getc(cfile)) != EOF && 238bfb50190SJoerg Wunsch !isspace(c); ++i) { 239bfb50190SJoerg Wunsch *tmp++ = c; 240bfb50190SJoerg Wunsch } 241bfb50190SJoerg Wunsch if (c == EOF) { 242bfb50190SJoerg Wunsch printf("Macro definition missing null line terminator.\n"); 243bfb50190SJoerg Wunsch goto bad; 244bfb50190SJoerg Wunsch } 245bfb50190SJoerg Wunsch *tmp = '\0'; 246bfb50190SJoerg Wunsch if (c != '\n') { 247bfb50190SJoerg Wunsch while ((c=getc(cfile)) != EOF && c != '\n'); 248bfb50190SJoerg Wunsch } 249bfb50190SJoerg Wunsch if (c == EOF) { 250bfb50190SJoerg Wunsch printf("Macro definition missing null line terminator.\n"); 251bfb50190SJoerg Wunsch goto bad; 252bfb50190SJoerg Wunsch } 253bfb50190SJoerg Wunsch if (macnum == 0) { 254bfb50190SJoerg Wunsch macros[macnum].mac_start = macbuf; 255bfb50190SJoerg Wunsch } 256bfb50190SJoerg Wunsch else { 257bfb50190SJoerg Wunsch macros[macnum].mac_start = macros[macnum-1].mac_end + 1; 258bfb50190SJoerg Wunsch } 259bfb50190SJoerg Wunsch tmp = macros[macnum].mac_start; 260bfb50190SJoerg Wunsch while (tmp != macbuf + 4096) { 261bfb50190SJoerg Wunsch if ((c=getc(cfile)) == EOF) { 262bfb50190SJoerg Wunsch printf("Macro definition missing null line terminator.\n"); 263bfb50190SJoerg Wunsch goto bad; 264bfb50190SJoerg Wunsch } 265bfb50190SJoerg Wunsch *tmp = c; 266bfb50190SJoerg Wunsch if (*tmp == '\n') { 267bfb50190SJoerg Wunsch if (*(tmp-1) == '\0') { 268bfb50190SJoerg Wunsch macros[macnum++].mac_end = tmp - 1; 269bfb50190SJoerg Wunsch break; 270bfb50190SJoerg Wunsch } 271bfb50190SJoerg Wunsch *tmp = '\0'; 272bfb50190SJoerg Wunsch } 273bfb50190SJoerg Wunsch tmp++; 274bfb50190SJoerg Wunsch } 275bfb50190SJoerg Wunsch if (tmp == macbuf + 4096) { 276bfb50190SJoerg Wunsch printf("4K macro buffer exceeded\n"); 277bfb50190SJoerg Wunsch goto bad; 278bfb50190SJoerg Wunsch } 279bfb50190SJoerg Wunsch break; 280bfb50190SJoerg Wunsch default: 281bfb50190SJoerg Wunsch warnx("Unknown .netrc keyword %s", tokval); 282bfb50190SJoerg Wunsch break; 283bfb50190SJoerg Wunsch } 284bfb50190SJoerg Wunsch goto done; 285bfb50190SJoerg Wunsch } 286bfb50190SJoerg Wunsch done: 287bfb50190SJoerg Wunsch (void) fclose(cfile); 288bfb50190SJoerg Wunsch return (0); 289bfb50190SJoerg Wunsch bad: 290bfb50190SJoerg Wunsch (void) fclose(cfile); 291bfb50190SJoerg Wunsch return (-1); 292bfb50190SJoerg Wunsch } 293bfb50190SJoerg Wunsch 29451295a4dSJordan K. Hubbard int 29558f0484fSRodney W. Grimes rexec(ahost, rport, name, pass, cmd, fd2p) 29658f0484fSRodney W. Grimes char **ahost; 29758f0484fSRodney W. Grimes int rport; 29858f0484fSRodney W. Grimes char *name, *pass, *cmd; 29958f0484fSRodney W. Grimes int *fd2p; 30058f0484fSRodney W. Grimes { 30158f0484fSRodney W. Grimes struct sockaddr_in sin, sin2, from; 30258f0484fSRodney W. Grimes struct hostent *hp; 30358f0484fSRodney W. Grimes u_short port; 30458f0484fSRodney W. Grimes int s, timo = 1, s3; 305b9c4b6b4SRoman Divacky char c, *acct; 30658f0484fSRodney W. Grimes 30758f0484fSRodney W. Grimes hp = gethostbyname(*ahost); 308*50a7cc95SPedro F. Giffuni if (hp == NULL) { 30958f0484fSRodney W. Grimes herror(*ahost); 31058f0484fSRodney W. Grimes return (-1); 31158f0484fSRodney W. Grimes } 31258f0484fSRodney W. Grimes *ahost = hp->h_name; 313b9c4b6b4SRoman Divacky acct = NULL; 314b9c4b6b4SRoman Divacky ruserpass(hp->h_name, &name, &pass, &acct); 315b9c4b6b4SRoman Divacky free(acct); 31658f0484fSRodney W. Grimes retry: 31758f0484fSRodney W. Grimes s = socket(AF_INET, SOCK_STREAM, 0); 31858f0484fSRodney W. Grimes if (s < 0) { 31958f0484fSRodney W. Grimes perror("rexec: socket"); 32058f0484fSRodney W. Grimes return (-1); 32158f0484fSRodney W. Grimes } 32258f0484fSRodney W. Grimes sin.sin_family = hp->h_addrtype; 32358f0484fSRodney W. Grimes sin.sin_port = rport; 32458f0484fSRodney W. Grimes bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length); 32558f0484fSRodney W. Grimes if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { 32658f0484fSRodney W. Grimes if (errno == ECONNREFUSED && timo <= 16) { 32758f0484fSRodney W. Grimes (void) close(s); 32858f0484fSRodney W. Grimes sleep(timo); 32958f0484fSRodney W. Grimes timo *= 2; 33058f0484fSRodney W. Grimes goto retry; 33158f0484fSRodney W. Grimes } 33258f0484fSRodney W. Grimes perror(hp->h_name); 33358f0484fSRodney W. Grimes return (-1); 33458f0484fSRodney W. Grimes } 33558f0484fSRodney W. Grimes port = 0; 33646bf2f53SPedro F. Giffuni if (fd2p == 0) 33746bf2f53SPedro F. Giffuni (void) write(s, "", 1); 33846bf2f53SPedro F. Giffuni else { 33958f0484fSRodney W. Grimes char num[8]; 34058f0484fSRodney W. Grimes int s2, sin2len; 34158f0484fSRodney W. Grimes 34258f0484fSRodney W. Grimes s2 = socket(AF_INET, SOCK_STREAM, 0); 34358f0484fSRodney W. Grimes if (s2 < 0) { 34458f0484fSRodney W. Grimes (void) close(s); 34558f0484fSRodney W. Grimes return (-1); 34658f0484fSRodney W. Grimes } 34758f0484fSRodney W. Grimes listen(s2, 1); 34858f0484fSRodney W. Grimes sin2len = sizeof (sin2); 34958f0484fSRodney W. Grimes if (getsockname(s2, (struct sockaddr *)&sin2, &sin2len) < 0 || 35058f0484fSRodney W. Grimes sin2len != sizeof (sin2)) { 35158f0484fSRodney W. Grimes perror("getsockname"); 35258f0484fSRodney W. Grimes (void) close(s2); 35358f0484fSRodney W. Grimes goto bad; 35458f0484fSRodney W. Grimes } 35558f0484fSRodney W. Grimes port = ntohs((u_short)sin2.sin_port); 35658f0484fSRodney W. Grimes (void) sprintf(num, "%u", port); 35758f0484fSRodney W. Grimes (void) write(s, num, strlen(num)+1); 35858f0484fSRodney W. Grimes { int len = sizeof (from); 35958f0484fSRodney W. Grimes s3 = accept(s2, (struct sockaddr *)&from, &len); 36058f0484fSRodney W. Grimes close(s2); 36158f0484fSRodney W. Grimes if (s3 < 0) { 36258f0484fSRodney W. Grimes perror("accept"); 36358f0484fSRodney W. Grimes port = 0; 36458f0484fSRodney W. Grimes goto bad; 36558f0484fSRodney W. Grimes } 36658f0484fSRodney W. Grimes } 36758f0484fSRodney W. Grimes *fd2p = s3; 36858f0484fSRodney W. Grimes } 36958f0484fSRodney W. Grimes (void) write(s, name, strlen(name) + 1); 37058f0484fSRodney W. Grimes /* should public key encypt the password here */ 37158f0484fSRodney W. Grimes (void) write(s, pass, strlen(pass) + 1); 37258f0484fSRodney W. Grimes (void) write(s, cmd, strlen(cmd) + 1); 37358f0484fSRodney W. Grimes if (read(s, &c, 1) != 1) { 37458f0484fSRodney W. Grimes perror(*ahost); 37558f0484fSRodney W. Grimes goto bad; 37658f0484fSRodney W. Grimes } 37758f0484fSRodney W. Grimes if (c != 0) { 37858f0484fSRodney W. Grimes while (read(s, &c, 1) == 1) { 37958f0484fSRodney W. Grimes (void) write(2, &c, 1); 38058f0484fSRodney W. Grimes if (c == '\n') 38158f0484fSRodney W. Grimes break; 38258f0484fSRodney W. Grimes } 38358f0484fSRodney W. Grimes goto bad; 38458f0484fSRodney W. Grimes } 38558f0484fSRodney W. Grimes return (s); 38658f0484fSRodney W. Grimes bad: 38758f0484fSRodney W. Grimes if (port) 38858f0484fSRodney W. Grimes (void) close(*fd2p); 38958f0484fSRodney W. Grimes (void) close(s); 39058f0484fSRodney W. Grimes return (-1); 39158f0484fSRodney W. Grimes } 392