Program A (ReportHandler) calls program B (Specific Report). In order for me to get my "specific report" I need to go through program A, which then calls program B and gets me my report. My problem here is that Program B has a "security" measure that checks for program B to be a child process of program A. (This is because program A makes sure no-one else is running this program B, makes sure it gets run between x and y hour of the day, or other programs that may interfere with the running of program B, etc.)
Program A & B are C based, but I cannot (must not) change them. I checked the code and I cannot pass parameters to program A to run B from console.. SOOO, the only idea I have left, is to try and "trick" the system so that program B shows up as a child of program A so that I can run it from console.
The reason for me to try and automate this, is that I need to dial into a dozen servers each day to get this report... I want to centralize this script so that I can remotely ssh this script to each server and be done with it. would save me an hour of my day. or more.
Check being made
if ( TRUE != child_of_Program_A() )
{
epause( win[MAIN], 1,
_("This Program Must Be Run From Program A"));
return( FAILURE );
}
STATIC BOOL child_of_Program_A()
{
FILE *fp;
char statname[32];
pid_t ppid;
char proc_name[32];
char buffer[128];
char *ptr;
ppid = getppid();
while(ppid != 1)
{
snprintf(statname, sizeof(statname), "/proc/%d/status", ppid);
if (NULL == (fp = fopen(statname, "r")))
{
return(FALSE);
}
proc_name[0] = '\0';
ppid = -1;
while (NULL != fgets(buffer, sizeof(buffer), fp))
{
if (NULL != (ptr = strtok(buffer, STAT_SEP)))
{
if (strcasecmp(ptr, "name") == 0)
{
if (NULL != (ptr = strtok(NULL, STAT_SEP)))
{
if (strcmp(ptr, "Program_A") == 0)
{
fclose(fp);
return(TRUE);
}
strncpy(proc_name, ptr, sizeof(proc_name));
}
}
else if (strcasecmp(ptr, "ppid") == 0)
{
if (NULL != (ptr = strtok(NULL, STAT_SEP)))
{
ppid = atoi(ptr);
}
}
}
if (ppid != -1 && proc_name[0] != '\0')
break;
}
fclose(fp);
}
return(FALSE);