39 char Cmd[FILENAME_MAX*4];
40 char Line[FILENAME_MAX];
44 char TempSource[FILENAME_MAX];
45 char CWD[FILENAME_MAX];
48 if ((NULL == Source) || (!strcmp(Source,
"")) || (NULL == Destination) || (!strcmp(Destination,
"")))
51 if (getcwd(CWD,
sizeof(CWD)) == NULL)
53 fprintf(stderr,
"ERROR: directory name longer than %d characters\n",(
int)
sizeof(CWD));
58 printf(
"CWD: %s\n",CWD);
59 if (!
Quiet) fprintf(stderr,
"Extracting ar: %s\n",Source);
62 if(chdir(Destination) != 0)
64 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n",
65 __FILE__, __LINE__, Destination);
66 fprintf(stderr,
"ERROR: errno is: %s\n", strerror(errno));
69 if (
TaintString(TempSource,FILENAME_MAX,Source,1,NULL))
71 memset(Cmd,
'\0',
sizeof(Cmd));
75 if (TempSource[0] !=
'/')
76 snprintf(Cmd,
sizeof(Cmd),
" (ar t '%s/%s') 2>/dev/null",CWD,TempSource);
78 snprintf(Cmd,
sizeof(Cmd),
" (ar t '%s') 2>/dev/null",TempSource);
83 fprintf(stderr,
"ERROR: ar failed: %s\n",Cmd);
86 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n",
87 __FILE__, __LINE__, CWD);
88 fprintf(stderr,
"ERROR: errno is: %s\n", strerror(errno));
92 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
95 if (Line[0]==
'/') { pclose(Fin);
return(1); }
97 if (s == NULL)
continue;
101 fprintf(stderr,
"ERROR: Unable to mkdir(%s) in ExtractAR\n",Line);
108 if (TempSource[0] !=
'/')
109 snprintf(Cmd,
sizeof(Cmd),
" (ar x '%s/%s') 2>/dev/null",CWD,TempSource);
111 snprintf(Cmd,
sizeof(Cmd),
" (ar x '%s') 2>/dev/null",TempSource);
112 rc = WEXITSTATUS(system(Cmd));
115 fprintf(stderr,
"ERROR: Command failed (rc=%d): %s\n",rc,Cmd);
121 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n",
122 __FILE__, __LINE__, CWD);
123 fprintf(stderr,
"ERROR: errno is: %s\n", strerror(errno));
int Quiet
Run in quiet mode?
int Verbose
Verbose level.
int s
The socket that the CLI will use to communicate.
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.
Stores all extern variables used by the agent.
char * TaintString(char *S)
Create a string with taint quoting.
int ReadLine(FILE *Fin, char *Line, int MaxLine)
int ForceContinue
Force continue when unpack tool fails?