27 if (Line[1]==
'r') Mode |= S_IRUSR;
29 if (Line[2]==
'w') Mode |= S_IWUSR;
31 if (Line[3]==
'x') Mode |= S_IXUSR;
32 if (Line[3]==
's') Mode |= S_IXUSR | S_ISUID;
33 if (Line[3]==
'S') Mode |= S_ISUID;
35 if (Line[4]==
'r') Mode |= S_IRGRP;
37 if (Line[5]==
'w') Mode |= S_IWGRP;
39 if (Line[6]==
'x') Mode |= S_IXGRP;
40 if (Line[6]==
's') Mode |= S_IXGRP | S_ISGID;
41 if (Line[6]==
'S') Mode |= S_ISGID;
43 if (Line[7]==
'r') Mode |= S_IROTH;
45 if (Line[8]==
'w') Mode |= S_IWOTH;
47 if (Line[9]==
'x') Mode |= S_IXOTH;
48 if (Line[9]==
't') Mode |= S_IXOTH | S_ISVTX;
49 if (Line[9]==
'T') Mode |= S_ISVTX;
70 char Cmd[FILENAME_MAX*5];
71 char Line[FILENAME_MAX];
76 char TempSource[FILENAME_MAX], TempDestination[FILENAME_MAX];
77 char TempIso[FILENAME_MAX], TempOut[FILENAME_MAX];
80 if ((NULL == Source) || (!strcmp(Source,
"")) || (NULL == Destination) || (!strcmp(Destination,
"")))
83 if (!
Quiet &&
Verbose) fprintf(stderr,
"Extracting ISO: %s\n",Source);
86 if (
TaintString(TempSource,FILENAME_MAX,Source,1,NULL) ||
87 TaintString(TempDestination,FILENAME_MAX,Destination,1,NULL))
89 memset(Cmd,
'\0',
sizeof(Cmd));
90 snprintf(Cmd,
sizeof(Cmd),
" (isoinfo -l -R -J -i '%s' || isoinfo -l -R -i '%s' "
91 "|| isoinfo -l -i '%s') 2>/dev/null | grep '^Directory'",
92 TempSource, TempSource, TempSource);
98 fprintf(stderr,
"ERROR: ISO failed: %s\n",Cmd);
101 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
104 if (
s==NULL)
continue;
105 snprintf(Cmd,
sizeof(Cmd),
"%s%s",Destination,
s);
106 if (
Verbose > 1) printf(
"ISO directory: %s\n",Cmd);
109 fprintf(stderr,
"ERROR: Unable to mkdir(%s) in ExtractISO\n",Cmd);
116 snprintf(Cmd,
sizeof(Cmd),
"(isoinfo -f -R -J -i '%s' || isoinfo -f -R -i '%s' || isoinfo -f -i '%s') 2>/dev/null",
117 TempSource, TempSource, TempSource);
119 Fin = popen(Cmd,
"r");
122 fprintf(stderr,
"ERROR: ISO failed: %s\n",Cmd);
126 memset(Line,
'\0',
sizeof(Line));
127 strcpy(Line,Destination);
128 Len=strlen(Destination);
129 while(
ReadLine(Fin,Line+Len,
sizeof(Line)-1-Len) >= 0)
131 if (Line[Len] !=
'/')
continue;
132 if (
IsDir(Line))
continue;
133 if (
Verbose > 1) printf(
"ISO file: %s\n",Line);
139 if (
TaintString(TempIso,FILENAME_MAX,Line+Len,1,NULL) ||
143 rc = snprintf(Cmd,
sizeof(Cmd),
"(isoinfo -R -J -i '%s' -x '%s' || isoinfo -R -i '%s' -x '%s' || isoinfo -i '%s' -x '%s') > '%s' 2>/dev/null",TempSource,TempIso,TempSource,TempIso,TempSource, TempIso,TempOut);
144 if (rc < 0 || (
size_t)rc >=
sizeof(Cmd))
147 fprintf(stderr,
"WARNING pfile %s ISO extraction command too long, skipping '%s'\n",
Pfile,Line+Len);
153 printf(
"ERROR: Process killed by signal (%d): %s\n",WTERMSIG(rc),Cmd);
156 rc = WEXITSTATUS(rc);
159 fprintf(stderr,
"ERROR: Command failed (rc=%d): %s\n",rc,Cmd);
169 snprintf(Cmd,
sizeof(Cmd),
"(isoinfo -d -R -i '%s' || isoinfo -d -R -J -i '%s' || isoinfo -d -i '%s') > '%s/ISO_INFO' 2>/dev/null",
170 TempSource, TempSource, TempSource, TempDestination);
174 printf(
"ERROR: Process killed by signal (%d): %s\n",WTERMSIG(rc),Cmd);
177 rc = WEXITSTATUS(rc);
180 fprintf(stderr,
"ERROR: Command failed (rc=%d): %s\n",rc,Cmd);
188 snprintf(Cmd,
sizeof(Cmd),
"(isoinfo -l -R -J -i '%s' || isoinfo -l -R -i '%s' || isoinfo -l -i '%s') 2>/dev/null",
189 TempSource, TempSource, TempSource);
190 Fin = popen(Cmd,
"r");
194 char Dir[FILENAME_MAX];
195 memset(Dir,
'\0',
sizeof(Dir));
196 while((Len =
ReadLine(Fin,Line,
sizeof(Line)-1)) >= 0)
198 if (Len == 0)
continue;
199 if (!strchr(
"Dd-",Line[0]))
continue;
201 if (!strncmp(Line,
"Directory listing of ",21))
206 snprintf(Cmd,
sizeof(Cmd)-1,
"%s/%s%s",Destination,Dir,Line+67);
int Verbose
Verbose level.
Stores all extern variables used by the agent.
char * Pfile
Pfile name (SHA1.MD5.Size)
int Quiet
Run in quiet mode?
int ForceContinue
Force continue when unpack tool fails?
char * TaintString(char *S)
Create a string with taint quoting.
int s
The socket that the CLI will use to communicate.
int ReadLine(FILE *Fin, char *Line, int MaxLine)
int ExtractISO(char *Source, char *Destination)
Given an ISO image and a directory, extract the image to the directory.
mode_t GetISOMode(char *Line)
Given a line in drwxrwxrwx format, convert it to a numeric mode.
int MkDir(char *Fname)
Smart mkdir.
void SafeExit(int rc)
Close scheduler and database connections, then exit.
int IsDir(char *Fname)
Given a filename, is it a directory?