27 const char*
SCM_REGEX =
"/\\.git|\\.hg|\\.bzr|CVS/ROOT|\\.svn/";
43 char FileNameParent[PATH_MAX];
44 struct stat st, stParent;
45 memcpy(FileNameParent, FileName,
sizeof(FileNameParent));
46 FileNameParent[PATH_MAX-1] = 0;
47 char *lastSlashPos = strrchr(FileNameParent,
'/');
48 if (NULL != lastSlashPos)
53 FileNameParent[lastSlashPos - FileNameParent] =
'\0';
54 if (!strcmp(FileNameParent + strlen(FileNameParent) - 4,
".dir"))
59 FileNameParent[strlen(FileNameParent) - 4] =
'\0';
60 stat(FileNameParent, &stParent);
62 if(S_ISREG(stParent.st_mode) && (st.st_size/stParent.st_size > InflateSize))
92 if (NULL == Name)
return;
94 char *LastDot = strrchr(Name,
'.');
95 if (LastDot == NULL)
return;
97 if ((LastDot[1]>=
'0')&&(LastDot[1]<=
'9'))
return;
98 if (LastDot) *LastDot = 0;
114 for(i=0;
CMD[i].Magic != NULL; i++)
122 for(i=0;
CMD[i].Magic != NULL; i++)
124 if (
CMD[i].Magic[0] ==
'\0')
continue;
126 memset(
SQL,
'\0',MAXSQL);
127 snprintf(
SQL,MAXSQL,
"SELECT mimetype_pk FROM mimetype WHERE mimetype_name = '%s';",
CMD[i].Magic);
130 else if (PQntuples(result) > 0)
132 CMD[i].
DBindex = atol(PQgetvalue(result,0,0));
138 memset(
SQL,
'\0',MAXSQL);
139 snprintf(
SQL,MAXSQL,
"INSERT INTO mimetype (mimetype_name) VALUES ('%s');",
CMD[i].Magic);
166 char *
Src,
int ProtectQuotes,
char *Replace)
169 char Temp[FILENAME_MAX];
171 memset(Dest,
'\0',DestLen);
174 while((
Src[i] !=
'\0') && (d < DestLen))
177 if (ProtectQuotes && (
Src[i]==
'\''))
179 if (d+4 >= DestLen)
return(1);
180 strcpy(Dest+d,
"'\\''");
184 else if (!ProtectQuotes && strchr(
"\\",
Src[i]))
186 if (d+2 >= DestLen)
return(1);
188 Dest[d] =
Src[i]; d++;
191 else if (Replace && (
Src[i]==
'%') && (
Src[i+1]==
's'))
194 if (d+strlen(Temp) >= DestLen)
return(1);
217 int Prune (
char *Fname,
struct stat Stat)
219 if (!Fname || (Fname[0]==
'\0'))
return(1);
221 if (S_ISLNK(Stat.st_mode) || S_ISCHR(Stat.st_mode) ||
222 S_ISBLK(Stat.st_mode) || S_ISFIFO(Stat.st_mode) ||
223 S_ISSOCK(Stat.st_mode))
229 if (S_ISREG(Stat.st_mode) && (Stat.st_nlink > 1))
235 if (S_ISREG(Stat.st_mode) && (Stat.st_size == 0))
250 char Dir[FILENAME_MAX+1];
255 memset(Dir,
'\0',
sizeof(Dir));
257 for(i=1; Dir[i] !=
'\0'; i++)
263 if (stat(Dir,&Status) == 0)
265 if (!S_ISDIR(Status.st_mode))
267 LOG_FATAL(
"'%s' is not a directory.",Dir);
274 if (rc && (errno == EEXIST)) rc=0;
277 LOG_FATAL(
"mkdir %s' failed, error: %s",Dir,strerror(errno));
285 rc = mkdir(Dir,0770);
286 if (rc && (errno == EEXIST)) rc=0;
289 LOG_FATAL(
"mkdir %s' failed, error: %s",Dir,strerror(errno));
305 if (mkdir(Fname,0770))
307 if (errno == EEXIST)
return(0);
323 if (!Fname || (Fname[0]==
'\0'))
return(0);
324 rc = lstat(Fname,&Stat);
325 if (rc != 0)
return(0);
326 return(S_ISDIR(Stat.st_mode));
339 if (!Fname || (Fname[0]==
'\0'))
return(0);
340 if (Link) rc = stat(Fname,&Stat);
341 else rc = lstat(Fname,&Stat);
342 if (rc != 0)
return(0);
343 return(S_ISREG(Stat.st_mode));
361 if (!Fin)
return(-1);
362 if (feof(Fin))
return(-1);
363 memset(Line,
'\0',MaxLine);
367 while(!feof(Fin) && (C>=0) && (i<MaxLine))
371 if (i > 0)
return(i);
397 char TestCmd[FILENAME_MAX];
399 Path = getenv(
"PATH");
400 if (!Path)
return(0);
402 memset(TestCmd,
'\0',
sizeof(TestCmd));
404 for(i=0; (j<FILENAME_MAX-1) && (Path[i] !=
'\0'); i++)
408 if ((j>0) && (TestCmd[j-1] !=
'/')) strcat(TestCmd,
"/");
410 if (
IsFile(TestCmd,1))
return(1);
412 memset(TestCmd,
'\0',
sizeof(TestCmd));
425 if (TestCmd[j-1] !=
'/') strcat(TestCmd,
"/");
427 if (
IsFile(TestCmd,1))
return(1);
429 if (!
Quiet) LOG_WARNING(
"%s not found in $PATH",Exe);
443 unsigned char * Mmap;
444 int LenIn, LenOut, Wrote;
449 if (lstat(
Src,&Stat) == -1)
return(1);
450 LenIn = Stat.st_size;
451 if (!S_ISREG(Stat.st_mode))
return(1);
453 Fin = open(
Src,O_RDONLY);
456 LOG_FATAL(
"Unable to open source '%s'",
Src);
461 Slash = strrchr(
Dst,
'/');
462 if (Slash && (Slash !=
Dst))
469 Fout = open(
Dst,O_WRONLY|O_CREAT|O_TRUNC,Stat.st_mode);
472 LOG_FATAL(
"Unable to open target '%s'",
Dst);
478 Mmap = mmap(0,LenIn,PROT_READ,MAP_PRIVATE,Fin,0);
481 LOG_FATAL(
"pfile %s Unable to process file.",
Pfile_Pk);
482 LOG_WARNING(
"pfile %s Mmap failed during copy.",
Pfile_Pk);
490 while((LenOut < LenIn) && (Wrote >= 0))
492 Wrote = write(Fout,Mmap+LenOut,LenIn-LenOut);
516 if (Pid <= 0)
return(-1);
519 for(i=0; (i<MAXCHILD) && (
Queue[i].ChildPid != Pid); i++) ;
520 if (
Queue[i].ChildPid != Pid)
527 if (!WIFEXITED(Status))
531 LOG_FATAL(
"Child had unnatural death");
537 else Status = WEXITSTATUS(Status);
542 LOG_FATAL(
"Child had non-zero status: %d",Status);
543 LOG_FATAL(
"Child was to recurse on %s",
Queue[i].ChildRecurse);
551 Queue[i].ChildPid = 0;
573 for(i=0;
CMD[i].
Cmd != NULL; i++)
575 if (
CMD[i].Cmd[0] ==
'\0')
continue;
594 for(i=0;
CMD[i].
Cmd != NULL; i++)
601 for(i=0;
CMD[i].
Cmd != NULL; i++)
622 char *Out,
char *Where)
624 char Cmd1[FILENAME_MAX * 5];
625 char CWD[FILENAME_MAX];
627 char TempPre[FILENAME_MAX];
628 char TempFile[FILENAME_MAX];
629 char TempCwd[FILENAME_MAX];
630 char TempPost[FILENAME_MAX];
638 LOG_DEBUG(
"Extracting %s: %s > %s",Cmd,
File,Out);
644 LOG_DEBUG(
"Extracting %s in %s: %s\n",Cmd,Where,
File);
648 LOG_DEBUG(
"Testing %s: %s\n",Cmd,
File);
653 if (getcwd(CWD,
sizeof(CWD)) == NULL)
655 LOG_FATAL(
"directory name longer than %d characters",(
int)
sizeof(CWD));
658 if (
Verbose > 1){ LOG_DEBUG(
"CWD: %s\n",CWD);}
659 if ((Where != NULL) && (Where[0] !=
'\0'))
661 if (chdir(Where) != 0)
664 if (chdir(Where) != 0)
666 LOG_FATAL(
"Unable to access directory '%s'",Where);
670 if (
Verbose > 1) LOG_DEBUG(
"CWD: %s",Where);
675 memset(Cmd1,
'\0',
sizeof(Cmd1));
676 if (
TaintString(TempPre,FILENAME_MAX,CmdPre,0,Out) ||
685 snprintf(Cmd1,
sizeof(Cmd1),
"%s %s '%s/%s' %s",
686 Cmd,TempPre,TempCwd,TempFile,TempPost);
690 snprintf(Cmd1,
sizeof(Cmd1),
"%s %s '%s' %s",
691 Cmd,TempPre,TempFile,TempPost);
696 LOG_ERROR(
"Process killed by signal (%d): %s",WTERMSIG(rc),Cmd1);
699 if (WIFEXITED(rc)) rc = WEXITSTATUS(rc);
701 if (
Verbose) LOG_DEBUG(
"in %s -- %s ; rc=%d",Where,Cmd1,rc);
704 LOG_ERROR(
"Unable to change directory to %s", CWD);
705 if (
Verbose > 1) LOG_DEBUG(
"CWD: %s",CWD);
720 LOG_FATAL(
"Failed to initialize magic cookie");
745 if (strcmp(pExt,
".dsc")==0)
750 if ((fp = fopen(
Filename,
"r")) == NULL)
return 0;
752 while ((c = fgetc(fp)) != EOF && j < 500 ){
757 if ((strstr(line,
"-----BEGIN PGP SIGNED MESSAGE-----") && strstr(line,
"Source:")) ||
758 (strstr(line,
"Format:") && strstr(line,
"Source:") && strstr(line,
"Version:")))
784 if (strstr(Type,
"Debian binary package"))
786 strcpy(TypeBuf,
"application/x-debian-package");
790 if (strstr(Type,
"ISO 9660"))
792 strcpy(TypeBuf,
"application/x-iso9660-image");
801 rc3 =
RunCommand(
"7z",
"t -y -pjunk",
Filename,
"|grep 'Wrong password' >/dev/null 2>&1",NULL,NULL);
804 LOG_ERROR(
"'%s' cannot be unpacked, password required.",
Filename);
810 strcpy(TypeBuf,
"application/x-7z-w-compressed");
814 if (strstr(Type,
" ext2 "))
816 strcpy(TypeBuf,
"application/x-ext2");
820 if (strstr(Type,
" ext3 "))
822 strcpy(TypeBuf,
"application/x-ext3");
826 if (strstr(Type,
"x86 boot sector, mkdosfs"))
828 strcpy(TypeBuf,
"application/x-fat");
832 if (strstr(Type,
"NTFS"))
834 strcpy(TypeBuf,
"application/x-ntfs");
838 if (strstr(Type,
"x86 boot"))
840 strcpy(TypeBuf,
"application/x-x86_boot");
862 if (Type == NULL)
return(-1);
870 if ((strcmp(basename(
Filename),
".bss") == 0) && (strstr(Type,
"octet")))
872 Type = strdup(
"text/plain");
878 strncpy(TypeBuf, Type,
sizeof(TypeBuf));
881 if (strstr(Type,
"octet" ))
888 if (strstr(Type,
"msword") || strstr(Type,
"vnd.ms"))
889 strcpy(TypeBuf,
"application/x-7z-w-compressed");
892 if (strstr(Type,
"application/x-exe") ||
893 strstr(Type,
"application/x-shellscript"))
896 if ((rc==0) || (rc==1) || (rc==2) || (rc==51))
898 strcpy(TypeBuf,
"application/x-zip");
901 else if (strstr(Type,
"application/x-tar"))
911 for(i=0; (
CMD[i].
Cmd != NULL) && (
Match == -1); i++)
913 if (
CMD[i].Status == 0)
continue;
914 if (
CMD[i].Type == CMD_DEFAULT)
919 if (!strstr(TypeBuf,
CMD[i].Magic))
931 LOG_DEBUG(
"MISS: Type=%s %s",TypeBuf,
Filename);
960 if (d->Name) free(d->Name);
972 dirlist *dlist=NULL, *dhead=NULL;
974 struct dirent *Entry;
978 Dir = opendir(Fullname);
979 if (Dir == NULL)
return(NULL);
981 Entry = readdir(Dir);
984 if (!strcmp(Entry->d_name,
"."))
goto skip;
985 if (!strcmp(Entry->d_name,
".."))
goto skip;
989 LOG_FATAL(
"Failed to allocate dirlist memory");
992 dhead->Name = (
char *)malloc(strlen(Entry->d_name)+1);
995 LOG_FATAL(
"Failed to allocate dirlist.Name memory");
998 memset(dhead->Name,
'\0',strlen(Entry->d_name)+1);
999 strcpy(dhead->Name,Entry->d_name);
1001 dhead->Next = dlist;
1009 while(dhead->Next && (strcmp(dhead->Name,dhead->Next->Name) > 0))
1013 dhead->Name = dhead->Next->Name;
1014 dhead->Next->Name = Name;
1015 dhead = dhead->Next;
1021 Entry = readdir(Dir);
1027 printf(
"Directory: %s\n",Fullname);
1028 for(dhead=dlist; dhead; dhead=dhead->
Next)
1030 printf(
" %s\n",dhead->Name);
1047 void SetDir (
char *Dest,
int DestLen,
char *Smain,
char *Sfile)
1051 memset(Dest,
'\0',DestLen);
1056 if (Sfile && (Sfile[0]==
'/')) Sfile++;
1064 if (!memcmp(Sfile,
"../",3)) { Sfile+=3; i=1; }
1065 else if (!memcmp(Sfile,
"./",2)) { Sfile+=2; i=1; }
1067 while(Sfile && !memcmp(Sfile,
"../",3)) Sfile+=3;
1070 if ((strlen(Dest) > 0) && (Last(Smain) !=
'/') && (Sfile[0] !=
'/'))
1072 if (Sfile) strcat(Dest,Sfile);
1074 for(i=strlen(Dest)-1; (i>=0) && (Dest[i] !=
'/'); i--)
1087 LOG_DEBUG(
"Container:");
1088 printf(
" Source: %s\n",CI->Source);
1089 printf(
" Partdir: %s\n",CI->
Partdir);
1090 printf(
" Partname: %s\n",CI->
Partname);
1093 printf(
" HasChild: %d\n",CI->
HasChild);
1094 printf(
" Pruned: %d\n",CI->
Pruned);
1095 printf(
" Corrupt: %d\n",CI->
Corrupt);
1096 printf(
" Artifact: %d\n",CI->
Artifact);
1097 printf(
" IsDir: %d\n",CI->
IsDir);
1100 printf(
" pfile_pk: %ld\n",CI->
pfile_pk);
1102 printf(
" Parent Cmd: %d\n",CI->
PI.Cmd);
1122 if (!Fuid || (Fuid[0] ==
'\0'))
return(1);
1125 memset(
SQL,
'\0',MAXSQL);
1126 snprintf(
SQL,MAXSQL,
"SELECT pfile_pk,pfile_mimetypefk,pfile_sha256 FROM pfile "
1127 "WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
1128 Fuid,Fuid+41,Fuid+140);
1133 if (PQntuples(result) == 0)
1139 memset(
SQL,
'\0',MAXSQL);
1142 snprintf(
SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_sha256,pfile_size,pfile_mimetypefk) "
1143 "VALUES ('%.40s','%.32s','%.64s','%s','%ld');",
1144 Fuid,Fuid+41,Fuid+74,Fuid+140,
CMD[CI->
PI.Cmd].
DBindex);
1148 snprintf(
SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_sha256,pfile_size) VALUES ('%.40s','%.32s','%.64s','%s');",
1149 Fuid,Fuid+41,Fuid+74,Fuid+140);
1153 if ((result==0) || ((PQresultStatus(result) != PGRES_COMMAND_OK) &&
1154 (strncmp(
"23505", PQresultErrorField(result, PG_DIAG_SQLSTATE),5))))
1156 LOG_ERROR(
"Error inserting pfile, %s.",
SQL);
1163 memset(
SQL,
'\0',MAXSQL);
1164 snprintf(
SQL,MAXSQL,
"SELECT pfile_pk,pfile_mimetypefk,pfile_sha256 FROM pfile "
1165 "WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_sha256 = '%.64s' AND pfile_size = '%s';",
1166 Fuid,Fuid+41,Fuid+74,Fuid+140);
1172 Val = PQgetvalue(result,0,0);
1177 tempMimeType = atol(PQgetvalue(result,0,1));
1178 tempSha256 = PQgetvalue(result,0,2);
1184 memset(
SQL,
'\0',MAXSQL);
1185 snprintf(
SQL,MAXSQL,
"UPDATE pfile SET pfile_mimetypefk = '%ld' WHERE pfile_pk = '%ld';",
1191 if (strncasecmp(tempSha256, Fuid+74, 64) != 0)
1194 memset(
SQL,
'\0',MAXSQL);
1195 snprintf(
SQL,MAXSQL,
"UPDATE pfile SET pfile_sha256 = '%.64s' WHERE pfile_pk = '%ld';",
1230 err = regcomp (&preg,
SCM_REGEX, REG_NOSUB | REG_EXTENDED);
1235 match = regexec (&preg, sourcefilename, 0, NULL, 0);
1240 if (
Verbose) LOG_DEBUG(
"match found %s",sourcefilename);
1242 else if(
match == REG_NOMATCH)
1245 if (
Verbose) LOG_DEBUG(
"match not found %s",sourcefilename);
1251 size = regerror (err, &preg, NULL, 0);
1252 text = malloc (
sizeof (*text) * size);
1255 regerror (err, &preg, text, size);
1256 LOG_ERROR(
"Error regexc '%s' '%s' return %d, error %s",
SCM_REGEX,sourcefilename,
match,text);
1260 LOG_ERROR(
"Not enough memory (%lu)",
sizeof (*text) * size);
1268 LOG_ERROR(
"Error regcomp(%d)",err);
1288 char UfileName[1024];
1303 memset(UfileName,
'\0',
sizeof(UfileName));
1307 snprintf(UfileName,
sizeof(UfileName),
"SELECT upload_filename FROM upload WHERE upload_pk = %s;",
Upload_Pk);
1308 result = PQexec(
pgConn, UfileName);
1310 memset(UfileName,
'\0',
sizeof(UfileName));
1311 ufile_name = PQgetvalue(result,0,0);
1313 if (strchr(ufile_name,
'/')) ufile_name = strrchr(ufile_name,
'/')+1;
1321 if ((Len > 4) && !strcmp(CI->
Partname+Len-4,
".dir"))
1322 strcpy(UfileName,
"artifact.dir");
1323 else if ((Len > 9) && !strcmp(CI->
Partname+Len-9,
".unpacked"))
1324 strcpy(UfileName,
"artifact.unpacked");
1325 else if ((Len > 5) && !strcmp(CI->
Partname+Len-5,
".meta"))
1326 strcpy(UfileName,
"artifact.meta");
1328 strcpy(UfileName,
"artifact");
1335 LOG_WARNING(
"Error escaping filename with multibyte character set (%s).", CI->
Partname);
1339 strncpy(UfileName, EscBuf,
sizeof(UfileName));
1353 for (cp=UfileName; *cp; cp++)
if (!isprint(*cp) || (*cp==
'/') || (*cp==
'\\')) *cp =
'~';
1357 memset(
SQL,
'\0',MAXSQL);
1361 snprintf(
SQL,MAXSQL,
"INSERT INTO %s (parent,pfile_fk,ufile_mode,ufile_name,upload_fk) VALUES (%ld,%ld,%ld,E'%s',%s);",
1373 snprintf(
SQL,MAXSQL,
"INSERT INTO %s (upload_fk,pfile_fk,ufile_mode,ufile_name) VALUES (%s,%ld,%ld,E'%s');",
1380 memset(
SQL,
'\0',MAXSQL);
1381 snprintf(
SQL,MAXSQL,
"SELECT currval('uploadtree_uploadtree_pk_seq');");
1413 memset(FuidNew,
'\0',
sizeof(FuidNew));
1415 strncpy(FuidNew, Fuid, 74);
1417 strcat(FuidNew,Fuid+140);
1424 LOG_ERROR(
"Failed to import '%s' as '%s' into the repository",CI->Source,FuidNew);
1428 if (
Verbose) LOG_DEBUG(
"Repository[%s]: insert '%s' as '%s'",
1463 if (CI->Source[0] ==
'\0')
return(0);
1464 memset(Fuid,0,
sizeof(Fuid));
1471 for(i=0; CI->Source[i] !=
'\0'; i++)
1473 if (isalnum(CI->Source[i]) ||
1474 strchr(
" `~!@#$%^*()-=_+[]{}\\|;:',./?",CI->Source[i]))
1476 else fprintf(
ListOutFile,
"&#x%02x;",(
int)(CI->Source[i])&0xff);
1485 for(i=0; CI->
Partname[i] !=
'\0'; i++)
1488 strchr(
" `~!@#$%^*()-=_+[]{}\\|;:',./?",CI->
Partname[i]))
1496 if ((CI->
PI.Cmd >= 0) && (
CMD[CI->
PI.Cmd].
Type != CMD_DEFAULT))
1501 else if (S_ISDIR(CI->
Stat.st_mode))
1530 if (S_ISDIR(CI->
Stat.st_mode))
1534 else if (S_ISREG(CI->
Stat.st_mode))
1552 if (CI->
Stat.st_mtime)
1559 if (CI->
Stat.st_ctime)
1569 if (S_ISREG(CI->
Stat.st_mode) && !CI->
Pruned)
1575 memset(SHA256,
'\0',
sizeof(SHA256));
1578 if(calc_sha256sum(CI->Source, SHA256))
1580 LOG_FATAL(
"Unable to calculate SHA256 of %s\n", CI->Source);
1591 for(i=0; i<20; i++) { sprintf(Fuid+0+i*2,
"%02X",Sum->
SHA1digest[i]); }
1593 for(i=0; i<16; i++) { sprintf(Fuid+41+i*2,
"%02X",Sum->
MD5digest[i]); }
1595 for(i=0; i<64; i++) { sprintf(Fuid+74+i,
"%c",SHA256[i]); }
1597 snprintf(Fuid+140,
sizeof(Fuid)-140,
"%Lu",(
long long unsigned int)Sum->
DataLen);
1605 Fin = fopen(CI->Source,
"rb");
1611 for(i=0; i<20; i++) { sprintf(Fuid+0+i*2,
"%02X",Sum->
SHA1digest[i]); }
1613 for(i=0; i<16; i++) { sprintf(Fuid+41+i*2,
"%02X",Sum->
MD5digest[i]); }
1615 for(i=0; i<64; i++) { sprintf(Fuid+74+i,
"%c",SHA256[i]); }
1617 snprintf(Fuid+140,
sizeof(Fuid)-140,
"%Lu",(
long long unsigned int)Sum->
DataLen);
1643 char RMcmd[FILENAME_MAX];
1645 memset(RMcmd,
'\0',
sizeof(RMcmd));
1646 snprintf(RMcmd, FILENAME_MAX -1,
"rm -rf '%s' ", dirpath);
1667 char HostName[2048];
1668 struct timeval time_st;
1670 NewPath = strdup(DirPath);
1672 if ((subs = strstr(NewPath,
"%U")) )
1675 if (gettimeofday(&time_st, 0))
1678 LOG_WARNING(
"gettimeofday() failure.");
1679 time_st.tv_usec = 999999;
1683 snprintf(TmpPath,
sizeof(TmpPath),
"%s%ul", NewPath, (
unsigned)time_st.tv_usec);
1685 NewPath = strdup(TmpPath);
1688 if ((subs = strstr(NewPath,
"%H")) )
1691 gethostname(HostName,
sizeof(HostName));
1694 snprintf(TmpPath,
sizeof(TmpPath),
"%s%s%s", NewPath, HostName, subs+2);
1696 NewPath = strdup(TmpPath);
1699 if ((subs = strstr(NewPath,
"%R")) )
1704 snprintf(TmpPath,
sizeof(TmpPath),
"%s%s%s", NewPath,
fo_config_get(
sysconfig,
"FOSSOLOGY",
"path", NULL), subs+2);
1706 NewPath = strdup(TmpPath);
1712 void deleteTmpFiles(
char *dir)
1725 fprintf(stderr,
"Universal Unpacker, %s, compiled %s %s\n",
1726 Version,__DATE__,__TIME__);
1727 fprintf(stderr,
"Usage: %s [options] file [file [file...]]\n",Name);
1728 fprintf(stderr,
" Extracts each file.\n");
1729 fprintf(stderr,
" If filename specifies a directory, then extracts everything in it.\n");
1730 fprintf(stderr,
" Unpack Options:\n");
1731 fprintf(stderr,
" -h :: help (print this message), then exit.\n");
1732 fprintf(stderr,
" -C :: force continue when unpack tool fails.\n");
1733 fprintf(stderr,
" -d dir :: specify alternate extraction directory. %%U substitutes a unique ID.\n");
1734 fprintf(stderr,
" Default is the same directory as file (usually not a good idea).\n");
1735 fprintf(stderr,
" -m # :: number of CPUs to use (default: 1).\n");
1736 fprintf(stderr,
" -P :: prune files: remove links, >1 hard links, zero files, etc.\n");
1737 fprintf(stderr,
" -R :: recursively unpack (same as '-r -1')\n");
1738 fprintf(stderr,
" -r # :: recurse to a specified depth (0=none/default, -1=infinite)\n");
1739 fprintf(stderr,
" -X :: remove recursive sources after unpacking.\n");
1740 fprintf(stderr,
" -x :: remove ALL unpacked files when done (clean up).\n");
1741 fprintf(stderr,
" I/O Options:\n");
1742 fprintf(stderr,
" -L out :: Generate a log of files extracted (in XML) to out.\n");
1743 fprintf(stderr,
" -F :: Using files from the repository.\n");
1744 fprintf(stderr,
" -i :: Initialize the database queue system, then exit.\n");
1745 fprintf(stderr,
" -I :: Ignore SCM Data.\n");
1746 fprintf(stderr,
" -Q :: Using scheduler queue system. (Includes -F)\n");
1747 fprintf(stderr,
" If -L is used, unpacked files are placed in 'files'.\n");
1748 fprintf(stderr,
" -T rep :: Set gold repository name to 'rep' (for testing)\n");
1749 fprintf(stderr,
" -t rep :: Set files repository name to 'rep' (for testing)\n");
1750 fprintf(stderr,
" -A :: do not set the initial DB container as an artifact.\n");
1751 fprintf(stderr,
" -f :: force processing files that already exist in the DB.\n");
1752 fprintf(stderr,
" -q :: quiet (generate no output).\n");
1753 fprintf(stderr,
" -U upload_pk :: upload to unpack (implies -RQ). Writes to db.\n");
1754 fprintf(stderr,
" -v :: verbose (-vv = more verbose).\n");
1755 fprintf(stderr,
" -V :: print the version info, then exit.\n");
1756 fprintf(stderr,
"Currently identifies and processes:\n");
1757 fprintf(stderr,
" Compressed files: .Z .gz .bz .bz2 upx\n");
1758 fprintf(stderr,
" Archives files: tar cpio zip jar ar rar cab\n");
1759 fprintf(stderr,
" Data files: pdf\n");
1760 fprintf(stderr,
" Installer files: rpm deb\n");
1761 fprintf(stderr,
" File images: iso9660(plain/Joliet/Rock Ridge) FAT(12/16/32) ext2/ext3 NTFS\n");
1762 fprintf(stderr,
" Boot partitions: x86, vmlinuz\n");
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 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?