* Copyright (c) 1985 Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)ruserpass.c 5.2 (Berkeley) %G%";
char *renvlook(), *malloc(), *index(), *getenv(), *getpass(), *getlogin();
ruserpass(host
, aname
, apass
, aacct
)
char *host
, **aname
, **apass
, **aacct
;
char *hdir
, buf
[BUFSIZ
], *tmp
;
char myname
[MAXHOSTNAMELEN
], *mydomain
;
int t
, i
, c
, usedefault
= 0;
(void) sprintf(buf
, "%s/.netrc", hdir
);
if (gethostname(myname
, sizeof(myname
)) < 0)
if ((mydomain
= index(myname
, '.')) == NULL
)
while ((t
= token())) switch(t
) {
* Allow match either for user's input host name
* or official hostname. Also allow match of
* incompletely-specified host in local domain.
if (strcasecmp(host
, tokval
) == 0)
if (strcasecmp(hostname
, tokval
) == 0)
if ((tmp
= index(hostname
, '.')) != NULL
&&
strcasecmp(tmp
, mydomain
) == 0 &&
strncasecmp(hostname
, tokval
, tmp
-hostname
) == 0 &&
tokval
[tmp
- hostname
] == '\0')
if ((tmp
= index(host
, '.')) != NULL
&&
strcasecmp(tmp
, mydomain
) == 0 &&
strncasecmp(host
, tokval
, tmp
- host
) == 0 &&
tokval
[tmp
- host
] == '\0')
while ((t
= token()) && t
!= MACH
&& t
!= DEFAULT
) switch(t
) {
*aname
= malloc((unsigned) strlen(tokval
) + 1);
(void) strcpy(*aname
, tokval
);
if (strcmp(*aname
, tokval
))
if (strcmp(*aname
, "anonymous") &&
fstat(fileno(cfile
), &stb
) >= 0 &&
(stb
.st_mode
& 077) != 0) {
fprintf(stderr
, "Error - .netrc file not correct mode.\n");
fprintf(stderr
, "Remove password or correct mode.\n");
if (token() && *apass
== 0) {
*apass
= malloc((unsigned) strlen(tokval
) + 1);
(void) strcpy(*apass
, tokval
);
if (fstat(fileno(cfile
), &stb
) >= 0
&& (stb
.st_mode
& 077) != 0) {
fprintf(stderr
, "Error - .netrc file not correct mode.\n");
fprintf(stderr
, "Remove account or correct mode.\n");
if (token() && *aacct
== 0) {
*aacct
= malloc((unsigned) strlen(tokval
) + 1);
(void) strcpy(*aacct
, tokval
);
while ((c
=getc(cfile
)) != EOF
&& c
== ' ' || c
== '\t');
if (c
== EOF
|| c
== '\n') {
printf("Missing macdef name argument.\n");
printf("Limit of 16 macros have already been defined\n");
tmp
= macros
[macnum
].mac_name
;
for (i
=0; i
< 8 && (c
=getc(cfile
)) != EOF
&&
printf("Macro definition missing null line terminator.\n");
while ((c
=getc(cfile
)) != EOF
&& c
!= '\n');
printf("Macro definition missing null line terminator.\n");
macros
[macnum
].mac_start
= macbuf
;
macros
[macnum
].mac_start
= macros
[macnum
-1].mac_end
+ 1;
tmp
= macros
[macnum
].mac_start
;
while (tmp
!= macbuf
+ 4096) {
if ((c
=getc(cfile
)) == EOF
) {
printf("Macro definition missing null line terminator.\n");
macros
[macnum
++].mac_end
= tmp
- 1;
if (tmp
== macbuf
+ 4096) {
printf("4K macro buffer exceeded\n");
fprintf(stderr
, "Unknown .netrc keyword %s\n", tokval
);
while ((c
= getc(cfile
)) != EOF
&&
(c
== '\n' || c
== '\t' || c
== ' ' || c
== ','))
while ((c
= getc(cfile
)) != EOF
&& c
!= '"') {
while ((c
= getc(cfile
)) != EOF
&& c
!= '\n' && c
!= '\t' && c
!= ' ' && c
!= ',') {
for (t
= toktab
; t
->tokstr
; t
++)
if (!strcmp(t
->tokstr
, tokval
))