FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ununpack.h
1 /*
2  Ununpack: The universal unpacker.
3 
4  SPDX-FileCopyrightText: © 2007-2011 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 
8  This time, it's rewritten in C for speed and multithreading.
9 */
10 #ifndef UNUNPACK_H
11 #define UNUNPACK_H
12 
13 
14 #include <ctype.h>
15 #include <dirent.h>
16 #include <errno.h>
17 #include <fcntl.h>
18 #include <magic.h>
19 #include <signal.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <time.h>
24 #include <unistd.h>
25 #include <libgen.h>
26 
27 #include <sys/mman.h>
28 #include <sys/stat.h>
29 #include <sys/time.h>
30 //#include <sys/timeb.h>
31 #include <sys/types.h>
32 #include <sys/wait.h>
33 
34 #include "checksum.h"
35 #include "ununpack-ar.h"
36 #include "ununpack-disk.h"
37 #include "ununpack-iso.h"
38 #include "ununpack-zstd.h"
39 
40 #ifdef STANDALONE
41 #include "standalone.h"
42 #else
43 #include "libfossology.h"
44 #endif
45 
46 #define Last(x) (x)[strlen(x)-1]
47 #define MAXCHILD 4096
48 #define MAXSQL 4096
49 #define PATH_MAX 4096
50 
54 enum cmdtype
55 {
56  CMD_NULL=0,
57  CMD_PACK,
58  CMD_RPM,
59  CMD_ARC,
60  CMD_AR,
61  CMD_PARTITION,
62  CMD_ISO,
63  CMD_DISK,
64  CMD_DEB,
65  CMD_ZSTD,
66  CMD_DEFAULT
67 };
68 
69 typedef enum cmdtype cmdtype;
75 struct ParentInfo
76 {
77  int Cmd;
78  time_t StartTime;
79  time_t EndTime;
82 };
83 typedef struct ParentInfo ParentInfo;
84 
89 {
90  int ChildPid;
91  char ChildRecurse[FILENAME_MAX+1];
94  int ChildEnd;
96  struct stat ChildStat;
98 };
99 typedef struct unpackqueue unpackqueue;
100 
104 struct dirlist
105 {
106  char *Name;
107  struct dirlist *Next;
108 };
109 typedef struct dirlist dirlist;
110 
116 {
117  char Source[FILENAME_MAX];
118  char Partdir[FILENAME_MAX];
119  char Partname[FILENAME_MAX];
120  char PartnameNew[FILENAME_MAX];
122  int HasChild;
123  int Pruned;
124  int Corrupt;
125  struct stat Stat;
127  int Artifact;
128  int IsDir;
131  long pfile_pk;
132  long ufile_mode;
133 };
134 typedef struct ContainerInfo ContainerInfo;
135 
142 struct cmdlist
143 {
144  char * Magic;
145  char * Cmd;
146  char * CmdPre;
147  char * CmdPost;
148  char * MetaCmd;
149  cmdtype Type;
150  int Status;
153  long DBindex;
154 };
155 typedef struct cmdlist cmdlist;
156 
157 /* utils.c */
158 int IsInflatedFile(char *FileName, int InflateSize);
159 int IsDebianSourceFile(char *Filename);
160 void SafeExit (int rc);
161 void RemovePostfix(char *Name);
162 void InitCmd ();
163 int TaintString (char *Dest, int DestLen, char *Src, int ProtectQuotes, char *Replace);
164 extern int Prune (char *Fname, struct stat Stat);
165 extern int MkDirs (char *Fname);
166 extern int MkDir (char *Fname);
167 extern int IsDir (char *Fname);
168 extern int RemoveDir (char *dirpath);
169 int IsFile (char *Fname, int Link);
170 int ReadLine (FILE *Fin, char *Line, int MaxLine);
171 int IsExe (char *Exe, int Quiet);
172 int CopyFile (char *Src, char *Dst);
173 int ParentWait();
174 void CheckCommands (int Show);
175 int RunCommand (char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where);
176 int InitMagic();
177 int FindCmd (char *Filename);
178 void FreeDirList (dirlist *DL);
179 dirlist * MakeDirList (char *Fullname);
180 void SetDir (char *Dest, int DestLen, char *Smain, char *Sfile);
182 int DBInsertPfile (ContainerInfo *CI, char *Fuid);
183 int DBInsertUploadTree (ContainerInfo *CI, int Mask);
184 int AddToRepository (ContainerInfo *CI, char *Fuid, int Mask);
185 int DisplayContainerInfo (ContainerInfo *CI, int Cmd);
186 char *PathCheck(char *DirPath);
187 void Usage (char *Name, char *Version);
188 void deleteTmpFiles(char *dir);
189 void SQLNoticeProcessor(void *arg, const char *message);
190 
191 /* traverse.c */
192 void TraverseStart (char *Filename, char *Label, char *NewDir, int Recurse);
193 void TraverseChild (int Index, ContainerInfo *CI, char *NewDir);
194 int Traverse (char *Filename, char *Basename, char *Label, char *NewDir,
195  int Recurse, ParentInfo *PI);
196 
197 #endif
198 
int Quiet
Run in quiet mode?
char * TaintString(char *S)
Create a string with taint quoting.
Definition: finder.c:35
Usage()
Print Usage statement.
Definition: fo_dbcheck.php:63
The main FOSSology C library.
void CopyFile(char *Source, char *Type, char *Name)
Definition: repcopyin.c:39
int ReadLine(FILE *Fin, char *Line, int MaxLine)
Definition: repcopyin.c:64
Structure for storing information about a particular file.
Definition: ununpack.h:116
int IsCompressed
Definition: ununpack.h:129
long pfile_pk
Definition: ununpack.h:131
int TopContainer
Definition: ununpack.h:121
ParentInfo PI
Definition: ununpack.h:126
char Partname[FILENAME_MAX]
Definition: ununpack.h:119
long uploadtree_pk
Definition: ununpack.h:130
long ufile_mode
Definition: ununpack.h:132
struct stat Stat
Definition: ununpack.h:125
char PartnameNew[FILENAME_MAX]
Definition: ununpack.h:120
char Partdir[FILENAME_MAX]
Definition: ununpack.h:118
Definition: monk.h:61
time_t StartTime
Definition: ununpack.h:78
long uploadtree_pk
Definition: ununpack.h:81
int ChildRecurseArtifact
Definition: ununpack.h:80
time_t EndTime
Definition: ununpack.h:79
Command table's single row.
Definition: ununpack.h:143
cmdtype Type
Definition: ununpack.h:149
long DBindex
Definition: ununpack.h:153
int Status
Definition: ununpack.h:150
char * MetaCmd
Definition: ununpack.h:148
char * Cmd
Definition: ununpack.h:145
int ModeMaskReg
Definition: ununpack.h:152
char * CmdPost
Definition: ununpack.h:147
char * CmdPre
Definition: ununpack.h:146
int ModeMaskDir
Definition: ununpack.h:151
Directory linked list.
Definition: ununpack.h:105
struct dirlist * Next
Definition: ununpack.h:107
Queue for files to be unpacked.
Definition: ununpack.h:89
int ChildStatus
Definition: ununpack.h:92
ParentInfo PI
Definition: ununpack.h:97
struct stat ChildStat
Definition: ununpack.h:96
int ChildEnd
Definition: ununpack.h:94
char ChildRecurse[FILENAME_MAX+1]
Definition: ununpack.h:91
int ChildCorrupt
Definition: ununpack.h:93
int ChildHasChild
Definition: ununpack.h:95
static char * Dst
Destination location.
Definition: test_CopyFile.c:14
static char * Src
Souce location.
Definition: test_CopyFile.c:13
void TraverseStart(char *Filename, char *Label, char *NewDir, int Recurse)
Find all files (assuming a directory) and process (unpack) all of them.
Definition: traverse.c:23
void TraverseChild(int Index, ContainerInfo *CI, char *NewDir)
Called by exec'd child to process.
Definition: traverse.c:96
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!
Definition: traverse.c:275
int RunCommand(char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where)
Try a command and return command code.
Definition: utils.c:621
int DisplayContainerInfo(ContainerInfo *CI, int Cmd)
Print what can be printed in XML.
Definition: utils.c:1457
void DebugContainerInfo(ContainerInfo *CI)
Print a ContainerInfo structure.
Definition: utils.c:1085
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
Definition: utils.c:1641
int MkDirs(char *Fname)
Same as command-line "mkdir -p".
Definition: utils.c:248
int Prune(char *Fname, struct stat Stat)
Given a filename and its stat, prune it.
Definition: utils.c:217
int InitMagic()
Open and load Magic file Initializes global MagicCookie.
Definition: utils.c:715
void CheckCommands(int Show)
Make sure all commands are usable.
Definition: utils.c:567
int IsDebianSourceFile(char *Filename)
Read file to see if it is a Debian source file.
Definition: utils.c:733
int MkDir(char *Fname)
Smart mkdir.
Definition: utils.c:303
void SetDir(char *Dest, int DestLen, char *Smain, char *Sfile)
Set a destination directory name.
Definition: utils.c:1047
int ParentWait()
Wait for a child. Sets child status.
Definition: utils.c:509
void RemovePostfix(char *Name)
get rid of the postfix
Definition: utils.c:90
int AddToRepository(ContainerInfo *CI, char *Fuid, int Mask)
Add a ContainerInfo record to the repository AND to the database.
Definition: utils.c:1402
void FreeDirList(dirlist *DL)
Free a list of files in a directory list.
Definition: utils.c:951
int DBInsertPfile(ContainerInfo *CI, char *Fuid)
Insert a Pfile record. Sets the pfile_pk in CI.
Definition: utils.c:1114
int DBInsertUploadTree(ContainerInfo *CI, int Mask)
Insert an UploadTree record.
Definition: utils.c:1286
void InitCmd()
Initialize the metahandler CMD table.
Definition: utils.c:108
int IsExe(char *Exe, int Quiet)
Check if the executable exists.
Definition: utils.c:393
void SafeExit(int rc)
Close scheduler and database connections, then exit.
Definition: utils.c:77
int FindCmd(char *Filename)
Given a file name, determine the type of extraction command. This uses Magic.
Definition: utils.c:850
int IsInflatedFile(char *FileName, int InflateSize)
Test if the file is a compression bomb.
Definition: utils.c:40
char * PathCheck(char *DirPath)
Check if path contains a "%U" or "%H". If so, substitute a unique ID for U.
Definition: utils.c:1662
void SQLNoticeProcessor(void *arg, const char *message)
Dummy postgresql notice processor. This prevents Notices from being written to stderr.
Definition: utils.c:1772
dirlist * MakeDirList(char *Fullname)
Create a list of files in a directory.
Definition: utils.c:970
int IsDir(char *Fname)
Given a filename, is it a directory?
Definition: utils.c:319
int Recurse
Level of unpack recursion. Default to infinite.
Definition: run_tests.c:19
char * NewDir
Test result directory.
Definition: run_tests.c:18
char * Filename
Filename.
Definition: run_tests.c:17
int IsFile(long mode)
Check if the pfile_id is a file.
Definition: wc_agent.c:55