This file is meant to handle all the machine
dependencies in the network code.
Everything is conditionally compiled.
It can be uses w/o network stuff to simulate
v7 for other programs, too.
Set the owner uid/gid of a file.
On v7, this is done by the chown command
with three args - (file, uid, gid).
On Vanilla V6 this is done using the
top byte of the second parameter as the gid byte.
On Berkeley Funny uids on V6, no gid is specified.
uid
= ((gid
&0377) << 8) | (uid
& 0377);
The login name corresponding to uid.
Successive calls overwrite the static string returned.
register struct passwd
*pwd
;
static char oresult
[20] = "";
if(getname(uid
,oresult
) == 0){
strcpy(oresult
,pwd
->pw_name
);
/* handle the regular unix and local mods difference for user id's */
/* this call returns the 1 word uid = to what getuid will return */
return((uid
& 0377) | (gid
<< 8));
char *ttyname(i
){ /* return NULL if not TTY */
static char ttystr
[] = "/dev/ttyx";
return(c
== 'x' ? NULL
: ttystr
);
myttyname(i
){ /* return NULL for non tty */
if(p
== NULL
)return(NULL
);
# define ttyname(S) myttyname(S)
/* get passwd from passwdf */
char buf1
[BUFSIZ
], found
;
pw
= fopen("/etc/passwdf","r");
while(fgets(buf1
,BUFSIZ
,pw
) != NULL
){
for(p
=buf1
; *p
&& *p
!= ':'; p
++);
if(strcmp(buf1
,pwd
->pw_name
) == 0){
for(;*p
&& *p
!= ':';p
++);
strcpy(pwd
->pw_passwd
,q
);
debug("user %s passwd %s %s",pwd->pw_name,pwd->pw_passwd);
these are all the v7 routines not available on the v6 machines
char **environ
; /* global environment pointer */
return(0); /* always succeeds */
while('0' <= *s
&& *s
<= '9')
i
= i
* 10 + (*s
++ - '0');
wk
= ((long)(str
->st_size0
& 0377)) << 16;
wk
+= (long)((unsigned)str
->st_size1
);
always returns home directory.
returns NULL if there is error.
register char *shdir
= NULL
;
register struct passwd
*pwd
;
if(shomedir
[0] != 0)return(shomedir
);
if(it
== 'x')it
= ttyn(1);
if(it
== 'x')it
= ttyn(0);
if(it
!= 'x' && hget(it
) == 0)shdir
= hgethome();
if(it
== -1)it
= ttyn(1);
if(it
== -1)it
= ttyn(0);
if(it
!= -1 && hget(it
) == 0)shdir
= hgethome();
if(pwd
!= NULL
)shdir
= pwd
->pw_dir
;
if(shdir
!= NULL
)strcpy(shomedir
,shdir
);
/* doesn't handle split passwd files */
register struct passwd
*p
;
struct passwd
*getpwent();
while( (p
= getpwent()) && guid(p
->pw_uid
,p
->pw_gid
) != uid
);
static char PASSWD
[] = "/etc/passwd";
static char EMPTY
[] = "";
static char line
[BUFSIZ
+1];
static struct passwd passwd
;
pwf
= fopen( PASSWD
, "r" );
if( (pwf
= fopen( PASSWD
, "r" )) == NULL
)
p
= fgets(line
, BUFSIZ
, pwf
);
passwd
.pw_uid
= uidmask(passwd
.pw_uid
);
passwd
.pw_comment
= EMPTY
;
while(*p
&& *p
!= '\n') p
++;
register struct passwd
*p
;
struct passwd
*getpwent();
while( (p
= getpwent()) && strcmp(name
,p
->pw_name
) );
Return current user name by looking at /etc/utmp.
Returns NULL if not found.
register char *sttyname
,*s
;
if(sttyname
== NULL
)sttyname
= ttyname(1);
if(sttyname
== NULL
)sttyname
= ttyname(0);
if(sttyname
== NULL
)return(NULL
);
fp
= fopen("/etc/utmp","r");
if(fp
== NULL
)return(NULL
);
while(fread(&utmpstr
,1,sizeof utmpstr
,fp
) == sizeof utmpstr
){
if(utmpstr
.ut_tty
== sttyname
[8]){
if(strcmp(utmpstr
.ut_line
,sttyname
+5) == 0){
strcpy(snSave
,utmpstr
.ut_name
);
while(*s
!= 0 && *s
!= ' ')s
++;
if(snSave
[0] == 0)return(NULL
);
* Unix routine to do an "fopen" on file descriptor
* The mode has to be repeated because you can't query its
for (iop
= _iob
; iop
->_flag
&(_IOREAD
|_IOWRT
); iop
++)
register int (*istat
)(), (*qstat
)();
while((pid
= fork()) == -1)sleep(2);
execl("/bin/sh", "sh", "-c", s
, 0);
istat
= signal(SIGINT
, SIG_IGN
);
qstat
= signal(SIGQUIT
, SIG_IGN
);
while ((w
= wait(&status
)) != pid
&& w
!= -1)
/* modified because Cory needs super-user to stty /dev/tty */
if ((fi
= fopen("/dev/tty", "r")) == NULL
)
setbuf(fi
, (char *)NULL
);
if(gtty(0,&ttyb
) >= 0)fi
= stdin
;
else if(gtty(2,&ttyb
) >= 0)fi
= stderr
;
sig
= signal(SIGINT
, SIG_IGN
);
if(stty(fileno(fi
), &ttyb
) < 0) perror("stty:");
for (p
=pbuf
; (c
= getc(fi
))!='\n' && c
!=EOF
;) {
/* end of non-vax v7 routines */