- if (chmod (file_name, mode) != 0)
- chmod_error_details (file_name, mode);
+ chmod_errno = chmod (file_name, mode) == 0 ? 0 : errno;
+ if (chmod_errno == EPERM && (mode & S_ISUID) != 0)
+ {
+ /* On Solaris, chmod may fail if we don't have PRIV_ALL, because
+ setuid-root files would otherwise be a backdoor. See
+ http://opensolaris.org/jive/thread.jspa?threadID=95826
+ (2009-09-03). */
+ if (priv_set_restore_linkdir () == 0)
+ {
+ chmod_errno = chmod (file_name, mode) == 0 ? 0 : errno;
+ priv_set_remove_linkdir ();
+ }
+ }
+ if (chmod_errno)
+ {
+ errno = chmod_errno;
+ chmod_error_details (file_name, mode);
+ }