10 date 97.04.11.19.49.50; author shettich; state Exp;
25 * Copyright (c) 1985 Regents of the University of California.
26 * All rights reserved.
28 * Redistribution and use in source and binary forms are permitted
29 * provided that the above copyright notice and this paragraph are
30 * duplicated in all such forms and that any documentation,
31 * advertising materials, and other materials related to such
32 * distribution and use acknowledge that the software was developed
33 * by the University of California, Berkeley. The name of the
34 * University may not be used to endorse or promote products derived
35 * from this software without specific prior written permission.
36 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
37 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
38 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 static char sccsid[] = "@@(#)ruserpass.c 5.1 (Berkeley) 3/1/89";
45 #include <sys/types.h>
52 char *malloc(), *index(), *getenv(), *getpass(), *getlogin();
56 #ifndef MAXHOSTNAMELEN
57 #define MAXHOSTNAMELEN 64
69 static char tokval[100];
71 static struct toktab {
85 ruserpass(host, aname, apass)
86 char *host, **aname, **apass;
88 char *hdir, buf[BUFSIZ], *tmp;
89 char myname[MAXHOSTNAMELEN], *mydomain;
90 int t, i, c, usedefault = 0;
94 hdir = getenv("HOME");
97 (void) sprintf(buf, "%s/.netrc", hdir);
98 cfile = fopen(buf, "r");
105 while ((t = token())) switch(t) {
115 * Allow match either for user's host name.
117 if (strcasecmp(host, tokval) == 0)
122 while ((t = token()) && t != MACH && t != DEFAULT) switch(t) {
125 if (token() && *aname == 0) {
126 *aname = malloc((unsigned) strlen(tokval) + 1);
127 (void) strcpy(*aname, tokval);
131 if (fstat(fileno(cfile), &stb) >= 0 &&
132 (stb.st_mode & 077) != 0) {
133 fprintf(stderr, "Error - .netrc file not correct mode.\n");
134 fprintf(stderr, "Remove password or correct mode.\n");
137 if (token() && *apass == 0) {
138 *apass = malloc((unsigned) strlen(tokval) + 1);
139 (void) strcpy(*apass, tokval);
149 fprintf(stderr, "Unknown .netrc keyword %s\n", tokval);
156 (void) fclose(cfile);
163 if ((myname = getlogin()) == NULL) {
166 if ((pp = getpwuid (getuid())) != NULL)
167 myname = pp->pw_name;
169 printf("Name (%s:%s): ", host, myname);
171 (void) fgets(tmp, sizeof(tmp) - 1, stdin);
172 tmp[strlen(tmp) - 1] = '\0';
177 *aname = malloc((unsigned) strlen(myname) + 1);
178 strcpy (*aname, myname);
185 sprintf(prompt, "Password (%s:%s): ", host, *aname);
186 mypass = getpass (prompt);
188 if (*mypass == '\0') {
192 *apass = malloc((unsigned) strlen(mypass) + 1);
193 strcpy (*apass, mypass);
198 (void) fclose(cfile);
211 while ((c = getc(cfile)) != EOF &&
212 (c == '\n' || c == '\t' || c == ' ' || c == ','))
218 while ((c = getc(cfile)) != EOF && c != '"') {
225 while ((c = getc(cfile)) != EOF
226 && c != '\n' && c != '\t' && c != ' ' && c != ',') {
235 for (t = toktab; t->tokstr; t++)
236 if (!strcmp(t->tokstr, tokval))