41 for(i=0; Name[i] !=
'\0'; i++)
43 if (isupper(Name[i])) Name[i]=tolower(Name[i]);
48 if (Name[i] !=
')')
return;
50 while((i>1) && (Name[i] !=
'(')) i--;
54 if (Name[i]==
' ') Name[i]=
'\0';
68 if (List->inode) free(List->inode);
85 char Cmd[FILENAME_MAX*2];
86 char Line[FILENAME_MAX*2];
113 snprintf(Cmd,
sizeof(Cmd),
"fls -m / -f '%s' -lpr '%s' 2>/dev/null",
115 Fin = popen(Cmd,
"r");
118 fprintf(stderr,
"ERROR: Disk failed: %s\n",Cmd);
122 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
127 printf(
"FATAL: Unable to allocated %d bytes of memory\n",(
int)
sizeof(
permlist));
130 NewList->inode = NULL;
131 NewList->Next = NULL;
133 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
135 if (strstr(L,
"realloc)|")) {
FreeDiskPerms(NewList);
continue;}
136 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
137 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
139 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
140 NewList->perm = atoi(L);
143 NewList->inode = (
char *)calloc(L-inode,1);
146 printf(
"FATAL: Unable to allocate %d bytes.\n",(
int)(L-inode));
149 memcpy(NewList->inode,inode,L-inode-1);
151 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
152 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
153 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
154 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
155 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
156 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
157 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
158 NewList->Times.actime = atoi(L);
159 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
160 NewList->Times.modtime = atoi(L);
163 NewList->Next = List;
182 for(i=0; Inode1[i] && Inode2[i]; i++)
184 if (isdigit(Inode1[i]) || (Inode1[i]==
'-'))
186 if (Inode1[i] != Inode2[i])
return(0);
191 v1 = (isdigit(Inode1[i]) || (Inode1[i]==
'-'));
192 v2 = (isdigit(Inode2[i]) || (Inode2[i]==
'-'));
206 char *Destination,
char *Target)
212 if (!List)
return(NULL);
215 while((inode[0] !=
'\0') && !isdigit(inode[0])) inode++;
218 if (
SameInode(List->inode,inode))
goto FoundPerm;
227 NewList = Parent->
Next;
229 NewList->
Next = List;
233 Parent = Parent->
Next;
235 if (
Verbose) fprintf(stderr,
"LOG pfile %s WARNING Could not find inode: %s\n",
Pfile,inode);
239 Cwd = getcwd(NULL,0);
242 printf(
"ERROR: Current directory no longer exists! Aborting!\n");
246 if(chdir(Destination) != 0)
248 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n",
249 __FILE__, __LINE__, Destination);
250 fprintf(stderr,
"ERROR: errno is: %s\n", strerror(errno));
253 if (
Verbose > 1) fprintf(stderr,
"DEBUG: setting inode %s, name %s to %07o\n",List->inode,Target,List->
perm);
254 chmod(Target,List->
perm);
255 utime(Target,&(List->
Times));
259 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n",
260 __FILE__, __LINE__, Cwd);
261 fprintf(stderr,
"ERROR: errno is: %s\n", strerror(errno));
291 char Cmd[FILENAME_MAX*7];
292 char Line[FILENAME_MAX*2];
299 char TempSource[FILENAME_MAX];
300 char TempInode[FILENAME_MAX], TempDest[FILENAME_MAX], TempS[FILENAME_MAX];
304 if ((NULL == FStype) || (!strcmp(FStype,
"")) || (NULL == Source) || (!strcmp(Source,
"")) || (NULL == Destination) || (!strcmp(Destination,
"")))
307 if (!
Quiet &&
Verbose) fprintf(stderr,
"Extracting %s: %s\n",FStype,Source);
309 if (!strcmp(FStype,
"fat")) FatFlag=1;
314 if (
TaintString(TempSource,FILENAME_MAX,Source,1,NULL))
316 snprintf(Cmd,
sizeof(Cmd),
"fls -f '%s' -Dpr '%s' 2>&1",FStype,TempSource);
317 Fin = popen(Cmd,
"r");
320 fprintf(stderr,
"ERROR: Disk failed: %s\n",Cmd);
323 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
326 if (!memcmp(Line,
"fls: ",5))
328 fprintf(stderr,
"WARNING pfile %s Unable to extract\n",
Pfile);
329 fprintf(stderr,
"LOG pfile %s WARNING: fls extraction issue on '%s'. %s\n",
330 Pfile,TempSource,Line);
334 if (memcmp(Line,
"d/d",3) != 0)
continue;
335 if (strstr(Line,
" (deleted-realloc)") != NULL)
continue;
338 if (
s==NULL)
continue;
340 snprintf(Cmd,
sizeof(Cmd),
"%s/%s",Destination,
s);
343 printf(
"ERROR: Unable to mkdir(%s) in ExtractDisk\n",Cmd);
359 fprintf(stderr,
"WARNING pfile %s Unable to extract permission\n",
Pfile);
360 fprintf(stderr,
"LOG pfile %s WARNING: Unable to extract permission from %s\n",
Pfile,Source);
366 snprintf(Cmd,
sizeof(Cmd),
"fls -f '%s' -Fupr '%s' 2>/dev/null",FStype,TempSource);
367 Fin = popen(Cmd,
"r");
370 fprintf(stderr,
"ERROR: Disk failed: %s\n",Cmd);
374 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
379 if (memcmp(Line,
"r/r",3) != 0)
continue;
381 if (
s==NULL)
continue;
386 while(Inode[InodeLen] && (Inode[InodeLen] !=
':'))
393 Inode[InodeLen]=
'\0';
394 if (
TaintString(TempInode,FILENAME_MAX,Inode,1,NULL) ||
395 TaintString(TempDest,FILENAME_MAX,Destination,1,NULL) ||
403 if (
Verbose) printf(
"Extracting: icat '%s/%s'\n",TempDest,TempS);
404 snprintf(Cmd,
sizeof(Cmd),
"icat -f '%s' '%s' '%s' > '%s/%s' 2>/dev/null",
405 FStype,TempSource,TempInode,TempDest,TempS);
410 printf(
"ERROR: Process killed by signal (%d): %s\n",WTERMSIG(rc),Cmd);
413 rc = WEXITSTATUS(rc);
416 fprintf(stderr,
"WARNING pfile %s File extraction failed\n",
Pfile);
417 fprintf(stderr,
"LOG pfile %s WARNING: Extraction failed (rc=%d): %s\n",
Pfile,rc,Cmd);
427 snprintf(Cmd,
sizeof(Cmd),
"fls -f '%s' -Fdpr '%s' 2>/dev/null",FStype,TempSource);
428 Fin = popen(Cmd,
"r");
431 fprintf(stderr,
"ERROR: Disk failed: %s\n",Cmd);
435 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
440 if (memcmp(Line,
"r/r",3) != 0)
continue;
442 if (
s==NULL)
continue;
446 while(Inode[InodeLen] && !strchr(
":(",Inode[InodeLen]))
450 if (Inode[InodeLen] ==
'(')
continue;
456 Inode[InodeLen]=
'\0';
457 if (
TaintString(TempInode,FILENAME_MAX,Inode,1,NULL) ||
458 TaintString(TempDest,FILENAME_MAX,Destination,1,NULL) ||
466 snprintf(Cmd,
sizeof(Cmd),
"icat -f '%s' '%s' '%s' > '%s/%s.deleted.%s' 2>/dev/null",
467 FStype,TempSource,TempInode,TempDest,TempS,TempInode);
469 if (
Verbose) printf(
"Extracting: icat '%s/%s'\n",TempDest,TempS);
473 printf(
"ERROR: Process killed by signal (%d): %s\n",WTERMSIG(rc),Cmd);
476 rc = WEXITSTATUS(rc);
479 fprintf(stderr,
"WARNING pfile %s File extraction failed\n",
Pfile);
480 fprintf(stderr,
"LOG pfile %s WARNING: Extraction failed (rc=%d): %s\n",
Pfile,rc,Cmd);
489 snprintf(Cmd,
sizeof(Cmd),
"fls -f '%s' -Dpr '%s' 2>/dev/null",FStype,TempSource);
490 Fin = popen(Cmd,
"r");
493 fprintf(stderr,
"ERROR: Disk failed: %s\n",Cmd);
496 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
498 if (memcmp(Line,
"d/d",3) != 0)
continue;
502 if (
s==NULL)
continue;
int Verbose
Verbose level.
Stores all extern variables used by the agent.
char * Pfile
Pfile name (SHA1.MD5.Size)
int Quiet
Run in quiet mode?
int ForceContinue
Force continue when unpack tool fails?
char * TaintString(char *S)
Create a string with taint quoting.
int s
The socket that the CLI will use to communicate.
int ReadLine(FILE *Fin, char *Line, int MaxLine)
Structure to hold permission about an inode.
permlist * SetDiskPerm(char *inode, permlist *List, char *Destination, char *Target)
Find a disk permission by inode, set the permissions on the file, and free the memory.
permlist * ExtractDiskPerms(char *FStype, char *Source)
Given a disk, load in all of the file permissions. Assumes Source is already quote-tainted!
void FatDiskName(char *Name)
Special handling for FAT names.
int ExtractDisk(char *Source, char *FStype, char *Destination)
Given a disk image, type of system, and a directory, extract all files!
void FreeDiskPerms(permlist *List)
Deallocate perms.
int SameInode(char *Inode1, char *Inode2)
Determine if two inodes are the same.
int MkDir(char *Fname)
Smart mkdir.
void SafeExit(int rc)
Close scheduler and database connections, then exit.