1 // -*- mode: c++; c-basic-offset: 4 -*- 2 /* 3 * changeuid.{cc,hh} -- element relinquishes root privilege 4 * Eddie Kohler 5 * 6 * Copyright (c) 2005 Regents of the University of California 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the "Software"), 10 * to deal in the Software without restriction, subject to the conditions 11 * listed in the Click LICENSE file. These conditions include: you must 12 * preserve this copyright notice, and you cannot mention the copyright 13 * holders in advertising related to the Software without their permission. 14 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This 15 * notice is a summary of the Click LICENSE file; the license in that file is 16 * legally binding. 17 */ 18 19 #include <click/config.h> 20 #include "changeuid.hh" 21 #include <click/error.hh> 22 #include <unistd.h> 23 CLICK_DECLS 24 ChangeUID()25ChangeUID::ChangeUID() 26 { 27 } 28 ~ChangeUID()29ChangeUID::~ChangeUID() 30 { 31 } 32 33 int initialize(ErrorHandler * errh)34ChangeUID::initialize(ErrorHandler *errh) 35 { 36 if (setgid(getgid()) != 0 || setuid(getuid()) != 0) 37 return errh->error("could not drop privilege: %s", strerror(errno)); 38 return 0; 39 } 40 41 CLICK_ENDDECLS 42 ELEMENT_REQUIRES(userlevel) 43 EXPORT_ELEMENT(ChangeUID) 44