static char sccsid
[] = "@(#)mach.c 4.2 (Berkeley) 10/2/82";
static char *mach_sid
= "@(#)mach.c 1.6";
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.
/* the CC and SRC machines have the submit() call */
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);
fprintf(stderr
, "chown %s to %d(%o)\n",sfn
,uid
,uid
);
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
);
register struct passwd
*pwd
;
if(pwd
!= NULL
)him
= guid(pwd
->pw_uid
,pwd
->pw_gid
);
/* 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
);
char *myttyname(i
){ /* return NULL for non tty */
if(p
== NULL
)return(NULL
);
# define ttyname(S) myttyname(S)
/* expand control chars in string s */
/* get passwd from passwdf */
char buf1
[BUFSIZ
], found
;
debug("reading passwdf\n");
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);
return a pointer to the system utmp structure associated with
terminal sttyname, e.g. "/dev/tty3"
Is version independent-- will work on v6 systems
struct utmp
*getutmp(sttyname
)
static struct utmp utmpstr
;
if(sttyname
== NULL
|| sttyname
[0] == 0)return(NULL
);
fdutmp
= fopen("/etc/utmp","r");
if(fdutmp
== NULL
)return(NULL
);
while(fread(&utmpstr
,1,sizeof utmpstr
,fdutmp
) == sizeof utmpstr
)
if(strcmp(utmpstr
.ut_line
,sttyname
+5) == 0){
while(fread(&v6utmpstr
,1,sizeof v6utmpstr
,fdutmp
) == sizeof v6utmpstr
)
if(v6utmpstr
.v6ut_tty
== sttyname
[8]){
strcpy(utmpstr
.ut_name
,v6utmpstr
.v6ut_name
);
strcpy(utmpstr
.ut_line
,"ttyx");
utmpstr
.ut_line
[3] = v6utmpstr
.v6ut_tty
;
utmpstr
.ut_time
= v6utmpstr
.v6ut_time
;
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
);
/* hget only works on Berkeley machines */
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
;
debug("reading passwd\n");
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 (calls getutmp()).
Returns NULL if not found.
register struct utmp
*putmp
;
if(isatty(2))strcpy(sttyname
,ttyname(2));
else if(isatty(0))strcpy(sttyname
,ttyname(0));
else if(isatty(1))strcpy(sttyname
,ttyname(1));
putmp
= getutmp(sttyname
);
if(putmp
== NULL
)return(NULL
);
while(*s
!= 0 && *s
!= ' ')s
++;
if(putmp
->ut_name
[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(fileno(fi
),&ttyb
) < 0){
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
;) {
* Compare strings (at most n bytes): s1>s2: >0 s1==s2: 0 s1<s2: <0
while (--n
>= 0 && *s1
== *s2
++)
return(n
<0 ? 0 : *s1
- *--s2
);
/* set the umask, ignore in v6 */
/* end of non-vax v7 routines */
Read the password file and return pwd to
This code is a little screwed up because of the conventions
regarding the state of the utmp file after someone su's--
either to root or to another person.
The final decision was to return getpwuid(getuid) if
the machine has one login name per userid,
and if there are multiple login names per userid, to
search the passwd file for the getlogin() name and return
the passwd file entry for that.
If there is no utmp entry, just use the userid.
This means that people who su on machine with multiple
user-id's will get the passwd entry for the account recorded
in the utmp file, not their current userid.
register struct passwd
*pwd
;
if(sn
!= NULL
&& sn
[0] != 0 && sn
[0] != ' '){
if(pwd
!= NULL
)return(pwd
);
return(getpwuid(uidmask(getuid())));
debug(s
,a
,b
,c
,d
,e
,f
,g
,h
,i
,j
,k
,l
,m
,n
,o
,p
,q
,r
,t
)
printf(s
,a
,b
,c
,d
,e
,f
,g
,h
,i
,j
,k
,l
,m
,n
,o
,p
,q
,r
,t
);