/*
- * Copyright (c) 1985, 1993
+ * Copyright (c) 1985, 1993, 1994
* 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
-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>
-#include <stdio.h>
-#include <utmp.h>
-#include <ctype.h>
#include <sys/stat.h>
+
+#include <ctype.h>
+#include <err.h>
#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.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
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;
{
char myname[MAXHOSTNAMELEN], *mydomain;
int t, i, c, usedefault = 0;
struct stat stb;
- static int token();
hdir = getenv("HOME");
if (hdir == NULL)
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 ((mydomain = index(myname, '.')) == NULL)
+ if ((mydomain = strchr(myname, '.')) == NULL)
mydomain = "";
next:
while ((t = token())) switch(t) {
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;
- if ((tmp = index(host, '.')) != NULL &&
+ if ((tmp = strchr(host, '.')) != NULL &&
strcasecmp(tmp, mydomain) == 0 &&
strncasecmp(host, tokval, tmp - host) == 0 &&
tokval[tmp - host] == '\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) {
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) {
case MACDEF:
if (proxy) {
(void) fclose(cfile);
- return(0);
+ return (0);
}
while ((c=getc(cfile)) != EOF && c == ' ' || c == '\t');
if (c == EOF || c == '\n') {
}
break;
default:
- fprintf(stderr, "Unknown .netrc keyword %s\n", tokval);
+ warnx("Unknown .netrc keyword %s", tokval);
break;
}
goto done;
}
done:
(void) fclose(cfile);
- return(0);
+ return (0);
bad:
(void) fclose(cfile);
- return(-1);
+ return (-1);
}
-static
+static int
token()
{
char *cp;