![]() |
FOSSology
4.5.1
Open Source License Compliance by Open Source Software
|
Contains all utility functions used by FOSSology. More...

Go to the source code of this file.
Enumerations | |
| enum | BITS { BITS_PROJECT = 27 , BITS_ARTIFACT = 28 , BITS_CONTAINER = 29 } |
| File mode BITS. | |
Functions | |
| int | IsInflatedFile (char *FileName, int InflateSize) |
| Test if the file is a compression bomb. More... | |
| void | SafeExit (int rc) |
| Close scheduler and database connections, then exit. More... | |
| void | RemovePostfix (char *Name) |
| get rid of the postfix More... | |
| void | InitCmd () |
| Initialize the metahandler CMD table. More... | |
| int | TaintString (char *Dest, int DestLen, char *Src, int ProtectQuotes, char *Replace) |
| Protect strings intelligently. More... | |
| int | Prune (char *Fname, struct stat Stat) |
| Given a filename and its stat, prune it. More... | |
| int | MkDirs (char *Fname) |
| Same as command-line "mkdir -p". More... | |
| int | MkDir (char *Fname) |
| Smart mkdir. More... | |
| int | IsDir (char *Fname) |
| Given a filename, is it a directory? More... | |
| int | IsFile (char *Fname, int Link) |
| Given a filename, is it a file? More... | |
| int | ReadLine (FILE *Fin, char *Line, int MaxLine) |
| Read a command from a stream. More... | |
| int | IsExe (char *Exe, int Quiet) |
| Check if the executable exists. More... | |
| int | CopyFile (char *Src, char *Dst) |
| Copy a file. For speed: mmap and save. More... | |
| int | ParentWait () |
| Wait for a child. Sets child status. More... | |
| void | CheckCommands (int Show) |
| Make sure all commands are usable. More... | |
| int | RunCommand (char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where) |
| Try a command and return command code. More... | |
| int | InitMagic () |
| Open and load Magic file Initializes global MagicCookie. More... | |
| int | IsDebianSourceFile (char *Filename) |
| Read file to see if it is a Debian source file. More... | |
| void | OctetType (char *Filename, char *TypeBuf) |
| Figure out the real type of "octet" files in case we can unarchive them. More... | |
| int | FindCmd (char *Filename) |
| Given a file name, determine the type of extraction command. This uses Magic. More... | |
| void | FreeDirList (dirlist *DL) |
| Free a list of files in a directory list. More... | |
| dirlist * | MakeDirList (char *Fullname) |
| Create a list of files in a directory. More... | |
| void | SetDir (char *Dest, int DestLen, char *Smain, char *Sfile) |
| Set a destination directory name. More... | |
| void | DebugContainerInfo (ContainerInfo *CI) |
| Print a ContainerInfo structure. More... | |
| int | DBInsertPfile (ContainerInfo *CI, char *Fuid) |
| Insert a Pfile record. Sets the pfile_pk in CI. More... | |
| int | TestSCMData (char *sourcefilename) |
| Search for SCM data in the filename. More... | |
| int | DBInsertUploadTree (ContainerInfo *CI, int Mask) |
| Insert an UploadTree record. More... | |
| int | AddToRepository (ContainerInfo *CI, char *Fuid, int Mask) |
| Add a ContainerInfo record to the repository AND to the database. More... | |
| int | DisplayContainerInfo (ContainerInfo *CI, int Cmd) |
| Print what can be printed in XML. More... | |
| int | RemoveDir (char *dirpath) |
| Remove all files under dirpath (rm -rf) More... | |
| char * | PathCheck (char *DirPath) |
| Check if path contains a "%U" or "%H". If so, substitute a unique ID for U. More... | |
| void | deleteTmpFiles (char *dir) |
| void | Usage (char *Name, char *Version) |
| Display program usage. More... | |
| void | SQLNoticeProcessor (void *arg, const char *message) |
| Dummy postgresql notice processor. This prevents Notices from being written to stderr. More... | |
| int | ShouldExclude (char *Filename, const char *ExcludePatterns) |
| Determines if a file or folder should be excluded. More... | |
Variables | |
| const char * | SCM_REGEX = "/\\.git|\\.hg|\\.bzr|CVS/ROOT|\\.svn/" |
Contains all utility functions used by FOSSology.
Definition in file utils.c.
| int AddToRepository | ( | ContainerInfo * | CI, |
| char * | Fuid, | ||
| int | Mask | ||
| ) |
Add a ContainerInfo record to the repository AND to the database.
This modifies the CI record's pfile and ufile indexes!
| CI | |
| Fuid | sha1.md5.sha256.size |
| Mask | file mode mask |
| void CheckCommands | ( | int | Show | ) |
| int CopyFile | ( | char * | Src, |
| char * | Dst | ||
| ) |
| int DBInsertPfile | ( | ContainerInfo * | CI, |
| char * | Fuid | ||
| ) |
| int DBInsertUploadTree | ( | ContainerInfo * | CI, |
| int | Mask | ||
| ) |
Insert an UploadTree record.
If the tree is a duplicate, then we need to replicate all of the uploadtree records for the tree. This uses Upload_Pk.
| CI | |
| Mask | mask file mode for ufile_mode |
| void DebugContainerInfo | ( | ContainerInfo * | CI | ) |
Print a ContainerInfo structure.
| CI | ContainerInfo struct to print |
| int DisplayContainerInfo | ( | ContainerInfo * | CI, |
| int | Cmd | ||
| ) |
| int FindCmd | ( | char * | Filename | ) |
| void FreeDirList | ( | dirlist * | DL | ) |
| void InitCmd | ( | ) |
| int InitMagic | ( | ) |
| int IsDebianSourceFile | ( | char * | Filename | ) |
| int IsDir | ( | char * | Fname | ) |
| int IsExe | ( | char * | Exe, |
| int | Quiet | ||
| ) |
Check if the executable exists.
(Like the command-line "which" but without returning the path.)
| Exe | Executable file name |
| Quiet | If true, do not write warning on file not found |
| int IsFile | ( | char * | Fname, |
| int | Link | ||
| ) |
| int IsInflatedFile | ( | char * | FileName, |
| int | InflateSize | ||
| ) |
Test if the file is a compression bomb.
If the size of FileName is a factor of InflateSize more than the size of the directory containing it, then it is a bomb.
| FileName | pathname to file |
| InflateSize | Inflation factor. |
| dirlist* MakeDirList | ( | char * | Fullname | ) |
| int MkDir | ( | char * | Fname | ) |
| int MkDirs | ( | char * | Fname | ) |
| void OctetType | ( | char * | Filename, |
| char * | TypeBuf | ||
| ) |
| int ParentWait | ( | ) |
| char* PathCheck | ( | char * | DirPath | ) |
| int Prune | ( | char * | Fname, |
| struct stat | Stat | ||
| ) |
| int ReadLine | ( | FILE * | Fin, |
| char * | Line, | ||
| int | MaxLine | ||
| ) |
| int RemoveDir | ( | char * | dirpath | ) |
| void RemovePostfix | ( | char * | Name | ) |
| int RunCommand | ( | char * | Cmd, |
| char * | CmdPre, | ||
| char * | File, | ||
| char * | CmdPost, | ||
| char * | Out, | ||
| char * | Where | ||
| ) |
| void SafeExit | ( | int | rc | ) |
| void SetDir | ( | char * | Dest, |
| int | DestLen, | ||
| char * | Smain, | ||
| char * | Sfile | ||
| ) |
Set a destination directory name.
This will concatenate Smain and Sfile, but remove and terminating filename.
| [in,out] | Dest | returned directory name |
| DestLen | size of Dest | |
| Smain | main extraction directory (may be null) | |
| Sfile | filename |
NOTE: Someone that embeds "../" within the path can still climb out!
| int ShouldExclude | ( | char * | Filename, |
| const char * | ExcludePatterns | ||
| ) |
Determines if a file or folder should be excluded.
This function checks whether the supplied file name, Filename, contains any of the substrings listed in the comma-separated string ExcludePatterns. Each pattern is matched directly as a substring; no wildcard or directory-specific matching is performed.
| Filename | The name of the file or folder to be examined. |
| ExcludePatterns | A comma-separated list of substrings used for determining exclusion. |
| void SQLNoticeProcessor | ( | void * | arg, |
| const char * | message | ||
| ) |
| int TaintString | ( | char * | Dest, |
| int | DestLen, | ||
| char * | Src, | ||
| int | ProtectQuotes, | ||
| char * | Replace | ||
| ) |
Protect strings intelligently.
Prevents filenames containing ' or % or \ from screwing up system() and snprintf(). Even supports a "%s".
| [in,out] | Dest | Destination to store tainted string |
| DestLen | Length of Dest | |
| Src | Source string | |
| ProtectQuotes | Set to protect quotes for shell | |
| Replace | String to replace with |
| int TestSCMData | ( | char * | sourcefilename | ) |
| void Usage | ( | char * | Name, |
| char * | Version | ||
| ) |