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';
63 if (stat(FileNameParent, &stParent) != 0 || stat(FileName, &st) != 0)
69 if(S_ISREG(stParent.st_mode) && stParent.st_size > 0 &&
70 (st.st_size/stParent.st_size > InflateSize))
100 if (NULL == Name)
return;
102 char *LastDot = strrchr(Name,
'.');
103 if (LastDot == NULL)
return;
105 if ((LastDot[1]>=
'0')&&(LastDot[1]<=
'9'))
return;
106 if (LastDot) *LastDot = 0;
122 for(i=0;
CMD[i].Magic != NULL; i++)
130 for(i=0;
CMD[i].Magic != NULL; i++)
132 if (
CMD[i].Magic[0] ==
'\0')
continue;
134 memset(
SQL,
'\0',MAXSQL);
135 snprintf(
SQL,MAXSQL,
"SELECT mimetype_pk FROM mimetype WHERE mimetype_name = '%s';",
CMD[i].Magic);
138 else if (PQntuples(result) > 0)
140 CMD[i].
DBindex = atol(PQgetvalue(result,0,0));
146 memset(
SQL,
'\0',MAXSQL);
147 snprintf(
SQL,MAXSQL,
"INSERT INTO mimetype (mimetype_name) VALUES ('%s');",
CMD[i].Magic);
174 char *
Src,
int ProtectQuotes,
char *Replace)
177 char Temp[FILENAME_MAX];
179 memset(Dest,
'\0',DestLen);
182 while((
Src[i] !=
'\0') && (d < DestLen))
185 if (ProtectQuotes && (
Src[i]==
'\''))
187 if (d+4 >= DestLen)
return(1);
188 strcpy(Dest+d,
"'\\''");
192 else if (!ProtectQuotes && strchr(
"\\",
Src[i]))
194 if (d+2 >= DestLen)
return(1);
196 Dest[d] =
Src[i]; d++;
199 else if (Replace && (
Src[i]==
'%') && (
Src[i+1]==
's'))
202 if (d+strlen(Temp) >= DestLen)
return(1);
225 int Prune (
char *Fname,
struct stat Stat)
227 if (!Fname || (Fname[0]==
'\0'))
return(1);
229 if (S_ISLNK(Stat.st_mode) || S_ISCHR(Stat.st_mode) ||
230 S_ISBLK(Stat.st_mode) || S_ISFIFO(Stat.st_mode) ||
231 S_ISSOCK(Stat.st_mode))
237 if (S_ISREG(Stat.st_mode) && (Stat.st_nlink > 1))
243 if (S_ISREG(Stat.st_mode) && (Stat.st_size == 0))
258 char Dir[FILENAME_MAX+1];
263 memset(Dir,
'\0',
sizeof(Dir));
265 for(i=1; Dir[i] !=
'\0'; i++)
271 if (stat(Dir,&Status) == 0)
273 if (!S_ISDIR(Status.st_mode))
275 LOG_FATAL(
"'%s' is not a directory.",Dir);
282 if (rc && (errno == EEXIST)) rc=0;
285 LOG_FATAL(
"mkdir %s' failed, error: %s",Dir,strerror(errno));
293 rc = mkdir(Dir,0770);
294 if (rc && (errno == EEXIST)) rc=0;
297 LOG_FATAL(
"mkdir %s' failed, error: %s",Dir,strerror(errno));
313 if (mkdir(Fname,0770))
315 if (errno == EEXIST)
return(0);
331 if (!Fname || (Fname[0]==
'\0'))
return(0);
332 rc = lstat(Fname,&Stat);
333 if (rc != 0)
return(0);
334 return(S_ISDIR(Stat.st_mode));
347 if (!Fname || (Fname[0]==
'\0'))
return(0);
348 if (Link) rc = stat(Fname,&Stat);
349 else rc = lstat(Fname,&Stat);
350 if (rc != 0)
return(0);
351 return(S_ISREG(Stat.st_mode));
369 if (!Fin)
return(-1);
370 if (feof(Fin))
return(-1);
371 memset(Line,
'\0',MaxLine);
375 while(!feof(Fin) && (C>=0) && (i<MaxLine))
379 if (i > 0)
return(i);
405 char TestCmd[FILENAME_MAX];
407 Path = getenv(
"PATH");
408 if (!Path)
return(0);
410 memset(TestCmd,
'\0',
sizeof(TestCmd));
412 for(i=0; (j<FILENAME_MAX-1) && (Path[i] !=
'\0'); i++)
416 if ((j>0) && (TestCmd[j-1] !=
'/')) strcat(TestCmd,
"/");
418 if (
IsFile(TestCmd,1))
return(1);
420 memset(TestCmd,
'\0',
sizeof(TestCmd));
433 if (TestCmd[j-1] !=
'/') strcat(TestCmd,
"/");
435 if (
IsFile(TestCmd,1))
return(1);
437 if (!
Quiet) LOG_WARNING(
"%s not found in $PATH",Exe);
451 unsigned char * Mmap;
452 int LenIn, LenOut, Wrote;
457 if (lstat(
Src,&Stat) == -1)
return(1);
458 LenIn = Stat.st_size;
459 if (!S_ISREG(Stat.st_mode))
return(1);
461 Fin = open(
Src,O_RDONLY);
464 LOG_FATAL(
"Unable to open source '%s'",
Src);
469 Slash = strrchr(
Dst,
'/');
470 if (Slash && (Slash !=
Dst))
477 Fout = open(
Dst,O_WRONLY|O_CREAT|O_TRUNC,Stat.st_mode);
480 LOG_FATAL(
"Unable to open target '%s'",
Dst);
486 Mmap = mmap(0,LenIn,PROT_READ,MAP_PRIVATE,Fin,0);
487 if (Mmap == MAP_FAILED)
489 LOG_FATAL(
"pfile %s Unable to process file.",
Pfile_Pk);
490 LOG_WARNING(
"pfile %s Mmap failed during copy.",
Pfile_Pk);
498 while((LenOut < LenIn) && (Wrote >= 0))
500 Wrote = write(Fout,Mmap+LenOut,LenIn-LenOut);
524 if (Pid <= 0)
return(-1);
527 for(i=0; (i<MAXCHILD) && (
Queue[i].ChildPid != Pid); i++) ;
528 if (
Queue[i].ChildPid != Pid)
535 if (!WIFEXITED(Status))
539 LOG_FATAL(
"Child had unnatural death");
545 else Status = WEXITSTATUS(Status);
550 LOG_FATAL(
"Child had non-zero status: %d",Status);
551 LOG_FATAL(
"Child was to recurse on %s",
Queue[i].ChildRecurse);
559 Queue[i].ChildPid = 0;
581 for(i=0;
CMD[i].
Cmd != NULL; i++)
583 if (
CMD[i].Cmd[0] ==
'\0')
continue;
603 for(i=0;
CMD[i].
Cmd != NULL; i++)
610 for(i=0;
CMD[i].
Cmd != NULL; i++)
631 char *Out,
char *Where)
633 char Cmd1[FILENAME_MAX * 5];
634 char CWD[FILENAME_MAX];
636 char TempPre[FILENAME_MAX];
637 char TempFile[FILENAME_MAX];
638 char TempCwd[FILENAME_MAX];
639 char TempPost[FILENAME_MAX];
647 LOG_DEBUG(
"Extracting %s: %s > %s",Cmd,
File,Out);
653 LOG_DEBUG(
"Extracting %s in %s: %s\n",Cmd,Where,
File);
657 LOG_DEBUG(
"Testing %s: %s\n",Cmd,
File);
662 if (getcwd(CWD,
sizeof(CWD)) == NULL)
664 LOG_FATAL(
"directory name longer than %d characters",(
int)
sizeof(CWD));
667 if (
Verbose > 1){ LOG_DEBUG(
"CWD: %s\n",CWD);}
668 if ((Where != NULL) && (Where[0] !=
'\0'))
670 if (chdir(Where) != 0)
673 if (chdir(Where) != 0)
675 LOG_FATAL(
"Unable to access directory '%s'",Where);
679 if (
Verbose > 1) LOG_DEBUG(
"CWD: %s",Where);
684 memset(Cmd1,
'\0',
sizeof(Cmd1));
685 if (
TaintString(TempPre,FILENAME_MAX,CmdPre,0,Out) ||
694 snprintf(Cmd1,
sizeof(Cmd1),
"%s %s '%s/%s' %s",
695 Cmd,TempPre,TempCwd,TempFile,TempPost);
699 snprintf(Cmd1,
sizeof(Cmd1),
"%s %s '%s' %s",
700 Cmd,TempPre,TempFile,TempPost);
705 LOG_ERROR(
"Process killed by signal (%d): %s",WTERMSIG(rc),Cmd1);
708 if (WIFEXITED(rc)) rc = WEXITSTATUS(rc);
710 if (
Verbose) LOG_DEBUG(
"in %s -- %s ; rc=%d",Where,Cmd1,rc);
713 LOG_ERROR(
"Unable to change directory to %s", CWD);
714 if (
Verbose > 1) LOG_DEBUG(
"CWD: %s",CWD);
729 LOG_FATAL(
"Failed to initialize magic cookie");
754 if (strcmp(pExt,
".dsc")==0)
759 if ((fp = fopen(
Filename,
"r")) == NULL)
return 0;
761 while ((c = fgetc(fp)) != EOF && j < 500 ){
766 if ((strstr(line,
"-----BEGIN PGP SIGNED MESSAGE-----") && strstr(line,
"Source:")) ||
767 (strstr(line,
"Format:") && strstr(line,
"Source:") && strstr(line,
"Version:")))
793 if (strstr(Type,
"Debian binary package"))
795 strcpy(TypeBuf,
"application/x-debian-package");
799 if (strstr(Type,
"ISO 9660"))
801 strcpy(TypeBuf,
"application/x-iso9660-image");
810 rc3 =
RunCommand(
"7z",
"t -y -pjunk",
Filename,
"|grep 'Wrong password' >/dev/null 2>&1",NULL,NULL);
813 LOG_ERROR(
"'%s' cannot be unpacked, password required.",
Filename);
819 strcpy(TypeBuf,
"application/x-7z-w-compressed");
823 if (strstr(Type,
" ext2 "))
825 strcpy(TypeBuf,
"application/x-ext2");
829 if (strstr(Type,
" ext3 "))
831 strcpy(TypeBuf,
"application/x-ext3");
835 if (strstr(Type,
"x86 boot sector, mkdosfs"))
837 strcpy(TypeBuf,
"application/x-fat");
841 if (strstr(Type,
"NTFS"))
843 strcpy(TypeBuf,
"application/x-ntfs");
847 if (strstr(Type,
"x86 boot"))
849 strcpy(TypeBuf,
"application/x-x86_boot");
871 if (Type == NULL)
return(-1);
879 if ((strcmp(basename(
Filename),
".bss") == 0) && (strstr(Type,
"octet")))
881 Type = strdup(
"text/plain");
887 strncpy(TypeBuf, Type,
sizeof(TypeBuf));
890 if (strstr(Type,
"octet" ))
897 if (strstr(Type,
"msword") || strstr(Type,
"vnd.ms"))
898 strcpy(TypeBuf,
"application/x-7z-w-compressed");
901 if (strstr(Type,
"application/x-exe") ||
902 strstr(Type,
"application/x-shellscript"))
905 if ((rc==0) || (rc==1) || (rc==2) || (rc==51))
907 strcpy(TypeBuf,
"application/x-zip");
910 else if (strstr(Type,
"application/x-tar"))
920 for(i=0; (
CMD[i].
Cmd != NULL) && (
Match == -1); i++)
922 if (
CMD[i].Status == 0)
continue;
923 if (
CMD[i].Type == CMD_DEFAULT)
928 if (!strstr(TypeBuf,
CMD[i].Magic))
940 LOG_DEBUG(
"MISS: Type=%s %s",TypeBuf,
Filename);
969 if (d->Name) free(d->Name);
981 dirlist *dlist=NULL, *dhead=NULL;
983 struct dirent *Entry;
987 Dir = opendir(Fullname);
988 if (Dir == NULL)
return(NULL);
990 Entry = readdir(Dir);
993 if (!strcmp(Entry->d_name,
"."))
goto skip;
994 if (!strcmp(Entry->d_name,
".."))
goto skip;
998 LOG_FATAL(
"Failed to allocate dirlist memory");
1001 dhead->Name = (
char *)malloc(strlen(Entry->d_name)+1);
1004 LOG_FATAL(
"Failed to allocate dirlist.Name memory");
1007 memset(dhead->Name,
'\0',strlen(Entry->d_name)+1);
1008 strcpy(dhead->Name,Entry->d_name);
1010 dhead->Next = dlist;
1018 while(dhead->Next && (strcmp(dhead->Name,dhead->Next->Name) > 0))
1022 dhead->Name = dhead->Next->Name;
1023 dhead->Next->Name = Name;
1024 dhead = dhead->Next;
1030 Entry = readdir(Dir);
1036 printf(
"Directory: %s\n",Fullname);
1037 for(dhead=dlist; dhead; dhead=dhead->
Next)
1039 printf(
" %s\n",dhead->Name);
1056 void SetDir (
char *Dest,
int DestLen,
char *Smain,
char *Sfile)
1060 memset(Dest,
'\0',DestLen);
1065 if (Sfile && (Sfile[0]==
'/')) Sfile++;
1073 if (!memcmp(Sfile,
"../",3)) { Sfile+=3; i=1; }
1074 else if (!memcmp(Sfile,
"./",2)) { Sfile+=2; i=1; }
1076 while(Sfile && !memcmp(Sfile,
"../",3)) Sfile+=3;
1079 if ((strlen(Dest) > 0) && (Last(Smain) !=
'/') && (Sfile[0] !=
'/'))
1081 if (Sfile) strcat(Dest,Sfile);
1083 for(i=strlen(Dest)-1; (i>=0) && (Dest[i] !=
'/'); i--)
1096 LOG_DEBUG(
"Container:");
1097 printf(
" Source: %s\n",CI->Source);
1098 printf(
" Partdir: %s\n",CI->
Partdir);
1099 printf(
" Partname: %s\n",CI->
Partname);
1102 printf(
" HasChild: %d\n",CI->
HasChild);
1103 printf(
" Pruned: %d\n",CI->
Pruned);
1104 printf(
" Corrupt: %d\n",CI->
Corrupt);
1105 printf(
" Artifact: %d\n",CI->
Artifact);
1106 printf(
" IsDir: %d\n",CI->
IsDir);
1109 printf(
" pfile_pk: %ld\n",CI->
pfile_pk);
1111 printf(
" Parent Cmd: %d\n",CI->
PI.Cmd);
1131 if (!Fuid || (Fuid[0] ==
'\0'))
return(1);
1134 memset(
SQL,
'\0',MAXSQL);
1135 snprintf(
SQL,MAXSQL,
"SELECT pfile_pk,pfile_mimetypefk,pfile_sha256 FROM pfile "
1136 "WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
1137 Fuid,Fuid+41,Fuid+140);
1142 if (PQntuples(result) == 0)
1148 memset(
SQL,
'\0',MAXSQL);
1151 snprintf(
SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_sha256,pfile_size,pfile_mimetypefk) "
1152 "VALUES ('%.40s','%.32s','%.64s','%s','%ld');",
1153 Fuid,Fuid+41,Fuid+74,Fuid+140,
CMD[CI->
PI.Cmd].
DBindex);
1157 snprintf(
SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_sha256,pfile_size) VALUES ('%.40s','%.32s','%.64s','%s');",
1158 Fuid,Fuid+41,Fuid+74,Fuid+140);
1162 if ((result==0) || ((PQresultStatus(result) != PGRES_COMMAND_OK) &&
1163 (strncmp(
"23505", PQresultErrorField(result, PG_DIAG_SQLSTATE),5))))
1165 LOG_ERROR(
"Error inserting pfile, %s.",
SQL);
1172 memset(
SQL,
'\0',MAXSQL);
1173 snprintf(
SQL,MAXSQL,
"SELECT pfile_pk,pfile_mimetypefk,pfile_sha256 FROM pfile "
1174 "WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_sha256 = '%.64s' AND pfile_size = '%s';",
1175 Fuid,Fuid+41,Fuid+74,Fuid+140);
1181 Val = PQgetvalue(result,0,0);
1186 tempMimeType = atol(PQgetvalue(result,0,1));
1187 tempSha256 = PQgetvalue(result,0,2);
1193 memset(
SQL,
'\0',MAXSQL);
1194 snprintf(
SQL,MAXSQL,
"UPDATE pfile SET pfile_mimetypefk = '%ld' WHERE pfile_pk = '%ld';",
1200 if (strncasecmp(tempSha256, Fuid+74, 64) != 0)
1203 memset(
SQL,
'\0',MAXSQL);
1204 snprintf(
SQL,MAXSQL,
"UPDATE pfile SET pfile_sha256 = '%.64s' WHERE pfile_pk = '%ld';",
1239 err = regcomp (&preg,
SCM_REGEX, REG_NOSUB | REG_EXTENDED);
1244 match = regexec (&preg, sourcefilename, 0, NULL, 0);
1249 if (
Verbose) LOG_DEBUG(
"match found %s",sourcefilename);
1251 else if(
match == REG_NOMATCH)
1254 if (
Verbose) LOG_DEBUG(
"match not found %s",sourcefilename);
1260 size = regerror (err, &preg, NULL, 0);
1261 text = malloc (
sizeof (*text) * size);
1264 regerror (err, &preg, text, size);
1265 LOG_ERROR(
"Error regexc '%s' '%s' return %d, error %s",
SCM_REGEX,sourcefilename,
match,text);
1269 LOG_ERROR(
"Not enough memory (%lu)",
sizeof (*text) * size);
1277 LOG_ERROR(
"Error regcomp(%d)",err);
1297 char UfileName[1024];
1312 memset(UfileName,
'\0',
sizeof(UfileName));
1316 snprintf(UfileName,
sizeof(UfileName),
"SELECT upload_filename FROM upload WHERE upload_pk = %s;",
Upload_Pk);
1317 result = PQexec(
pgConn, UfileName);
1319 memset(UfileName,
'\0',
sizeof(UfileName));
1320 ufile_name = PQgetvalue(result,0,0);
1322 if (strchr(ufile_name,
'/')) ufile_name = strrchr(ufile_name,
'/')+1;
1330 if ((Len > 4) && !strcmp(CI->
Partname+Len-4,
".dir"))
1331 strcpy(UfileName,
"artifact.dir");
1332 else if ((Len > 9) && !strcmp(CI->
Partname+Len-9,
".unpacked"))
1333 strcpy(UfileName,
"artifact.unpacked");
1334 else if ((Len > 5) && !strcmp(CI->
Partname+Len-5,
".meta"))
1335 strcpy(UfileName,
"artifact.meta");
1337 strcpy(UfileName,
"artifact");
1344 LOG_WARNING(
"Error escaping filename with multibyte character set (%s).", CI->
Partname);
1348 strncpy(UfileName, EscBuf,
sizeof(UfileName));
1362 for (cp=UfileName; *cp; cp++)
if (!isprint(*cp) || (*cp==
'/') || (*cp==
'\\')) *cp =
'~';
1366 memset(
SQL,
'\0',MAXSQL);
1370 snprintf(
SQL,MAXSQL,
"INSERT INTO %s (parent,pfile_fk,ufile_mode,ufile_name,upload_fk) VALUES (%ld,%ld,%ld,E'%s',%s);",
1382 snprintf(
SQL,MAXSQL,
"INSERT INTO %s (upload_fk,pfile_fk,ufile_mode,ufile_name) VALUES (%s,%ld,%ld,E'%s');",
1389 memset(
SQL,
'\0',MAXSQL);
1390 snprintf(
SQL,MAXSQL,
"SELECT currval('uploadtree_uploadtree_pk_seq');");
1422 memset(FuidNew,
'\0',
sizeof(FuidNew));
1424 strncpy(FuidNew, Fuid, 74);
1426 strcat(FuidNew,Fuid+140);
1433 LOG_ERROR(
"Failed to import '%s' as '%s' into the repository",CI->Source,FuidNew);
1437 if (
Verbose) LOG_DEBUG(
"Repository[%s]: insert '%s' as '%s'",
1472 if (CI->Source[0] ==
'\0')
return(0);
1473 memset(Fuid,0,
sizeof(Fuid));
1480 for(i=0; CI->Source[i] !=
'\0'; i++)
1482 if (isalnum(CI->Source[i]) ||
1483 strchr(
" `~!@#$%^*()-=_+[]{}\\|;:',./?",CI->Source[i]))
1485 else fprintf(
ListOutFile,
"&#x%02x;",(
int)(CI->Source[i])&0xff);
1494 for(i=0; CI->
Partname[i] !=
'\0'; i++)
1497 strchr(
" `~!@#$%^*()-=_+[]{}\\|;:',./?",CI->
Partname[i]))
1505 if ((CI->
PI.Cmd >= 0) && (
CMD[CI->
PI.Cmd].
Type != CMD_DEFAULT))
1510 else if (S_ISDIR(CI->
Stat.st_mode))
1539 if (S_ISDIR(CI->
Stat.st_mode))
1543 else if (S_ISREG(CI->
Stat.st_mode))
1561 if (CI->
Stat.st_mtime)
1568 if (CI->
Stat.st_ctime)
1578 if (S_ISREG(CI->
Stat.st_mode) && !CI->
Pruned)
1584 memset(SHA256,
'\0',
sizeof(SHA256));
1587 if(calc_sha256sum(CI->Source, SHA256))
1589 LOG_FATAL(
"Unable to calculate SHA256 of %s\n", CI->Source);
1600 for(i=0; i<20; i++) { sprintf(Fuid+0+i*2,
"%02X",Sum->
SHA1digest[i]); }
1602 for(i=0; i<16; i++) { sprintf(Fuid+41+i*2,
"%02X",Sum->
MD5digest[i]); }
1604 for(i=0; i<64; i++) { sprintf(Fuid+74+i,
"%c",SHA256[i]); }
1606 snprintf(Fuid+140,
sizeof(Fuid)-140,
"%Lu",(
long long unsigned int)Sum->
DataLen);
1614 Fin = fopen(CI->Source,
"rb");
1620 for(i=0; i<20; i++) { sprintf(Fuid+0+i*2,
"%02X",Sum->
SHA1digest[i]); }
1622 for(i=0; i<16; i++) { sprintf(Fuid+41+i*2,
"%02X",Sum->
MD5digest[i]); }
1624 for(i=0; i<64; i++) { sprintf(Fuid+74+i,
"%c",SHA256[i]); }
1626 snprintf(Fuid+140,
sizeof(Fuid)-140,
"%Lu",(
long long unsigned int)Sum->
DataLen);
1652 char RMcmd[FILENAME_MAX];
1654 memset(RMcmd,
'\0',
sizeof(RMcmd));
1655 snprintf(RMcmd, FILENAME_MAX -1,
"rm -rf '%s' ", dirpath);
1676 char HostName[2048];
1677 struct timeval time_st;
1679 NewPath = strdup(DirPath);
1681 if ((subs = strstr(NewPath,
"%U")) )
1684 if (gettimeofday(&time_st, 0))
1687 LOG_WARNING(
"gettimeofday() failure.");
1688 time_st.tv_usec = 999999;
1692 snprintf(TmpPath,
sizeof(TmpPath),
"%s%ul", NewPath, (
unsigned)time_st.tv_usec);
1694 NewPath = strdup(TmpPath);
1697 if ((subs = strstr(NewPath,
"%H")) )
1700 gethostname(HostName,
sizeof(HostName));
1703 snprintf(TmpPath,
sizeof(TmpPath),
"%s%s%s", NewPath, HostName, subs+2);
1705 NewPath = strdup(TmpPath);
1708 if ((subs = strstr(NewPath,
"%R")) )
1713 snprintf(TmpPath,
sizeof(TmpPath),
"%s%s%s", NewPath,
fo_config_get(
sysconfig,
"FOSSOLOGY",
"path", NULL), subs+2);
1715 NewPath = strdup(TmpPath);
1721 void deleteTmpFiles(
char *dir)
1734 fprintf(stderr,
"Universal Unpacker, %s, compiled %s %s\n",
1735 Version,__DATE__,__TIME__);
1736 fprintf(stderr,
"Usage: %s [options] file [file [file...]]\n",Name);
1737 fprintf(stderr,
" Extracts each file.\n");
1738 fprintf(stderr,
" If filename specifies a directory, then extracts everything in it.\n");
1739 fprintf(stderr,
" Unpack Options:\n");
1740 fprintf(stderr,
" -h :: help (print this message), then exit.\n");
1741 fprintf(stderr,
" -C :: force continue when unpack tool fails.\n");
1742 fprintf(stderr,
" -d dir :: specify alternate extraction directory. %%U substitutes a unique ID.\n");
1743 fprintf(stderr,
" Default is the same directory as file (usually not a good idea).\n");
1744 fprintf(stderr,
" -m # :: number of CPUs to use (default: 1).\n");
1745 fprintf(stderr,
" -P :: prune files: remove links, >1 hard links, zero files, etc.\n");
1746 fprintf(stderr,
" -R :: recursively unpack (same as '-r -1')\n");
1747 fprintf(stderr,
" -r # :: recurse to a specified depth (0=none/default, -1=infinite)\n");
1748 fprintf(stderr,
" -X :: remove recursive sources after unpacking.\n");
1749 fprintf(stderr,
" -x :: remove ALL unpacked files when done (clean up).\n");
1750 fprintf(stderr,
" I/O Options:\n");
1751 fprintf(stderr,
" -L out :: Generate a log of files extracted (in XML) to out.\n");
1752 fprintf(stderr,
" -F :: Using files from the repository.\n");
1753 fprintf(stderr,
" -i :: Initialize the database queue system, then exit.\n");
1754 fprintf(stderr,
" -I :: Ignore SCM Data.\n");
1755 fprintf(stderr,
" -Q :: Using scheduler queue system. (Includes -F)\n");
1756 fprintf(stderr,
" If -L is used, unpacked files are placed in 'files'.\n");
1757 fprintf(stderr,
" -T rep :: Set gold repository name to 'rep' (for testing)\n");
1758 fprintf(stderr,
" -t rep :: Set files repository name to 'rep' (for testing)\n");
1759 fprintf(stderr,
" -A :: do not set the initial DB container as an artifact.\n");
1760 fprintf(stderr,
" -f :: force processing files that already exist in the DB.\n");
1761 fprintf(stderr,
" -q :: quiet (generate no output).\n");
1762 fprintf(stderr,
" -U upload_pk :: upload to unpack (implies -RQ). Writes to db.\n");
1763 fprintf(stderr,
" -v :: verbose (-vv = more verbose).\n");
1764 fprintf(stderr,
" -V :: print the version info, then exit.\n");
1765 fprintf(stderr,
"Currently identifies and processes:\n");
1766 fprintf(stderr,
" Compressed files: .Z .gz .bz .bz2 upx\n");
1767 fprintf(stderr,
" Archives files: tar cpio zip jar ar rar cab\n");
1768 fprintf(stderr,
" Data files: pdf\n");
1769 fprintf(stderr,
" Installer files: rpm deb\n");
1770 fprintf(stderr,
" File images: iso9660(plain/Joliet/Rock Ridge) FAT(12/16/32) ext2/ext3 NTFS\n");
1771 fprintf(stderr,
" Boot partitions: x86, vmlinuz\n");
1798 if (!ExcludePatterns || !
Filename)
return 0;
1800 char *patternsCopy = strdup(ExcludePatterns);
1801 if (!patternsCopy)
return 0;
1803 char *pattern = strtok(patternsCopy,
",");
1804 while (pattern != NULL) {
1806 if (
Verbose) LOG_DEBUG(
"Excluding: %s (matched substring: %s)",
Filename, pattern);
1810 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?