ditto@cbmvax.UUCP (Michael "Ford" Ditto) (02/22/89)
>In article <481@uncle.UUCP> jbm@uncle.UUCP (John B. Milton) writes: >> LOCKING(2). I always wondered if the UNIXpc had this one, but I >>A regular ho-hum user can cause a lot of trouble with this! Consider: In article <6034@cbmvax.UUCP> I write: >I thought locking() only provided advisory locks. Have you actually >tried those examples? Yow! I just tried John's locking program and it sure works! "lock /etc/passwd -z3600" pretty much stops the system! I wrote a quicky loadable driver to make the locking() system call require that the affected file be opened with write mode -- at least this is a bit more secure. It's short enough that I figure it's not worth a separate article to unix-pc.sources, so here it is, crossposted. -=] Ford [=- "The number of Unix installations (In Real Life: Mike Ditto) has grown to 10, with more expected." ford@kenobi.cts.com - The Unix Programmer's Manual, ...!sdcsvax!crash!kenobi!ford 2nd Edition, June, 1972. ditto@cbmvax.commodore.com #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # Install # lkfx.c # This archive created: Tue Feb 21 21:51:59 1989 export PATH; PATH=/bin:$PATH echo shar: extracting "'Install'" '(128 characters)' if test -f 'Install' then echo shar: will not over-write existing file "'Install'" else cat << \SHAR_EOF > 'Install' set -e /etc/masterupd -a init release lkfx make lkfx.o cp lkfx.o /etc/lddrv cd /etc/lddrv ./lddrv -av lkfx echo lkfx >> drivers SHAR_EOF if test 128 -ne "`wc -c < 'Install'`" then echo shar: error transmitting "'Install'" '(should have been 128 characters)' fi chmod +x 'Install' fi # end of overwriting check echo shar: extracting "'lkfx.c'" '(773 characters)' if test -f 'lkfx.c' then echo shar: will not over-write existing file "'lkfx.c'" else cat << \SHAR_EOF > 'lkfx.c' #define KERNEL #include <sys/types.h> #include <sys/conf.h> #include <sys/user.h> #include <sys/file.h> #include <sys/errno.h> #include <sys/systm.h> extern int locking(); #define SYS_locking 67 int fakelocking(); lkfxinit() { if (sysent[SYS_locking].sy_call != locking) { eprintf("lkfxinit: can't install: syscall %d is not `locking'"); u.u_error = EINVAL; return; } sysent[SYS_locking].sy_call = fakelocking; } fakelocking() { register struct a { int fd; int mode; off_t size; } *uap = (struct a *)u.u_ap; struct file *fp; if ((fp = getf(uap->fd)) == NULL) return; if (!(fp->f_flag & FWRITE)) { u.u_error = EACCES; return; } locking(); } lkfxrelease() { sysent[SYS_locking].sy_call = locking; } SHAR_EOF if test 773 -ne "`wc -c < 'lkfx.c'`" then echo shar: error transmitting "'lkfx.c'" '(should have been 773 characters)' fi fi # end of overwriting check # End of shell archive exit 0 -- -=] Ford [=- "The number of Unix installations (In Real Life: Mike Ditto) has grown to 10, with more expected." ford@kenobi.cts.com - The Unix Programmer's Manual, ...!sdcsvax!crash!kenobi!ford 2nd Edition, June, 1972. ditto@cbmvax.commodore.com