28 const char*
SCM_REGEX =
"/\\.git|\\.hg|\\.bzr|CVS/ROOT|\\.svn/";
44 char FileNameParent[PATH_MAX];
45 struct stat st, stParent;
46 memcpy(FileNameParent, FileName,
sizeof(FileNameParent));
47 FileNameParent[PATH_MAX-1] = 0;
48 char *lastSlashPos = strrchr(FileNameParent,
'/');
49 if (NULL != lastSlashPos)
54 FileNameParent[lastSlashPos - FileNameParent] =
'\0';
55 if (!strcmp(FileNameParent + strlen(FileNameParent) - 4,
".dir"))
60 FileNameParent[strlen(FileNameParent) - 4] =
'\0';
61 stat(FileNameParent, &stParent);
63 if(S_ISREG(stParent.st_mode) && (st.st_size/stParent.st_size > InflateSize))
93 if (NULL == Name)
return;
95 char *LastDot = strrchr(Name,
'.');
96 if (LastDot == NULL)
return;
98 if ((LastDot[1]>=
'0')&&(LastDot[1]<=
'9'))
return;
99 if (LastDot) *LastDot = 0;
115 for(i=0;
CMD[i].Magic != NULL; i++)
123 for(i=0;
CMD[i].Magic != NULL; i++)
125 if (
CMD[i].Magic[0] ==
'\0')
continue;
127 memset(
SQL,
'\0',MAXSQL);
128 snprintf(
SQL,MAXSQL,
"SELECT mimetype_pk FROM mimetype WHERE mimetype_name = '%s';",
CMD[i].Magic);
131 else if (PQntuples(result) > 0)
133 CMD[i].
DBindex = atol(PQgetvalue(result,0,0));
139 memset(
SQL,
'\0',MAXSQL);
140 snprintf(
SQL,MAXSQL,
"INSERT INTO mimetype (mimetype_name) VALUES ('%s');",
CMD[i].Magic);
167 char *
Src,
int ProtectQuotes,
char *Replace)
170 char Temp[FILENAME_MAX];
172 memset(Dest,
'\0',DestLen);
175 while((
Src[i] !=
'\0') && (d < DestLen))
178 if (ProtectQuotes && (
Src[i]==
'\''))
180 if (d+4 >= DestLen)
return(1);
181 strcpy(Dest+d,
"'\\''");
185 else if (!ProtectQuotes && strchr(
"\\",
Src[i]))
187 if (d+2 >= DestLen)
return(1);
189 Dest[d] =
Src[i]; d++;
192 else if (Replace && (
Src[i]==
'%') && (
Src[i+1]==
's'))
195 if (d+strlen(Temp) >= DestLen)
return(1);
218 int Prune (
char *Fname,
struct stat Stat)
220 if (!Fname || (Fname[0]==
'\0'))
return(1);
222 if (S_ISLNK(Stat.st_mode) || S_ISCHR(Stat.st_mode) ||
223 S_ISBLK(Stat.st_mode) || S_ISFIFO(Stat.st_mode) ||
224 S_ISSOCK(Stat.st_mode))
230 if (S_ISREG(Stat.st_mode) && (Stat.st_nlink > 1))
236 if (S_ISREG(Stat.st_mode) && (Stat.st_size == 0))
251 char Dir[FILENAME_MAX+1];
256 memset(Dir,
'\0',
sizeof(Dir));
258 for(i=1; Dir[i] !=
'\0'; i++)
264 if (stat(Dir,&Status) == 0)
266 if (!S_ISDIR(Status.st_mode))
268 LOG_FATAL(
"'%s' is not a directory.",Dir);
275 if (rc && (errno == EEXIST)) rc=0;
278 LOG_FATAL(
"mkdir %s' failed, error: %s",Dir,strerror(errno));
286 rc = mkdir(Dir,0770);
287 if (rc && (errno == EEXIST)) rc=0;
290 LOG_FATAL(
"mkdir %s' failed, error: %s",Dir,strerror(errno));
306 if (mkdir(Fname,0770))
308 if (errno == EEXIST)
return(0);
324 if (!Fname || (Fname[0]==
'\0'))
return(0);
325 rc = lstat(Fname,&Stat);
326 if (rc != 0)
return(0);
327 return(S_ISDIR(Stat.st_mode));
340 if (!Fname || (Fname[0]==
'\0'))
return(0);
341 if (Link) rc = stat(Fname,&Stat);
342 else rc = lstat(Fname,&Stat);
343 if (rc != 0)
return(0);
344 return(S_ISREG(Stat.st_mode));
362 if (!Fin)
return(-1);
363 if (feof(Fin))
return(-1);
364 memset(Line,
'\0',MaxLine);
368 while(!feof(Fin) && (C>=0) && (i<MaxLine))
372 if (i > 0)
return(i);
398 char TestCmd[FILENAME_MAX];
400 Path = getenv(
"PATH");
401 if (!Path)
return(0);
403 memset(TestCmd,
'\0',
sizeof(TestCmd));
405 for(i=0; (j<FILENAME_MAX-1) && (Path[i] !=
'\0'); i++)
409 if ((j>0) && (TestCmd[j-1] !=
'/')) strcat(TestCmd,
"/");
411 if (
IsFile(TestCmd,1))
return(1);
413 memset(TestCmd,
'\0',
sizeof(TestCmd));
426 if (TestCmd[j-1] !=
'/') strcat(TestCmd,
"/");
428 if (
IsFile(TestCmd,1))
return(1);
430 if (!
Quiet) LOG_WARNING(
"%s not found in $PATH",Exe);
444 unsigned char * Mmap;
445 int LenIn, LenOut, Wrote;
450 if (lstat(
Src,&Stat) == -1)
return(1);
451 LenIn = Stat.st_size;
452 if (!S_ISREG(Stat.st_mode))
return(1);
454 Fin = open(
Src,O_RDONLY);
457 LOG_FATAL(
"Unable to open source '%s'",
Src);
462 Slash = strrchr(
Dst,
'/');
463 if (Slash && (Slash !=
Dst))
470 Fout = open(
Dst,O_WRONLY|O_CREAT|O_TRUNC,Stat.st_mode);
473 LOG_FATAL(
"Unable to open target '%s'",
Dst);
479 Mmap = mmap(0,LenIn,PROT_READ,MAP_PRIVATE,Fin,0);
482 LOG_FATAL(
"pfile %s Unable to process file.",
Pfile_Pk);
483 LOG_WARNING(
"pfile %s Mmap failed during copy.",
Pfile_Pk);
491 while((LenOut < LenIn) && (Wrote >= 0))
493 Wrote = write(Fout,Mmap+LenOut,LenIn-LenOut);
517 if (Pid <= 0)
return(-1);
520 for(i=0; (i<MAXCHILD) && (
Queue[i].ChildPid != Pid); i++) ;
521 if (
Queue[i].ChildPid != Pid)
528 if (!WIFEXITED(Status))
532 LOG_FATAL(
"Child had unnatural death");
538 else Status = WEXITSTATUS(Status);
543 LOG_FATAL(
"Child had non-zero status: %d",Status);
544 LOG_FATAL(
"Child was to recurse on %s",
Queue[i].ChildRecurse);
552 Queue[i].ChildPid = 0;
574 for(i=0;
CMD[i].
Cmd != NULL; i++)
576 if (
CMD[i].Cmd[0] ==
'\0')
continue;
595 for(i=0;
CMD[i].
Cmd != NULL; i++)
602 for(i=0;
CMD[i].
Cmd != NULL; i++)
623 char *Out,
char *Where)
625 char Cmd1[FILENAME_MAX * 5];
626 char CWD[FILENAME_MAX];
628 char TempPre[FILENAME_MAX];
629 char TempFile[FILENAME_MAX];
630 char TempCwd[FILENAME_MAX];
631 char TempPost[FILENAME_MAX];
639 LOG_DEBUG(
"Extracting %s: %s > %s",Cmd,
File,Out);
645 LOG_DEBUG(
"Extracting %s in %s: %s\n",Cmd,Where,
File);
649 LOG_DEBUG(
"Testing %s: %s\n",Cmd,
File);
654 if (getcwd(CWD,
sizeof(CWD)) == NULL)
656 LOG_FATAL(
"directory name longer than %d characters",(
int)
sizeof(CWD));
659 if (
Verbose > 1){ LOG_DEBUG(
"CWD: %s\n",CWD);}
660 if ((Where != NULL) && (Where[0] !=
'\0'))
662 if (chdir(Where) != 0)
665 if (chdir(Where) != 0)
667 LOG_FATAL(
"Unable to access directory '%s'",Where);
671 if (
Verbose > 1) LOG_DEBUG(
"CWD: %s",Where);
676 memset(Cmd1,
'\0',
sizeof(Cmd1));
677 if (
TaintString(TempPre,FILENAME_MAX,CmdPre,0,Out) ||
686 snprintf(Cmd1,
sizeof(Cmd1),
"%s %s '%s/%s' %s",
687 Cmd,TempPre,TempCwd,TempFile,TempPost);
691 snprintf(Cmd1,
sizeof(Cmd1),
"%s %s '%s' %s",
692 Cmd,TempPre,TempFile,TempPost);
697 LOG_ERROR(
"Process killed by signal (%d): %s",WTERMSIG(rc),Cmd1);
700 if (WIFEXITED(rc)) rc = WEXITSTATUS(rc);
702 if (
Verbose) LOG_DEBUG(
"in %s -- %s ; rc=%d",Where,Cmd1,rc);
705 LOG_ERROR(
"Unable to change directory to %s", CWD);
706 if (
Verbose > 1) LOG_DEBUG(
"CWD: %s",CWD);
721 LOG_FATAL(
"Failed to initialize magic cookie");
746 if (strcmp(pExt,
".dsc")==0)
751 if ((fp = fopen(
Filename,
"r")) == NULL)
return 0;
753 while ((c = fgetc(fp)) != EOF && j < 500 ){
758 if ((strstr(line,
"-----BEGIN PGP SIGNED MESSAGE-----") && strstr(line,
"Source:")) ||
759 (strstr(line,
"Format:") && strstr(line,
"Source:") && strstr(line,
"Version:")))
785 if (strstr(Type,
"Debian binary package"))
787 strcpy(TypeBuf,
"application/x-debian-package");
791 if (strstr(Type,
"ISO 9660"))
793 strcpy(TypeBuf,
"application/x-iso9660-image");
802 rc3 =
RunCommand(
"7z",
"t -y -pjunk",
Filename,
"|grep 'Wrong password' >/dev/null 2>&1",NULL,NULL);
805 LOG_ERROR(
"'%s' cannot be unpacked, password required.",
Filename);
811 strcpy(TypeBuf,
"application/x-7z-w-compressed");
815 if (strstr(Type,
" ext2 "))
817 strcpy(TypeBuf,
"application/x-ext2");
821 if (strstr(Type,
" ext3 "))
823 strcpy(TypeBuf,
"application/x-ext3");
827 if (strstr(Type,
"x86 boot sector, mkdosfs"))
829 strcpy(TypeBuf,
"application/x-fat");
833 if (strstr(Type,
"NTFS"))
835 strcpy(TypeBuf,
"application/x-ntfs");
839 if (strstr(Type,
"x86 boot"))
841 strcpy(TypeBuf,
"application/x-x86_boot");
863 if (Type == NULL)
return(-1);
871 if ((strcmp(basename(
Filename),
".bss") == 0) && (strstr(Type,
"octet")))
873 Type = strdup(
"text/plain");
879 strncpy(TypeBuf, Type,
sizeof(TypeBuf));
882 if (strstr(Type,
"octet" ))
889 if (strstr(Type,
"msword") || strstr(Type,
"vnd.ms"))
890 strcpy(TypeBuf,
"application/x-7z-w-compressed");
893 if (strstr(Type,
"application/x-exe") ||
894 strstr(Type,
"application/x-shellscript"))
897 if ((rc==0) || (rc==1) || (rc==2) || (rc==51))
899 strcpy(TypeBuf,
"application/x-zip");
902 else if (strstr(Type,
"application/x-tar"))
912 for(i=0; (
CMD[i].
Cmd != NULL) && (
Match == -1); i++)
914 if (
CMD[i].Status == 0)
continue;
915 if (
CMD[i].Type == CMD_DEFAULT)
920 if (!strstr(TypeBuf,
CMD[i].Magic))
932 LOG_DEBUG(
"MISS: Type=%s %s",TypeBuf,
Filename);
961 if (d->Name) free(d->Name);
973 dirlist *dlist=NULL, *dhead=NULL;
975 struct dirent *Entry;
979 Dir = opendir(Fullname);
980 if (Dir == NULL)
return(NULL);
982 Entry = readdir(Dir);
985 if (!strcmp(Entry->d_name,
"."))
goto skip;
986 if (!strcmp(Entry->d_name,
".."))
goto skip;
990 LOG_FATAL(
"Failed to allocate dirlist memory");
993 dhead->Name = (
char *)malloc(strlen(Entry->d_name)+1);
996 LOG_FATAL(
"Failed to allocate dirlist.Name memory");
999 memset(dhead->Name,
'\0',strlen(Entry->d_name)+1);
1000 strcpy(dhead->Name,Entry->d_name);
1002 dhead->Next = dlist;
1010 while(dhead->Next && (strcmp(dhead->Name,dhead->Next->Name) > 0))
1014 dhead->Name = dhead->Next->Name;
1015 dhead->Next->Name = Name;
1016 dhead = dhead->Next;
1022 Entry = readdir(Dir);
1028 printf(
"Directory: %s\n",Fullname);
1029 for(dhead=dlist; dhead; dhead=dhead->
Next)
1031 printf(
" %s\n",dhead->Name);
1048 void SetDir (
char *Dest,
int DestLen,
char *Smain,
char *Sfile)
1052 memset(Dest,
'\0',DestLen);
1057 if (Sfile && (Sfile[0]==
'/')) Sfile++;
1065 if (!memcmp(Sfile,
"../",3)) { Sfile+=3; i=1; }
1066 else if (!memcmp(Sfile,
"./",2)) { Sfile+=2; i=1; }
1068 while(Sfile && !memcmp(Sfile,
"../",3)) Sfile+=3;
1071 if ((strlen(Dest) > 0) && (Last(Smain) !=
'/') && (Sfile[0] !=
'/'))
1073 if (Sfile) strcat(Dest,Sfile);
1075 for(i=strlen(Dest)-1; (i>=0) && (Dest[i] !=
'/'); i--)
1088 LOG_DEBUG(
"Container:");
1089 printf(
" Source: %s\n",CI->Source);
1090 printf(
" Partdir: %s\n",CI->
Partdir);
1091 printf(
" Partname: %s\n",CI->
Partname);
1094 printf(
" HasChild: %d\n",CI->
HasChild);
1095 printf(
" Pruned: %d\n",CI->
Pruned);
1096 printf(
" Corrupt: %d\n",CI->
Corrupt);
1097 printf(
" Artifact: %d\n",CI->
Artifact);
1098 printf(
" IsDir: %d\n",CI->
IsDir);
1101 printf(
" pfile_pk: %ld\n",CI->
pfile_pk);
1103 printf(
" Parent Cmd: %d\n",CI->
PI.Cmd);
1123 if (!Fuid || (Fuid[0] ==
'\0'))
return(1);
1126 memset(
SQL,
'\0',MAXSQL);
1127 snprintf(
SQL,MAXSQL,
"SELECT pfile_pk,pfile_mimetypefk,pfile_sha256 FROM pfile "
1128 "WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
1129 Fuid,Fuid+41,Fuid+140);
1134 if (PQntuples(result) == 0)
1140 memset(
SQL,
'\0',MAXSQL);
1143 snprintf(
SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_sha256,pfile_size,pfile_mimetypefk) "
1144 "VALUES ('%.40s','%.32s','%.64s','%s','%ld');",
1145 Fuid,Fuid+41,Fuid+74,Fuid+140,
CMD[CI->
PI.Cmd].
DBindex);
1149 snprintf(
SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_sha256,pfile_size) VALUES ('%.40s','%.32s','%.64s','%s');",
1150 Fuid,Fuid+41,Fuid+74,Fuid+140);
1154 if ((result==0) || ((PQresultStatus(result) != PGRES_COMMAND_OK) &&
1155 (strncmp(
"23505", PQresultErrorField(result, PG_DIAG_SQLSTATE),5))))
1157 LOG_ERROR(
"Error inserting pfile, %s.",
SQL);
1164 memset(
SQL,
'\0',MAXSQL);
1165 snprintf(
SQL,MAXSQL,
"SELECT pfile_pk,pfile_mimetypefk,pfile_sha256 FROM pfile "
1166 "WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_sha256 = '%.64s' AND pfile_size = '%s';",
1167 Fuid,Fuid+41,Fuid+74,Fuid+140);
1173 Val = PQgetvalue(result,0,0);
1178 tempMimeType = atol(PQgetvalue(result,0,1));
1179 tempSha256 = PQgetvalue(result,0,2);
1185 memset(
SQL,
'\0',MAXSQL);
1186 snprintf(
SQL,MAXSQL,
"UPDATE pfile SET pfile_mimetypefk = '%ld' WHERE pfile_pk = '%ld';",
1192 if (strncasecmp(tempSha256, Fuid+74, 64) != 0)
1195 memset(
SQL,
'\0',MAXSQL);
1196 snprintf(
SQL,MAXSQL,
"UPDATE pfile SET pfile_sha256 = '%.64s' WHERE pfile_pk = '%ld';",
1231 err = regcomp (&preg,
SCM_REGEX, REG_NOSUB | REG_EXTENDED);
1236 match = regexec (&preg, sourcefilename, 0, NULL, 0);
1241 if (
Verbose) LOG_DEBUG(
"match found %s",sourcefilename);
1243 else if(
match == REG_NOMATCH)
1246 if (
Verbose) LOG_DEBUG(
"match not found %s",sourcefilename);
1252 size = regerror (err, &preg, NULL, 0);
1253 text = malloc (
sizeof (*text) * size);
1256 regerror (err, &preg, text, size);
1257 LOG_ERROR(
"Error regexc '%s' '%s' return %d, error %s",
SCM_REGEX,sourcefilename,
match,text);
1261 LOG_ERROR(
"Not enough memory (%lu)",
sizeof (*text) * size);
1269 LOG_ERROR(
"Error regcomp(%d)",err);
1289 char UfileName[1024];
1304 memset(UfileName,
'\0',
sizeof(UfileName));
1308 snprintf(UfileName,
sizeof(UfileName),
"SELECT upload_filename FROM upload WHERE upload_pk = %s;",
Upload_Pk);
1309 result = PQexec(
pgConn, UfileName);
1311 memset(UfileName,
'\0',
sizeof(UfileName));
1312 ufile_name = PQgetvalue(result,0,0);
1314 if (strchr(ufile_name,
'/')) ufile_name = strrchr(ufile_name,
'/')+1;
1322 if ((Len > 4) && !strcmp(CI->
Partname+Len-4,
".dir"))
1323 strcpy(UfileName,
"artifact.dir");
1324 else if ((Len > 9) && !strcmp(CI->
Partname+Len-9,
".unpacked"))
1325 strcpy(UfileName,
"artifact.unpacked");
1326 else if ((Len > 5) && !strcmp(CI->
Partname+Len-5,
".meta"))
1327 strcpy(UfileName,
"artifact.meta");
1329 strcpy(UfileName,
"artifact");
1336 LOG_WARNING(
"Error escaping filename with multibyte character set (%s).", CI->
Partname);
1340 strncpy(UfileName, EscBuf,
sizeof(UfileName));
1354 for (cp=UfileName; *cp; cp++)
if (!isprint(*cp) || (*cp==
'/') || (*cp==
'\\')) *cp =
'~';
1358 memset(
SQL,
'\0',MAXSQL);
1362 snprintf(
SQL,MAXSQL,
"INSERT INTO %s (parent,pfile_fk,ufile_mode,ufile_name,upload_fk) VALUES (%ld,%ld,%ld,E'%s',%s);",
1374 snprintf(
SQL,MAXSQL,
"INSERT INTO %s (upload_fk,pfile_fk,ufile_mode,ufile_name) VALUES (%s,%ld,%ld,E'%s');",
1381 memset(
SQL,
'\0',MAXSQL);
1382 snprintf(
SQL,MAXSQL,
"SELECT currval('uploadtree_uploadtree_pk_seq');");
1414 memset(FuidNew,
'\0',
sizeof(FuidNew));
1416 strncpy(FuidNew, Fuid, 74);
1418 strcat(FuidNew,Fuid+140);
1425 LOG_ERROR(
"Failed to import '%s' as '%s' into the repository",CI->Source,FuidNew);
1429 if (
Verbose) LOG_DEBUG(
"Repository[%s]: insert '%s' as '%s'",
1464 if (CI->Source[0] ==
'\0')
return(0);
1465 memset(Fuid,0,
sizeof(Fuid));
1472 for(i=0; CI->Source[i] !=
'\0'; i++)
1474 if (isalnum(CI->Source[i]) ||
1475 strchr(
" `~!@#$%^*()-=_+[]{}\\|;:',./?",CI->Source[i]))
1477 else fprintf(
ListOutFile,
"&#x%02x;",(
int)(CI->Source[i])&0xff);
1486 for(i=0; CI->
Partname[i] !=
'\0'; i++)
1489 strchr(
" `~!@#$%^*()-=_+[]{}\\|;:',./?",CI->
Partname[i]))
1497 if ((CI->
PI.Cmd >= 0) && (
CMD[CI->
PI.Cmd].
Type != CMD_DEFAULT))
1502 else if (S_ISDIR(CI->
Stat.st_mode))
1531 if (S_ISDIR(CI->
Stat.st_mode))
1535 else if (S_ISREG(CI->
Stat.st_mode))
1553 if (CI->
Stat.st_mtime)
1560 if (CI->
Stat.st_ctime)
1570 if (S_ISREG(CI->
Stat.st_mode) && !CI->
Pruned)
1576 memset(SHA256,
'\0',
sizeof(SHA256));
1579 if(calc_sha256sum(CI->Source, SHA256))
1581 LOG_FATAL(
"Unable to calculate SHA256 of %s\n", CI->Source);
1592 for(i=0; i<20; i++) { sprintf(Fuid+0+i*2,
"%02X",Sum->
SHA1digest[i]); }
1594 for(i=0; i<16; i++) { sprintf(Fuid+41+i*2,
"%02X",Sum->
MD5digest[i]); }
1596 for(i=0; i<64; i++) { sprintf(Fuid+74+i,
"%c",SHA256[i]); }
1598 snprintf(Fuid+140,
sizeof(Fuid)-140,
"%Lu",(
long long unsigned int)Sum->
DataLen);
1606 Fin = fopen(CI->Source,
"rb");
1612 for(i=0; i<20; i++) { sprintf(Fuid+0+i*2,
"%02X",Sum->
SHA1digest[i]); }
1614 for(i=0; i<16; i++) { sprintf(Fuid+41+i*2,
"%02X",Sum->
MD5digest[i]); }
1616 for(i=0; i<64; i++) { sprintf(Fuid+74+i,
"%c",SHA256[i]); }
1618 snprintf(Fuid+140,
sizeof(Fuid)-140,
"%Lu",(
long long unsigned int)Sum->
DataLen);
1644 char RMcmd[FILENAME_MAX];
1646 memset(RMcmd,
'\0',
sizeof(RMcmd));
1647 snprintf(RMcmd, FILENAME_MAX -1,
"rm -rf '%s' ", dirpath);
1668 char HostName[2048];
1669 struct timeval time_st;
1671 NewPath = strdup(DirPath);
1673 if ((subs = strstr(NewPath,
"%U")) )
1676 if (gettimeofday(&time_st, 0))
1679 LOG_WARNING(
"gettimeofday() failure.");
1680 time_st.tv_usec = 999999;
1684 snprintf(TmpPath,
sizeof(TmpPath),
"%s%ul", NewPath, (
unsigned)time_st.tv_usec);
1686 NewPath = strdup(TmpPath);
1689 if ((subs = strstr(NewPath,
"%H")) )
1692 gethostname(HostName,
sizeof(HostName));
1695 snprintf(TmpPath,
sizeof(TmpPath),
"%s%s%s", NewPath, HostName, subs+2);
1697 NewPath = strdup(TmpPath);
1700 if ((subs = strstr(NewPath,
"%R")) )
1705 snprintf(TmpPath,
sizeof(TmpPath),
"%s%s%s", NewPath,
fo_config_get(
sysconfig,
"FOSSOLOGY",
"path", NULL), subs+2);
1707 NewPath = strdup(TmpPath);
1713 void deleteTmpFiles(
char *dir)
1726 fprintf(stderr,
"Universal Unpacker, %s, compiled %s %s\n",
1727 Version,__DATE__,__TIME__);
1728 fprintf(stderr,
"Usage: %s [options] file [file [file...]]\n",Name);
1729 fprintf(stderr,
" Extracts each file.\n");
1730 fprintf(stderr,
" If filename specifies a directory, then extracts everything in it.\n");
1731 fprintf(stderr,
" Unpack Options:\n");
1732 fprintf(stderr,
" -h :: help (print this message), then exit.\n");
1733 fprintf(stderr,
" -C :: force continue when unpack tool fails.\n");
1734 fprintf(stderr,
" -d dir :: specify alternate extraction directory. %%U substitutes a unique ID.\n");
1735 fprintf(stderr,
" Default is the same directory as file (usually not a good idea).\n");
1736 fprintf(stderr,
" -m # :: number of CPUs to use (default: 1).\n");
1737 fprintf(stderr,
" -P :: prune files: remove links, >1 hard links, zero files, etc.\n");
1738 fprintf(stderr,
" -R :: recursively unpack (same as '-r -1')\n");
1739 fprintf(stderr,
" -r # :: recurse to a specified depth (0=none/default, -1=infinite)\n");
1740 fprintf(stderr,
" -X :: remove recursive sources after unpacking.\n");
1741 fprintf(stderr,
" -x :: remove ALL unpacked files when done (clean up).\n");
1742 fprintf(stderr,
" I/O Options:\n");
1743 fprintf(stderr,
" -L out :: Generate a log of files extracted (in XML) to out.\n");
1744 fprintf(stderr,
" -F :: Using files from the repository.\n");
1745 fprintf(stderr,
" -i :: Initialize the database queue system, then exit.\n");
1746 fprintf(stderr,
" -I :: Ignore SCM Data.\n");
1747 fprintf(stderr,
" -Q :: Using scheduler queue system. (Includes -F)\n");
1748 fprintf(stderr,
" If -L is used, unpacked files are placed in 'files'.\n");
1749 fprintf(stderr,
" -T rep :: Set gold repository name to 'rep' (for testing)\n");
1750 fprintf(stderr,
" -t rep :: Set files repository name to 'rep' (for testing)\n");
1751 fprintf(stderr,
" -A :: do not set the initial DB container as an artifact.\n");
1752 fprintf(stderr,
" -f :: force processing files that already exist in the DB.\n");
1753 fprintf(stderr,
" -q :: quiet (generate no output).\n");
1754 fprintf(stderr,
" -U upload_pk :: upload to unpack (implies -RQ). Writes to db.\n");
1755 fprintf(stderr,
" -v :: verbose (-vv = more verbose).\n");
1756 fprintf(stderr,
" -V :: print the version info, then exit.\n");
1757 fprintf(stderr,
"Currently identifies and processes:\n");
1758 fprintf(stderr,
" Compressed files: .Z .gz .bz .bz2 upx\n");
1759 fprintf(stderr,
" Archives files: tar cpio zip jar ar rar cab\n");
1760 fprintf(stderr,
" Data files: pdf\n");
1761 fprintf(stderr,
" Installer files: rpm deb\n");
1762 fprintf(stderr,
" File images: iso9660(plain/Joliet/Rock Ridge) FAT(12/16/32) ext2/ext3 NTFS\n");
1763 fprintf(stderr,
" Boot partitions: x86, vmlinuz\n");
1790 if (!ExcludePatterns || !
Filename)
return 0;
1792 char *patternsCopy = strdup(ExcludePatterns);
1793 if (!patternsCopy)
return 0;
1795 char *pattern = strtok(patternsCopy,
",");
1796 while (pattern != NULL) {
1798 if (
Verbose) LOG_DEBUG(
"Excluding: %s (matched substring: %s)",
Filename, pattern);
1802 pattern = strtok(NULL,
",");
char SQL[256]
SQL query to execute.
char * uploadtree_tablename
upload.uploadtree_tablename
Cksum * SumComputeBuff(CksumFile *CF)
Compute the checksum, allocate and return a Cksum containing the sum value.
Cksum * SumComputeFile(FILE *Fin)
Compute the checksum, allocate and return a string containing the sum value.
CksumFile * SumOpenFile(char *Fname)
Open and mmap a file.
void SumCloseFile(CksumFile *CF)
Close a file that was opened with SumOpenFile()
int Verbose
Verbose level.
PGconn * pgConn
Database connection.
Stores all extern variables used by the agent.
char * Pfile_Pk
Pfile pk in DB.
int ReunpackSwitch
Set if the uploadtree records are missing from db.
int UseRepository
Using files from the repository?
int TotalDirectories
Number of directories.
unpackqueue Queue[MAXCHILD+1]
Manage children.
int Quiet
Run in quiet mode?
int TotalFiles
Number of regular files.
int TotalArtifacts
Number of artifacts.
cmdlist CMD[]
Global command table.
char * Upload_Pk
Upload pk in DB.
char REP_FILES[16]
Files repository name.
FILE * ListOutFile
File to store unpack list.
long TotalItems
Number of records inserted.
int IgnoreSCMData
1: Ignore SCM data, 0: dont ignore it.
int TotalCompressedFiles
Number of compressed files.
int ForceDuplicate
When using db, should it process duplicates?
int ForceContinue
Force continue when unpack tool fails?
magic_t MagicCookie
for Magic
char * fo_config_get(fo_conf *conf, const char *group, const char *key, GError **error)
Gets an element based on its group name and key name. If the group or key is not found,...
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
int fo_checkPQcommand(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres commands (not select) If an error occured, write the error to s...
int fo_RepImport(char *Source, char *Type, char *Filename, int Link)
Import a file into the repository.
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
void fo_scheduler_heart(int i)
This function must be called by agents to let the scheduler know they are alive and how many items th...
Store file handler and mmap of a file.
Store check sum of a file.
uint8_t SHA1digest[20]
SHA1 digest of the file.
uint64_t DataLen
Size of the file.
uint8_t MD5digest[16]
MD5 digest of the file.
Structure for storing information about a particular file.
char Partname[FILENAME_MAX]
char PartnameNew[FILENAME_MAX]
char Partdir[FILENAME_MAX]
Store the results of a regex match.
static char * Dst
Destination location.
static char * Src
Souce location.
int RunCommand(char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where)
Try a command and return command code.
int IsFile(char *Fname, int Link)
Given a filename, is it a file?
int DisplayContainerInfo(ContainerInfo *CI, int Cmd)
Print what can be printed in XML.
void DebugContainerInfo(ContainerInfo *CI)
Print a ContainerInfo structure.
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
int MkDirs(char *Fname)
Same as command-line "mkdir -p".
int Prune(char *Fname, struct stat Stat)
Given a filename and its stat, prune it.
int TestSCMData(char *sourcefilename)
Search for SCM data in the filename.
int InitMagic()
Open and load Magic file Initializes global MagicCookie.
void CheckCommands(int Show)
Make sure all commands are usable.
int IsDebianSourceFile(char *Filename)
Read file to see if it is a Debian source file.
int MkDir(char *Fname)
Smart mkdir.
int TaintString(char *Dest, int DestLen, char *Src, int ProtectQuotes, char *Replace)
Protect strings intelligently.
void SetDir(char *Dest, int DestLen, char *Smain, char *Sfile)
Set a destination directory name.
int ParentWait()
Wait for a child. Sets child status.
void RemovePostfix(char *Name)
get rid of the postfix
void OctetType(char *Filename, char *TypeBuf)
Figure out the real type of "octet" files in case we can unarchive them.
int AddToRepository(ContainerInfo *CI, char *Fuid, int Mask)
Add a ContainerInfo record to the repository AND to the database.
void FreeDirList(dirlist *DL)
Free a list of files in a directory list.
int DBInsertPfile(ContainerInfo *CI, char *Fuid)
Insert a Pfile record. Sets the pfile_pk in CI.
int DBInsertUploadTree(ContainerInfo *CI, int Mask)
Insert an UploadTree record.
void Usage(char *Name, char *Version)
Display program usage.
void InitCmd()
Initialize the metahandler CMD table.
int IsExe(char *Exe, int Quiet)
Check if the executable exists.
void SafeExit(int rc)
Close scheduler and database connections, then exit.
int FindCmd(char *Filename)
Given a file name, determine the type of extraction command. This uses Magic.
int ShouldExclude(char *Filename, const char *ExcludePatterns)
Determines if a file or folder should be excluded.
int CopyFile(char *Src, char *Dst)
Copy a file. For speed: mmap and save.
int IsInflatedFile(char *FileName, int InflateSize)
Test if the file is a compression bomb.
char * PathCheck(char *DirPath)
Check if path contains a "%U" or "%H". If so, substitute a unique ID for U.
void SQLNoticeProcessor(void *arg, const char *message)
Dummy postgresql notice processor. This prevents Notices from being written to stderr.
dirlist * MakeDirList(char *Fullname)
Create a list of files in a directory.
int ReadLine(FILE *Fin, char *Line, int MaxLine)
Read a command from a stream.
int IsDir(char *Fname)
Given a filename, is it a directory?