BSD 4_4_Lite1 release
[unix-history] / usr / src / usr.bin / ftp / ruserpass.c
index 897a6bf..07bb1f4 100644 (file)
@@ -1,25 +1,54 @@
 /*
 /*
- * Copyright (c) 1985, 1993
+ * Copyright (c) 1985, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  *     The Regents of the University of California.  All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ruserpass.c        8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)ruserpass.c        8.3 (Berkeley) 4/2/94";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
-#include <stdio.h>
-#include <utmp.h>
-#include <ctype.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
+
+#include <ctype.h>
+#include <err.h>
 #include <errno.h>
 #include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include "ftp_var.h"
 
 #include "ftp_var.h"
 
-char   *renvlook(), *malloc(), *index(), *getenv(), *getpass(), *getlogin();
-char   *strcpy();
-struct utmp *getutmp();
+static int token __P((void));
 static FILE *cfile;
 
 #define        DEFAULT 1
 static FILE *cfile;
 
 #define        DEFAULT 1
@@ -36,16 +65,17 @@ static struct toktab {
        char *tokstr;
        int tval;
 } toktab[]= {
        char *tokstr;
        int tval;
 } toktab[]= {
-       "default",      DEFAULT,
-       "login",        LOGIN,
-       "password",     PASSWD,
-       "passwd",       PASSWD,
-       "account",      ACCOUNT,
-       "machine",      MACH,
-       "macdef",       MACDEF,
-       0,              0
+       { "default",    DEFAULT },
+       { "login",      LOGIN },
+       { "password",   PASSWD },
+       { "passwd",     PASSWD },
+       { "account",    ACCOUNT },
+       { "machine",    MACH },
+       { "macdef",     MACDEF },
+       { NULL,         0 }
 };
 
 };
 
+int
 ruserpass(host, aname, apass, aacct)
        char *host, **aname, **apass, **aacct;
 {
 ruserpass(host, aname, apass, aacct)
        char *host, **aname, **apass, **aacct;
 {
@@ -53,7 +83,6 @@ ruserpass(host, aname, apass, aacct)
        char myname[MAXHOSTNAMELEN], *mydomain;
        int t, i, c, usedefault = 0;
        struct stat stb;
        char myname[MAXHOSTNAMELEN], *mydomain;
        int t, i, c, usedefault = 0;
        struct stat stb;
-       static int token();
 
        hdir = getenv("HOME");
        if (hdir == NULL)
 
        hdir = getenv("HOME");
        if (hdir == NULL)
@@ -62,12 +91,12 @@ ruserpass(host, aname, apass, aacct)
        cfile = fopen(buf, "r");
        if (cfile == NULL) {
                if (errno != ENOENT)
        cfile = fopen(buf, "r");
        if (cfile == NULL) {
                if (errno != ENOENT)
-                       perror(buf);
-               return(0);
+                       warn("%s", buf);
+               return (0);
        }
        if (gethostname(myname, sizeof(myname)) < 0)
                myname[0] = '\0';
        }
        if (gethostname(myname, sizeof(myname)) < 0)
                myname[0] = '\0';
-       if ((mydomain = index(myname, '.')) == NULL)
+       if ((mydomain = strchr(myname, '.')) == NULL)
                mydomain = "";
 next:
        while ((t = token())) switch(t) {
                mydomain = "";
 next:
        while ((t = token())) switch(t) {
@@ -89,12 +118,12 @@ next:
                                goto match;
                        if (strcasecmp(hostname, tokval) == 0)
                                goto match;
                                goto match;
                        if (strcasecmp(hostname, tokval) == 0)
                                goto match;
-                       if ((tmp = index(hostname, '.')) != NULL &&
+                       if ((tmp = strchr(hostname, '.')) != NULL &&
                            strcasecmp(tmp, mydomain) == 0 &&
                            strncasecmp(hostname, tokval, tmp-hostname) == 0 &&
                            tokval[tmp - hostname] == '\0')
                                goto match;
                            strcasecmp(tmp, mydomain) == 0 &&
                            strncasecmp(hostname, tokval, tmp-hostname) == 0 &&
                            tokval[tmp - hostname] == '\0')
                                goto match;
-                       if ((tmp = index(host, '.')) != NULL &&
+                       if ((tmp = strchr(host, '.')) != NULL &&
                            strcasecmp(tmp, mydomain) == 0 &&
                            strncasecmp(host, tokval, tmp - host) == 0 &&
                            tokval[tmp - host] == '\0')
                            strcasecmp(tmp, mydomain) == 0 &&
                            strncasecmp(host, tokval, tmp - host) == 0 &&
                            tokval[tmp - host] == '\0')
@@ -118,9 +147,8 @@ next:
                        if (strcmp(*aname, "anonymous") &&
                            fstat(fileno(cfile), &stb) >= 0 &&
                            (stb.st_mode & 077) != 0) {
                        if (strcmp(*aname, "anonymous") &&
                            fstat(fileno(cfile), &stb) >= 0 &&
                            (stb.st_mode & 077) != 0) {
-       fprintf(stderr, "Error: .netrc file is readable by others.\n");
-       fprintf(stderr, 
-               "Remove password or make file unreadable by others.\n\n");
+       warnx("Error: .netrc file is readable by others.");
+       warnx("Remove password or make file unreadable by others.");
                                goto bad;
                        }
                        if (token() && *apass == 0) {
                                goto bad;
                        }
                        if (token() && *apass == 0) {
@@ -131,9 +159,8 @@ next:
                case ACCOUNT:
                        if (fstat(fileno(cfile), &stb) >= 0
                            && (stb.st_mode & 077) != 0) {
                case ACCOUNT:
                        if (fstat(fileno(cfile), &stb) >= 0
                            && (stb.st_mode & 077) != 0) {
-       fprintf(stderr, "Error: .netrc file is readable by others.\n");
-       fprintf(stderr, 
-               "Remove account or make file unreadable by others.\n\n");
+       warnx("Error: .netrc file is readable by others.");
+       warnx("Remove account or make file unreadable by others.");
                                goto bad;
                        }
                        if (token() && *aacct == 0) {
                                goto bad;
                        }
                        if (token() && *aacct == 0) {
@@ -144,7 +171,7 @@ next:
                case MACDEF:
                        if (proxy) {
                                (void) fclose(cfile);
                case MACDEF:
                        if (proxy) {
                                (void) fclose(cfile);
-                               return(0);
+                               return (0);
                        }
                        while ((c=getc(cfile)) != EOF && c == ' ' || c == '\t');
                        if (c == EOF || c == '\n') {
                        }
                        while ((c=getc(cfile)) != EOF && c == ' ' || c == '\t');
                        if (c == EOF || c == '\n') {
@@ -201,20 +228,20 @@ next:
                        }
                        break;
                default:
                        }
                        break;
                default:
-       fprintf(stderr, "Unknown .netrc keyword %s\n", tokval);
+                       warnx("Unknown .netrc keyword %s", tokval);
                        break;
                }
                goto done;
        }
 done:
        (void) fclose(cfile);
                        break;
                }
                goto done;
        }
 done:
        (void) fclose(cfile);
-       return(0);
+       return (0);
 bad:
        (void) fclose(cfile);
 bad:
        (void) fclose(cfile);
-       return(-1);
+       return (-1);
 }
 
 }
 
-static
+static int
 token()
 {
        char *cp;
 token()
 {
        char *cp;