RMANGALD@CLARKU.BITNET (08/19/87)
Listmember Jerry Keough (keough@mitre-bedford.arpa) writes: > Would anyone have source code for changing file protections from >within an executing program? We're aware of access to these through >QIOs and the information in volume 10A on I/O programming, but perhaps >someone has already written a simple interface for getting at file >protections. -------------------------------- Jerry: Someone indeed has: DEC. But this applies only only if you have VAX C. (Or may be not: I heard that DEC ships its run-time libraries with VMS, rather than the compiler, so you might have the C run-time libraries even though you may not have VAX C. The library of interest is SYS$LIBRARY:VAXCRTL.OLB, or it's shareable image cousin, SYS$SHARE:VAXCRTL.EXE) Anyway, there is a function in the VAX C run-time library, "chmod()", that does what you want. The C declaration of the function is: int chmod(filespec, mode) char *filespec; unsigned mode; <filespec> is the file specification of the file you want to change the protection of and <mode> is the new protection. The <mode> value is constructed by performing an "or" between the following values (note that these are -octal- values; in C, a leading 0 signifies an octal value): mode protection ---- ---------- 0400 owner: READ 0200 owner: WRITE 0100 owner: EXECUTE 0040 group: READ 0020 group: WRITE 0010 group: EXECUTE 0004 world: READ 0002 world: WRITE 0001 world: EXECUTE If <mode> is 0, the user's default protection is used. The system is given the same privileges as the owner, and a WRITE privilege also enables the DELETE privilege. You must have WRITE privilege to the file to be changed; the function returns 0 if the change was successful, -1 if it wasn't. To call this routine from another language, you'd have to pass it the address of a null-terminated array of characters for <filespec> and the proper mask for <mode> (by immediate value). The function is described in Section 25 of the VAX C manual. Rahul. -------------------------------- Rahul Mangaldas (rmangaldas@clarku.bitnet) Box 1311, Clark University 950 Main Street Worcester, MA 01610-1477