contrib/openpam/lib/libpam/openpam_check_owner_perms.c
/*
 * OpenPAM internal
 *
 * Verify that the file or directory referenced by the given descriptor is
 * owned by either root or the arbitrator and that it is not writable by
 * group or other.
 */
OpenPAM internal
Verify that the file or directory referenced by the given descriptor is
owned by either root or the arbitrator and that it is not writable by
group or other.
OpenPAM internal Verify that the file or directory referenced by the given descriptor is owned by either root or the arbitrator and that it is not writable by group or other .
int
openpam_check_desc_owner_perms(const char *name, int fd)
{
	uid_t root, arbitrator;
	struct stat sb;
	int serrno;
	root = 0;
	arbitrator = geteuid();
	if (fstat(fd, &sb) != 0) {
		serrno = errno;
		openpam_log(PAM_LOG_ERROR, "%s: %m", name);
		errno = serrno;
		return (-1);
	}
	if (!S_ISREG(sb.st_mode)) {
		openpam_log(PAM_LOG_ERROR,
		    "%s: not a regular file", name);
		errno = EINVAL;
		return (-1);
	}
	if ((sb.st_uid != root && sb.st_uid != arbitrator) ||
	    (sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
		openpam_log(PAM_LOG_ERROR,
		    "%s: insecure ownership or permissions", name);
		errno = EPERM;
		return (-1);
	}
	return (0);
}
int openpam_check_desc_owner_perms ( const char * name , int fd ) { uid_t root , arbitrator ; struct stat sb ; int serrno ; root = 0 ; arbitrator = geteuid ( ) ; if ( fstat ( fd , & sb ) != 0 ) { serrno = errno ; openpam_log ( PAM_LOG_ERROR , " " , name ) ; errno = serrno ; return ( -1 ) ; } if ( ! S_ISREG ( sb . st_mode ) ) { openpam_log ( PAM_LOG_ERROR , " " , name ) ; errno = EINVAL ; return ( -1 ) ; } if ( ( sb . st_uid != root && sb . st_uid != arbitrator ) || ( sb . st_mode & ( S_IWGRP | S_IWOTH ) ) != 0 ) { openpam_log ( PAM_LOG_ERROR , " " , name ) ; errno = EPERM ; return ( -1 ) ; } return ( 0 ) ; }
OpenPAM internal
 Verify that the file or directory referenced by the given descriptor is
 owned by either root or the arbitrator and that it is not writable by
 group or other.
OpenPAM internal Verify that the file or directory referenced by the given descriptor is owned by either root or the arbitrator and that it is not writable by group or other .