38 char Name[FILENAME_MAX];
46 Basename = strrchr(Filename,
'/');
47 if (Basename) Basename++;
49 memset(
SQL,
'\0',MAXSQL);
52 memset(Name,
'\0',
sizeof(Name));
53 strcpy(Name,Filename);
54 Traverse(Filename,Basename,Label,NewDir,Recurse,&PI);
59 for(DLentry=DLhead; DLentry; DLentry=DLentry->
Next)
62 memset(Name,
'\0',
sizeof(Name));
63 strcpy(Name,Filename);
64 if (Last(Name) !=
'/') strcat(Name,
"/");
65 strcat(Name,DLentry->Name);
77 SetDir(Name,
sizeof(Name),NewDir,Basename);
78 for(i=strlen(Filename)-1; (i>=0) && (Filename[i] !=
'/'); i--)
80 if (strcmp(Filename+i+1,
".")) strcat(Name,Filename+i+1);
85 printf(
" Src: %ld %s\n",(
long)Src.st_ino,Filename);
86 printf(
" Dst: %ld %s\n",(
long)Dst.st_ino,Name);
89 if (Src.st_ino != Dst.st_ino)
91 if (
IsDir(Name)) rmdir(Name);
175 if (!strcmp(
CMD[CI->
PI.Cmd].Magic,
"application/x-zip") &&
176 ((rc==1) || (rc==2) || (rc==51)) )
178 LOG_WARNING(
"pfile %s Minor zip error(%d)... ignoring error.",
Pfile_Pk,rc)
222 if (strstr(
CMD[CI->
PI.Cmd].
Cmd,
"unzip") && (rc == 82))
224 LOG_ERROR(
"pfile %s Command %s failed on: %s, Password required.",
229 LOG_ERROR(
"pfile %s Command %s failed on: %s",
252 FullDirname = calloc(strlen(Dirname) + 3,
sizeof(
char));
253 sprintf(FullDirname,
"/%s/", Dirname);
254 NameLen = strlen(FullDirname);
257 while (((sp = strstr(sp, FullDirname)) != NULL))
291 int MaxRepeatingName = 3;
293 if (!Filename || (Filename[0]==
'\0'))
return(IsContainer);
294 if (
Verbose > 0) LOG_DEBUG(
"Traverse(%s) -- %s",Filename,Label)
299 if (
CountFilename(Filename, basename(Filename)) >= MaxRepeatingName)
301 LOG_NOTICE(
"Traverse() recursion terminating due to max directory repetition: %s", Filename);
323 rc = lstat(Filename,&CI.
Stat);
327 strcpy(CI.Source,Filename);
334 for(i=strlen(CI.Source)-1; (i>=0) && (CI.Source[i] !=
'/'); i--)
342 if (CI.
Stat.st_mode & S_IFMT & ~(S_IFREG | S_IFDIR))
351 LOG_ERROR(
"pfile %s \"%s\" DOES NOT EXIST!!!",
Pfile_Pk,Filename)
373 if (S_ISDIR(CI.
Stat.st_mode))
387 if (!NewDir && ((CI.
Stat.st_mode & 0700) != 0700))
389 chmod(Filename,(CI.
Stat.st_mode | 0700));
392 if (CI.Source[strlen(CI.Source)-1] !=
'/') strcat(CI.Source,
"/");
397 for(DLentry=DLhead; DLentry; DLentry=DLentry->
Next)
400 strcat(CI.
Partdir,DLentry->Name);
416 else if (S_ISLNK(CI.
Stat.st_mode) || S_ISCHR(CI.
Stat.st_mode) ||
417 S_ISBLK(CI.
Stat.st_mode) || S_ISFIFO(CI.
Stat.st_mode) ||
418 S_ISSOCK(CI.
Stat.st_mode))
427 else if (S_ISREG(CI.
Stat.st_mode))
438 if (CI.
PI.Cmd < 0)
goto TraverseEnd;
441 if (!NewDir && ((CI.
Stat.st_mode & 0600) != 0600))
443 chmod(Filename,(CI.
Stat.st_mode | 0600));
449 while((Index < MAXCHILD) && (
Queue[Index].ChildPid != 0))
471 strcat(
Queue[Index].ChildRecurse,
".dir");
477 LOG_FATAL(
"Unable to mkdir(%s) in Traverse",
Queue[Index].ChildRecurse)
483 if (
CMD[CI.
PI.Cmd].
Type == CMD_PARTITION)
494 snprintf(SQL, MAXSQL,
"SELECT upload_filename FROM upload WHERE upload_pk = %s;",
Upload_Pk);
495 result = PQexec(
pgConn, SQL);
500 UFileName = PQgetvalue(result,0,0);
502 if (strchr(UFileName,
'/')) UFileName = strrchr(UFileName,
'/') + 1;
512 strcat(
Queue[Index].ChildRecurse,
".unpacked");
537 char Cmd[2*FILENAME_MAX];
538 char Fname[FILENAME_MAX];
539 memcpy(&CImeta,&CI,
sizeof(CI));
545 memset(Cmd,0,
sizeof(Cmd));
546 memset(Fname,0,
sizeof(Fname));
547 strcpy(Fname,CImeta.Source);
548 strcat(CImeta.Source,
".meta");
553 unlink(CImeta.Source);
556 sprintf(Cmd,
CMD[CI.
PI.Cmd].
MetaCmd,Fname,CImeta.Source);
560 LOG_ERROR(
"Process killed by signal (%d): %s",WTERMSIG(rc),Cmd)
563 if (WIFEXITED(rc)) rc = WEXITSTATUS(rc);
565 if (rc != 0) LOG_ERROR(
"Unable to run command '%s'",Cmd)
589 LOG_FATAL(
"Unable to fork child.")
592 Queue[Index].ChildPid = Pid;
604 if (Index < 0)
goto TraverseEnd;
622 Traverse(
Queue[Index].ChildRecurse,NULL,
"Called by dir/wait",NULL,Recurse-1,&
Queue[Index].PI);
623 else if (Recurse < 0)
624 Traverse(
Queue[Index].ChildRecurse,NULL,
"Called by dir/wait",NULL,Recurse,&
Queue[Index].PI);
645 LOG_DEBUG(
"Skipping (not a file or directory): %s",CI.Source)
653 printf(
"Source: '%s'\n",CI.Source);
654 printf(
"NewDir: '%s'\n",NewDir ? NewDir :
"");
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
char ChildRecurse[FILENAME_MAX+1]
int ParentWait()
Wait for a child. Sets child status.
Queue for files to be unpacked.
Structure for storing information about a particular file.
unpackqueue Queue[MAXCHILD+1]
Manage children.
void CopyFile(char *Source, char *Type, char *Name)
char Partname[FILENAME_MAX]
PGconn * pgConn
Database connection.
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
int IsFile(long mode)
Check if the pfile_id is a file.
int DisplayContainerInfo(ContainerInfo *CI, int Cmd)
Print what can be printed in XML.
int ExtractDisk(char *Source, char *FStype, char *Destination)
Given a disk image, type of system, and a directory, extract all files!
int Thread
Number of threads in execution.
int IsDir(char *Fname)
Given a filename, is it a directory?
int Verbose
Verbose level.
FILE * ListOutFile
File to store unpack list.
int ExtractISO(char *Source, char *Destination)
Given an ISO image and a directory, extract the image to the directory.
char * Pfile_Pk
Pfile pk in DB.
int ExtractAR(char *Source, char *Destination)
Given an AR file, extract the contents to the directory. This uses the command ar.
int IsInflatedFile(char *FileName, int InflateSize)
Test if the file is a compression bomb.
int Traverse(char *Filename, char *Basename, char *Label, char *NewDir, int Recurse, ParentInfo *PI)
Find all files, traverse all directories. This is a depth-first search, in inode order! ...
int CountFilename(char *Pathname, char *Dirname)
Count the number of times Dirname appears in Pathname This is used to limit recursion in test archive...
char UploadFileName[FILENAME_MAX]
Upload file name.
int MkDir(char *Fname)
Smart mkdir.
int FindCmd(char *Filename)
Given a file name, determine the type of extraction command. This uses Magic.
void SetDir(char *Dest, int DestLen, char *Smain, char *Sfile)
Set a destination directory name.
cmdlist CMD[]
Global command table.
void RemovePostfix(char *Name)
get rid of the postfix
char Partdir[FILENAME_MAX]
dirlist * MakeDirList(char *Fullname)
Create a list of files in a directory.
char SQL[256]
SQL query to execute.
int UseRepository
Using files from the repository?
int PruneFiles
Remove links? >1 hard links, zero files, etc.
int TotalContainers
Number of containers.
char * NewDir
Test result directory.
int Prune(char *Fname, struct stat Stat)
Given a filename and its stat, prune it.
int UnlinkSource
Remove recursive sources after unpacking?
Stores all extern variables used by the agent.
char * Upload_Pk
Upload pk in DB.
void FreeDirList(dirlist *DL)
Free a list of files in a directory list.
void TraverseChild(int Index, ContainerInfo *CI, char *NewDir)
Called by exec'd child to process.
int RunCommand(char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where)
Try a command and return command code.
int MaxThread
Value between 1 and MAXCHILD.
void TraverseStart(char *Filename, char *Label, char *NewDir, int Recurse)
Find all files (assuming a directory) and process (unpack) all of them.
int UnlinkAll
Remove ALL unpacked files when done (clean up)?
void SafeExit(int rc)
Close scheduler and database connections, then exit.
int Recurse
Level of unpack recursion. Default to infinite.
int ForceContinue
Force continue when unpack tool fails?
char PartnameNew[FILENAME_MAX]