23 int ExtractLzip(
char *Source,
const char *OrigName,
char *Destination)
25 char Cmd[FILENAME_MAX * 4];
27 char TempSource[FILENAME_MAX];
28 char CWD[FILENAME_MAX];
29 char OutputName[FILENAME_MAX] = {
'\0'};
33 if ((NULL == Source) || (!strcmp(Source,
"")) || (NULL == Destination) ||
34 (!strcmp(Destination,
""))) {
38 if (getcwd(CWD,
sizeof(CWD)) == NULL) {
39 fprintf(stderr,
"ERROR: directory name longer than %d characters\n",
45 while (OrigName[i] !=
'\0') {
46 if (OrigName[i] ==
'.') {
47 const char *ext = &OrigName[i + 1];
48 if (strncasecmp(ext,
"lz", 2) == 0) {
51 else if (strncasecmp(ext,
"tlz", 3) == 0) {
57 OutputName[i] = OrigName[i];
64 printf(
"CWD: %s\n", CWD);
65 if (!
Quiet) { fprintf(stderr,
"Extracting lzip: %s\n", Source); }
68 if (chdir(Destination) != 0) {
69 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n",
70 __FILE__, __LINE__, Destination);
71 fprintf(stderr,
"ERROR: errno is: %s\n", strerror(errno));
74 if (
TaintString(TempSource, FILENAME_MAX, Source, 1, NULL)) {
77 memset(Cmd,
'\0',
sizeof(Cmd));
80 printf(
"Extracting lzip with output name: %s\n", OutputName);
89 if (TempSource[0] !=
'/') {
90 snprintf(Cmd,
sizeof(Cmd),
91 " (lzip --decompress --keep --force -o '%s/%s' "
92 "'%s/%s') 2>/dev/null", Destination, OutputName,
96 snprintf(Cmd,
sizeof(Cmd),
97 " (lzip --decompress --keep --force -o '%s/%s' "
98 "'%s') 2>/dev/null", Destination, OutputName,
102 rc = WEXITSTATUS(system(Cmd));
104 fprintf(stderr,
"ERROR: Command failed (rc=%d): %s\n", rc, Cmd);
107 if (chdir(CWD) != 0) {
108 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n", __FILE__, __LINE__, CWD);
109 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?
char * TaintString(char *S)
Create a string with taint quoting.
int ExtractLzip(char *Source, const char *OrigName, char *Destination)
Given an lzip file, extract the contents to the directory.