Home | History | Annotate | Download | only in mount
      1 /*
      2  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
      3  *
      4  * This program is free software; you can redistribute it and/or modify it
      5  * under the terms of version 2 of the GNU General Public License as
      6  * published by the Free Software Foundation.
      7  *
      8  * This program is distributed in the hope that it would be useful, but
      9  * WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     11  *
     12  * You should have received a copy of the GNU General Public License along
     13  * with this program; if not, write the Free Software Foundation, Inc.,
     14  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     15  *
     16  */
     17 
     18 /*
     19  * Description: This is a setuid to root program invoked by a non-root
     20  *              process to validate the mount flag MS_NOSUID.
     21  *
     22  *              This function exit with 0 or 1 depending upon the
     23  *              success/failure of setuid(2) system call.
     24  */
     25 
     26 #include <stdio.h>
     27 #include <sys/types.h>
     28 #include <unistd.h>
     29 #include <stdlib.h>
     30 #include <stdlib.h>
     31 #include <errno.h>
     32 
     33 /* Save the effective and real UIDs. */
     34 
     35 static uid_t ruid;
     36 
     37 /* Restore the effective UID to its original value. */
     38 
     39 int do_setuid(void)
     40 {
     41 	int status;
     42 
     43 	status = setreuid(ruid, 0);
     44 	if (status < 0) {
     45 		return 1;
     46 	} else {
     47 		return 0;
     48 	}
     49 	return 0;
     50 }
     51 
     52 /* Main program. */
     53 
     54 int main(void)
     55 {
     56 	int exit_status;
     57 
     58 	/* Save the real and effective user IDs.  */
     59 	ruid = getuid();
     60 	exit_status = do_setuid();
     61 
     62 	exit(exit_status);
     63 }
     64