Everhart, Glenn (FUSA) From: Boris Gubenko [Boris.Gubenko@digital.com] Sent: Wednesday, April 14, 1999 3:19 PM To: Info-VAX@Mvb.Saic.Com Cc: Boris.Gubenko@digital.com Subject: Re: access() odd behavior Richard Levitte - VMS Whacker wrote: > > It seems that when you do an access check on a directory with mode > bits including X_OK, access() will fail (return -1) unconditionally (I > tried giving myself all permissions, including adding an ACL). > > So far, I've tested this on VMS 7.2 with DEC C 5.7 and VAX C 3.2. > > This is the code that I used to check this: > > ------------------------------- snip ------------------------------ > #include > #include > #ifdef __DECC > #include > #else > #define F_OK 0 > #define X_OK 1 > #define W_OK 2 > #define R_OK 4 > #endif > #include > #include > > int states[]={F_OK, X_OK, R_OK, W_OK}; > char *staten[]={"F_OK", "X_OK", "R_OK", "W_OK"}; > > main() > { > int i; > int status; > > for(i = 0; i < 4; i++) { > errno = 0; > printf("%s %d ", staten[i], > status = access("USER1:[LEVITTE.TEST]",states[i])); > if (status < 0) > printf("%d \"%s\"\n", errno, strerror(errno,vaxc$errno)); > else > printf("OK!\n"); > } > } > ------------------------------- snip ------------------------------ > > Of course, when I change the test string to "USER1:[LEVITTE]TEST.DIR", > I get the results I expected (X_OK also makes access() return 0). > > Personally, I find this behavior insane. The work-around would be to > hack the file spec. as soon as you detect it to be a directory spec. > It can be done, but it is a pain in my lower parts (having done so > just too damn many times). > [...] -- I'm not sure why it fails for you. I could not reproduce the problem using your (slightly modified) program example on OpenVMS Alpha V7.2. This is what I get: $ cc/ver _nl0: DEC C V5.5-002 on OpenVMS Alpha V7.2 $ show log work5 /full "WORK5" [exec] = "_$64$DUA1240:" [concealed] (LNM$SYSTEM_TABLE) $ show log boris$root /full "BORIS$ROOT" [super] = "_$64$DUA1240:[BORIS.]" [concealed,terminal] (LNM$JOB_ 81071180) $ r x testing work5:[boris.tmp.tmp] F_OK 0 OK! X_OK 0 OK! R_OK 0 OK! W_OK -1 "permission denied" testing work5:[boris.tmp]tmp.dir F_OK 0 OK! X_OK 0 OK! R_OK 0 OK! W_OK -1 "permission denied" testing boris$root:[tmp.tmp] F_OK 0 OK! X_OK 0 OK! R_OK 0 OK! W_OK -1 "permission denied" testing boris$root:[tmp]tmp.dir F_OK 0 OK! X_OK 0 OK! R_OK 0 OK! W_OK -1 "permission denied" $ Failure of access(W_OK) for a directory file is expected. It fails because on VMS W_OK implies both Write and Delete privilege. There is no Delete protection bit on Unix, so access() was implemented on VMS to map W_OK to Write + Delete which is as reasonable as implementing it the other way ignoring Delete privilege at all, for example. This is documented in the DEC C RTL Reference Manual. How USER1 is defined on your system? $show log/full USER1 ? x.c === #include #include #include #include #define DIM(_s) (sizeof(_s) / sizeof(_s[0])) int states[]={F_OK, X_OK, R_OK, W_OK}; char *staten[]={"F_OK", "X_OK", "R_OK", "W_OK"}; char *filename[] = { "work5:[boris.tmp.tmp]", "work5:[boris.tmp]tmp.dir", "boris$root:[tmp.tmp]", "boris$root:[tmp]tmp.dir" }; main() { int i, j; int status; for(j=0; j < DIM(filename); ++j) { printf("\ntesting %s\n", filename[j]); for(i = 0; i < 4; i++) { errno = 0; printf("%s %d ", staten[i], status = access(filename[j],states[i])); if (status < 0) printf("\"%s\"\n", strerror(errno)); else printf("OK!\n"); } } } +--------------------------------------------------------+ | Boris Gubenko. Compaq Computer Corporarion. Nashua, NH.| | DEC C RTL / C++ libraries. Boris.Gubenko@digital.com | |========================================================| | All the opinions voiced are mine alone and do not | | reflect anyone else's opinion, including my employer's.| +--------------------------------------------------------+