52 for(i=0; Name[i] !=
'\0'; i++)
54 if (isupper(Name[i])) Name[i]=tolower(Name[i]);
59 if (Name[i] !=
')')
return;
61 while((i>1) && (Name[i] !=
'(')) i--;
65 if (Name[i]==
' ') Name[i]=
'\0';
79 if (List->inode) free(List->inode);
96 char Cmd[FILENAME_MAX*2];
97 char Line[FILENAME_MAX*2];
124 snprintf(Cmd,
sizeof(Cmd),
"fls -m / -f '%s' -lpr '%s' 2>/dev/null",
126 Fin = popen(Cmd,
"r");
129 fprintf(stderr,
"ERROR: Disk failed: %s\n",Cmd);
133 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
138 printf(
"FATAL: Unable to allocated %d bytes of memory\n",(
int)
sizeof(
permlist));
141 NewList->inode = NULL;
142 NewList->Next = NULL;
144 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
146 if (strstr(L,
"realloc)|")) {
FreeDiskPerms(NewList);
continue;}
147 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
148 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
150 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
151 NewList->perm = atoi(L);
154 NewList->inode = (
char *)calloc(L-inode,1);
157 printf(
"FATAL: Unable to allocate %d bytes.\n",(
int)(L-inode));
160 memcpy(NewList->inode,inode,L-inode-1);
162 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
163 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
164 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
165 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
166 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
167 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
168 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
169 NewList->Times.actime = atoi(L);
170 L=strchr(L,
'|');
if (!L) {
FreeDiskPerms(NewList);
continue;} L++;
171 NewList->Times.modtime = atoi(L);
174 NewList->Next = List;
193 for(i=0; Inode1[i] && Inode2[i]; i++)
195 if (isdigit(Inode1[i]) || (Inode1[i]==
'-'))
197 if (Inode1[i] != Inode2[i])
return(0);
202 v1 = (isdigit(Inode1[i]) || (Inode1[i]==
'-'));
203 v2 = (isdigit(Inode2[i]) || (Inode2[i]==
'-'));
217 char *Destination,
char *Target)
223 if (!List)
return(NULL);
226 while((inode[0] !=
'\0') && !isdigit(inode[0])) inode++;
229 if (
SameInode(List->inode,inode))
goto FoundPerm;
238 NewList = Parent->
Next;
240 NewList->
Next = List;
244 Parent = Parent->
Next;
246 if (
Verbose) fprintf(stderr,
"LOG pfile %s WARNING Could not find inode: %s\n",
Pfile,inode);
250 Cwd = getcwd(NULL,0);
253 printf(
"ERROR: Current directory no longer exists! Aborting!\n");
257 if(chdir(Destination) != 0)
259 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n",
260 __FILE__, __LINE__, Destination);
261 fprintf(stderr,
"ERROR: errno is: %s\n", strerror(errno));
264 if (
Verbose > 1) fprintf(stderr,
"DEBUG: setting inode %s, name %s to %07o\n",List->inode,Target,List->
perm);
265 chmod(Target,List->
perm);
266 utime(Target,&(List->
Times));
270 fprintf(stderr,
"ERROR %s.%d: Unable to change directory to %s\n",
271 __FILE__, __LINE__, Cwd);
272 fprintf(stderr,
"ERROR: errno is: %s\n", strerror(errno));
302 char Cmd[FILENAME_MAX*7];
303 char Line[FILENAME_MAX*2];
310 char TempSource[FILENAME_MAX];
311 char TempInode[FILENAME_MAX], TempDest[FILENAME_MAX], TempS[FILENAME_MAX];
315 if ((NULL == FStype) || (!strcmp(FStype,
"")) || (NULL == Source) || (!strcmp(Source,
"")) || (NULL == Destination) || (!strcmp(Destination,
"")))
318 if (!
Quiet &&
Verbose) fprintf(stderr,
"Extracting %s: %s\n",FStype,Source);
320 if (!strcmp(FStype,
"fat")) FatFlag=1;
325 if (
TaintString(TempSource,FILENAME_MAX,Source,1,NULL))
327 snprintf(Cmd,
sizeof(Cmd),
"fls -f '%s' -Dpr '%s' 2>&1",FStype,TempSource);
328 Fin = popen(Cmd,
"r");
331 fprintf(stderr,
"ERROR: Disk failed: %s\n",Cmd);
334 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
337 if (!memcmp(Line,
"fls: ",5))
339 fprintf(stderr,
"WARNING pfile %s Unable to extract\n",
Pfile);
340 fprintf(stderr,
"LOG pfile %s WARNING: fls extraction issue on '%s'. %s\n",
341 Pfile,TempSource,Line);
345 if (memcmp(Line,
"d/d",3) != 0)
continue;
346 if (strstr(Line,
" (deleted-realloc)") != NULL)
continue;
349 if (s==NULL)
continue;
351 snprintf(Cmd,
sizeof(Cmd),
"%s/%s",Destination,s);
354 printf(
"ERROR: Unable to mkdir(%s) in ExtractDisk\n",Cmd);
370 fprintf(stderr,
"WARNING pfile %s Unable to extract permission\n",
Pfile);
371 fprintf(stderr,
"LOG pfile %s WARNING: Unable to extract permission from %s\n",
Pfile,Source);
377 snprintf(Cmd,
sizeof(Cmd),
"fls -f '%s' -Fupr '%s' 2>/dev/null",FStype,TempSource);
378 Fin = popen(Cmd,
"r");
381 fprintf(stderr,
"ERROR: Disk failed: %s\n",Cmd);
385 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
390 if (memcmp(Line,
"r/r",3) != 0)
continue;
392 if (s==NULL)
continue;
397 while(Inode[InodeLen] && (Inode[InodeLen] !=
':'))
404 Inode[InodeLen]=
'\0';
405 if (
TaintString(TempInode,FILENAME_MAX,Inode,1,NULL) ||
406 TaintString(TempDest,FILENAME_MAX,Destination,1,NULL) ||
414 if (
Verbose) printf(
"Extracting: icat '%s/%s'\n",TempDest,TempS);
415 snprintf(Cmd,
sizeof(Cmd),
"icat -f '%s' '%s' '%s' > '%s/%s' 2>/dev/null",
416 FStype,TempSource,TempInode,TempDest,TempS);
421 printf(
"ERROR: Process killed by signal (%d): %s\n",WTERMSIG(rc),Cmd);
424 rc = WEXITSTATUS(rc);
427 fprintf(stderr,
"WARNING pfile %s File extraction failed\n",
Pfile);
428 fprintf(stderr,
"LOG pfile %s WARNING: Extraction failed (rc=%d): %s\n",
Pfile,rc,Cmd);
438 snprintf(Cmd,
sizeof(Cmd),
"fls -f '%s' -Fdpr '%s' 2>/dev/null",FStype,TempSource);
439 Fin = popen(Cmd,
"r");
442 fprintf(stderr,
"ERROR: Disk failed: %s\n",Cmd);
446 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
451 if (memcmp(Line,
"r/r",3) != 0)
continue;
453 if (s==NULL)
continue;
457 while(Inode[InodeLen] && !strchr(
":(",Inode[InodeLen]))
461 if (Inode[InodeLen] ==
'(')
continue;
467 Inode[InodeLen]=
'\0';
468 if (
TaintString(TempInode,FILENAME_MAX,Inode,1,NULL) ||
469 TaintString(TempDest,FILENAME_MAX,Destination,1,NULL) ||
477 snprintf(Cmd,
sizeof(Cmd),
"icat -f '%s' '%s' '%s' > '%s/%s.deleted.%s' 2>/dev/null",
478 FStype,TempSource,TempInode,TempDest,TempS,TempInode);
480 if (
Verbose) printf(
"Extracting: icat '%s/%s'\n",TempDest,TempS);
484 printf(
"ERROR: Process killed by signal (%d): %s\n",WTERMSIG(rc),Cmd);
487 rc = WEXITSTATUS(rc);
490 fprintf(stderr,
"WARNING pfile %s File extraction failed\n",
Pfile);
491 fprintf(stderr,
"LOG pfile %s WARNING: Extraction failed (rc=%d): %s\n",
Pfile,rc,Cmd);
500 snprintf(Cmd,
sizeof(Cmd),
"fls -f '%s' -Dpr '%s' 2>/dev/null",FStype,TempSource);
501 Fin = popen(Cmd,
"r");
504 fprintf(stderr,
"ERROR: Disk failed: %s\n",Cmd);
507 while(
ReadLine(Fin,Line,
sizeof(Line)-1) >= 0)
509 if (memcmp(Line,
"d/d",3) != 0)
continue;
513 if (s==NULL)
continue;
int Quiet
Run in quiet mode?
void FreeDiskPerms(permlist *List)
Deallocate perms.
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!
int Verbose
Verbose level.
char * Pfile
Pfile name (SHA1.MD5.Size)
int s
The socket that the CLI will use to communicate.
int SameInode(char *Inode1, char *Inode2)
Determine if two inodes are the same.
int MkDir(char *Fname)
Smart mkdir.
Structure to hold permission about an inode.
permlist * ExtractDiskPerms(char *FStype, char *Source)
Given a disk, load in all of the file permissions. Assumes Source is already quote-tainted! ...
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.
Stores all extern variables used by the agent.
char * TaintString(char *S)
Create a string with taint quoting.
int ReadLine(FILE *Fin, char *Line, int MaxLine)
void SafeExit(int rc)
Close scheduler and database connections, then exit.
int ForceContinue
Force continue when unpack tool fails?