This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: O_NOFOLLOW


>>>>> Roland McGrath writes:

>> It means to not follow symlinks when opening - but if a symlink is
>> tried it's not opened at all.

Roland> I see.  It just returns some error if the final component is a symlink?

>> This was AFAIK implemented to guard against creating, e.g. forcing
>> root to create a file (core) that is symlinked to /etc/passwd.

Roland> ? What's wrong with O_CREAT|O_EXCL?

I don't know - here's a part of patch-2.1.126 (linux/fs/namei.c):

+/* 
+ * Special case: O_CREAT|O_EXCL implies O_NOFOLLOW for security
+ * reasons.
+ *
+ * O_DIRECTORY translates into forcing a directory lookup.
+ */
+static inline int lookup_flags(unsigned int f)
+{
+       unsigned long retval = LOOKUP_FOLLOW;
+
+       if (f & O_NOFOLLOW)
+               retval &= ~LOOKUP_FOLLOW;
+       
+       if ((f & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL))
+               retval &= ~LOOKUP_FOLLOW;

I fear I'm as confused as you're;-).

Andreas
-- 
 Andreas Jaeger   aj@arthur.rhein-neckar.de    jaeger@informatik.uni-kl.de
  for pgp-key finger ajaeger@aixd1.rhrk.uni-kl.de


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]