28 char Cmd[FILENAME_MAX*4];
29 char Line[FILENAME_MAX];
33 char TempSource[FILENAME_MAX];
34 char CWD[FILENAME_MAX];
37 if ((NULL == Source) || (!strcmp(Source,
"")) || (NULL == Destination) || (!strcmp(Destination,
"")))
40 if (getcwd(CWD,
sizeof(CWD)) == NULL)
42 fprintf(stderr,
"ERROR: directory name longer than %d characters\n",(
int)
sizeof(CWD));
47 printf(
"CWD: %s\n",CWD);
48 if (!
Quiet) fprintf(stderr,
"Extracting ar: %s\n",Source);
51 if(chdir(Destination) != 0)
53 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n",
54 __FILE__, __LINE__, Destination);
55 fprintf(stderr,
"ERROR: errno is: %s\n", strerror(errno));
58 if (
TaintString(TempSource,FILENAME_MAX,Source,1,NULL))
60 memset(Cmd,
'\0',
sizeof(Cmd));
64 if (TempSource[0] !=
'/')
65 snprintf(Cmd,
sizeof(Cmd),
" (ar t '%s/%s') 2>/dev/null",CWD,TempSource);
67 snprintf(Cmd,
sizeof(Cmd),
" (ar t '%s') 2>/dev/null",TempSource);
72 fprintf(stderr,
"ERROR: ar failed: %s\n",Cmd);
75 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n",
76 __FILE__, __LINE__, CWD);
77 fprintf(stderr,
"ERROR: errno is: %s\n", strerror(errno));
81 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
84 if (Line[0]==
'/') { pclose(Fin);
return(1); }
86 if (
s == NULL)
continue;
90 fprintf(stderr,
"ERROR: Unable to mkdir(%s) in ExtractAR\n",Line);
97 if (TempSource[0] !=
'/')
98 snprintf(Cmd,
sizeof(Cmd),
" (ar x '%s/%s') 2>/dev/null",CWD,TempSource);
100 snprintf(Cmd,
sizeof(Cmd),
" (ar x '%s') 2>/dev/null",TempSource);
101 rc = WEXITSTATUS(system(Cmd));
104 fprintf(stderr,
"ERROR: Command failed (rc=%d): %s\n",rc,Cmd);
110 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n",
111 __FILE__, __LINE__, CWD);
112 fprintf(stderr,
"ERROR: errno is: %s\n", strerror(errno));
int Verbose
Verbose level.
Stores all extern variables used by the agent.
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 ExtractAR(char *Source, char *Destination)
Given an AR file, extract the contents to the directory. This uses the command ar.
int MkDir(char *Fname)
Smart mkdir.