38 const char*
SCM_REGEX =
"/\\.git|\\.hg|\\.bzr|CVS/ROOT|\\.svn/";
54 char FileNameParent[PATH_MAX];
55 struct stat st, stParent;
56 memcpy(FileNameParent, FileName,
sizeof(FileNameParent));
57 FileNameParent[PATH_MAX-1] = 0;
58 char *lastSlashPos = strrchr(FileNameParent,
'/');
59 if (NULL != lastSlashPos)
64 FileNameParent[lastSlashPos - FileNameParent] =
'\0';
65 if (!strcmp(FileNameParent + strlen(FileNameParent) - 4,
".dir"))
70 FileNameParent[strlen(FileNameParent) - 4] =
'\0';
71 stat(FileNameParent, &stParent);
73 if(S_ISREG(stParent.st_mode) && (st.st_size/stParent.st_size > InflateSize))
103 if (NULL == Name)
return;
105 char *LastDot = strrchr(Name,
'.');
106 if (LastDot == NULL)
return;
108 if ((LastDot[1]>=
'0')&&(LastDot[1]<=
'9'))
return;
109 if (LastDot) *LastDot = 0;
125 for(i=0;
CMD[i].Magic != NULL; i++)
133 for(i=0;
CMD[i].Magic != NULL; i++)
135 if (
CMD[i].Magic[0] ==
'\0')
continue;
137 memset(
SQL,
'\0',MAXSQL);
138 snprintf(
SQL,MAXSQL,
"SELECT mimetype_pk FROM mimetype WHERE mimetype_name = '%s';",
CMD[i].Magic);
141 else if (PQntuples(result) > 0)
143 CMD[i].
DBindex = atol(PQgetvalue(result,0,0));
149 memset(
SQL,
'\0',MAXSQL);
150 snprintf(
SQL,MAXSQL,
"INSERT INTO mimetype (mimetype_name) VALUES ('%s');",
CMD[i].Magic);
177 char *
Src,
int ProtectQuotes,
char *Replace)
180 char Temp[FILENAME_MAX];
182 memset(Dest,
'\0',DestLen);
185 while((Src[i] !=
'\0') && (d < DestLen))
188 if (ProtectQuotes && (Src[i]==
'\''))
190 if (d+4 >= DestLen)
return(1);
191 strcpy(Dest+d,
"'\\''");
195 else if (!ProtectQuotes && strchr(
"\\",Src[i]))
197 if (d+2 >= DestLen)
return(1);
199 Dest[d] = Src[i]; d++;
202 else if (Replace && (Src[i]==
'%') && (Src[i+1]==
's'))
205 if (d+strlen(Temp) >= DestLen)
return(1);
228 int Prune (
char *Fname,
struct stat Stat)
230 if (!Fname || (Fname[0]==
'\0'))
return(1);
232 if (S_ISLNK(Stat.st_mode) || S_ISCHR(Stat.st_mode) ||
233 S_ISBLK(Stat.st_mode) || S_ISFIFO(Stat.st_mode) ||
234 S_ISSOCK(Stat.st_mode))
240 if (S_ISREG(Stat.st_mode) && (Stat.st_nlink > 1))
246 if (S_ISREG(Stat.st_mode) && (Stat.st_size == 0))
261 char Dir[FILENAME_MAX+1];
266 memset(Dir,
'\0',
sizeof(Dir));
268 for(i=1; Dir[i] !=
'\0'; i++)
274 if (stat(Dir,&Status) == 0)
276 if (!S_ISDIR(Status.st_mode))
278 LOG_FATAL(
"'%s' is not a directory.",Dir);
285 if (rc && (errno == EEXIST)) rc=0;
288 LOG_FATAL(
"mkdir %s' failed, error: %s",Dir,strerror(errno));
296 rc = mkdir(Dir,0770);
297 if (rc && (errno == EEXIST)) rc=0;
300 LOG_FATAL(
"mkdir %s' failed, error: %s",Dir,strerror(errno));
316 if (mkdir(Fname,0770))
318 if (errno == EEXIST)
return(0);
334 if (!Fname || (Fname[0]==
'\0'))
return(0);
335 rc = lstat(Fname,&Stat);
336 if (rc != 0)
return(0);
337 return(S_ISDIR(Stat.st_mode));
350 if (!Fname || (Fname[0]==
'\0'))
return(0);
351 if (Link) rc = stat(Fname,&Stat);
352 else rc = lstat(Fname,&Stat);
353 if (rc != 0)
return(0);
354 return(S_ISREG(Stat.st_mode));
372 if (!Fin)
return(-1);
373 if (feof(Fin))
return(-1);
374 memset(Line,
'\0',MaxLine);
378 while(!feof(Fin) && (C>=0) && (i<MaxLine))
382 if (i > 0)
return(i);
408 char TestCmd[FILENAME_MAX];
410 Path = getenv(
"PATH");
411 if (!Path)
return(0);
413 memset(TestCmd,
'\0',
sizeof(TestCmd));
415 for(i=0; (j<FILENAME_MAX-1) && (Path[i] !=
'\0'); i++)
419 if ((j>0) && (TestCmd[j-1] !=
'/')) strcat(TestCmd,
"/");
421 if (
IsFile(TestCmd,1))
return(1);
423 memset(TestCmd,
'\0',
sizeof(TestCmd));
436 if (TestCmd[j-1] !=
'/') strcat(TestCmd,
"/");
438 if (
IsFile(TestCmd,1))
return(1);
440 if (!Quiet) LOG_WARNING(
"%s not found in $PATH",Exe);
454 unsigned char * Mmap;
455 int LenIn, LenOut, Wrote;
460 if (lstat(Src,&Stat) == -1)
return(1);
461 LenIn = Stat.st_size;
462 if (!S_ISREG(Stat.st_mode))
return(1);
464 Fin = open(Src,O_RDONLY);
467 LOG_FATAL(
"Unable to open source '%s'",Src);
472 Slash = strrchr(Dst,
'/');
473 if (Slash && (Slash != Dst))
480 Fout = open(Dst,O_WRONLY|O_CREAT|O_TRUNC,Stat.st_mode);
483 LOG_FATAL(
"Unable to open target '%s'",Dst);
489 Mmap = mmap(0,LenIn,PROT_READ,MAP_PRIVATE,Fin,0);
492 LOG_FATAL(
"pfile %s Unable to process file.",
Pfile_Pk);
493 LOG_WARNING(
"pfile %s Mmap failed during copy.",
Pfile_Pk);
501 while((LenOut < LenIn) && (Wrote >= 0))
503 Wrote = write(Fout,Mmap+LenOut,LenIn-LenOut);
527 if (Pid <= 0)
return(-1);
530 for(i=0; (i<MAXCHILD) && (
Queue[i].ChildPid != Pid); i++) ;
531 if (
Queue[i].ChildPid != Pid)
538 if (!WIFEXITED(Status))
542 LOG_FATAL(
"Child had unnatural death");
548 else Status = WEXITSTATUS(Status);
553 LOG_FATAL(
"Child had non-zero status: %d",Status);
554 LOG_FATAL(
"Child was to recurse on %s",
Queue[i].ChildRecurse);
562 Queue[i].ChildPid = 0;
584 for(i=0;
CMD[i].
Cmd != NULL; i++)
586 if (
CMD[i].Cmd[0] ==
'\0')
continue;
604 for(i=0;
CMD[i].
Cmd != NULL; i++)
611 for(i=0;
CMD[i].
Cmd != NULL; i++)
632 char *Out,
char *Where)
634 char Cmd1[FILENAME_MAX * 5];
635 char CWD[FILENAME_MAX];
637 char TempPre[FILENAME_MAX];
638 char TempFile[FILENAME_MAX];
639 char TempCwd[FILENAME_MAX];
640 char TempPost[FILENAME_MAX];
648 LOG_DEBUG(
"Extracting %s: %s > %s",Cmd,File,Out);
654 LOG_DEBUG(
"Extracting %s in %s: %s\n",Cmd,Where,File);
658 LOG_DEBUG(
"Testing %s: %s\n",Cmd,File);
663 if (getcwd(CWD,
sizeof(CWD)) == NULL)
665 LOG_FATAL(
"directory name longer than %d characters",(
int)
sizeof(CWD));
668 if (
Verbose > 1){ LOG_DEBUG(
"CWD: %s\n",CWD);}
669 if ((Where != NULL) && (Where[0] !=
'\0'))
671 if (chdir(Where) != 0)
674 if (chdir(Where) != 0)
676 LOG_FATAL(
"Unable to access directory '%s'",Where);
680 if (
Verbose > 1) LOG_DEBUG(
"CWD: %s",Where);
685 memset(Cmd1,
'\0',
sizeof(Cmd1));
686 if (
TaintString(TempPre,FILENAME_MAX,CmdPre,0,Out) ||
695 snprintf(Cmd1,
sizeof(Cmd1),
"%s %s '%s/%s' %s",
696 Cmd,TempPre,TempCwd,TempFile,TempPost);
700 snprintf(Cmd1,
sizeof(Cmd1),
"%s %s '%s' %s",
701 Cmd,TempPre,TempFile,TempPost);
706 LOG_ERROR(
"Process killed by signal (%d): %s",WTERMSIG(rc),Cmd1);
709 if (WIFEXITED(rc)) rc = WEXITSTATUS(rc);
711 if (
Verbose) LOG_DEBUG(
"in %s -- %s ; rc=%d",Where,Cmd1,rc);
714 LOG_ERROR(
"Unable to change directory to %s", CWD);
715 if (
Verbose > 1) LOG_DEBUG(
"CWD: %s",CWD);
730 LOG_FATAL(
"Failed to initialize magic cookie");
752 pExt = strrchr(Filename,
'.');
755 if (strcmp(pExt,
".dsc")==0)
760 if ((fp = fopen(Filename,
"r")) == NULL)
return 0;
762 while ((c = fgetc(fp)) != EOF && j < 500 ){
767 if ((strstr(line,
"-----BEGIN PGP SIGNED MESSAGE-----") && strstr(line,
"Source:")) ||
768 (strstr(line,
"Format:") && strstr(line,
"Source:") && strstr(line,
"Version:")))
794 if (strstr(Type,
"Debian binary package"))
796 strcpy(TypeBuf,
"application/x-debian-package");
800 if (strstr(Type,
"ISO 9660"))
802 strcpy(TypeBuf,
"application/x-iso9660-image");
807 rc1 =
RunCommand(
"7z",
"l -y ",Filename,
">/dev/null 2>&1",NULL,NULL);
808 rc2 =
RunCommand(
"7z",
"t -y -pjunk",Filename,
">/dev/null 2>&1",NULL,NULL);
811 rc3 =
RunCommand(
"7z",
"t -y -pjunk",Filename,
"|grep 'Wrong password' >/dev/null 2>&1",NULL,NULL);
814 LOG_ERROR(
"'%s' cannot be unpacked, password required.",Filename);
820 strcpy(TypeBuf,
"application/x-7z-w-compressed");
824 if (strstr(Type,
" ext2 "))
826 strcpy(TypeBuf,
"application/x-ext2");
830 if (strstr(Type,
" ext3 "))
832 strcpy(TypeBuf,
"application/x-ext3");
836 if (strstr(Type,
"x86 boot sector, mkdosfs"))
838 strcpy(TypeBuf,
"application/x-fat");
842 if (strstr(Type,
"NTFS"))
844 strcpy(TypeBuf,
"application/x-ntfs");
848 if (strstr(Type,
"x86 boot"))
850 strcpy(TypeBuf,
"application/x-x86_boot");
872 if (Type == NULL)
return(-1);
880 if ((strcmp(basename(Filename),
".bss") == 0) && (strstr(Type,
"octet")))
882 Type = strdup(
"text/plain");
888 strncpy(TypeBuf, Type,
sizeof(TypeBuf));
891 if (strstr(Type,
"octet" ))
898 if (strstr(Type,
"msword") || strstr(Type,
"vnd.ms"))
899 strcpy(TypeBuf,
"application/x-7z-w-compressed");
902 if (strstr(Type,
"application/x-exe") ||
903 strstr(Type,
"application/x-shellscript"))
905 rc =
RunCommand(
"unzip",
"-q -l",Filename,
">/dev/null 2>&1",NULL,NULL);
906 if ((rc==0) || (rc==1) || (rc==2) || (rc==51))
908 strcpy(TypeBuf,
"application/x-zip");
911 else if (strstr(Type,
"application/x-tar"))
913 if (
RunCommand(
"tar",
"-tf",Filename,
">/dev/null 2>&1",NULL,NULL) != 0)
921 for(i=0; (
CMD[i].
Cmd != NULL) && (Match == -1); i++)
923 if (
CMD[i].Status == 0)
continue;
924 if (
CMD[i].Type == CMD_DEFAULT)
929 if (!strstr(TypeBuf,
CMD[i].Magic))
941 LOG_DEBUG(
"MISS: Type=%s %s",TypeBuf,Filename);
945 LOG_DEBUG(
"MATCH: Type=%d %s %s %s %s",
CMD[Match].Type,
CMD[Match].Cmd,
CMD[Match].CmdPre,Filename,
CMD[Match].CmdPost);
970 if (d->Name) free(d->Name);
982 dirlist *dlist=NULL, *dhead=NULL;
984 struct dirent *Entry;
988 Dir = opendir(Fullname);
989 if (Dir == NULL)
return(NULL);
991 Entry = readdir(Dir);
994 if (!strcmp(Entry->d_name,
"."))
goto skip;
995 if (!strcmp(Entry->d_name,
".."))
goto skip;
999 LOG_FATAL(
"Failed to allocate dirlist memory");
1002 dhead->Name = (
char *)malloc(strlen(Entry->d_name)+1);
1005 LOG_FATAL(
"Failed to allocate dirlist.Name memory");
1008 memset(dhead->Name,
'\0',strlen(Entry->d_name)+1);
1009 strcpy(dhead->Name,Entry->d_name);
1011 dhead->Next = dlist;
1019 while(dhead->Next && (strcmp(dhead->Name,dhead->Next->Name) > 0))
1023 dhead->Name = dhead->Next->Name;
1024 dhead->Next->Name = Name;
1025 dhead = dhead->Next;
1031 Entry = readdir(Dir);
1037 printf(
"Directory: %s\n",Fullname);
1038 for(dhead=dlist; dhead; dhead=dhead->
Next)
1040 printf(
" %s\n",dhead->Name);
1057 void SetDir (
char *Dest,
int DestLen,
char *Smain,
char *Sfile)
1061 memset(Dest,
'\0',DestLen);
1066 if (Sfile && (Sfile[0]==
'/')) Sfile++;
1074 if (!memcmp(Sfile,
"../",3)) { Sfile+=3; i=1; }
1075 else if (!memcmp(Sfile,
"./",2)) { Sfile+=2; i=1; }
1077 while(Sfile && !memcmp(Sfile,
"../",3)) Sfile+=3;
1080 if ((strlen(Dest) > 0) && (Last(Smain) !=
'/') && (Sfile[0] !=
'/'))
1082 if (Sfile) strcat(Dest,Sfile);
1084 for(i=strlen(Dest)-1; (i>=0) && (Dest[i] !=
'/'); i--)
1097 LOG_DEBUG(
"Container:");
1098 printf(
" Source: %s\n",CI->Source);
1099 printf(
" Partdir: %s\n",CI->
Partdir);
1100 printf(
" Partname: %s\n",CI->
Partname);
1103 printf(
" HasChild: %d\n",CI->
HasChild);
1104 printf(
" Pruned: %d\n",CI->
Pruned);
1105 printf(
" Corrupt: %d\n",CI->
Corrupt);
1106 printf(
" Artifact: %d\n",CI->
Artifact);
1107 printf(
" IsDir: %d\n",CI->
IsDir);
1110 printf(
" pfile_pk: %ld\n",CI->
pfile_pk);
1112 printf(
" Parent Cmd: %d\n",CI->
PI.Cmd);
1132 if (!Fuid || (Fuid[0] ==
'\0'))
return(1);
1135 memset(
SQL,
'\0',MAXSQL);
1136 snprintf(
SQL,MAXSQL,
"SELECT pfile_pk,pfile_mimetypefk,pfile_sha256 FROM pfile " 1137 "WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
1138 Fuid,Fuid+41,Fuid+140);
1143 if (PQntuples(result) == 0)
1149 memset(
SQL,
'\0',MAXSQL);
1152 snprintf(
SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_sha256,pfile_size,pfile_mimetypefk) " 1153 "VALUES ('%.40s','%.32s','%.64s','%s','%ld');",
1154 Fuid,Fuid+41,Fuid+74,Fuid+140,
CMD[CI->
PI.Cmd].
DBindex);
1158 snprintf(
SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_sha256,pfile_size) VALUES ('%.40s','%.32s','%.64s','%s');",
1159 Fuid,Fuid+41,Fuid+74,Fuid+140);
1163 if ((result==0) || ((PQresultStatus(result) != PGRES_COMMAND_OK) &&
1164 (strncmp(
"23505", PQresultErrorField(result, PG_DIAG_SQLSTATE),5))))
1166 LOG_ERROR(
"Error inserting pfile, %s.",
SQL);
1173 memset(
SQL,
'\0',MAXSQL);
1174 snprintf(
SQL,MAXSQL,
"SELECT pfile_pk,pfile_mimetypefk,pfile_sha256 FROM pfile " 1175 "WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_sha256 = '%.64s' AND pfile_size = '%s';",
1176 Fuid,Fuid+41,Fuid+74,Fuid+140);
1182 Val = PQgetvalue(result,0,0);
1187 tempMimeType = atol(PQgetvalue(result,0,1));
1188 tempSha256 = PQgetvalue(result,0,2);
1194 memset(
SQL,
'\0',MAXSQL);
1195 snprintf(
SQL,MAXSQL,
"UPDATE pfile SET pfile_mimetypefk = '%ld' WHERE pfile_pk = '%ld';",
1201 if (strncasecmp(tempSha256, Fuid+74, 64) != 0)
1204 memset(
SQL,
'\0',MAXSQL);
1205 snprintf(
SQL,MAXSQL,
"UPDATE pfile SET pfile_sha256 = '%.64s' WHERE pfile_pk = '%ld';",
1240 err = regcomp (&preg,
SCM_REGEX, REG_NOSUB | REG_EXTENDED);
1245 match = regexec (&preg, sourcefilename, 0, NULL, 0);
1250 if (
Verbose) LOG_DEBUG(
"match found %s",sourcefilename);
1252 else if(match == REG_NOMATCH)
1255 if (
Verbose) LOG_DEBUG(
"match not found %s",sourcefilename);
1261 size = regerror (err, &preg, NULL, 0);
1262 text = malloc (
sizeof (*text) * size);
1265 regerror (err, &preg, text, size);
1266 LOG_ERROR(
"Error regexc '%s' '%s' return %d, error %s",
SCM_REGEX,sourcefilename,match,text);
1270 LOG_ERROR(
"Not enough memory (%lu)",
sizeof (*text) * size);
1278 LOG_ERROR(
"Error regcomp(%d)",err);
1298 char UfileName[1024];
1313 memset(UfileName,
'\0',
sizeof(UfileName));
1317 snprintf(UfileName,
sizeof(UfileName),
"SELECT upload_filename FROM upload WHERE upload_pk = %s;",
Upload_Pk);
1318 result = PQexec(
pgConn, UfileName);
1320 memset(UfileName,
'\0',
sizeof(UfileName));
1321 ufile_name = PQgetvalue(result,0,0);
1323 if (strchr(ufile_name,
'/')) ufile_name = strrchr(ufile_name,
'/')+1;
1331 if ((Len > 4) && !strcmp(CI->
Partname+Len-4,
".dir"))
1332 strcpy(UfileName,
"artifact.dir");
1333 else if ((Len > 9) && !strcmp(CI->
Partname+Len-9,
".unpacked"))
1334 strcpy(UfileName,
"artifact.unpacked");
1335 else if ((Len > 5) && !strcmp(CI->
Partname+Len-5,
".meta"))
1336 strcpy(UfileName,
"artifact.meta");
1338 strcpy(UfileName,
"artifact");
1345 LOG_WARNING(
"Error escaping filename with multibyte character set (%s).", CI->
Partname);
1349 strncpy(UfileName, EscBuf,
sizeof(UfileName));
1363 for (cp=UfileName; *cp; cp++)
if (!isprint(*cp) || (*cp==
'/') || (*cp==
'\\')) *cp =
'~';
1367 memset(
SQL,
'\0',MAXSQL);
1371 snprintf(
SQL,MAXSQL,
"INSERT INTO %s (parent,pfile_fk,ufile_mode,ufile_name,upload_fk) VALUES (%ld,%ld,%ld,E'%s',%s);",
1383 snprintf(
SQL,MAXSQL,
"INSERT INTO %s (upload_fk,pfile_fk,ufile_mode,ufile_name) VALUES (%s,%ld,%ld,E'%s');",
1390 memset(
SQL,
'\0',MAXSQL);
1391 snprintf(
SQL,MAXSQL,
"SELECT currval('uploadtree_uploadtree_pk_seq');");
1423 memset(FuidNew,
'\0',
sizeof(FuidNew));
1425 strncpy(FuidNew, Fuid, 74);
1427 strcat(FuidNew,Fuid+140);
1434 LOG_ERROR(
"Failed to import '%s' as '%s' into the repository",CI->Source,FuidNew);
1438 if (
Verbose) LOG_DEBUG(
"Repository[%s]: insert '%s' as '%s'",
1473 if (CI->Source[0] ==
'\0')
return(0);
1474 memset(Fuid,0,
sizeof(Fuid));
1481 for(i=0; CI->Source[i] !=
'\0'; i++)
1483 if (isalnum(CI->Source[i]) ||
1484 strchr(
" `~!@#$%^*()-=_+[]{}\\|;:',./?",CI->Source[i]))
1486 else fprintf(
ListOutFile,
"&#x%02x;",(
int)(CI->Source[i])&0xff);
1495 for(i=0; CI->
Partname[i] !=
'\0'; i++)
1498 strchr(
" `~!@#$%^*()-=_+[]{}\\|;:',./?",CI->
Partname[i]))
1506 if ((CI->
PI.Cmd >= 0) && (
CMD[CI->
PI.Cmd].
Type != CMD_DEFAULT))
1511 else if (S_ISDIR(CI->
Stat.st_mode))
1540 if (S_ISDIR(CI->
Stat.st_mode))
1544 else if (S_ISREG(CI->
Stat.st_mode))
1562 if (CI->
Stat.st_mtime)
1569 if (CI->
Stat.st_ctime)
1579 if (S_ISREG(CI->
Stat.st_mode) && !CI->
Pruned)
1585 memset(SHA256,
'\0',
sizeof(SHA256));
1588 if(calc_sha256sum(CI->Source, SHA256))
1590 LOG_FATAL(
"Unable to calculate SHA256 of %s\n", CI->Source);
1601 for(i=0; i<20; i++) { sprintf(Fuid+0+i*2,
"%02X",Sum->
SHA1digest[i]); }
1603 for(i=0; i<16; i++) { sprintf(Fuid+41+i*2,
"%02X",Sum->
MD5digest[i]); }
1605 for(i=0; i<64; i++) { sprintf(Fuid+74+i,
"%c",SHA256[i]); }
1607 snprintf(Fuid+140,
sizeof(Fuid)-140,
"%Lu",(
long long unsigned int)Sum->
DataLen);
1615 Fin = fopen(CI->Source,
"rb");
1621 for(i=0; i<20; i++) { sprintf(Fuid+0+i*2,
"%02X",Sum->
SHA1digest[i]); }
1623 for(i=0; i<16; i++) { sprintf(Fuid+41+i*2,
"%02X",Sum->
MD5digest[i]); }
1625 for(i=0; i<64; i++) { sprintf(Fuid+74+i,
"%c",SHA256[i]); }
1627 snprintf(Fuid+140,
sizeof(Fuid)-140,
"%Lu",(
long long unsigned int)Sum->
DataLen);
1653 char RMcmd[FILENAME_MAX];
1655 memset(RMcmd,
'\0',
sizeof(RMcmd));
1656 snprintf(RMcmd, FILENAME_MAX -1,
"rm -rf '%s' ", dirpath);
1677 char HostName[2048];
1678 struct timeval time_st;
1680 NewPath = strdup(DirPath);
1682 if ((subs = strstr(NewPath,
"%U")) )
1685 if (gettimeofday(&time_st, 0))
1688 LOG_WARNING(
"gettimeofday() failure.");
1689 time_st.tv_usec = 999999;
1693 snprintf(TmpPath,
sizeof(TmpPath),
"%s%ul", NewPath, (
unsigned)time_st.tv_usec);
1695 NewPath = strdup(TmpPath);
1698 if ((subs = strstr(NewPath,
"%H")) )
1701 gethostname(HostName,
sizeof(HostName));
1704 snprintf(TmpPath,
sizeof(TmpPath),
"%s%s%s", NewPath, HostName, subs+2);
1706 NewPath = strdup(TmpPath);
1709 if ((subs = strstr(NewPath,
"%R")) )
1714 snprintf(TmpPath,
sizeof(TmpPath),
"%s%s%s", NewPath,
fo_config_get(
sysconfig,
"FOSSOLOGY",
"path", NULL), subs+2);
1716 NewPath = strdup(TmpPath);
1722 void deleteTmpFiles(
char *dir)
1735 fprintf(stderr,
"Universal Unpacker, %s, compiled %s %s\n",
1736 Version,__DATE__,__TIME__);
1737 fprintf(stderr,
"Usage: %s [options] file [file [file...]]\n",Name);
1738 fprintf(stderr,
" Extracts each file.\n");
1739 fprintf(stderr,
" If filename specifies a directory, then extracts everything in it.\n");
1740 fprintf(stderr,
" Unpack Options:\n");
1741 fprintf(stderr,
" -h :: help (print this message), then exit.\n");
1742 fprintf(stderr,
" -C :: force continue when unpack tool fails.\n");
1743 fprintf(stderr,
" -d dir :: specify alternate extraction directory. %%U substitutes a unique ID.\n");
1744 fprintf(stderr,
" Default is the same directory as file (usually not a good idea).\n");
1745 fprintf(stderr,
" -m # :: number of CPUs to use (default: 1).\n");
1746 fprintf(stderr,
" -P :: prune files: remove links, >1 hard links, zero files, etc.\n");
1747 fprintf(stderr,
" -R :: recursively unpack (same as '-r -1')\n");
1748 fprintf(stderr,
" -r # :: recurse to a specified depth (0=none/default, -1=infinite)\n");
1749 fprintf(stderr,
" -X :: remove recursive sources after unpacking.\n");
1750 fprintf(stderr,
" -x :: remove ALL unpacked files when done (clean up).\n");
1751 fprintf(stderr,
" I/O Options:\n");
1752 fprintf(stderr,
" -L out :: Generate a log of files extracted (in XML) to out.\n");
1753 fprintf(stderr,
" -F :: Using files from the repository.\n");
1754 fprintf(stderr,
" -i :: Initialize the database queue system, then exit.\n");
1755 fprintf(stderr,
" -I :: Ignore SCM Data.\n");
1756 fprintf(stderr,
" -Q :: Using scheduler queue system. (Includes -F)\n");
1757 fprintf(stderr,
" If -L is used, unpacked files are placed in 'files'.\n");
1758 fprintf(stderr,
" -T rep :: Set gold repository name to 'rep' (for testing)\n");
1759 fprintf(stderr,
" -t rep :: Set files repository name to 'rep' (for testing)\n");
1760 fprintf(stderr,
" -A :: do not set the initial DB container as an artifact.\n");
1761 fprintf(stderr,
" -f :: force processing files that already exist in the DB.\n");
1762 fprintf(stderr,
" -q :: quiet (generate no output).\n");
1763 fprintf(stderr,
" -U upload_pk :: upload to unpack (implies -RQ). Writes to db.\n");
1764 fprintf(stderr,
" -v :: verbose (-vv = more verbose).\n");
1765 fprintf(stderr,
" -V :: print the version info, then exit.\n");
1766 fprintf(stderr,
"Currently identifies and processes:\n");
1767 fprintf(stderr,
" Compressed files: .Z .gz .bz .bz2 upx\n");
1768 fprintf(stderr,
" Archives files: tar cpio zip jar ar rar cab\n");
1769 fprintf(stderr,
" Data files: pdf\n");
1770 fprintf(stderr,
" Installer files: rpm deb\n");
1771 fprintf(stderr,
" File images: iso9660(plain/Joliet/Rock Ridge) FAT(12/16/32) ext2/ext3 NTFS\n");
1772 fprintf(stderr,
" Boot partitions: x86, vmlinuz\n");
PGconn * pgConn
Database connection.
int CopyFile(char *Src, char *Dst)
Copy a file. For speed: mmap and save.
char * PathCheck(char *DirPath)
Check if path contains a "%U" or "%H". If so, substitute a unique ID for U.
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
int Quiet
Run in quiet mode?
int TotalFiles
Number of regular files.
int ParentWait()
Wait for a child. Sets child status.
Structure for storing information about a particular file.
unpackqueue Queue[MAXCHILD+1]
Manage children.
CksumFile * SumOpenFile(char *Fname)
Open and mmap a file.
Store the results of a regex match.
char Partname[FILENAME_MAX]
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
int DisplayContainerInfo(ContainerInfo *CI, int Cmd)
Print what can be printed in XML.
int IsDir(char *Fname)
Given a filename, is it a directory?
int Verbose
Verbose level.
int TotalCompressedFiles
Number of compressed files.
FILE * ListOutFile
File to store unpack list.
char * Pfile_Pk
Pfile pk in DB.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
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, the error object is set and NULL is returned.
int IsInflatedFile(char *FileName, int InflateSize)
Test if the file is a compression bomb.
Cksum * SumComputeFile(FILE *Fin)
Compute the checksum, allocate and return a string containing the sum value.
int TotalArtifacts
Number of artifacts.
int IsDebianSourceFile(char *Filename)
Read file to see if it is a Debian source file.
int IgnoreSCMData
1: Ignore SCMÂ data, 0: dont ignore it.
int MkDir(char *Fname)
Smart mkdir.
int FindCmd(char *Filename)
Given a file name, determine the type of extraction command. This uses Magic.
int TestSCMData(char *sourcefilename)
Search for SCM data in the filename.
void SetDir(char *Dest, int DestLen, char *Smain, char *Sfile)
Set a destination directory name.
cmdlist CMD[]
Global command table.
static char * Src
Souce location.
void RemovePostfix(char *Name)
get rid of the postfix
uint8_t SHA1digest[20]
SHA1 digest of the file.
void SQLNoticeProcessor(void *arg, const char *message)
Dummy postgresql notice processor. This prevents Notices from being written to stderr.
int ReunpackSwitch
Set if the uploadtree records are missing from db.
int IsExe(char *Exe, int Quiet)
Check if the executable exists.
static char * Dst
Destination location.
char Partdir[FILENAME_MAX]
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...
uint8_t MD5digest[16]
MD5 digest of the file.
dirlist * MakeDirList(char *Fullname)
Create a list of files in a directory.
char SQL[256]
SQL query to execute.
int ForceDuplicate
When using db, should it process duplicates?
int UseRepository
Using files from the repository?
void CheckCommands(int Show)
Make sure all commands are usable.
int ReadLine(FILE *Fin, char *Line, int MaxLine)
Read a command from a stream.
int Prune(char *Fname, struct stat Stat)
Given a filename and its stat, prune it.
Stores all extern variables used by the agent.
char * uploadtree_tablename
upload.uploadtree_tablename
int TaintString(char *Dest, int DestLen, char *Src, int ProtectQuotes, char *Replace)
Protect strings intelligently.
Store check sum of a file.
uint64_t DataLen
Size of the file.
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.
char * Upload_Pk
Upload pk in DB.
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...
magic_t MagicCookie
for Magic
void FreeDirList(dirlist *DL)
Free a list of files in a directory list.
char REP_FILES[16]
Files repository name.
int RunCommand(char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where)
Try a command and return command code.
int TotalDirectories
Number of directories.
void Usage(char *Name, char *Version)
Display program usage.
int fo_RepImport(char *Source, char *Type, char *Filename, int Link)
Import a file into the repository.
int MkDirs(char *Fname)
Same as command-line "mkdir -p".
int DBInsertUploadTree(ContainerInfo *CI, int Mask)
Insert an UploadTree record.
void SumCloseFile(CksumFile *CF)
Close a file that was opened with SumOpenFile()
long TotalItems
Number of records inserted.
void InitCmd()
Initialize the metahandler CMD table.
Cksum * SumComputeBuff(CksumFile *CF)
Compute the checksum, allocate and return a Cksum containing the sum value.
void SafeExit(int rc)
Close scheduler and database connections, then exit.
int InitMagic()
Open and load Magic file Initializes global MagicCookie.
int ForceContinue
Force continue when unpack tool fails?
void DebugContainerInfo(ContainerInfo *CI)
Print a ContainerInfo structure.
int IsFile(char *Fname, int Link)
Given a filename, is it a file?
Store file handler and mmap of a file.
char PartnameNew[FILENAME_MAX]
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.
int DBInsertPfile(ContainerInfo *CI, char *Fuid)
Insert a Pfile record. Sets the pfile_pk in CI.