1/*++ 2/* NAME 3/* stat_as 3 4/* SUMMARY 5/* stat file as user 6/* SYNOPSIS 7/* #include <sys/stat.h> 8/* #include <stat_as.h> 9/* 10/* int stat_as(path, st, euid, egid) 11/* const char *path; 12/* struct stat *st; 13/* uid_t euid; 14/* gid_t egid; 15/* DESCRIPTION 16/* stat_as() looks up the file status of the named \fIpath\fR, 17/* using the effective rights specified by \fIeuid\fR 18/* and \fIegid\fR, and stores the result into the structure pointed 19/* to by \fIst\fR. A -1 result means the lookup failed. 20/* This call follows symbolic links. 21/* DIAGNOSTICS 22/* Fatal error: no permission to change privilege level. 23/* SEE ALSO 24/* set_eugid(3) switch effective rights 25/* LICENSE 26/* .ad 27/* .fi 28/* The Secure Mailer license must be distributed with this software. 29/* AUTHOR(S) 30/* Wietse Venema 31/* IBM T.J. Watson Research 32/* P.O. Box 704 33/* Yorktown Heights, NY 10598, USA 34/*--*/ 35 36/* System library. */ 37 38#include <sys_defs.h> 39#include <sys/stat.h> 40#include <unistd.h> 41 42/* Utility library. */ 43 44#include "msg.h" 45#include "set_eugid.h" 46#include "stat_as.h" 47#include "warn_stat.h" 48 49/* stat_as - stat file as user */ 50 51int stat_as(const char *path, struct stat * st, uid_t euid, gid_t egid) 52{ 53 uid_t saved_euid = geteuid(); 54 gid_t saved_egid = getegid(); 55 int status; 56 57 /* 58 * Switch to the target user privileges. 59 */ 60 set_eugid(euid, egid); 61 62 /* 63 * Stat that file. 64 */ 65 status = stat(path, st); 66 67 /* 68 * Restore saved privileges. 69 */ 70 set_eugid(saved_euid, saved_egid); 71 72 return (status); 73} 74