]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/sbr/ruserpass.c
2 * Copyright (c) 1985 Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 static char sccsid
[] = "@(#)ruserpass.c 5.1 (Berkeley) 3/1/89";
22 #include <sys/types.h>
30 char *malloc(), *index(), *getenv(), *getpass(), *getlogin();
34 #ifndef MAXHOSTNAMELEN
35 #define MAXHOSTNAMELEN 64
47 static char tokval
[100];
49 static struct toktab
{
63 ruserpass(host
, aname
, apass
)
64 char *host
, **aname
, **apass
;
66 char *hdir
, buf
[BUFSIZ
], *tmp
;
67 char myname
[MAXHOSTNAMELEN
], *mydomain
;
68 int t
, i
, c
, usedefault
= 0;
72 hdir
= getenv("HOME");
75 (void) sprintf(buf
, "%s/.netrc", hdir
);
76 cfile
= fopen(buf
, "r");
83 while ((t
= token())) switch(t
) {
93 * Allow match either for user's host name.
95 if (strcasecmp(host
, tokval
) == 0)
100 while ((t
= token()) && t
!= MACH
&& t
!= DEFAULT
) switch(t
) {
103 if (token() && *aname
== 0) {
104 *aname
= malloc((unsigned) strlen(tokval
) + 1);
105 (void) strcpy(*aname
, tokval
);
109 if (fstat(fileno(cfile
), &stb
) >= 0 &&
110 (stb
.st_mode
& 077) != 0) {
111 fprintf(stderr
, "Error - .netrc file not correct mode.\n");
112 fprintf(stderr
, "Remove password or correct mode.\n");
115 if (token() && *apass
== 0) {
116 *apass
= malloc((unsigned) strlen(tokval
) + 1);
117 (void) strcpy(*apass
, tokval
);
127 fprintf(stderr
, "Unknown .netrc keyword %s\n", tokval
);
134 (void) fclose(cfile
);
141 if ((myname
= getlogin()) == NULL
) {
144 if ((pp
= getpwuid (getuid())) != NULL
)
145 myname
= pp
->pw_name
;
147 printf("Name (%s:%s): ", host
, myname
);
149 (void) fgets(tmp
, sizeof(tmp
) - 1, stdin
);
150 tmp
[strlen(tmp
) - 1] = '\0';
155 *aname
= malloc((unsigned) strlen(myname
) + 1);
156 strcpy (*aname
, myname
);
163 sprintf(prompt
, "Password (%s:%s): ", host
, *aname
);
164 mypass
= getpass (prompt
);
166 if (*mypass
== '\0') {
170 *apass
= malloc((unsigned) strlen(mypass
) + 1);
171 strcpy (*apass
, mypass
);
176 (void) fclose(cfile
);
189 while ((c
= getc(cfile
)) != EOF
&&
190 (c
== '\n' || c
== '\t' || c
== ' ' || c
== ','))
196 while ((c
= getc(cfile
)) != EOF
&& c
!= '"') {
203 while ((c
= getc(cfile
)) != EOF
204 && c
!= '\n' && c
!= '\t' && c
!= ' ' && c
!= ',') {
213 for (t
= toktab
; t
->tokstr
; t
++)
214 if (!strcmp(t
->tokstr
, tokval
))