FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ununpack.h
1 /*******************************************************************
2  Ununpack: The universal unpacker.
3 
4  Copyright (C) 2007-2011 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  ******************
20  This time, it's rewritten in C for speed and multithreading.
21  *******************************************************************/
22 #ifndef UNUNPACK_H
23 #define UNUNPACK_H
24 
25 
26 #include <ctype.h>
27 #include <dirent.h>
28 #include <errno.h>
29 #include <fcntl.h>
30 #include <magic.h>
31 #include <signal.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <time.h>
36 #include <unistd.h>
37 #include <libgen.h>
38 
39 #include <sys/mman.h>
40 #include <sys/stat.h>
41 #include <sys/time.h>
42 //#include <sys/timeb.h>
43 #include <sys/types.h>
44 #include <sys/wait.h>
45 
46 #include "libfossology.h"
47 #include "checksum.h"
48 #include "ununpack-ar.h"
49 #include "ununpack-disk.h"
50 #include "ununpack-iso.h"
51 
52 #define Last(x) (x)[strlen(x)-1]
53 #define MAXCHILD 4096
54 #define MAXSQL 4096
55 #define PATH_MAX 4096
56 
60 enum cmdtype
61 {
62  CMD_NULL=0,
63  CMD_PACK,
64  CMD_RPM,
65  CMD_ARC,
66  CMD_AR,
67  CMD_PARTITION,
68  CMD_ISO,
69  CMD_DISK,
70  CMD_DEB,
71  CMD_DEFAULT
72 };
73 
74 typedef enum cmdtype cmdtype;
80 struct ParentInfo
81 {
82  int Cmd;
83  time_t StartTime;
84  time_t EndTime;
87 };
88 typedef struct ParentInfo ParentInfo;
89 
94 {
95  int ChildPid;
96  char ChildRecurse[FILENAME_MAX+1];
99  int ChildEnd;
101  struct stat ChildStat;
103 };
104 typedef struct unpackqueue unpackqueue;
105 
109 struct dirlist
110 {
111  char *Name;
112  struct dirlist *Next;
113 };
114 typedef struct dirlist dirlist;
115 
121 {
122  char Source[FILENAME_MAX];
123  char Partdir[FILENAME_MAX];
124  char Partname[FILENAME_MAX];
125  char PartnameNew[FILENAME_MAX];
127  int HasChild;
128  int Pruned;
129  int Corrupt;
130  struct stat Stat;
132  int Artifact;
133  int IsDir;
136  long pfile_pk;
137  long ufile_mode;
138 };
139 typedef struct ContainerInfo ContainerInfo;
140 
147 struct cmdlist
148 {
149  char * Magic;
150  char * Cmd;
151  char * CmdPre;
152  char * CmdPost;
153  char * MetaCmd;
154  cmdtype Type;
155  int Status;
158  long DBindex;
159 };
160 typedef struct cmdlist cmdlist;
161 
162 /* utils.c */
163 int IsInflatedFile(char *FileName, int InflateSize);
164 int IsDebianSourceFile(char *Filename);
165 void SafeExit (int rc);
166 void RemovePostfix(char *Name);
167 void InitCmd ();
168 int TaintString (char *Dest, int DestLen, char *Src, int ProtectQuotes, char *Replace);
169 extern int Prune (char *Fname, struct stat Stat);
170 extern int MkDirs (char *Fname);
171 extern int MkDir (char *Fname);
172 extern int IsDir (char *Fname);
173 extern int RemoveDir (char *dirpath);
174 int IsFile (char *Fname, int Link);
175 int ReadLine (FILE *Fin, char *Line, int MaxLine);
176 int IsExe (char *Exe, int Quiet);
177 int CopyFile (char *Src, char *Dst);
178 int ParentWait();
179 void CheckCommands (int Show);
180 int RunCommand (char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where);
181 int InitMagic();
182 int FindCmd (char *Filename);
183 void FreeDirList (dirlist *DL);
184 dirlist * MakeDirList (char *Fullname);
185 void SetDir (char *Dest, int DestLen, char *Smain, char *Sfile);
187 int DBInsertPfile (ContainerInfo *CI, char *Fuid);
188 int DBInsertUploadTree (ContainerInfo *CI, int Mask);
189 int AddToRepository (ContainerInfo *CI, char *Fuid, int Mask);
190 int DisplayContainerInfo (ContainerInfo *CI, int Cmd);
191 char *PathCheck(char *DirPath);
192 void Usage (char *Name, char *Version);
193 void deleteTmpFiles(char *dir);
194 void SQLNoticeProcessor(void *arg, const char *message);
195 
196 /* traverse.c */
197 void TraverseStart (char *Filename, char *Label, char *NewDir, int Recurse);
198 void TraverseChild (int Index, ContainerInfo *CI, char *NewDir);
199 int Traverse (char *Filename, char *Basename, char *Label, char *NewDir,
200  int Recurse, ParentInfo *PI);
201 
202 #endif
203 
char * PathCheck(char *DirPath)
Check if path contains a "%U" or "%H". If so, substitute a unique ID for U.
Definition: utils.c:1672
int Quiet
Run in quiet mode?
int ParentWait()
Wait for a child. Sets child status.
Definition: utils.c:520
Queue for files to be unpacked.
Definition: ununpack.h:93
Structure for storing information about a particular file.
Definition: ununpack.h:120
void CopyFile(char *Source, char *Type, char *Name)
Definition: repcopyin.c:52
Definition: monk.h:72
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
Definition: utils.c:1651
int IsFile(long mode)
Check if the pfile_id is a file.
Definition: wc_agent.c:67
int DisplayContainerInfo(ContainerInfo *CI, int Cmd)
Print what can be printed in XML.
Definition: utils.c:1467
int IsDir(char *Fname)
Given a filename, is it a directory?
Definition: utils.c:330
ParentInfo PI
Definition: ununpack.h:131
int IsInflatedFile(char *FileName, int InflateSize)
Test if the file is a compression bomb.
Definition: utils.c:51
long uploadtree_pk
Definition: ununpack.h:135
char * CmdPost
Definition: ununpack.h:152
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:282
long DBindex
Definition: ununpack.h:158
int IsDebianSourceFile(char *Filename)
Read file to see if it is a Debian source file.
Definition: utils.c:743
int MkDir(char *Fname)
Smart mkdir.
Definition: utils.c:314
int FindCmd(char *Filename)
Given a file name, determine the type of extraction command. This uses Magic.
Definition: utils.c:860
int ModeMaskDir
Definition: ununpack.h:156
int Status
Definition: ununpack.h:155
void SetDir(char *Dest, int DestLen, char *Smain, char *Sfile)
Set a destination directory name.
Definition: utils.c:1057
int ModeMaskReg
Definition: ununpack.h:157
static char * Src
Souce location.
Definition: test_CopyFile.c:24
ParentInfo PI
Definition: ununpack.h:102
int ChildCorrupt
Definition: ununpack.h:98
void RemovePostfix(char *Name)
get rid of the postfix
Definition: utils.c:101
char * Cmd
Definition: ununpack.h:150
Command table&#39;s single row.
Definition: ununpack.h:147
int IsCompressed
Definition: ununpack.h:134
void SQLNoticeProcessor(void *arg, const char *message)
Dummy postgresql notice processor. This prevents Notices from being written to stderr.
Definition: utils.c:1782
long ufile_mode
Definition: ununpack.h:137
time_t EndTime
Definition: ununpack.h:84
int IsExe(char *Exe, int Quiet)
Check if the executable exists.
Definition: utils.c:404
static char * Dst
Destination location.
Definition: test_CopyFile.c:25
dirlist * MakeDirList(char *Fullname)
Create a list of files in a directory.
Definition: utils.c:980
int ChildRecurseArtifact
Definition: ununpack.h:85
long uploadtree_pk
Definition: ununpack.h:86
int ChildHasChild
Definition: ununpack.h:100
char * MetaCmd
Definition: ununpack.h:153
Usage()
Print Usage statement.
Definition: fo_dbcheck.php:75
char * CmdPre
Definition: ununpack.h:151
The main FOSSology C library.
void CheckCommands(int Show)
Make sure all commands are usable.
Definition: utils.c:578
char * NewDir
Test result directory.
Definition: run_tests.c:29
int Prune(char *Fname, struct stat Stat)
Given a filename and its stat, prune it.
Definition: utils.c:228
int AddToRepository(ContainerInfo *CI, char *Fuid, int Mask)
Add a ContainerInfo record to the repository AND to the database.
Definition: utils.c:1412
int TopContainer
Definition: ununpack.h:126
time_t StartTime
Definition: ununpack.h:83
void FreeDirList(dirlist *DL)
Free a list of files in a directory list.
Definition: utils.c:961
char * TaintString(char *S)
Create a string with taint quoting.
Definition: finder.c:46
void TraverseChild(int Index, ContainerInfo *CI, char *NewDir)
Called by exec&#39;d child to process.
Definition: traverse.c:107
int RunCommand(char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where)
Try a command and return command code.
Definition: utils.c:631
int ReadLine(FILE *Fin, char *Line, int MaxLine)
Definition: repcopyin.c:77
int ChildEnd
Definition: ununpack.h:99
char * Filename
Filename.
Definition: run_tests.c:28
int MkDirs(char *Fname)
Same as command-line "mkdir -p".
Definition: utils.c:259
cmdtype Type
Definition: ununpack.h:154
int DBInsertUploadTree(ContainerInfo *CI, int Mask)
Insert an UploadTree record.
Definition: utils.c:1296
struct dirlist * Next
Definition: ununpack.h:112
void InitCmd()
Initialize the metahandler CMD table.
Definition: utils.c:119
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:34
Directory linked list.
Definition: ununpack.h:109
void SafeExit(int rc)
Close scheduler and database connections, then exit.
Definition: utils.c:88
int Recurse
Level of unpack recursion. Default to infinite.
Definition: run_tests.c:30
int InitMagic()
Open and load Magic file Initializes global MagicCookie.
Definition: utils.c:725
int ChildStatus
Definition: ununpack.h:97
void DebugContainerInfo(ContainerInfo *CI)
Print a ContainerInfo structure.
Definition: utils.c:1095
long pfile_pk
Definition: ununpack.h:136
int DBInsertPfile(ContainerInfo *CI, char *Fuid)
Insert a Pfile record. Sets the pfile_pk in CI.
Definition: utils.c:1124