X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Fshared%2Fprivsep_op.c;fp=src%2Fshared%2Fprivsep_op.c;h=b2ac25cead6a6e8ac65ec89d34695330ce0dcf04;hp=b24cb31d6a93150cd467309ea55af9b505365e8b;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hpb=927951d1c1ad45ba9e7325f07d996154a91c911b diff --git a/src/shared/privsep_op.c b/src/shared/privsep_op.c old mode 100755 new mode 100644 index b24cb31..b2ac25c --- a/src/shared/privsep_op.c +++ b/src/shared/privsep_op.c @@ -1,5 +1,3 @@ -/* $OSSEC, privsep_op.h, v0.2, 2004/08/05, Daniel B. Cid$ */ - /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * @@ -9,12 +7,7 @@ * Foundation */ -/* Part of the OSSEC HIDS - * Available at http://www.ossec.net - */ - -/* Functions for privilege separation. - */ +/* Functions for privilege separation */ #ifndef WIN32 @@ -24,79 +17,82 @@ #include #include +#include "privsep_op.h" #include "headers/os_err.h" -int Privsep_GetUser(char * name) -{ - int os_uid = -1; +uid_t Privsep_GetUser(const char *name) +{ struct passwd *pw; pw = getpwnam(name); - if(pw == NULL) - return(OS_INVALID); + if (pw == NULL) { + return ((uid_t)OS_INVALID); + } - os_uid = (int)pw->pw_uid; - endpwent(); - - return(os_uid); + return (pw->pw_uid); } -int Privsep_GetGroup(char * name) +gid_t Privsep_GetGroup(const char *name) { - int os_gid = -1; - struct group *grp; grp = getgrnam(name); - if(grp == NULL) - return(OS_INVALID); + if (grp == NULL) { + return ((gid_t)OS_INVALID); + } - os_gid = (int)grp->gr_gid; - endgrent(); - - return(os_gid); + return (grp->gr_gid); } int Privsep_SetUser(uid_t uid) { - if(setuid(uid) < 0) - return(OS_INVALID); - - #ifndef HPUX - if(seteuid(uid) < 0) - return(OS_INVALID); - #endif + if (setuid(uid) < 0) { + return (OS_INVALID); + } + +#ifndef HPUX + if (seteuid(uid) < 0) { + return (OS_INVALID); + } +#endif - return(OS_SUCCESS); + return (OS_SUCCESS); } int Privsep_SetGroup(gid_t gid) { - if (setgroups(1, &gid) == -1) - return(OS_INVALID); - - #ifndef HPUX - if(setegid(gid) < 0) - return(OS_INVALID); - #endif + if (setgroups(1, &gid) == -1) { + return (OS_INVALID); + } + +#ifndef HPUX + if (setegid(gid) < 0) { + return (OS_INVALID); + } +#endif - if(setgid(gid) < 0) - return(OS_INVALID); + if (setgid(gid) < 0) { + return (OS_INVALID); + } - return(OS_SUCCESS); + return (OS_SUCCESS); } -int Privsep_Chroot(char * path) +int Privsep_Chroot(const char *path) { - if(chdir(path) < 0) - return(OS_INVALID); + if (chdir(path) < 0) { + return (OS_INVALID); + } - if(chroot(path) < 0) - return(OS_INVALID); + if (chroot(path) < 0) { + return (OS_INVALID); + } - chdir("/"); + if (chdir("/") < 0) { + return (OS_INVALID); + } - return(OS_SUCCESS); + return (OS_SUCCESS); } -#endif -/* EOF */ +#endif /* !WIN32 */ +