FIX: check return values of some important functions

This commit is contained in:
Juan José Gutiérrez de Quevedo Pérez 2014-06-29 21:32:56 +02:00
parent a96826a208
commit 53bd14e419

View file

@ -160,13 +160,21 @@ main
{ {
//this is needed to get hermes to load the dns resolver BEFORE chrooting //this is needed to get hermes to load the dns resolver BEFORE chrooting
(void)gethostbyname("hermes-project.com"); (void)gethostbyname("hermes-project.com");
chdir(cfg.getChroot().c_str()); if(-1 == chdir(cfg.getChroot().c_str()))
{
LERR(_("Couldn't chdir into ") + cfg.getChroot() + " " + Utils::errnotostrerror(errno) );
return -1;
}
if(-1==chroot(cfg.getChroot().c_str())) if(-1==chroot(cfg.getChroot().c_str()))
{ {
LERR(_("Couldn't chroot ") + Utils::errnotostrerror(errno)); LERR(_("Couldn't chroot ") + Utils::errnotostrerror(errno));
return -1; return -1;
} }
chdir("/"); if(-1 == chdir("/"))
{
LERR(_("Couldn't chdir into /, this shouldn't happen: " + Utils::errnotostrerror(errno)) );
return -1;
}
} }
#endif //WIN32 #endif //WIN32
@ -187,10 +195,26 @@ main
if(cfg.getDropPrivileges()) if(cfg.getDropPrivileges())
{ {
//drop privileges once we have opened the listening port //drop privileges once we have opened the listening port
setgroups(0,NULL); if(-1 == setgroups(0,NULL))
setgid(cfg.getGid()); {
setuid(cfg.getUid()); LERR(_("Error dropping priviledges " + Utils::errnotostrerror(errno)) );
setuid(cfg.getUid()); return -1;
}
if(-1 == setgid(cfg.getGid()))
{
LERR(_("Error setting gid " + Utils::inttostr(cfg.getGid()) + " " + Utils::errnotostrerror(errno)) );
return -1;
}
if(-1 == setuid(cfg.getUid()))
{
LERR(_("Error setting uid " + Utils::inttostr(cfg.getUid()) + " " + Utils::errnotostrerror(errno)) );
return -1;
}
if(-1 == setuid(cfg.getUid()))
{
LERR(_("Error setting uid " + Utils::inttostr(cfg.getUid()) + " " + Utils::errnotostrerror(errno)) );
return -1;
}
} }
#endif //WIN32 #endif //WIN32