127 Info(
"argc=%d: at least 5 additional arguments required - exit", argc);
145 std::string errlog(argv[6]);
146 if (!(
gLogger = fopen(errlog.c_str(),
"a"))) {
147 Info(
"FATAL: could not open '%s' for error logging - errno: %d",
148 errlog.c_str(), (
int) errno);
154 snprintf(spid, 20,
"%d", (
int)getpid());
157 std::string user = argv[3];
158 struct passwd *pw = getpwnam(user.c_str());
160 Info(
"ERROR: could noy get identity info for '%s' - errno: %d", user.c_str(), (
int) errno);
166 std::string::size_type loc = 0;
170 std::string sessdir(argv[4]), logfile(argv[4]), tenvfile, trcfile;
173 if ((loc = sessdir.rfind(
'/')) != std::string::npos) sessdir.erase(loc, std::string::npos);
178 if ((loc = sessdir.rfind(
'/')) != std::string::npos) sessdir.erase(loc, std::string::npos);
180 if ((loc = tenvfile.rfind(
"<pid>")) != std::string::npos) tenvfile.erase(loc, std::string::npos);
183 trcfile +=
".rootrc";
186 if ((loc = sessdir.find(
"<pid>")) != std::string::npos) sessdir.replace(loc, 5, spid);
187 if (
assertdir(sessdir, uid, gid, 0755) != 0) {
188 Info(
"ERROR: could not assert dir '%s'", sessdir.c_str());
191 Info(
"session dir: %s", sessdir.c_str());
194 while ((loc = logfile.find(
"<pid>")) != std::string::npos) { logfile.replace(loc, 5, spid); }
195 std::string stag(logfile), envfile(logfile), userdir(logfile), rcfile(logfile);
201 if (
assertdir(userdir, uid, gid, 0755) != 0) {
202 Info(
"ERROR: could not assert dir '%s'", userdir.c_str());
207 if ((loc = stag.rfind(
'/')) != std::string::npos) stag.erase(0, loc);
208 if ((loc = stag.find(
'-')) != std::string::npos) loc = stag.find(
'-', loc+1);
209 if (loc != std::string::npos) stag.erase(0, loc+1);
210 Info(
"session tag: %s", stag.c_str());
213 std::string sockpath = argv[5];
214 rpdunix *uconn =
new rpdunix(sockpath.c_str());
215 if (!uconn || (uconn && !uconn->isvalid(0))) {
216 Info(
"ERROR: failure calling back parent on '%s'", sockpath.c_str());
217 if (uconn)
delete uconn;
223 if ((rcc = uconn->send((
int) getpid())) != 0) {
224 Info(
"ERROR: failure sending pid to parent (errno: %d)", -rcc);
231 if ((rcc = uconn->recv(msg)) != 0) {
232 Info(
"ERROR: failure receiving admin path and executable from parent (errno: %d)", -rcc);
237 std::string srvadmin, adminpath, pspath;
238 msg >> srvadmin >> adminpath >> pspath >> ppid;
239 Info(
"srv admin path: %s", srvadmin.c_str());
240 Info(
"partial admin path: %s", adminpath.c_str());
241 Info(
"executable: %s", pspath.c_str());
242 Info(
"parent pid: %d", ppid);
246 if ((rcc = uconn->recv(msg)) != 0) {
247 Info(
"ERROR: failure receiving information about dataset and data dir(s) from parent (errno: %d)", -rcc);
252 std::string
group, creds, ord, datadir, ddiropts, datasetsrcs;
253 msg >> euid >>
group >> creds >> ord >> datadir >> ddiropts >> datasetsrcs;
254 Info(
"euid at startup: %d", euid);
255 Info(
"group, ord: %s, %s",
group.c_str(), ord.c_str());
256 Info(
"datadir: %s", datadir.c_str());
257 Info(
"datasetsrcs: %s", datasetsrcs.c_str());
262 Info(
"ERROR: problems setting relevant user ownerships");
268 if (
mvfile(tenvfile, envfile, uid, gid, 0644) != 0) {
269 Info(
"ERROR: problems renaming '%s' to '%s' (errno: %d)",
270 tenvfile.c_str(), envfile.c_str(), errno);
275 if (
mvfile(trcfile, rcfile, uid, gid, 0644) != 0) {
276 Info(
"ERROR: problems renaming '%s' to '%s' (errno: %d)",
277 trcfile.c_str(), rcfile.c_str(), errno);
284 Info(
"ERROR: problems completing '%s'", rcfile.c_str());
290 Info(
"ERROR: problems setting environment from '%s'", envfile.c_str());
297 Info(
"ERROR: problems exporting file descriptor");
304 if (
loginuser(userdir, user, uid, gid) != 0) {
305 Info(
"ERROR: problems login user '%s' in", user.c_str());
312 Info(
"ERROR: problems redirecting logs to '%s'", logfile.c_str());
318 char *argvv[6] = {0};
321 if (adminpath.length() > 0) {
323 int len = srvadmin.length() + strlen(
"xpdpath:") + 1;
324 sxpd =
new char[
len];
325 snprintf(sxpd,
len,
"xpdpath:%s", adminpath.c_str());
337 argvv[0] = (
char *) pspath.c_str();
338 argvv[1] = (
char *)((
gType == 0) ?
"proofslave" :
"proofserv");
339 argvv[2] = (
char *)
"xpd";
340 argvv[3] = (
char *)sxpd;
341 argvv[4] = (
char *)slog;
347 sigaddset(&myset, SIGUSR1);
348 sigaddset(&myset, SIGUSR2);
349 pthread_sigmask(SIG_UNBLOCK, &myset, 0);
351 Info(
"%d: uid: %d, euid: %d", (
int)getpid(), getuid(), geteuid());
352 Info(
"argvv: '%s' '%s' '%s' '%s' '%s'", argvv[0], argvv[1], argvv[2], argvv[3], argvv[4]);
355 execv(pspath.c_str(), argvv);
358 Info(
"ERROR: returned from execv: bad, bad sign !!!");
int setownerships(int euid, const std::string &us, const std::string &gr, const std::string &creds, const std::string &dsrcs, const std::string &ddir, const std::string &ddiro, const std::string &ord, const std::string &stag)
Set user ownerships on some critical files or directories.