O_NOFOLLOW
Andreas Jaeger
aj@arthur.rhein-neckar.de
Sat Oct 24 06:28:00 GMT 1998
>>>>> 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
More information about the Libc-hacker
mailing list