]>
diplodocus.org Git - nmh/blob - 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.
26 #ifndef MAXHOSTNAMELEN
27 # define MAXHOSTNAMELEN 64
38 static char tokval
[100];
45 static struct toktab toktabs
[] = {
46 { "default", DEFAULT
},
48 { "password", PASSWD
},
50 { "account", ACCOUNT
},
59 static int token(void);
63 ruserpass(char *host
, char **aname
, char **apass
)
65 char *hdir
, buf
[BUFSIZ
];
66 int t
, usedefault
= 0;
70 hdir
= getenv("HOME");
73 snprintf(buf
, sizeof(buf
), "%s/.netrc", hdir
);
74 cfile
= fopen(buf
, "r");
81 while ((t
= token())) {
92 * Allow match either for user's host name.
94 if (strcasecmp(host
, tokval
) == 0)
99 while ((t
= token()) && t
!= MACH
&& t
!= DEFAULT
) {
102 if (token() && *aname
== 0) {
103 *aname
= malloc((size_t) strlen(tokval
) + 1);
104 strcpy(*aname
, tokval
);
108 if (fstat(fileno(cfile
), &stb
) >= 0 &&
109 (stb
.st_mode
& 077) != 0) {
110 fprintf(stderr
, "Error - .netrc file not correct mode.\n");
111 fprintf(stderr
, "Remove password or correct mode.\n");
114 if (token() && *apass
== 0) {
115 *apass
= malloc((size_t) strlen(tokval
) + 1);
116 strcpy(*apass
, tokval
);
126 fprintf(stderr
, "Unknown .netrc keyword %s\n", tokval
);
142 if ((myname
= getlogin()) == NULL
) {
145 if ((pp
= getpwuid (getuid())) != NULL
)
146 myname
= pp
->pw_name
;
148 printf("Name (%s:%s): ", host
, myname
);
150 fgets(tmp
, sizeof(tmp
) - 1, stdin
);
151 tmp
[strlen(tmp
) - 1] = '\0';
156 *aname
= malloc((size_t) strlen(myname
) + 1);
157 strcpy (*aname
, myname
);
164 snprintf(prompt
, sizeof(prompt
), "Password (%s:%s): ", host
, *aname
);
165 mypass
= (char *)getpass (prompt
);
167 if (*mypass
== '\0') {
171 *apass
= malloc((size_t) strlen(mypass
) + 1);
172 strcpy (*apass
, mypass
);
190 while ((c
= getc(cfile
)) != EOF
&&
191 (c
== '\n' || c
== '\t' || c
== ' ' || c
== ','))
197 while ((c
= getc(cfile
)) != EOF
&& c
!= '"') {
204 while ((c
= getc(cfile
)) != EOF
205 && c
!= '\n' && c
!= '\t' && c
!= ' ' && c
!= ',') {
214 for (t
= toktabs
; t
->tokstr
; t
++)
215 if (!strcmp(t
->tokstr
, tokval
))