#include #include #include #include using namespace std; void MyID(string header) { uid_t real, effective, saved; cout << endl; cout << "*****************************************" << endl; cout << header << endl; cout << "real user id " << getuid() << endl; cout << "effecitve user id " << geteuid() << endl; getresuid(&real, &effective, &saved); cout << "saved user id " << saved << endl; cout << "*****************************************" << endl; cout << endl; } int main(int argc, char * argv[]) { int targetID = 1001; string phrase ; if (argc > 1) { targetID = atoi(argv[1]); cout << "The targetID is " << targetID << endl; } MyID("At start of process"); if (setuid(1000) != 0) { perror("setuid(1000) failed: "); return -1; } MyID("After a call to setuid(1000)"); if (setuid(targetID) != 0) { perror("setuid failed"); return -1; } cout << "called setuid " << targetID << endl; MyID("After a call to setuid()"); return 0; }