static char sccsid
[] = "@(#)netrc.c 4.1 (Berkeley) %G%";
static char *netrc_sid
= "@(#)netrc.c 1.2";
procedures to read and parse the .netrc file
commandfile() to read the file.
rdnetfile(cfile) to read the file.
will read the passwd file
if getenv(HOME) searches the passwd file
login string current login
Fabry has suggested that machine names be more general:
so the formulation would look like:
key: machine login passwd ...
Gould has suggested the format be:
pseudo cory real Cory login fabry
pseudo caf real Cory login caf
pseudo c real C login fabry
machine A local C link /dev/net-A speed 9
machine Cory local C link /dev/net-Cory speed 9
if remote == 0, default is A
passwords work as follows:
passwd = "\n" means no password
/* tokens, returned by parser */
struct daemonparms netd
= {
"/dev/null", /* device */
static struct tokstruct
{
"hispeedlink", HISPEEDLINK
,
static struct stat statbuf
;
this procedure reads in and parses the .netrc file.
when you call this, if the remote machine is to be explicitely
set, the global variable "remote" must have a value.
on return, if it is non-zero, "remote" will have the
remote machine the data was collected for.
status.localname need not have a value.
if(hdir
== NULL
)hdir
= ".";
sprintf(buf
,"%s/.netrc",hdir
);
read the file cfile and parse
if(fstat(fileno(cfile
),&statbuf
) < 0 || (statbuf
.st_mode
& 0444) == 0)
while((t
= token(cfile
))){
if(token(cfile
) == ID
&& remote
== 0)remote
= lookup(tokval
);
debug("rem %c\n",remote);
if(remote
== 0)remote
= getremote(local
);
if(token(cfile
) != ID
)continue;
if(remote
!= lookup(tokval
))continue;
/* this is the entry for the remote mach we want */
while((t
= token(cfile
))){
/* these options are usually in the .netrc file */
if(token(cfile
) && status
.login
[0] == 0)
strcpy(status
.login
,tokval
);
if(fstat(fileno(cfile
),&statbuf
) >= 0
&& (statbuf
.st_mode
& 077) != 0){
err("Error - .netrc file not correct mode.\n");
err("Remove password or correct mode.\n");
if(token(cfile
) && status
.mpasswd
[0] == 0)
strcpy(status
.mpasswd
,tokval
);
debug("mp:%s:%s\n",status.mpasswd,tokval);
status
.nonotify
= token(cfile
) == NO
;
status
.nowrite
= token(cfile
) == NO
;
if(token(cfile
) && status
.defcmd
[0] == 0)
strcpy(status
.defcmd
,tokval
);
status
.quiet
= token(cfile
) == YES
;
status
.force
= token(cfile
) == YES
;
/* these options are usually in /usr/net/initfile */
if(token(cfile
))local
= lookup(tokval
);
if(token(cfile
))strcpy(netd
.dp_device
,tokval
);
netd
.dp_inspeed
= netd
.dp_outspeed
=atoi(tokval
);
if(token(cfile
))netd
.dp_inspeed
= atoi(tokval
);
if(token(cfile
))netd
.dp_outspeed
= atoi(tokval
);
if(token(cfile
))netd
.dp_datasize
= atoi(tokval
);
if(token(cfile
))netd
.dp_oatime
= atoi(tokval
);
if(token(cfile
))netd
.dp_maxbread
= atoi(tokval
);
if(token(cfile
))netd
.dp_onlyuid
= atoi(tokval
);
if(token(cfile
))strcpy(netd
.dp_hispeedlink
,tokval
);
err("Unknown .netrc option %s\n",tokval
);
{ /* returns next token in cfile, 0 on EOF */
if(feof(cfile
))return(0);
while((c
= getc(cfile
)) != EOF
&& (c
== '\n' || c
== '\t'
|| c
== ' ' || c
== ','));
/* next char begins token */
if(c
== '"'){ /* process quoted string */
while((c
= getc(cfile
)) != EOF
&& c
!= '"'){
if(c
== '\\')c
= getc(cfile
);
while((c
= getc(cfile
)) != EOF
&& c
!= '\n' && c
!= '\t'
&& c
!= ' ' && c
!= ','){
if(c
== '\\')c
= getc(cfile
);
if(tokval
[0] == 0)return(0);
for(p
= toktab
; p
->tokstr
; p
++)
if(streql(p
->tokstr
,str
) == 0){