* Copyright (c) 1985 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)ruserpass.c 1.6 (Berkeley) %G%";
char mac_name
[9]; /* macro name */
char *mac_start
; /* start of macro in macbuf */
char *mac_end
; /* end of macro in macbuf */
extern int macnum
, proxy
; /* number of defined macros */
extern struct macel macros
[16], *macpt
;
extern char macbuf
[4096];
char *renvlook(), *malloc(), *index(), *getenv(), *getpass(), *getlogin();
ruserpass(host
, aname
, apass
, aacct
)
char *host
, **aname
, **apass
, **aacct
;
/* renv(host, aname, apass, aacct);
if (*aname == 0 || *apass == 0) */
return(rnetrc(host
, aname
, apass
, aacct
));
rnetrc(host
, aname
, apass
, aacct
)
char *host
, **aname
, **apass
, **aacct
;
char *hdir
, buf
[BUFSIZ
], *tmp
;
(void) sprintf(buf
, "%s/.netrc", hdir
);
while ((t
= token())) switch(t
) {
if (token() != ID
|| strcmp(host
, tokval
))
while ((t
= token()) && t
!= MACHINE
) switch(t
) {
*aname
= malloc((unsigned) strlen(tokval
) + 1);
(void) strcpy(*aname
, tokval
);
if (strcmp(*aname
, tokval
))
if (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
))