Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!ames!ucbcad!ucbvax!CLARKU.BITNET!RMANGALD From: RMANGALD@CLARKU.BITNET Newsgroups: comp.os.vms Subject: Re: Changing File Protection Message-ID: <8708200002.AA00103@ucbvax.Berkeley.EDU> Date: Wed, 19-Aug-87 12:51:00 EDT Article-I.D.: ucbvax.8708200002.AA00103 Posted: Wed Aug 19 12:51:00 1987 Date-Received: Sat, 22-Aug-87 05:08:36 EDT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: world Organization: The ARPA Internet Lines: 64 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; is the file specification of the file you want to change the protection of and is the new protection. The 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 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 and the proper mask for (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