DABC (Data Acquisition Backbone Core)  2.9.9
rawProcUn.c
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright:
3  * GSI, Gesellschaft fuer Schwerionenforschung mbH
4  * Planckstr. 1
5  * D-64291 Darmstadt
6  * Germany
7  * created 16. 5.1997 by Horst Goeringer
8  *********************************************************************
9  * rawProcUn.c
10  * Unix specific utility programs for gStore package: client and server
11  *********************************************************************
12  * rawGetDirEntries: get number of entries in FS (via opendir/readdir)
13  * rawGetDirEntryList: get/enhance list of matching FS entries
14  * rawGetRecEntryList: get/enhance recursive list of matching entries
15  * rawGetFSEntries: get number of entries in FS (via scandir)
16  * rawGetFSfree: get free space in specified filesystem (via ls)
17  * rawGetFSSpace: get space statistics of file system (via statfs)
18  * rawGetFileAttr: get file attributes
19  * rawGetFileList: get/enhance file list from generic input
20  * rawGetHostConn: get network connection type of client host
21  * rawGetBaseDir: get fixed dir name part above wildcarded subdirs
22  * rawGetUserid: get user identification
23  *********************************************************************
24  * 4. 2.1998, H.G.: new entry rawGetFSfree
25  * 6. 2.1998, H.G.: rawGetFSfree: ex shell-cmd via system()
26  * 13. 4.1999, H.G.: mod. declaration of rawGetFileAttr
27  * 22. 2.2000, H.G.: rawGetFileAttr: fix occurence of pipe message:
28  * '\nYour .kshrc is not executable!'
29  * 28. 7.2000, H.G.: rawGetFileList: ls -pdL -> ls
30  * 18. 6.2001, H.G.: rawGetFileList: check upper case in names
31  * 21. 6.2001, H.G.: rawGetFileList: control acceptance of upper case
32  * 31.10.2001, H.G.: rawGetFSfree added
33  * 26. 2.2002, H.G.: rawGetFSSpace added
34  * 6. 6.2002, H.G.: rawGetDirEntries, rawGetFSEntries added
35  * 29.10.2002, H.G.: rawGetFileList: MAX_FILE_NO -> MAX_STAGE_FILE_NO
36  * 31. 1.2003, H.G.: use rawdefn.h
37  * 25. 6.2003, H.G.: handle offset of old files in filelist
38  * rename rawGetFilelist -> rawGetFileList
39  * 9. 7.2003, H.G.: rawGetFileList: ignore directories
40  * 16. 7.2003, H.G.: rawGetFileList: avoid duplicate file names
41  * 6. 8.2004, H.G.: ported to Lynx
42  * 1. 2.2005, H.G.: ported to Linux and gcc322
43  * 2. 2.2007, H.G.: two steps for char ptr increments (gcc 3.3.5)
44  * 9. 5.2008, H.G.: remove (client header) file rawclin.h
45  * 22. 9.2008, H.G.: rawGetFileList: suppress subdir contents
46  * 12.11.2008, H.G.: add suggestions of Hakan
47  * 10. 2.2009, H.G.: rawGetFileList: don't stop scan if ls output
48  * buffer starts with '\n'
49  * 11. 2.2009, H.G.: rawGetFileList: stop scanning subdirs
50  * DDD for recursive filelist: remove stop + ident files
51  * 22. 6.2008, H.G.: replace long->int if 64bit client (ifdef SYSTEM64)
52  * 3. 9.2009, H.G.: rawGetFileList: MAX_STAGE_FILE_NO -> MAX_FILE_NO
53  * 29. 1.2010, H.G.: rawGetFileList, cBuf: MAX_FILE -> MAX_FULL_FILE
54  * rawGetFSfree, cTempFile: 128 -> MAX_FULL_FILE
55  * 24. 6.2010, H.G.: new entry rawGetDirEntryList
56  * 12. 8.2010, H.G.: rawGetDirEntryList: increase filelist, if too small
57  * 16. 8.2010, H.G.: rawGetDirEntryList: handle (xfs) filesystems
58  * providing entry type "DT_UNKNOWN"
59  * 23. 8.2010, H.G.: rawGetFileAttr, rawGetFileList:
60  * remove SYSTEM64 (allow "long")
61  * rawGetUserid: lr: long -> int
62  * 5.11.2010, H.G.: replace perror by strerror(errno),
63  * reset errno after error
64  * 26.11.2010, H.G.: rawGetFileAttr, rawGetFileList:
65  * reset errno after successful!! pclose
66  * 7.12.2010, H.G.: remove fnmatch.h (Linux: not needed, Lynx: unavail)
67  * 25. 7.2011, H.G.: new function rawGetRecEntryList
68  * 12. 9.2011, H.G.: rawGetRecEntryList: new entry type 20: recursive
69  * scan with fully qualified match string
70  * 13. 9.2011, H.G.: rawGetRecEntryList, fully qualified match string:
71  * allow wildcard chars in file and dir name
72  * 21. 9.2011, H.G.: rawGetRecEntryList, new entry type 30:
73  * not recursive, wildcards in file/dir name allowed
74  * 4.11.2011, H.G.: new function rawGetTopDir
75  * 6.12.2011, H.G.: rawGetRecEntryList: separate args for no.s of
76  * files/subdirs
77  * 27.12.2012, H.G.: rename rawGetTopDir -> rawGetBaseDir
78  * 5.12.2012, H.G.: include fnmatch.h only in case of Linux (not Lynx)
79  *********************************************************************
80  */
81 
82 #include <stdio.h>
83 #include <string.h>
84 #include <unistd.h>
85 #include <ctype.h>
86 #include <stdlib.h>
87 #include <time.h>
88 #include <errno.h>
89 
90 #ifndef Lynx
91 #include <fnmatch.h>
92 #include <sys/types.h>
93 #include <sys/stat.h>
94 #include <sys/dir.h>
95 #ifdef __MACH__
96 #include <sys/param.h>
97 #include <sys/mount.h>
98 #else
99 #include <sys/statfs.h>
100 #endif
101 #endif
102 
103 #include "rawcommn.h"
104 #include "rawdefn.h"
105 #include "rawentn.h"
106 
107 extern FILE *fLogFile;
108 
109 static int iFileList = sizeof(srawFileList);
110 
111 #define BUFSIZE_SMALL 80
112 
113 #ifndef Lynx
114 /********************************************************************
115  * rawGetDirEntries:
116  * get number of entries in file system (via opendir/readdir)
117  *
118  * created 6. 6.2002, Horst Goeringer
119  ********************************************************************/
120 
121 int rawGetDirEntries(char *pcStageFS)
122 {
123  char cModule[32]="rawGetDirEntries";
124  int iDebug = 0;
125 
126  int iRC;
127  int iEntries = 0;
128 
129  DIR *pDir;
130  struct dirent *pEntry;
131 
132  if (iDebug) fprintf(fLogFile,
133  "\n-D- begin %s: FS %s\n", cModule, pcStageFS);
134 
135  pDir = opendir(pcStageFS);
136  if (pDir == NULL)
137  {
138  fprintf(fLogFile,
139  "-E- %s: cannot open directory %s\n", cModule, pcStageFS);
140  if (errno)
141  {
142  fprintf(fLogFile, " %s\n", strerror(errno));
143  errno = 0;
144  }
145 
146  return -1;
147  }
148 
149  while ( (pEntry = readdir(pDir)) != NULL)
150  {
151  if ( (strcmp(pEntry->d_name, ".") == 0) ||
152  (strcmp(pEntry->d_name, "..") == 0) )
153  continue;
154 
155  iEntries++;
156 
157  if (iDebug)
158  fprintf(fLogFile, " %d: %s\n", iEntries, pEntry->d_name);
159  }
160 
161  iRC = closedir(pDir);
162 
163  if (iDebug)
164  fprintf(fLogFile, " rc(closedir) = %d\n-D- end %s\n\n", iRC, cModule);
165 
166  return(iEntries);
167 
168 } /* rawGetDirEntries */
169 #endif
170 
171 #ifndef Lynx
172 /*********************************************************************
173  * rawGetDirEntryList:
174  * get/enhance list of matching entries in file system
175  * created 23.6.2010, Horst Goeringer
176  *********************************************************************
177  */
178 
180  char *pcDirName,
181  char *pcEntryMask, /* entry name mask */
182  int iEntryType,
183  /* = 0: all entries (in FileList)
184  = 1: all files (in FileList)
185  = 2: all subdirectories (in DirList)
186  =10: all entries, but files only if matching with mask
187  =11: all files, but only if matching with mask
188  =12: all subdirs, but only if matching with mask */
189  int iEntryLoop, /* = 1: in loop, append new entries */
190  int iPrefixDir, /* = 1: prefix files in list with cur path */
191  char **ppFileList, /* ptr to entry list ptr */
192  char **ppDirList) /* ptr to dir list ptr */
193 {
194  char cModule[32] = "rawGetDirEntryList";
195  int iDebug = 0; /* =1: verbose, =2: entry details */
196  int iRC = 0;
197  int iRCE = 0;
198  int ilen, iloc, ii, jj;
199  char cTemp[MAX_FULL_FILE] = "";
200 
201  int iTypeFound = 0;
202  /* keep entry type, if DT_UNKNOWN (xfs): =1: reg file, =2: dir */
203  char cEntryType[32] = "";
204  int iEntries = 0; /* no. of entries in specified file system */
205  int iEntriesMatch = 0; /* no. of matching entries in specified FS */
206 
207  int iFileEntryMax = 0; /* max. no. of file names in buffer */
208  int iFileEntryRem = 0; /* remaining no. of file names in buffer */
209  int iFileEntries = 0;
210  int iFileEntriesOld = 0;
211  int iFileEntriesNew = 0;
212  int *piFileNo; /* points to no. of entries in file list */
213  int *piFileList; /* points to first file name */
214  srawFileList *psFileList; /* points to current file name */
215  srawFileList *psFileList0; /* points to first file name */
216 
217  char *pcFileList2;
218  int *piFileList2; /* points to first file in reallocated filelist */
219 
220  int iDirEntryMax = 0; /* max. no. of subdir names in buffer */
221  int iDirEntryRem = 0; /* remaining no. of subdir names in buffer */
222  int iDirEntries = 0;
223  int iDirEntriesOld = 0;
224  int iDirEntriesNew = 0;
225  int *piDirNo; /* points to no. of subdirs in entrylist */
226  int *piDirList; /* points to first subdir name */
227  srawFileList *psDirList; /* points to current subdir name */
228  srawFileList *psDirList0; /* points to first subdir name */
229 
230  int iMatch = 0; /* = 1: handle only entries matching with mask */
231  int iStore = 0; /* =1: cur entry will be stored in list */
232  int iCheck = 0; /* =1: cur entry must be compared with mask */
233 
234  DIR *pDir;
235  struct dirent *pEntry;
236 
237  struct stat sEntryStatus, *pEntryStatus;
238 
239  if (iDebug)
240  fprintf(fLogFile, "\n-D- begin %s\n", cModule);
241 
242  pEntryStatus = &sEntryStatus;
243 
244  if (strlen(pcDirName) <= 0)
245  {
246  fprintf(fLogFile, "-E- %s: empty directory name\n", cModule);
247 
248  iRCE = -1;
249  goto gEndDirEntryList;
250  }
251 
252  if (iEntryType >= 10)
253  {
254  if (strlen(pcEntryMask) <= 0)
255  {
256  fprintf(fLogFile,
257  "-E- %s: empty mask for entry name\n", cModule);
258 
259  iRCE = -1;
260  goto gEndDirEntryList;
261  }
262 
263  iEntryType -= 10;
264 
265  if (strcmp(pcEntryMask, "*") != 0)
266  iMatch = 1;
267  }
268 
269  if (iEntryType == 0)
270  strcpy(cEntryType, "entries");
271  else if (iEntryType == 1)
272  strcpy(cEntryType, "files");
273  else if (iEntryType == 2)
274  strcpy(cEntryType, "subdirs");
275  else
276  {
277  fprintf(fLogFile,
278  "-E- %s: invalid EntryType %d (allowed 0-2, 10-12)\n",
279  cModule, iEntryType);
280 
281  iRCE = -1;
282  goto gEndDirEntryList;
283  }
284 
285  /* handle files */
286  if ( (iEntryType == 0) || (iEntryType == 1) )
287  {
288  if (ppFileList == NULL)
289  {
290  fprintf(fLogFile,
291  "-E- %s: invalid pointer for entry list\n", cModule);
292 
293  iRCE = -1;
294  goto gEndDirEntryList;
295  }
296 
297  piFileNo = (int *) *ppFileList;
298  piFileList = piFileNo;
299  iFileEntriesOld = *piFileNo;
300 
301  if (iEntryLoop)
302  {
303  if (iDebug)
304  {
305  if (iFileEntriesOld) fprintf(fLogFile,
306  " %d files already available in list:\n",
307  iFileEntriesOld);
308  else fprintf(fLogFile,
309  " still no files in list\n");
310  }
311  }
312  else
313  {
314  if (iFileEntriesOld) fprintf(fLogFile,
315  "-W- %s: no entry loop, but %d files already available in list\n",
316  cModule, iFileEntriesOld);
317  }
318 
319  piFileList++;
320  psFileList = (srawFileList *) piFileList;
321  psFileList0 = psFileList;
322 
323  if (iDebug)
324  {
325  if (iFileEntriesOld)
326  {
327  fprintf(fLogFile, "old files:\n");
328  for (ii=1; ii<=iFileEntriesOld; ii++)
329  {
330  fprintf(fLogFile, " %d: %s\n", ii, psFileList->cFile);
331  psFileList++;
332  }
333  }
334  }
335  else
336  psFileList += iFileEntriesOld;
337 
338  iFileEntries = iFileEntriesOld;
339  iFileEntryMax = MAX_FILE_NO;
340  /* iFileEntryMax = 2; DDDMax */
341 
342  /* already add. space allocated */
343  if (iFileEntriesOld > iFileEntryMax)
344  {
345  ii = iFileEntriesOld / iFileEntryMax;
346  ii++;
347  iFileEntryMax *= ii;
348  }
349  iFileEntryRem = iFileEntryMax - iFileEntriesOld;
350 
351  if (iDebug) fprintf(fLogFile,
352  " space available for %d file entries (max %d)\n",
353  iFileEntryRem, iFileEntryMax);
354 
355  } /* (iEntryType == 0 || 1) */
356 
357  /* handle subdirectories */
358  if ( (iEntryType == 0) || (iEntryType == 2) )
359  {
360  if (ppDirList == NULL)
361  {
362  fprintf(fLogFile,
363  "-E- %s: invalid pointer for subdir list\n", cModule);
364 
365  iRCE = -1;
366  goto gEndDirEntryList;
367  }
368 
369  piDirNo = (int *) *ppDirList;
370  piDirList = piDirNo;
371  iDirEntriesOld = *piDirNo;
372 
373  if (iEntryLoop)
374  {
375  if (iDebug)
376  {
377  if (iDirEntriesOld) fprintf(fLogFile,
378  " %d subdirectories already available in list:\n",
379  iDirEntriesOld);
380  else fprintf(fLogFile,
381  " still no subdirectories in list\n");
382  }
383  }
384  else if (iDirEntriesOld) fprintf(fLogFile,
385  "-W- %s: no entry loop, but %d subdirectories available in list\n",
386  cModule, iDirEntriesOld);
387 
388  piDirList++;
389  psDirList = (srawFileList *) piDirList;
390  psDirList0 = psDirList;
391 
392  for (ii=1; ii<=iDirEntriesOld; ii++)
393  {
394  if (iDebug == 2)
395  {
396  if (ii == 1)
397  fprintf(fLogFile, "previous subdirs:\n");
398  fprintf(fLogFile, " %d: %s\n", ii, psDirList->cFile);
399  }
400 
401  psDirList++;
402  }
403  /* psDirList now located for new entry */
404 
405  iDirEntries = iDirEntriesOld;
406  iDirEntryMax = MAX_FILE_NO;
407 
408  /* already add. space allocated */
409  if (iDirEntriesOld > iDirEntryMax)
410  {
411  ii = iDirEntriesOld / iDirEntryMax;
412  ii++;
413  iDirEntryMax *= ii;
414  }
415  iDirEntryRem = iDirEntryMax - iDirEntriesOld;
416 
417  if (iDebug) fprintf(fLogFile,
418  " space available for %d subdir entries (max %d)\n",
419  iDirEntryRem, iDirEntryMax);
420 
421  } /* (iEntryType == 0 || 2) */
422 
423  if (iDebug)
424  {
425  if ( (iEntryType == 0) && (iMatch) )
426  {
427  fprintf(fLogFile,
428  " provide all files matching with %s and all subdirs in directory %s\n",
429  pcEntryMask, pcDirName);
430  }
431  else
432  {
433  fprintf(fLogFile, " provide all %s", cEntryType);
434  if (iMatch) fprintf(fLogFile,
435  " matching with %s", pcEntryMask);
436  fprintf(fLogFile, " in directory %s\n", pcDirName);
437  }
438  }
439 
440  pDir = opendir(pcDirName);
441  if (pDir == NULL)
442  {
443  fprintf(fLogFile,
444  "-E- %s: cannot open directory %s\n", cModule, pcDirName);
445  if (errno)
446  {
447  fprintf(fLogFile, "%s\n", strerror(errno));
448  errno = 0;
449  }
450 
451  iRCE = -1;
452  goto gEndDirEntryList;
453  }
454 
455  while ( (pEntry = readdir(pDir)) != NULL)
456  {
457  if ( (strcmp(pEntry->d_name, ".") == 0) ||
458  (strcmp(pEntry->d_name, "..") == 0) )
459  continue;
460 
461  iEntries++;
462  iCheck = 0;
463  iStore = 0;
464 
465  /* for xfs */
466  if (pEntry->d_type == DT_UNKNOWN)
467  {
468  if ( (iEntries == 1) && (iDebug) ) fprintf(fLogFile,
469  " %s: of type DT_UNKNOWN (1st entry)\n",
470  pEntry->d_name);
471 
472  strcpy(cTemp, pcDirName);
473  strcat(cTemp, "/");
474  strcat(cTemp, pEntry->d_name);
475 
476  iRC = stat(cTemp, pEntryStatus);
477  if (iRC)
478  {
479  if (errno)
480  {
481  fprintf(fLogFile, "-E- stat %s: %s\n",
482  cTemp, strerror(errno));
483 
484  /* only valid for 32 bit OS */
485  if (strcmp(strerror(errno),
486  "Value too large for defined data type") == 0)
487  {
488  fprintf(fLogFile,
489  "-E- %s: filesize of %s > 2 GByte: use 64 bit gStore client\n",
490  cModule, cTemp);
491 
492  errno = 0;
493  return -99;
494  }
495  errno = 0;
496  }
497  else fprintf(fLogFile,
498  "-W- %s: entry %s unavailable\n", cModule, pEntry->d_name);
499 
500  continue;
501  }
502 
503  if (S_ISREG(pEntryStatus->st_mode))
504  iTypeFound = 1;
505  else if (S_ISDIR(pEntryStatus->st_mode))
506  iTypeFound = 2;
507  else
508  {
509  fprintf(fLogFile,
510  "-W- %s: entry %s neither file nor directory, ignored\n",
511  cModule, pEntry->d_name);
512 
513  continue;
514  }
515  } /* (pEntry->d_type == DT_UNKNOWN) */
516  else
517  iTypeFound = 0;
518 
519  /* check in which cases entry could be stored */
520  if ( (pEntry->d_type == DT_REG) || (iTypeFound == 1) )
521  {
522  if ( (iEntryType == 0) || (iEntryType == 1) )
523  {
524  if (iMatch)
525  iCheck = 1;
526  else
527  iStore = 1;
528  }
529  }
530  else if ( (pEntry->d_type == DT_DIR) || (iTypeFound == 2) )
531  {
532  if ( (iEntryType == 0) || (iEntryType == 2) )
533  {
534  if ( (iMatch) && (iEntryType == 2) )
535  iCheck = 1;
536  else
537  iStore = 1;
538  }
539  }
540 
541  if (iDebug == 2) fprintf(fLogFile,
542  " %d: entry %s (check %d, store %d, type %d) \n",
543  iEntries, pEntry->d_name, iCheck, iStore, pEntry->d_type);
544 
545  /* check if matching with input mask */
546  if (iCheck)
547  {
548  /* wildcards do not match '/' */
549  if (fnmatch(pcEntryMask, pEntry->d_name, FNM_PATHNAME) == 0)
550  {
551  iStore = 1; /* match, store this entry */
552  iEntriesMatch++;
553  }
554  else
555  iStore = 0;
556  }
557 
558  if (iStore)
559  {
560  /* store new file names */
561  if ( (pEntry->d_type == DT_REG) ||
562  (pEntry->d_type == DT_UNKNOWN) )
563  {
564  if (iPrefixDir)
565  {
566  strcpy(psFileList->cFile, pcDirName);
567  strcat(psFileList->cFile, "/");
568  strcat(psFileList->cFile, pEntry->d_name);
569  }
570  else
571  strcpy(psFileList->cFile, pEntry->d_name);
572 
573  iFileEntries++;
574  iFileEntriesNew++;
575 
576  if (iDebug)
577  {
578  if (iFileEntriesNew == 1)
579  fprintf(fLogFile, "new files:\n");
580  fprintf(fLogFile, " %d(%d): %s\n",
581  iFileEntriesNew, iFileEntries, psFileList->cFile);
582  }
583 
584  if (iFileEntryRem <= 0)
585  {
586  iFileEntryMax += MAX_FILE_NO;
587  /* iFileEntryMax += 2; DDDMax */
588 
589  ii = sizeof(int) + iFileEntryMax*iFileList;
590  if ((pcFileList2 = (char *) calloc((unsigned) ii, 1)) == NULL)
591  {
592  fprintf(fLogFile,
593  "-E- %s: allocating new filelist buffer (%d byte, %d entries)\n",
594  cModule, ii, iFileEntryMax);
595  if (errno)
596  {
597  fprintf(fLogFile, " %s\n", strerror(errno));
598  errno = 0;
599  }
600 
601  iRCE = -1;
602  goto gEndDirEntryList;
603  }
604 
605  if (iDebug) fprintf(fLogFile,
606  " new filelist buffer allocated (%d byte, %d entries)\n",
607  ii, iFileEntryMax);
608 
609  iFileEntryRem = iFileEntryMax - iFileEntries;
610  piFileList2 = (int *) pcFileList2;
611  *piFileList2 = iFileEntries;
612  *ppFileList = (char *) piFileList2;
613  piFileList2++;
614 
615  ii = iFileEntries*iFileList;
616  memcpy(piFileList2, piFileList, ii);
617 
618  psFileList = (srawFileList *) piFileList2;
619  psFileList0 = psFileList;
620 
621  if (iDebug) fprintf(fLogFile,
622  " %d filelist entries copied, first %s\n",
623  iFileEntries, psFileList->cFile);
624  fflush(fLogFile);
625 
626  psFileList += iFileEntries;
627  piFileList = piFileList2;
628  piFileList2--;
629  piFileNo = piFileList2;
630 
631  } /* (iFileEntryRem <= 0) */
632  else
633  psFileList++;
634 
635  iFileEntryRem--;
636 
637  } /* files */
638 
639  /* store new subdirectory names */
640  if (pEntry->d_type == DT_DIR)
641  {
642  strcpy(psDirList->cFile, pEntry->d_name);
643  iDirEntries++;
644  iDirEntriesNew++;
645  iDirEntryRem--;
646 
647  if (iDebug)
648  {
649  if (iDirEntriesNew == 1)
650  fprintf(fLogFile, "new subdirs:\n");
651  fprintf(fLogFile, " %d(%d): %s\n",
652  iDirEntriesNew, iDirEntries, psDirList->cFile);
653  }
654 
655  if (iDirEntryRem <= 0)
656  {
657  fprintf(fLogFile, "DDD2 new space must be allocated\n");
658  }
659 
660  psDirList++;
661 
662  } /* subdirs */
663  } /* current entry matches and is of requested type */
664  }
665 
666 gEndDirEntryClose:
667  iRC = closedir(pDir);
668 
669  if (iDebug)
670  fprintf(fLogFile, " rc(closedir) = %d\n", iRC);
671 
672  if (iDebug)
673  {
674  fprintf(fLogFile,
675  " %d entries in directory %s found\n",
676  iEntries, pcDirName);
677  if (iMatch) fprintf(fLogFile,
678  " %d entries matching with %s\n", iEntriesMatch, pcEntryMask);
679  }
680 
681  if (iDebug)
682  {
683  if (iFileEntries) fprintf(fLogFile,
684  " thereof %d files (%d new)\n",
685  iFileEntries, iFileEntriesNew);
686  if (iDirEntries) fprintf(fLogFile,
687  " thereof %d subdirectories (%d new)\n",
688  iDirEntries, iDirEntriesNew);
689  }
690 
691  if ( (iEntryType == 0) || (iEntryType == 1) )
692  *piFileNo = iFileEntries;
693  if ( (iEntryType == 0) || (iEntryType == 2) )
694  *piDirNo = iDirEntries;
695 
696  if (iDebug)
697  {
698  if (iFileEntries) fprintf(fLogFile,
699  " %d files provided in list, first %s\n",
700  iFileEntries, psFileList0->cFile);
701  else if ( (iEntryType == 0) || (iEntryType == 1) )
702  {
703  fprintf(fLogFile, " no files in %s found",
704  pcDirName);
705  if (iMatch) fprintf(fLogFile,
706  " matching with %s\n", pcEntryMask);
707  else
708  fprintf(fLogFile, "\n");
709  }
710 
711  if (iDirEntries) fprintf(fLogFile,
712  " %d subdirs provided in list, first %s\n",
713  iDirEntries, psDirList0->cFile);
714  else if ( (iEntryType == 0) || (iEntryType == 2) )
715  {
716  fprintf(fLogFile, " no subdirs in %s found",
717  pcDirName);
718  if ( (iMatch) && (iEntryType == 2) ) fprintf(fLogFile,
719  " matching with %s\n", pcEntryMask);
720  else
721  fprintf(fLogFile, "\n");
722  }
723  }
724 
725 gEndDirEntryList:
726 
727  if (iDebug)
728  fprintf(fLogFile, "\n-D- end %s\n\n", cModule);
729 
730  if (iRCE)
731  return iRCE;
732 
733  if (iMatch)
734  return iEntriesMatch;
735  return iEntries;
736 
737 } /* rawGetDirEntryList */
738 #endif
739 
740 #ifndef Lynx
741 /*********************************************************************
742  * rawGetRecEntryList:
743  * get/enhance recursive list of matching entries in file system
744  * created 25. 7.2011 Horst Goeringer
745  *********************************************************************
746  */
747 
749  char *pcDirName, /* cur directory, no wildcards */
750  char *pcEntryMask, /* mask for entry names */
751  int iEntryType,
752  /* < 20: mask for relative file names (may be wildcarded)
753  = 0: all entries (recursive)
754  = 1: all files (in FileList) => in spec. dir only
755  = 2: all subdirs (in DirList) => in spec. dir only
756  =10: all matching entries (recursive),
757  =11: all files matching => in spec. dir only
758  =12: all subdirs matching => in spec. dir only
759 
760  >= 20: mask for fully qual file names (may be wildcarded)
761  =20: all matching entries (recursive),
762  =30: all matching entries
763  (NOT recursive, wildcarded dir in match string)
764  */
765  int iMaxFiles, /* max no. of files in file list */
766  char **ppFileList, /* ptr to entry list ptr */
767  int iMaxDirs, /* max no. of (sub)dirs in dir list */
768  char **ppDirList) /* ptr to dir list ptr */
769 {
770  char cModule[32] = "rawGetRecEntryList";
771  int iDebug = 0; /* =1: verbose, =2: entry details */
772  int iRC = 0;
773  int iRCE = 0;
774  int ilen, iloc, ii, jj;
775  char *pcc, *pcc1, *pcc2, *pcc3;
776  char cTemp[MAX_FULL_FILE] = "";
777 
778  int iDirNameLen = 0;
779  char cDirName[MAX_FULL_FILE] = ""; /* current directory */
780  char cDirNameOrig[MAX_FULL_FILE] = "";/* orig. provided directory */
781  char cFileMask[MAX_FULL_FILE] = ""; /* mask for rel file names */
782  char cDirMask[MAX_FULL_FILE] = "";/* mask for full directory names*/
783  char cEntryMask[MAX_FULL_FILE] = ""; /* mask for full file names */
784  char cEntryType[32] = "";
785  int iEntries = 0;
786  int iLastDir = 0;
787  int iDirMaskVar = 1; /* dirname in file mask: with wildcard chars */
788  int iMaskDirLevel = 0; /* no. of '/' in dir mask */
789  int icurDirLevel = 0; /* no. of '/' in cur dir */
790  int iaMaskSubdirLen[100]; /* length of all subdirs in mask */
791  int iacurSubdirLen[100]; /* length of all subdirs in cur dir */
792  int iRecursive = 1;
793 
794  int iFileEntryMax = 0; /* max. no. of file names in buffer */
795  int iFileEntryRem = 0; /* remaining no. of file names in buffer */
796  int iFileEntries = 0;
797  int iFileEntriesOld = 0;
798  int iFileEntriesNew = 0;
799  int *piFileNo; /* points to no. of entries in file list */
800  int *piFileList; /* points to first file name */
801  srawFileList *psFileList; /* points to current file name */
802  srawFileList *psFileList0; /* points to first file name */
803 
804  int iDirLoop = 0;
805  int iDirEntryMax = 0; /* max. no. of subdir names in buffer */
806  int iDirEntryRem = 0; /* remaining no. of subdir names in buffer */
807  int iDirEntries = 0;
808  int iDirEntriesOld = 0;
809  int iDirEntriesNew = 0;
810  int *piDirNo; /* points to no. of subdirs in entrylist */
811  int *piDirList; /* points to first subdir name */
812  srawFileList *psDirList; /* points to current subdir name */
813  srawFileList *psDirList0; /* points to first subdir name */
814  srawFileList *psDirListNew = NULL;/* 1st new entry in subdir list */
815 
816  int iMatch = 0; /* = 1: handle only entries matching with mask */
817  int iFullMatch = 0;
818  /* = 1: mask is for for fully qualified file names */
819  int iStore = 0; /* =1: cur entry will be stored in list */
820  int iCheck = 0; /* =1: cur entry must be compared with mask */
821  char cFullEntryCheck[MAX_FULL_FILE] = "";
822  /* current entry, fully qualified */
823  char cFullDirCheck[MAX_FULL_FILE] = "";
824  /* current subdir, fully qualified */
825 
826  DIR *pDir;
827  struct dirent *pEntry;
828 
829  FILE *fLogFile = stdout;
830 
831  if (strlen(pcDirName) <= 0)
832  {
833  fprintf(fLogFile, "-E- %s: empty directory name\n", cModule);
834 
835  iRCE = -1;
836  goto gEndRecEntryList;
837  }
838  strcpy(cDirName, pcDirName);
839  strcpy(cDirNameOrig, cDirName);
840  strncat(cDirNameOrig, "/", 1);
841 
842  if (iDebug) fprintf(fLogFile,
843  "\n-D- begin %s:\n top dir %s, entry type %d, max %d files, max %d dirs\n",
844  cModule, cDirName, iEntryType, iMaxFiles, iMaxDirs);
845 
846  /* only matching entries */
847  if (iEntryType >= 10)
848  {
849  ii = strlen(pcEntryMask);
850  if (ii <= 0)
851  {
852  fprintf(fLogFile,
853  "-E- %s: empty mask for entry name\n", cModule);
854 
855  iRCE = -1;
856  goto gEndRecEntryList;
857  }
858 
859  iMatch = 1;
860  pcc = pcEntryMask;
861  pcc += ii - 1; /* last char */
862  if (strncmp(pcc, "/", 1) == 0)
863  {
864  strncpy(pcc, "\0", 1);
865 
866  if (iDebug) fprintf(fLogFile,
867  " trailing '/' in file mask removed: %s\n", pcEntryMask);
868  }
869 
870  strcpy(cEntryMask, pcEntryMask);
871 
872  if (iEntryType >= 20)
873  {
874  iFullMatch = 1;
875 
876  pcc = strrchr(cEntryMask, '/');
877  if (pcc == NULL)
878  {
879  fprintf(fLogFile,
880  "-E- %s: invalid file mask %s: must be fully qualified for type %d\n",
881  cModule, cEntryMask, iEntryType);
882 
883  iRCE = -1;
884  goto gEndRecEntryList;
885  }
886 
887  /* get dir in mask */
888  strcpy(cDirMask, cEntryMask);
889  pcc1 = strrchr(cDirMask, '/');
890  strncpy(pcc1, "\0", 1);
891  pcc1++;
892  strcpy(cFileMask, pcc1); /* contains no '/' */
893 
894  pcc1 = strrchr(cDirMask, '/');
895  if (pcc1 == NULL)
896  {
897  fprintf(fLogFile,
898  "-E- %s: invalid file mask: must be fully qualified for type %d\n",
899  cModule, iEntryType);
900 
901  iRCE = -1;
902  goto gEndRecEntryList;
903  }
904 
905  if (iDebug) fprintf(fLogFile,
906  " dir mask %s, file mask %s\n", cDirMask, cFileMask);
907 
908  if ( (strchr(cDirMask, *pcStar) == NULL) &&
909  (strchr(cDirMask, *pcQM) == NULL) &&
910  (strchr(cDirMask, *pcPerc) == NULL) )
911  {
912  iDirMaskVar = 0;
913  if (strcmp(cDirMask, cDirName) == 0)
914  {
915  iLastDir = 1;
916  if (iDebug) fprintf(fLogFile,
917  " last dir %s\n", cDirName);
918  }
919  }
920 
921  iMaskDirLevel = 0;
922  pcc2 = cDirMask;
923  pcc = strchr(cDirMask, '/');
924  while (pcc != NULL)
925  {
926  iMaskDirLevel++;
927  iaMaskSubdirLen[iMaskDirLevel] = pcc - pcc2 + 1;
928  /* include trailing '/' */
929  if (iDebug == 2)
930  {
931  ii = iaMaskSubdirLen[iMaskDirLevel];
932 
933  /* strncpy does not work in this loop -
934  possibly due to optimization */
935  strcpy(cTemp, cDirMask);
936  pcc3 = cTemp;
937  pcc3 += ii;
938  strncpy(pcc3, "\0", 1);
939  fprintf(fLogFile, " mask dir level %d: %s (%d byte)\n",
940  iMaskDirLevel, cTemp, ii);
941  }
942 
943  pcc++;
944  pcc1 = strchr(pcc, '/');
945  if (pcc1 == NULL)
946  jj = strlen(pcc); /* keep length of deepest subdir */
947  pcc = pcc1;
948  }
949 
950  /* get lowest subdir */
951  iMaskDirLevel++;
952  ii = iaMaskSubdirLen[iMaskDirLevel-1] + jj;
953  iaMaskSubdirLen[iMaskDirLevel] = ii;
954 
955  if (iDebug == 2) fprintf(fLogFile,
956  " mask dir level %d: %s (%d byte)\n",
957  iMaskDirLevel, cDirMask, ii);
958 
959  if (iDebug) fprintf(fLogFile,
960  " mask dir has %d levels\n", iMaskDirLevel);
961 
962  if (iEntryType == 30)
963  {
964  iRecursive = 0;
965  if (iDebug) fprintf(fLogFile,
966  " action not recursive - no handling of subdirs below mask\n");
967  }
968  else
969  iRecursive = 1;
970 
971  iEntryType = 0;
972 
973  } /* (iEntryType >= 20) */
974  else
975  {
976  strcpy(cFileMask, pcEntryMask);
977  iEntryType -= 10;
978  if (iDebug) fprintf(fLogFile,
979  " mask %s for relative file/subdir names\n", cEntryMask);
980  }
981  } /* (iEntryType >= 10) */
982 
983  if (iEntryType == 0)
984  strcpy(cEntryType, "entries");
985  else if (iEntryType == 1)
986  strcpy(cEntryType, "files");
987  else if (iEntryType == 2)
988  strcpy(cEntryType, "subdirs");
989  else
990  {
991  fprintf(fLogFile,
992  "-E- %s: invalid EntryType %d (allowed 0-2, 10-12, 20, 30)\n",
993  cModule, iEntryType);
994 
995  iRCE = -1;
996  goto gEndRecEntryList;
997  }
998 
999  /* handle files */
1000  if ( (iEntryType == 0) || (iEntryType == 1) )
1001  {
1002  if (ppFileList == NULL)
1003  {
1004  fprintf(fLogFile,
1005  "-E- %s: invalid pointer for entry list\n", cModule);
1006 
1007  iRCE = -1;
1008  goto gEndRecEntryList;
1009  }
1010 
1011  piFileNo = (int *) *ppFileList;
1012  piFileList = piFileNo;
1013  iFileEntriesOld = *piFileNo;
1014 
1015  if (iDebug)
1016  {
1017  if (iFileEntriesOld) fprintf(fLogFile,
1018  " %d files already available in list:\n",
1019  iFileEntriesOld);
1020  else fprintf(fLogFile,
1021  " still no files in list\n");
1022  }
1023 
1024  piFileList++;
1025  psFileList = (srawFileList *) piFileList;
1026  psFileList0 = psFileList;
1027 
1028  for (ii=1; ii<=iFileEntriesOld; ii++)
1029  {
1030  if (iDebug== 2)
1031  {
1032  if (ii == 1)
1033  fprintf(fLogFile, "previous files:\n");
1034  fprintf(fLogFile, " %d: %s\n", ii, psFileList->cFile);
1035  }
1036 
1037  psFileList++;
1038  }
1039  /* psFileList now located for new entry */
1040 
1041  iFileEntries = iFileEntriesOld;
1042  iFileEntryMax = iMaxFiles;
1043 
1044  iFileEntryRem = iFileEntryMax - iFileEntriesOld;
1045 
1046  if (iDebug) fprintf(fLogFile,
1047  " space available for %d file entries (max %d)\n",
1048  iFileEntryRem, iFileEntryMax);
1049 
1050  } /* (iEntryType == 0 || 1) */
1051 
1052  /* handle subdirectories */
1053  if ( (iEntryType == 0) || (iEntryType == 2) )
1054  {
1055  if (ppDirList == NULL)
1056  {
1057  fprintf(fLogFile,
1058  "-E- %s: invalid pointer for subdir list\n", cModule);
1059 
1060  iRCE = -1;
1061  goto gEndRecEntryList;
1062  }
1063 
1064  piDirNo = (int *) *ppDirList;
1065  piDirList = piDirNo;
1066  iDirEntriesOld = *piDirNo;
1067 
1068  if (iDebug)
1069  {
1070  if (iDirEntriesOld) fprintf(fLogFile,
1071  " %d subdirectories already available in list:\n",
1072  iDirEntriesOld);
1073  else fprintf(fLogFile,
1074  " still no subdirectories in list\n");
1075  }
1076 
1077  piDirList++;
1078  psDirList = (srawFileList *) piDirList;
1079  psDirList0 = psDirList;
1080 
1081  for (ii=1; ii<=iDirEntriesOld; ii++)
1082  {
1083  if (iDebug == 2)
1084  {
1085  if (ii == 1)
1086  fprintf(fLogFile, "previous subdirs:\n");
1087  fprintf(fLogFile, " %d: %s\n", ii, psDirList->cFile);
1088  }
1089 
1090  psDirList++;
1091  }
1092  /* psDirList now located for new entry */
1093 
1094  iDirEntries = iDirEntriesOld;
1095  iDirEntryMax = iMaxDirs;
1096 
1097  /* already add. space allocated */
1098  if (iDirEntriesOld > iDirEntryMax)
1099  {
1100  ii = iDirEntriesOld / iDirEntryMax;
1101  ii++;
1102  iDirEntryMax *= ii;
1103  }
1104  else if (iDirEntriesOld == iDirEntryMax)
1105  {
1106  fprintf(fLogFile, "DDD1 new space must be allocated\n");
1107  }
1108 
1109  iDirEntryRem = iDirEntryMax - iDirEntriesOld;
1110 
1111  if (iDebug) fprintf(fLogFile,
1112  " space available for %d subdir entries (max %d)\n",
1113  iDirEntryRem, iDirEntryMax);
1114 
1115  } /* (iEntryType == 0 || 2) */
1116 
1117  if (iDebug)
1118  {
1119  if (iMatch)
1120  {
1121  fprintf(fLogFile,
1122  " provide all %s matching with %s",
1123  cEntryType, cEntryMask);
1124  if (iRecursive) fprintf(fLogFile,
1125  " in dir %s", cDirName);
1126  }
1127  else fprintf(fLogFile,
1128  " provide all %s in dir %s", cEntryType, cDirName);
1129 
1130  if (iRecursive) fprintf(fLogFile,
1131  " and all subdirs\n");
1132  else
1133  fprintf(fLogFile, "\n");
1134  }
1135 
1136  pDir = opendir(cDirName);
1137  if (pDir == NULL)
1138  {
1139  fprintf(fLogFile,
1140  "-E- %s: cannot open directory %s\n", cModule, cDirName);
1141  if (errno)
1142  fprintf(fLogFile, "%s\n", strerror(errno));
1143 
1144  iRCE = -1;
1145  goto gEndRecEntryList;
1146  }
1147 
1148  if (iDebug == 2) fprintf(fLogFile,
1149  " new dir %s opened\n", cDirName);
1150 
1151  if (iFullMatch)
1152  {
1153  icurDirLevel = 0;
1154  pcc2 = cDirName;
1155  pcc = strchr(cDirName, '/');
1156  while (pcc != NULL)
1157  {
1158  icurDirLevel++;
1159  iacurSubdirLen[icurDirLevel] = pcc - pcc2 + 1;
1160  /* include trailing '/' */
1161  if (iDebug == 2)
1162  {
1163  ii = iacurSubdirLen[icurDirLevel];
1164 
1165  /* strncpy does not work in this loop -
1166  possibly due to optimization */
1167  strcpy(cTemp, cDirName);
1168  pcc3 = cTemp;
1169  pcc3 += ii;
1170  strncpy(pcc3, "\0", 1);
1171 
1172  fprintf(fLogFile, " cur dir level %d: %s (%d byte)\n",
1173  icurDirLevel, cTemp, ii);
1174  }
1175 
1176  if (icurDirLevel > iMaskDirLevel)
1177  break; /* lower subdirs not needed */
1178 
1179  pcc++;
1180  pcc1 = strchr(pcc, '/');
1181  if (pcc1 == NULL)
1182  jj = strlen(pcc); /* keep length of deepest subdir */
1183  pcc = pcc1;
1184  }
1185 
1186  /* get lowest subdir */
1187  icurDirLevel++;
1188  ii = iacurSubdirLen[icurDirLevel-1] + jj;
1189  iacurSubdirLen[icurDirLevel] = ii;
1190 
1191  if (iDebug == 2) fprintf(fLogFile,
1192  " cur dir level %d: %s (%d byte)\n",
1193  icurDirLevel, cDirName, ii);
1194 
1195  if (iDebug) fprintf(fLogFile,
1196  " cur dir has %d levels\n", icurDirLevel);
1197 
1198  } /* (iFullMatch) */
1199 
1200  if ( (iFullMatch) && (iRecursive == 0) &&
1201  (icurDirLevel == iMaskDirLevel) )
1202  {
1203  if (iDebug) fprintf(fLogFile,
1204  " last subdir level (%d), check only for files\n",
1205  icurDirLevel);
1206  }
1207  else
1208  icurDirLevel++; /* prepare for lowest subdir */
1209 
1210  if ( (iFullMatch) && (iDebug) ) fprintf(fLogFile,
1211  " comparisons on subdir level %d (mask) - %d (new dir)\n",
1212  iMaskDirLevel, icurDirLevel);
1213 
1214  iDirNameLen = strlen(cDirName);
1215  psDirListNew = psDirList;
1216  strcat(cDirName, "/");
1217 
1218  while ( (pEntry = readdir(pDir)) != NULL)
1219  {
1220  if ( (strcmp(pEntry->d_name, ".") == 0) ||
1221  (strcmp(pEntry->d_name, "..") == 0) )
1222  continue;
1223 
1224  iEntries++;
1225  iCheck = 0;
1226  iStore = 0;
1227 
1228  /* check in which cases entry could be stored */
1229  if (iFullMatch)
1230  {
1231  if (icurDirLevel < iMaskDirLevel)
1232  {
1233  /* ignore files, check dirs */
1234  if (pEntry->d_type == DT_DIR)
1235  {
1236  iCheck = 1;
1237 
1238  if (iDebug == 2) fprintf(fLogFile,
1239  "%d: check dir %s (short)\n",
1240  iEntries, pEntry->d_name);
1241  }
1242  else if (iDebug == 2) fprintf(fLogFile,
1243  "%d: ignore file %s (short)\n",
1244  iEntries, pEntry->d_name);
1245  }
1246  else if (icurDirLevel == iMaskDirLevel)
1247  {
1248  iCheck = 1;
1249 
1250  if (iDebug == 2)
1251  {
1252  if (pEntry->d_type == DT_DIR) fprintf(fLogFile,
1253  "%d: check dir %s (last level)\n",
1254  iEntries, pEntry->d_name);
1255  else fprintf(fLogFile,
1256  "%d: check file %s (last subdir)\n",
1257  iEntries, pEntry->d_name);
1258  }
1259  }
1260  else
1261  {
1262  /* (icurDirLevel > iMaskDirLevel), must be recursive */
1263  if (pEntry->d_type == DT_REG)
1264  {
1265  iCheck = 1;
1266  if (iDebug == 2) fprintf(fLogFile,
1267  "%d: check file %s\n",
1268  iEntries, pEntry->d_name);
1269  }
1270  else
1271  {
1272  iStore = 1;
1273  if (iDebug == 2) fprintf(fLogFile,
1274  "%d: store dir %s\n",
1275  iEntries, pEntry->d_name);
1276  }
1277  }
1278  } /* (iFullMatch) */
1279  else
1280  {
1281  if (pEntry->d_type == DT_REG)
1282  {
1283  if ( (iEntryType == 0) || (iEntryType == 1) )
1284  {
1285  if (iMatch)
1286  {
1287  iCheck = 1;
1288  if (iDebug == 2) fprintf(fLogFile,
1289  "%d: check file %s\n", iEntries, pEntry->d_name);
1290  }
1291  else
1292  {
1293  iStore = 1;
1294  if (iDebug == 2) fprintf(fLogFile,
1295  "%d: store file %s\n", iEntries, pEntry->d_name);
1296  }
1297  }
1298  }
1299  else if (pEntry->d_type == DT_DIR)
1300  {
1301  if ( (iEntryType == 0) || (iEntryType == 2) )
1302  {
1303  iStore = 1;
1304  if (iDebug == 2) fprintf(fLogFile,
1305  "%d: store dir %s\n", iEntries, pEntry->d_name);
1306  }
1307  }
1308  else if (iDebug == 2) fprintf(fLogFile,
1309  "ignore %s%s (entry type %d)\n",
1310  cDirName, pEntry->d_name, pEntry->d_type);
1311 
1312  } /* (iFullMatch == 0) */
1313 
1314  /* check if matching with input mask: in all calls of fnmatch:
1315  wildcards do not match '/' due to option FNM_PATHNAME */
1316  if (iCheck)
1317  {
1318  iStore = 0;
1319  if (iFullMatch)
1320  {
1321  if (icurDirLevel < iMaskDirLevel)
1322  {
1323  /* must be dir */
1324  strcpy(cDirName, cDirNameOrig); /* with trailing '/' */
1325  strcat(cDirName, pEntry->d_name); /* add subdir */
1326 
1327  strncpy(cFullEntryCheck, cEntryMask,
1328  iaMaskSubdirLen[icurDirLevel]-1);
1329 
1330  if (iDebug == 2) fprintf(fLogFile,
1331  " compare dirs: '%s' - '%s'\n",
1332  cFullEntryCheck, cDirName);
1333 
1334  if (fnmatch(cFullEntryCheck, cDirName, FNM_PATHNAME) == 0)
1335  iStore = 1; /* match, store this entry */
1336  }
1337  else if (icurDirLevel == iMaskDirLevel)
1338  {
1339  strcpy(cFullEntryCheck, cDirName);
1340  strcat(cFullEntryCheck, pEntry->d_name);
1341 
1342  if (pEntry->d_type == DT_REG)
1343  {
1344  if (iDebug == 2) fprintf(fLogFile,
1345  " compare files: '%s' - '%s'\n",
1346  cEntryMask, cFullEntryCheck);
1347 
1348  if (fnmatch(cEntryMask, cFullEntryCheck, FNM_PATHNAME) == 0)
1349  iStore = 1;
1350  }
1351  else
1352  {
1353  if (iDebug == 2) fprintf(fLogFile,
1354  " compare dirs: '%s' - '%s'\n",
1355  cDirMask, cFullEntryCheck);
1356 
1357  if (fnmatch(cDirMask, cFullEntryCheck, FNM_PATHNAME) == 0)
1358  iStore = 1;
1359  }
1360  } /* (icurDirLevel == iMaskDirLevel) */
1361  else
1362  {
1363  /* must be file name */
1364  if (iDebug == 2) fprintf(fLogFile,
1365  " compare files: '%s' - '%s'\n",
1366  cFileMask, pEntry->d_name);
1367 
1368  if (fnmatch(cFileMask, pEntry->d_name, FNM_PATHNAME) == 0)
1369  iStore = 1;
1370 
1371  } /* (icurDirLevel > iMaskDirLevel) */
1372  } /* (iFullMatch) */
1373  else
1374  {
1375  if (iDebug == 2) fprintf(fLogFile,
1376  " compare entries: '%s' - '%s'\n",
1377  cEntryMask, pEntry->d_name);
1378 
1379  if (fnmatch(cEntryMask, pEntry->d_name, FNM_PATHNAME) == 0)
1380  iStore = 1;
1381  }
1382  } /* (iCheck) */
1383 
1384  if (iStore)
1385  {
1386  /* store new file names */
1387  if (pEntry->d_type == DT_REG)
1388  {
1389  strcpy(psFileList->cFile, cDirName);
1390  strcat(psFileList->cFile, pEntry->d_name);
1391 
1392  iFileEntries++;
1393  iFileEntriesNew++;
1394  iFileEntryRem--;
1395 
1396  if (iDebug)
1397  {
1398  if (iFileEntriesNew == 1)
1399  fprintf(fLogFile, "new files:\n");
1400  fprintf(fLogFile, " %d(%d): %s\n",
1401  iFileEntriesNew, iFileEntries, psFileList->cFile);
1402  }
1403 
1404  if (iFileEntryRem <= 0)
1405  {
1406  if (iDebug) fprintf(fLogFile,
1407  "-W- dir %s: max no. of %d file entries reached\n",
1408  cDirName, iMaxFiles);
1409  iRCE = -101;
1410  break;
1411  }
1412 
1413  psFileList++;
1414 
1415  } /* files */
1416 
1417  /* store new subdirectory names */
1418  if ( (pEntry->d_type == DT_DIR) && (iLastDir == 0) )
1419  {
1420  if ( (iFullMatch) && (icurDirLevel < iMaskDirLevel) )
1421  strcpy(psDirList->cFile, cDirName);
1422  else
1423  {
1424  strcpy(psDirList->cFile, cDirName);
1425  strcat(psDirList->cFile, pEntry->d_name);
1426  }
1427 
1428  iDirEntries++;
1429  iDirEntriesNew++;
1430  iDirEntryRem--;
1431 
1432  if (iDebug)
1433  {
1434  if (iDirEntriesNew == 1)
1435  fprintf(fLogFile, "new subdir(s):\n");
1436  fprintf(fLogFile, " %d(%d): %s\n",
1437  iDirEntriesNew, iDirEntries, psDirList->cFile);
1438  }
1439 
1440  if (iDirEntryRem <= 0)
1441  {
1442  if (iDebug) fprintf(fLogFile,
1443  "-W- dir %s: max no. of %d subdir entries reached\n",
1444  cDirName, iMaxDirs);
1445  iRCE = -102;
1446  break;
1447  }
1448 
1449  psDirList++;
1450 
1451  } /* subdirs */
1452  } /* current entry matches and is of requested type */
1453  } /* entry loop */
1454 
1455  iRC = closedir(pDir);
1456 
1457  if (iDebug)
1458  {
1459  fprintf(fLogFile, " rc(closedir) = %d\n", iRC);
1460 
1461  fprintf(fLogFile,
1462  " %d entries in directory %s found\n",
1463  iEntries, cDirName);
1464 
1465  if (iFileEntriesNew == 0)
1466  {
1467  if ( (iMatch) || (iFullMatch) )
1468  fprintf(fLogFile, " no new matching files found\n");
1469  else
1470  fprintf(fLogFile, " no new files found\n");
1471  }
1472  if (iDirEntriesNew == 0)
1473  {
1474  if ( (iMatch) || (iFullMatch) )
1475  fprintf(fLogFile, " no new matching subdirs found\n");
1476  else
1477  fprintf(fLogFile, " no new subdirs found\n");
1478  }
1479 
1480  if (iFileEntries)
1481  {
1482  if ( (iMatch) || (iFullMatch) ) fprintf(fLogFile,
1483  " overall %d matching files (%d new)\n",
1484  iFileEntries, iFileEntriesNew);
1485  else fprintf(fLogFile,
1486  " overall %d files (%d new)\n",
1487  iFileEntries, iFileEntriesNew);
1488  }
1489 
1490  if (iDirEntries)
1491  {
1492  if ( (iMatch) || (iFullMatch) ) fprintf(fLogFile,
1493  " overall %d matching subdirectories (%d new)\n",
1494  iDirEntries, iDirEntriesNew);
1495  else fprintf(fLogFile,
1496  " overall %d subdirectories (%d new)\n",
1497  iDirEntries, iDirEntriesNew);
1498  }
1499  }
1500 
1501  if ( (iEntryType == 0) || (iEntryType == 1) )
1502  *piFileNo = iFileEntries;
1503  if ( (iEntryType == 0) || (iEntryType == 2) )
1504  {
1505  *piDirNo = iDirEntries;
1506  psDirList = (srawFileList *) piDirList;
1507  }
1508 
1509  if ( (iRecursive == 0) && (iFullMatch) &&
1510  ( ((icurDirLevel == iMaskDirLevel) && (iDirEntriesNew == 0)) ||
1511  (icurDirLevel > iMaskDirLevel) ) )
1512  {
1513  if (iDebug) fprintf(fLogFile,
1514  "-D- stop searching\n");
1515 
1516  goto gEndRecEntryList;
1517  }
1518 
1519  strcpy(cDirNameOrig, cDirName); /* keep dir originally provided */
1520 
1521  if ( (iDirEntriesNew) && (iLastDir == 0) &&
1522  (iRCE != -101) && (iRCE != -102) )
1523  {
1524  psDirList = psDirListNew; /* 1st new entry in subdir list */
1525  for (iDirLoop=1; iDirLoop<=iDirEntriesNew; iDirLoop++)
1526  {
1527  strcpy(cDirName, psDirList->cFile);
1528  if (iDebug) fprintf(fLogFile,
1529  " next dir: %s\n", cDirName);
1530 
1531  if (iFullMatch)
1532  {
1533  if (iRecursive)
1534  iEntryType = 20;
1535  else
1536  iEntryType = 30;
1537  }
1538  else if ( (iMatch) && (iEntryType < 10) )
1539  iEntryType += 10;
1540 
1541  iRC = rawGetRecEntryList(cDirName, cEntryMask, iEntryType,
1542  iMaxFiles, ppFileList, iMaxDirs, ppDirList);
1543 
1544  if ( (iRC == -101) || (iRC == -102) )
1545  {
1546  if (iDebug)
1547  fprintf(fLogFile, "-W- stop scanning\n");
1548 
1549  iRCE = iRC;
1550  break;
1551  }
1552 
1553  psDirList++;
1554  }
1555  }
1556  else if ( (iRCE == -101) || (iRCE == -102) )
1557  {
1558  if (iDebug)
1559  fprintf(fLogFile, "-W- stop scanning\n");
1560  }
1561 
1562 gEndRecEntryList:
1563 
1564  if (iDebug) fprintf(fLogFile,
1565  "-D- end %s for dir %s\n\n", cModule, cDirNameOrig);
1566 
1567  if (iRCE)
1568  return iRCE;
1569 
1570  return iEntries;
1571 
1572 } /* rawGetRecEntryList */
1573 #endif
1574 
1575 #ifndef Lynx
1576 /********************************************************************
1577  * rawGetFSEntries:
1578  * get number of entries in file system (via scandir)
1579  *
1580  * created 6. 6.2002, Horst Goeringer
1581  ********************************************************************/
1582 
1583 int rawGetFSEntries(char *pcStageFS)
1584  /* struct dirent *(fEntryList[]) */
1585 {
1586  char cModule[32]="rawGetFSEntries";
1587  int iDebug = 0;
1588 
1589  int iRC;
1590  int ii = 0;
1591 
1592  int iEntries = 0;
1593  struct dirent **fEntryList;
1594 
1595  if (iDebug) fprintf(fLogFile,
1596  "\n-D- begin %s: FS %s\n", cModule, pcStageFS);
1597 
1598  iRC = scandir(pcStageFS, &fEntryList, NULL, NULL);
1599  if (iRC < 0 )
1600  {
1601  fprintf(fLogFile,
1602  "-E- %s: calling system function scandir, rc=%d\n",
1603  cModule, iRC);
1604  if (errno)
1605  {
1606  fprintf(fLogFile, " %s\n", strerror(errno));
1607  errno = 0;
1608  }
1609 
1610  return -1;
1611  }
1612 
1613  iEntries = 0;
1614  for (ii=0; ii<iRC; ii++)
1615  {
1616  if (iDebug) fprintf(fLogFile,
1617  " %d: %s\n", ii, fEntryList[ii]->d_name);
1618 
1619  if ( (strcmp(fEntryList[ii]->d_name, ".") == 0) ||
1620  (strcmp(fEntryList[ii]->d_name, "..") == 0) )
1621  continue;
1622 
1623  iEntries++;
1624  }
1625 
1626  if (iDebug)
1627  fprintf(fLogFile, "-D- end %s\n\n", cModule);
1628 
1629  return(iEntries);
1630 
1631 } /* rawGetFSEntries*/
1632 #endif
1633 
1634 /********************************************************************
1635  * rawGetFSfree: get free space (bytes) in specified filesystem
1636  *
1637  * created 4.2.98, Horst Goeringer
1638  ********************************************************************/
1639 
1640 int rawGetFSfree(char *pcStageFS)
1641 {
1642  char cModule[32]="rawGetFSfree";
1643  int iDebug = 0;
1644 
1645  int iRC;
1646  unsigned int itemsize, itemno;
1647  int iFree = 0;
1648 
1649  FILE *fPipe;
1650  int iBuf;
1651  char cName[BUFSIZE_SMALL] = "", *pName;
1652  char cBuf[BUFSIZE_SMALL] = "", *pBuf;
1653  char cTempFile[MAX_FULL_FILE] = "";
1654  char cCmd[256] = "/home/rawserv/rawdf.sh ";
1655 
1656  time_t tTime;
1657  pid_t pstr;
1658 
1659  pBuf = &cBuf[0];
1660  pName = &cName[0];
1661  strcpy(cTempFile, pcStageFS);
1662 
1663  tTime = time(NULL);
1664  pstr = getpid();
1665  sprintf(cName, "/size.t%d.p%d", (int) tTime, pstr);
1666  strcat(cTempFile, pName);
1667 
1668  strcat(cCmd, pcStageFS);
1669  strcat(cCmd, " ");
1670  strcat(cCmd, cTempFile);
1671 
1672  if (iDebug)
1673  fprintf(fLogFile, "\n-D- begin %s: execute\n '%s'\n",
1674  cModule, cCmd);
1675 
1676  if (system(NULL))
1677  {
1678  iRC = system(cCmd);
1679  if (iRC)
1680  {
1681  fprintf(fLogFile, "-W- %s: system() failed, rc = %d\n",
1682  cModule, iRC);
1683  return -1;
1684  }
1685  else
1686  {
1687  if (iDebug)
1688  fprintf(fLogFile,
1689  " shell command successfully executed\n");
1690  }
1691  }
1692  else
1693  {
1694  fprintf(fLogFile, "-W- %s: system() not available\n",
1695  cModule);
1696  return -1;
1697  }
1698 
1699  fPipe = NULL;
1700  fPipe = fopen(cTempFile, "r");
1701  if (fPipe == NULL)
1702  {
1703  fprintf(fLogFile, "-E- %s: opening file %s\n",
1704  cModule, cTempFile);
1705  if (errno)
1706  {
1707  fprintf(fLogFile, " %s\n", strerror(errno));
1708  errno = 0;
1709  }
1710 
1711  return -1;
1712  }
1713 
1714  if (iDebug)
1715  fprintf(fLogFile, " file %s opened\n", cTempFile);
1716 
1717  itemsize = sizeof(char);
1718  itemno = BUFSIZE_SMALL;
1719  iBuf = fread(pBuf, itemsize, itemno, fPipe);
1720  if (iBuf <= 0)
1721  {
1722  fprintf(fLogFile, "-E- %s: fread, rc = %d\n", cModule, iBuf);
1723  if (errno)
1724  {
1725  fprintf(fLogFile, " %s\n", strerror(errno));
1726  errno = 0;
1727  }
1728 
1729  fprintf(fLogFile, " NO status buffer sent\n");
1730 
1731  } /* (iBuf <= 0) */
1732  else
1733  {
1734  iFree = atoi(pBuf);
1735  if (iDebug)
1736  {
1737  fprintf(fLogFile, " %d bytes in file: %s", iBuf, pBuf);
1738  fprintf(fLogFile, " free kB: %d\n", iFree);
1739  }
1740  }
1741 
1742  iRC = fclose(fPipe);
1743  if (iRC)
1744  {
1745  fprintf(fLogFile, "-E- %s: rc = %d closing file\n",
1746  cModule, iRC);
1747  if (errno)
1748  {
1749  fprintf(fLogFile, " %s\n", strerror(errno));
1750  errno = 0;
1751  }
1752 
1753  return(-1);
1754  }
1755 
1756  if (iDebug)
1757  fprintf(fLogFile, " file %s closed\n", cTempFile);
1758 
1759  iRC = remove(cTempFile);
1760  if (iRC)
1761  {
1762  fprintf(fLogFile, "-E- %s: rc = %d removing file %s\n",
1763  cModule, iRC, cTempFile);
1764  if (errno)
1765  {
1766  fprintf(fLogFile, " %s\n", strerror(errno));
1767  errno = 0;
1768  }
1769 
1770  return -1;
1771  }
1772  if (iDebug)
1773  fprintf(fLogFile, " file %s removed\n", cTempFile);
1774 
1775  if (iDebug)
1776  fprintf(fLogFile, "-D- end %s\n\n", cModule);
1777 
1778  if (iBuf <= 0)
1779  return -1;
1780  else
1781  return(iFree);
1782 
1783 } /* rawGetFSfree */
1784 
1785 #ifndef Lynx
1786 /**********************************************************************
1787  * rawGetFSSpace
1788  * get file size (bytes)
1789  * created 19.2.2002, Horst Goeringer
1790  **********************************************************************
1791  */
1792 
1793 int rawGetFSSpace(char *pcFileSystem,
1794  int *piSizeAll,
1795  int *piSizeAvail,
1796  int *piNodeAll,
1797  int *piNodeAvail)
1798 {
1799  char cModule[32] = "rawGetFSSpace";
1800  int iDebug = 0;
1801 
1802  int iRC;
1803  int iBlockSize = 4; /* kB */
1804  int iSizeAll = 0;
1805  int iSizeFree = 0;
1806  int iSizeAvail = 0;
1807  int iNodeAll = 0;
1808  int iNodeAvail = 0;
1809 
1810  struct statfs sFSstatus, *pFSstatus;
1811 
1812  if (iDebug) fprintf(fLogFile,
1813  "\n-D- begin %s: FS %s\n", cModule, pcFileSystem);
1814 
1815  pFSstatus = &sFSstatus;
1816 
1817  iRC = statfs(pcFileSystem, pFSstatus);
1818  if (iRC)
1819  {
1820  fprintf(fLogFile,
1821  "-E- %s: calling system function statfs, rc=%d\n",
1822  cModule, iRC);
1823  if (errno)
1824  {
1825  fprintf(fLogFile, " %s\n", strerror(errno));
1826  errno = 0;
1827  }
1828 
1829  return -1;
1830  }
1831 
1832  iBlockSize = (int) pFSstatus->f_bsize;
1833  if (iBlockSize == 0)
1834  {
1835  fprintf(fLogFile,
1836  "-W- unexpected blocksize found: 0 byte\n");
1837  return 1;
1838  }
1839  else
1840  {
1841  if (iDebug) fprintf(fLogFile,
1842  " blocksize found %d byte\n", iBlockSize);
1843  if (iBlockSize >= 1024)
1844  iBlockSize /= 1024;
1845  else
1846  {
1847  fprintf(fLogFile,
1848  "-W- unexpected blocksize found: %d byte\n", iBlockSize);
1849  return 1;
1850  }
1851  }
1852 
1853  /* convert to MByte */
1854  iSizeAll = (int) (pFSstatus->f_blocks/1000)*iBlockSize;
1855  iSizeFree = (int) (pFSstatus->f_bfree/1000)*iBlockSize;
1856  iSizeAvail = (int) (pFSstatus->f_bavail/1000)*iBlockSize;
1857 
1858  iNodeAll = (int) pFSstatus->f_files;
1859  iNodeAvail = (int) pFSstatus->f_ffree;
1860 
1861  if (iDebug)
1862  {
1863  fprintf(fLogFile,
1864  " overall space %d MB, free %d MB, available %d MB\n",
1865  iSizeAll, iSizeFree, iSizeAvail);
1866  fprintf(fLogFile,
1867  " overall file nodes %d, available %d\n",
1868  iNodeAll, iNodeAvail);
1869  }
1870 
1871  *piSizeAll = iSizeAll;
1872  *piSizeAvail = iSizeAvail;
1873  *piNodeAll = iNodeAll;
1874  *piNodeAvail = iNodeAvail;
1875 
1876  if (iDebug)
1877  fprintf(fLogFile, "-D- end %s\n\n", cModule);
1878 
1879  return 0;
1880 
1881 } /* rawGetFSSpace */
1882 #endif
1883 
1884 /**********************************************************************/
1885 /* rawGetFileAttr: get file attributes (size in bytes) */
1886 /* utilize shell command output via pipes */
1887 /* created 17.4.96, Horst Goeringer */
1888 /**********************************************************************/
1889 
1890 int rawGetFileAttr(char *pcFile, unsigned long *plFileSize)
1891 {
1892  char cModule[32] = "rawGetFileAttr";
1893  int iDebug = 0;
1894 
1895  FILE *f_ifile;
1896  int iRC;
1897  unsigned long lFileSize;
1898  unsigned long lr;
1899  int iReclen;
1900 
1901  int ilocSize = 5; /* token no. 5 contains file size */
1902  int ilocFile = 9; /* token no. 9 contains file name (check) */
1903  int ii, ilen, iloc;
1904 
1905  char cCmd[CMDLEN] = "ls -l ";
1906  char *pCmd;
1907  const char *pType = "r";
1908  char *pBuf, *pBuf0;
1909  const char *pcDollar = "$"; /* requ. spec. treatment in file name */
1910  char *pcc, *ploc;
1911 
1912  char *pctoken;
1913  const char *pcblank = " ";
1914  /* char ctoken[20]; */
1915  int icount = 0;
1916 
1917 /******************** end of declarations *****************/
1918 
1919  if (iDebug)
1920  {
1921  fprintf(fLogFile,
1922  "\n-D- begin %s: file %s\n", cModule, pcFile);
1923  fflush(fLogFile);
1924  }
1925 
1926  iReclen = 0; /* not available in Unix system */
1927 
1928  /* treat $ in file name */
1929  ploc = strchr(pcFile, *pcDollar);
1930  if (ploc != NULL)
1931  {
1932  if (iDebug)
1933  {
1934  fprintf(fLogFile, "-D- $ in file name found: %s\n", pcFile);
1935  fflush(fLogFile);
1936  }
1937  ilen = strlen(pcFile);
1938  pcc = pcFile;
1939  for (ii = 1; ii <= ilen; ii++)
1940  {
1941  iloc = strncmp(pcc, pcDollar, 1);
1942  if (iloc == 0) strncat(cCmd, "\\", 1); /* $ found */
1943  strncat(cCmd, pcc++, 1);
1944  }
1945  } /* ploc != NULL, $ in file name */
1946  else strcat(cCmd, pcFile);
1947 
1948  if (iDebug)
1949  {
1950  fprintf(fLogFile, "-D- %s: ex '%s'\n", cModule, cCmd);
1951  fflush(fLogFile);
1952  }
1953 
1954  pCmd = &cCmd[0];
1955  f_ifile = popen(pCmd, pType);
1956  if (f_ifile == NULL)
1957  {
1958  fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
1959  return -1;
1960  }
1961  if (iDebug)
1962  {
1963  fprintf(fLogFile, " %s: pipe opened\n", cModule);
1964  fflush(fLogFile);
1965  }
1966 
1967  if ( !(pBuf0 = (char *) malloc(BUFSIZE)) )
1968  {
1969  fprintf(fLogFile, "-E- %s: allocation buffer failed\n", cModule);
1970  pclose(f_ifile);
1971  return(-1);
1972  }
1973  if (iDebug)
1974  {
1975  fprintf(fLogFile, " %s: buffer allocated\n", cModule);
1976  fflush(fLogFile);
1977  }
1978 
1979  pBuf = pBuf0;
1980  lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
1981  if (lr <= 0)
1982  {
1983  fprintf(fLogFile, "-E- %s: reading from pipe failed\n", cModule);
1984  pclose(f_ifile);
1985  return(-1);
1986  }
1987 
1988  pBuf += (lr-1);
1989  strncpy(pBuf, "\0", 1); /* overwrite newline character */
1990 
1991  if (iDebug)
1992  {
1993  fprintf(fLogFile, " %s: complete string: (%lu bytes): \n%s\n",
1994  cModule, lr, pBuf0);
1995  fflush(fLogFile);
1996  }
1997 
1998  pBuf = pBuf0;
1999  while ( (pctoken = strtok(pBuf, pcblank)) != NULL)
2000  {
2001  icount++;
2002  if (iDebug)
2003  {
2004  fprintf(fLogFile, " token %d: %s\n", icount, pctoken);
2005  fflush(fLogFile);
2006  }
2007 
2008  if (icount == 2)
2009  {
2010  /* check for leading string:
2011  '\nYour .kshrc is not executable!' */
2012  iRC = strcmp(pctoken, ".kshrc");
2013  if (iRC == 0)
2014  {
2015  fprintf(fLogFile, " %s: token %d: %s found\n",
2016  cModule, icount, pctoken);
2017  ilocSize += 4;
2018  ilocFile += 4;
2019  }
2020  }
2021 
2022  if (icount == ilocSize)
2023  {
2024  /* test large file size DDD
2025  strcpy(ctoken, "2000000000");
2026  pctoken = &ctoken;
2027  */
2028  if ( ( iRC = sscanf( pctoken, "%lu", &lFileSize) ) <= 0 )
2029  {
2030  fprintf(fLogFile, "-E- %s: filesize %lu (%s) invalid\n",
2031  cModule, lFileSize, pctoken);
2032  if (errno)
2033  {
2034  fprintf(fLogFile, " %s\n", strerror(errno));
2035  errno = 0;
2036  }
2037  pclose(f_ifile);
2038 
2039  return(-1);
2040  }
2041  if (iDebug)
2042  {
2043  fprintf(fLogFile, " file size %lu\n", lFileSize);
2044  fflush(fLogFile);
2045  }
2046 
2047  if ( (lFileSize == 0) && (iDebug) )
2048  fprintf(fLogFile, " file %s empty\n", pcFile);
2049 
2050  if (lFileSize > MAX_FILE_SIZE)
2051  {
2052  fprintf(fLogFile,
2053  "-E- %s: file %s too large (%lu byte), max allowed 2GB -1\n",
2054  cModule, pcFile, lFileSize);
2055  pclose(f_ifile);
2056  return(-1);
2057  }
2058  }
2059 
2060  if (icount == ilocFile)
2061  {
2062  if ( (iRC = strcmp(pctoken, pcFile) ) != 0)
2063  {
2064  fprintf(fLogFile,
2065  "-E- %s: file name check: %s\n", cModule, pctoken);
2066  pclose(f_ifile);
2067  return(-1);
2068  }
2069  }
2070 
2071  pBuf = NULL;
2072 
2073  } /* while ... */
2074 
2075  pclose(f_ifile);
2076 
2077  /* pclose provides "No child processes" only if iRC=0 */
2078  if (errno)
2079  errno = 0;
2080 
2081  *plFileSize = lFileSize;
2082  if (iDebug)
2083  {
2084  fprintf(fLogFile, "-D- end %s\n\n", cModule);
2085  fflush(fLogFile);
2086  }
2087 
2088  return 0;
2089 
2090 } /* rawGetFileAttr */
2091 
2092 /**********************************************************************/
2093 /* rawGetFileList: execute shell cmd ls and get file list vector */
2094 /* created 19.2.96, Horst Goeringer */
2095 /**********************************************************************/
2096 
2097 int rawGetFileList( char *pcFile,
2098  int iAccept, /* = 0: only lower case files
2099  = 1: also upper case files
2100  = 2: also directories */
2101  int iEntryLoop,
2102  char **ppFileList)
2103 {
2104  char cModule[32] = "rawGetFileList";
2105  int iDebug = 0;
2106 
2107  int iRC = 0;
2108  int iRCE = 0;
2109  int iIgnore = 0; /* =1: new file already in list */
2110  int ilen, iloc, ii, jj;
2111  int ird, ipc, ipc1, irem, grem = 0;
2112  int iFileno, iFilenoo;
2113  int *piFileno; /* points to no. of files in filelist */
2114  int *piFileList; /* points to first file in filelist */
2115 
2116  char *pcc, *pcc0, *ploc;
2117  unsigned long lr;
2118 
2119  FILE *f_ifile;
2120 
2121  char cCmd[CMDLEN] = "ls -L ";
2122  /* mark directory names with / to skip them */
2123  /* char cCmd[CMDLEN] = "ls "; was valid from 28.7.2000-18.6.2001 */
2124  char *pCmd;
2125  char *pBuf;
2126  char cBuf[MAX_FULL_FILE]; /* temp buffer for incompl file names */
2127  const char *pcDollar = "$"; /* requ. spec. treatment in file name */
2128 
2129  srawFileList *psFileList, /* points to actual file in filelist */
2130  *psFileList0, /* points to first file in filelist */
2131  *psFileList0c; /* current file in old filelist */
2132 
2133  /******************************************************************/
2134 
2135  if (iDebug)
2136  fprintf(fLogFile, "\n-D- begin %s\n", cModule);
2137 
2138  ploc = strchr(pcFile, *pcDollar);
2139  if (ploc != NULL)
2140  {
2141  if (iDebug)
2142  fprintf(fLogFile, " '$' in file name found: %s\n", pcFile);
2143  ilen = strlen(pcFile);
2144  pcc = pcFile;
2145  for (ii=1; ii<=ilen; ii++)
2146  {
2147  iloc = strncmp(pcc, pcDollar, 1);
2148  if (iloc == 0) strncat(cCmd, "\\", 1); /* $ found */
2149  strncat(cCmd, pcc++, 1);
2150  }
2151  } /* ploc != NULL, $ in file name */
2152  else strcat(cCmd, pcFile);
2153  strcat(cCmd, " 2>/dev/null");
2154 
2155  if (iDebug)
2156  fprintf(fLogFile, " command: %s\n", cCmd);
2157 
2158  piFileList = (int *) *ppFileList; /* pointer to file list buffer */
2159  piFileno = piFileList++; /* points to no. of files, updated later */
2160  iFilenoo = *piFileno;
2161  psFileList = (srawFileList *) piFileList;
2162  psFileList0 = psFileList; /* points now to first file name */
2163 
2164  if (iFilenoo) /* skip files from previous calls */
2165  {
2166  if (iDebug) fprintf(fLogFile,
2167  " %d old files in list\n", iFilenoo);
2168 
2169  for (ii=1; ii<=iFilenoo; ii++)
2170  {
2171  if (iDebug == 1) fprintf(fLogFile,
2172  " %d (old): %s\n", ii, psFileList->cFile);
2173  psFileList++;
2174  }
2175  }
2176 
2177  pCmd = &cCmd[0];
2178  f_ifile = popen(pCmd, "r");
2179  if (f_ifile == NULL)
2180  {
2181  fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
2182  return(-1);
2183  }
2184  if (iDebug) fprintf(fLogFile, " pipe opened\n");
2185 
2186  if ( !(pBuf = (char *) malloc(BUFSIZE)) )
2187  {
2188  fprintf(fLogFile,
2189  "-E- %s: allocation buffer failed\n", cModule);
2190  pclose(f_ifile);
2191  return(-1);
2192  }
2193  if (iDebug)
2194  fprintf(fLogFile, " buffer allocated\n");
2195 
2196  memset(&cBuf[0], '\0', MAX_FULL_FILE);
2197  lr = 1;
2198  iFileno = 0;
2199  while (lr > 0)
2200  {
2201 gRead:
2202  memset(pBuf, '\0', BUFSIZE);
2203  lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
2204  if (lr > 0)
2205  {
2206  pcc0 = pBuf;
2207  pcc = pBuf;
2208  ird = lr; /* meaningful bytes */
2209 
2210  if (iDebug == 2)
2211  fprintf(fLogFile, "-D- received %d bytes:\n", ird);
2212 
2213  while(ird > 0)
2214  {
2215  if (iDebug == 2)
2216  fprintf(fLogFile, " '%s'", pcc0);
2217  ipc = strcspn(pcc0, "\n");
2218  irem = strlen(pcc0);
2219  pcc = strchr(pcc0, '\n');
2220  if (iDebug == 2) fprintf(fLogFile,
2221  "\n first length %d, total %d, remainder %d\n",
2222  ipc, irem, grem);
2223 
2224  if (grem) /* incompl. file name from previous buffer */
2225  {
2226  if (ipc > 0)
2227  {
2228  strncat(cBuf, pcc0, (unsigned) ipc);
2229  if (iDebug == 2) fprintf(fLogFile,
2230  " last concatenated: %s\n", cBuf);
2231  }
2232 
2233  ii = strlen(cBuf);
2234 
2235  /* after file names: subdir (marked by trailing ":") */
2236  if (strncmp(&(cBuf[ii-1]), ":", 1) == 0)
2237  {
2238  if (iDebug) fprintf(fLogFile,
2239  "\n stop checking, ignore subdirectory %s\n",
2240  cBuf);
2241  lr = 0;
2242  break;
2243  }
2244 
2245  if ( (strcmp(cBuf, "./")) && /* ignore "./" */
2246  (ii) && /* ignore empty string */
2247  (strncmp(&(cBuf[ii-1]), ":", 1)) )
2248  /* ignore subdir (trailing ":") */
2249  {
2250  iRC = rawTestFileName(cBuf);
2251  if ( (iRC == 0) ||
2252  ( (iRC == 1) && (iAccept >= 1) ) )
2253  {
2254  if (iFilenoo)
2255  {
2256  psFileList0c = psFileList0; /* first old file */
2257 
2258  /* compare new name with old ones */
2259  for (jj=1; jj<=iFilenoo; jj++)
2260  {
2261  iRC = strcmp(cBuf, psFileList0c->cFile);
2262  if (iRC == 0)
2263  {
2264  iIgnore = 1;
2265  if (iDebug) fprintf(fLogFile,
2266  " entry %s already available(1)\n",
2267  cBuf);
2268  break;
2269  }
2270  psFileList0c++;
2271  }
2272  } /* (iFilenoo) */
2273 
2274  if (iIgnore == 0)
2275  {
2276  strcpy(psFileList->cFile, cBuf);
2277  iFileno++;
2278  if (iDebug) fprintf(fLogFile,
2279  " %s stored(1), addr %p\n",
2280  psFileList->cFile, psFileList);
2281 
2282  psFileList++;
2283  }
2284  else
2285  iIgnore = 0;
2286 
2287  if (iFileno >= MAX_FILE_NO)
2288  {
2289  fprintf(fLogFile,
2290  "-E- %s: List of files for archive/retrieve currently limited to %d entries\n",
2291  cModule, --iFileno);
2292  fprintf(fLogFile,
2293  " %s: NOT ALL files handled\n",
2294  cModule);
2295  goto gFinishList;
2296  }
2297  }
2298  else
2299  {
2300  if (iRC == 1)
2301  {
2302  fprintf(fLogFile,
2303  "-W- file name %s has uppercase letters - ignored\n",
2304  cBuf);
2305  iRCE = 1; /* client ends with error code */
2306  }
2307  if (iRC == 2) /* no error code */
2308  {
2309  fprintf(fLogFile,
2310  "-W- directory %s ignored\n", cBuf);
2311  }
2312  }
2313  }
2314 
2315  memset(&cBuf, '\0', strlen(cBuf));
2316  grem = 0;
2317  } /* if (grem) */
2318  else
2319  {
2320  strncpy(cBuf, pcc0, (unsigned) ipc);
2321  strcat(cBuf, "\0");
2322  if (irem - ipc == 0) /* current file name incomplete */
2323  {
2324  ipc1 = strlen(cBuf);
2325  if (iDebug == 2) fprintf(fLogFile,
2326  " grem set, cBuf: %s (%d byte) \n", cBuf, ipc1);
2327  grem = 1;
2328  }
2329  else
2330  {
2331  ii = strlen(cBuf);
2332 
2333  /* after file names: subdir (marked by trailing ":") */
2334  if (strncmp(&(cBuf[ii-1]), ":", 1) == 0)
2335  {
2336  if (iDebug) fprintf(fLogFile,
2337  "\n stop checking, ignore subdirectory %s\n",
2338  cBuf);
2339  lr = 0;
2340  break;
2341  }
2342 
2343  if ( (strcmp(cBuf, "./")) && /* ignore "./" */
2344  (ii) && /* ignore empty string */
2345  (strncmp(&(cBuf[ii-1]), ":", 1)) )
2346  /* ignore subdir (trailing ":") */
2347  {
2348  iRC = rawTestFileName(cBuf);
2349  if ( (iRC == 0) ||
2350  ( (iRC == 1) && (iAccept >= 1) ) )
2351  {
2352  if (iFilenoo)
2353  {
2354  psFileList0c = psFileList0;/* 1st old file */
2355 
2356  /* compare new name with old ones */
2357  for (jj=1; jj<=iFilenoo; jj++)
2358  {
2359  if (ipc == (int) strlen(psFileList0c->cFile))
2360  {
2361  iRC = strncmp(cBuf,
2362  psFileList0c->cFile,
2363  (unsigned) ipc);
2364  if (iRC == 0)
2365  {
2366  iIgnore = 1;
2367  if (iDebug) fprintf(fLogFile,
2368  " entry %s already available(2)\n",
2369  cBuf);
2370  break;
2371  }
2372  }
2373  psFileList0c++;
2374  }
2375  } /* (iFilenoo) */
2376 
2377  if (iIgnore == 0)
2378  {
2379  strncpy(psFileList->cFile, cBuf, (unsigned) ipc);
2380  iFileno++;
2381 
2382  if (iDebug) fprintf(fLogFile,
2383  " %s stored(2), addr %p\n",
2384  psFileList->cFile, psFileList);
2385  psFileList++;
2386  }
2387  else
2388  iIgnore = 0;
2389 
2390  if (iFileno >= MAX_FILE_NO)
2391  {
2392  fprintf(fLogFile,
2393  "-E- %s: List of files for archive/retrieve currently limited to %d entries\n",
2394  cModule, --iFileno);
2395  fprintf(fLogFile,
2396  " %s: NOT ALL files handled\n",
2397  cModule);
2398  goto gFinishList;
2399  }
2400  }
2401  else
2402  {
2403  if (iRC == 1)
2404  {
2405  fprintf(fLogFile,
2406  "-W- file name %s has uppercase letters - ignored\n",
2407  cBuf);
2408  iRCE = 1; /* client ends with error code */
2409  }
2410  if (iRC == 2) /* no error code */
2411  fprintf(fLogFile,
2412  "-W- directory %s ignored\n", cBuf);
2413  }
2414  }
2415 
2416  memset(&cBuf, '\0', strlen(cBuf));
2417  }
2418 
2419  } /* if (!grem) */
2420 
2421  pcc0 = ++pcc;
2422  ird -= (ipc+1);
2423  } /* while(ird > 0) */
2424 
2425  } /* if(lr > 0) */
2426 
2427  } /* while(lr > 0) */
2428 
2429 gFinishList:
2430  if (iEntryLoop)
2431  {
2432  if (iFileno == 0)
2433  fprintf(fLogFile, "-I- no (new) files found\n");
2434  else if (iFileno > 1)
2435  fprintf(fLogFile, "-I- %d (new) files found\n", iFileno);
2436  }
2437 
2438  if ( (iDebug) && (iFileno) )
2439  {
2440  psFileList = (srawFileList *) piFileList;
2441  /* points now to first file name */
2442  for (ii=1; ii<=iFilenoo; ii++)
2443  {
2444  if (iDebug == 1) fprintf(fLogFile,
2445  " %d (old): %s\n", ii, psFileList->cFile); psFileList++;
2446  }
2447  for (ii=iFilenoo+1; ii<=iFilenoo+iFileno; ii++)
2448  {
2449  if (iDebug == 1) fprintf(fLogFile,
2450  " %d: %s\n", ii, psFileList->cFile); psFileList++;
2451  }
2452  }
2453 
2454  iFileno += iFilenoo; /* total no. of files found */
2455  piFileno[0] = iFileno; /* pass total no. of files found */
2456 
2457  iRC = pclose(f_ifile);
2458  if (iDebug)
2459  {
2460  if (iRC)
2461  {
2462  fprintf(fLogFile, "-E- %s: iRC = %d closing pipe\n",
2463  cModule, iRC);
2464  if (errno)
2465  {
2466  fprintf(fLogFile, " %s\n", strerror(errno));
2467  errno = 0;
2468  }
2469  }
2470  else
2471  fprintf(fLogFile, " pipe closed\n");
2472 
2473  fprintf(fLogFile, "-D- end %s\n\n", cModule);
2474  }
2475 
2476  /* pclose provides "No child processes" only if iRC=0 */
2477  if (errno)
2478  errno = 0;
2479 
2480  if (iRCE)
2481  return iRCE;
2482  else
2483  return 0;
2484 
2485 } /* rawGetFileList */
2486 
2487 /**********************************************************************
2488  * rawGetHostConn: get network connection type of client host
2489  * created 19.3.98, Horst Goeringer
2490  **********************************************************************/
2491 
2493 {
2494  char cModule[32] = "rawGetHostConn";
2495  int iDebug = 0;
2496 
2497  int iRC;
2498  int ii;
2499  int iBuf = 0;
2500  int iCol = 0; /* no. of columns in cmd output */
2501  int iType = 0; /* network connection type
2502  = 1: ethernet (slow)
2503  = 2: ethernet (fast, nodes linux*
2504  = 3: fddi
2505  = 4: SP switch */
2506  char *pcc;
2507  char cToken[16] = "", *pToken;
2508  char cheadName[16], *pheadName;
2509  char cheadMtu[16] = "mtu", *pheadMtu;
2510  char cName[16] = "", *pName;
2511  char cMtu[16] = "", *pMtu;
2512  char cNameRef1[16] = "";
2513  char cNameRef2[16] = "";
2514 
2515  char cCmd[CMDLEN] = "netstat -i", *pCmd;
2516  char cBuf[1024] = "", *pBuf;
2517  char cNode[MAX_NODE] = "";
2518 
2519  FILE *f_ifile;
2520 
2521  if (iDebug)
2522  fprintf(fLogFile, "\n-D- in %s\n", cModule);
2523 
2524 #ifdef _AIX
2525  strcpy(cheadName, "name");
2526 #else
2527  strcpy(cheadName, "iface");
2528 #endif
2529 
2530  iRC = gethostname(cNode, MAX_NODE);
2531  if (iRC)
2532  {
2533  fprintf(fLogFile,
2534  "-E- %s: getting client host name: %s\n",
2535  cModule, strerror(iRC));
2536  return(1);
2537  }
2538  if (iDebug) fprintf(fLogFile,
2539  " %s: client host %s\n", cModule, cNode);
2540 
2541  if (strncmp(cNode, "lx", 2) == 0) /* fast ethernet */
2542  return(2);
2543  if (strncmp(cNode, "linux", 5) == 0) /* fast ethernet */
2544  return(2);
2545  if (strncmp(cNode, "sp2", 3) == 0) /* fddi */
2546  return(4);
2547 
2548  pToken = &cToken[0];
2549  pheadName = &cheadName[0];
2550  pheadMtu = &cheadMtu[0];
2551  pName = &cName[0];
2552  pMtu = &cMtu[0];
2553  pCmd = &cCmd[0];
2554  pBuf = &cBuf[0];
2555 
2556  f_ifile = popen(pCmd, "r");
2557  if (f_ifile == NULL)
2558  {
2559  fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
2560  return(-1);
2561  }
2562  if (iDebug)
2563  fprintf(fLogFile, " %s: pipe opened\n", cModule);
2564 
2565  iBuf = fread(pBuf, sizeof(char), 1024, f_ifile);
2566  if (iBuf <= 0)
2567  {
2568  fprintf(fLogFile, "-E- %s: reading from pipe failed\n", cModule);
2569  goto gError;
2570  }
2571 
2572  if (iDebug == 2)
2573  fprintf(fLogFile, " %s command output: \n%s", cModule, cBuf);
2574 
2575  pToken = strtok(pBuf, " \n");
2576  pcc = pToken;
2577  while (*pcc != '\0')
2578  {
2579  *pcc = tolower(*pcc);
2580  pcc++; /* gcc 3.3.5: need two steps, else string corrupted */
2581  }
2582 
2583  if (strcmp(pToken, pheadName))
2584  {
2585  fprintf(fLogFile, "-E- %s: invalid name heading (%s, expected %s)\n",
2586  cModule, pToken, pheadName);
2587  goto gError;
2588  }
2589 
2590  pToken = strtok(NULL, " \n");
2591  pcc = pToken;
2592  while (*pcc != '\0')
2593  {
2594  *pcc = tolower(*pcc);
2595  pcc++; /* gcc 3.3.5: need two steps, else string corrupted */
2596  }
2597 
2598  if (strcmp(pToken, pheadMtu))
2599  {
2600  fprintf(fLogFile, "-E- %s: invalid mtu heading (%s, expected %s)\n",
2601  cModule, pToken, pheadMtu);
2602  goto gError;
2603  }
2604 
2605 #ifdef _AIX
2606  iCol = 9;
2607  strcpy(cNameRef1, "en0");
2608  strcpy(cNameRef2, "fi0");
2609 #endif
2610 #ifdef Linux
2611  iCol = 12;
2612  strcpy(cNameRef1, "eth0");
2613  strcpy(cNameRef2, "fdd0");
2614 #endif
2615 
2616  for (ii=1; ii<=iCol-2; ii++) /* skip other headings */
2617  { pToken = strtok(NULL, " \n"); }
2618 
2619  for (;;) /* loop over command output words */
2620  {
2621  pToken = strtok(NULL, " \n");
2622  if (pToken == NULL) break; /* EOF */
2623  pcc = pToken;
2624  while (*pcc != '\0')
2625  {
2626  *pcc = tolower(*pcc);
2627  pcc++; /* gcc 3.3.5: need two steps, else string corrupted */
2628  }
2629 
2630  if (iDebug == 2)
2631  fprintf(fLogFile, "DDD %s: %s\n", cModule, pToken);
2632 
2633  if (strcmp(pToken, cNameRef1) == 0)
2634  {
2635  iType = 1;
2636  if (iDebug)
2637  fprintf(fLogFile, " %s: ethernet available\n", cModule);
2638  }
2639  else if (strcmp(pToken, cNameRef2) == 0)
2640  {
2641  iType = 3; /* fddi */
2642  break;
2643  }
2644  } /* loop over command output lines */
2645 
2646  pclose(f_ifile);
2647  if ( (iType != 3) && (iType != 1) )
2648  {
2649  fprintf(fLogFile,
2650  "-E- %s: invalid network connection type (%d)\n",
2651  cModule, iType);
2652  goto gError;
2653  }
2654  else if (iDebug)
2655  fprintf(fLogFile, "-D- end %s: network connection type %d\n\n",
2656  cModule, iType);
2657  goto gEnd;
2658 
2659 gError:
2660  iType = -1;
2661 
2662 gEnd:
2663  return(iType);
2664 
2665 } /* rawGetHostConn */
2666 
2667 /*********************************************************************
2668  * rawGetBaseDir:
2669  * get fixed directory name part above wildcarded subdirs (base dir)
2670  * support '*', '?', and '%' as wildcard characters
2671  * created 4.11.2011, Horst Goeringer
2672  *********************************************************************/
2673 
2675  char *pcVarDir, /* input */
2676  char *pcBaseDir) /* output */
2677 {
2678  char cModule[32] = "rawGetBaseDir";
2679  int iDebug = 0;
2680 
2681  char *pcc, *pcc1, *pcc2;
2682  int iRC;
2683  int ii;
2684 
2685  char cBaseDir[MAX_FULL_FILE] = "";
2686 
2687  strcpy(cBaseDir, pcVarDir);
2688 
2689  pcc = strchr(cBaseDir, *pcStar);
2690  pcc1 = strchr(cBaseDir, *pcQM);
2691  pcc2 = strchr(cBaseDir, *pcPerc);
2692 
2693  if (iDebug)
2694  {
2695  fprintf(fLogFile, "\n-D- begin %s\n", cModule);
2696  if (pcc)
2697  fprintf(fLogFile, " %s contains '%s'\n", cBaseDir, pcStar);
2698  if (pcc1)
2699  fprintf(fLogFile, " %s contains '%s'\n", cBaseDir, pcQM);
2700  if (pcc2)
2701  fprintf(fLogFile, " %s contains '%s'\n", cBaseDir, pcPerc);
2702  }
2703 
2704  ii = 0;
2705  if (pcc)
2706  {
2707  if (pcc1)
2708  {
2709  if (pcc2)
2710  {
2711  if (pcc < pcc1)
2712  {
2713  if (pcc < pcc2)
2714  ii = 1;
2715  else
2716  {
2717  if (pcc1 < pcc2)
2718  ii = 2;
2719  else
2720  ii = 3;
2721  }
2722  }
2723  else
2724  {
2725  if (pcc1 < pcc2)
2726  ii = 2;
2727  else
2728  ii = 3;
2729  }
2730  } /* (pcc2) */
2731  else
2732  {
2733  if (pcc < pcc1)
2734  ii = 1;
2735  else
2736  ii = 2;
2737  }
2738  } /* (pcc1) */
2739  else
2740  {
2741  if (pcc2)
2742  {
2743  if (pcc < pcc2)
2744  ii = 1;
2745  else
2746  ii = 3;
2747  }
2748  else
2749  ii = 1;
2750  }
2751  } /* (pcc) */
2752  else
2753  {
2754  if (pcc1)
2755  {
2756  if (pcc2)
2757  {
2758  if (pcc1 < pcc2)
2759  ii = 2;
2760  else
2761  ii = 3;
2762  }
2763  else
2764  ii = 2;
2765 
2766  } /* (pcc1) */
2767  else
2768  {
2769  if (pcc2)
2770  ii = 3;
2771  else
2772  {
2773  fprintf(fLogFile,
2774  "-E- dir %s: generic flag set, but no wildcard chars found\n",
2775  cBaseDir);
2776 
2777  iRC = -1;
2778  goto gDirEnd;
2779  }
2780  }
2781  } /* (pcc == NULL) */
2782 
2783  if (ii == 1)
2784  strncpy(pcc, "\0", 1);
2785  else if (ii == 2)
2786  strncpy(pcc1, "\0", 1);
2787  else
2788  strncpy(pcc2, "\0", 1);
2789 
2790  pcc = strrchr(cBaseDir, '/');
2791  if (pcc == NULL)
2792  {
2793  fprintf(fLogFile, "-E- invalid top directory %s\n", cBaseDir);
2794 
2795  iRC = -1;
2796  goto gDirEnd;
2797  }
2798 
2799  if (pcc == cBaseDir)
2800  pcc++; /* only '/' remaining */
2801  strncpy(pcc, "\0", 1);
2802 
2803  if (iDebug) fprintf(fLogFile,
2804  " top directory above wildcard chars: %s\n", cBaseDir);
2805 
2806  /* provide result */
2807  strcpy(pcBaseDir, cBaseDir);
2808  iRC = 0;
2809 
2810 gDirEnd:
2811  if (iDebug)
2812  fprintf(fLogFile, "-D- end %s\n\n", cModule);
2813 
2814  return(iRC);
2815 
2816 } /* rawGetBaseDir */
2817 
2818 /**********************************************************************/
2819 /* rawGetUserid get user identification */
2820 /* created 22.3.96, Horst Goeringer */
2821 /**********************************************************************/
2822 
2824 {
2825  char cModule[32] = "rawGetUserid";
2826  int iDebug = 0;
2827 
2828  unsigned int lr;
2829  FILE *f_ifile;
2830 
2831  char cCmd[CMDLEN] = "whoami";
2832  char *pCmd;
2833  char *pBuf, *pBuf0;
2834 
2835  pCmd = &cCmd[0];
2836  f_ifile = popen(pCmd, "r");
2837  if (f_ifile == NULL)
2838  {
2839  fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
2840  return(NULL);
2841  }
2842  if (iDebug)
2843  fprintf(fLogFile, " %s: pipe opened\n", cModule);
2844 
2845  if ( !(pBuf0 = (char *) malloc(BUFSIZE)) )
2846  {
2847  fprintf(fLogFile, "-E- %s: allocation buffer failed\n", cModule);
2848  pclose(f_ifile);
2849  return(NULL);
2850  }
2851  if (iDebug)
2852  fprintf(fLogFile, " %s: buffer allocated\n", cModule);
2853 
2854  pBuf = pBuf0;
2855  lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
2856  if (lr <= 0)
2857  {
2858  fprintf(fLogFile, "-E- %s: reading from pipe failed\n", cModule);
2859  pclose(f_ifile);
2860  return(NULL);
2861  }
2862 
2863  pBuf += (lr-1);
2864  strncpy(pBuf, "\0", 1); /* overwrite newline character */
2865 
2866  pclose(f_ifile);
2867 
2868  if (iDebug) fprintf(fLogFile,"-D- %s: user name (%u bytes): %s\n", cModule, lr, pBuf0);
2869 
2870  return(pBuf0);
2871 
2872 } /* rawGetUserid */
int rawGetFileList(char *pcFile, int iAccept, int iEntryLoop, char **ppFileList)
Definition: rawProcUn.c:2097
int rawGetDirEntryList(char *pcDirName, char *pcEntryMask, int iEntryType, int iEntryLoop, int iPrefixDir, char **ppFileList, char **ppDirList)
Definition: rawProcUn.c:179
int rawGetFSfree(char *pcStageFS)
Definition: rawProcUn.c:1640
int rawGetRecEntryList(char *pcDirName, char *pcEntryMask, int iEntryType, int iMaxFiles, char **ppFileList, int iMaxDirs, char **ppDirList)
Definition: rawProcUn.c:748
int rawGetHostConn()
Definition: rawProcUn.c:2492
char * rawGetUserid()
Definition: rawProcUn.c:2823
int rawGetFSSpace(char *pcFileSystem, int *piSizeAll, int *piSizeAvail, int *piNodeAll, int *piNodeAvail)
Definition: rawProcUn.c:1793
static int iFileList
Definition: rawProcUn.c:109
int rawGetFSEntries(char *pcStageFS)
Definition: rawProcUn.c:1583
FILE * fLogFile
Definition: rawapin.c:217
int rawGetBaseDir(char *pcVarDir, char *pcBaseDir)
Definition: rawProcUn.c:2674
int rawGetFileAttr(char *pcFile, unsigned long *plFileSize)
Definition: rawProcUn.c:1890
#define BUFSIZE_SMALL
Definition: rawProcUn.c:111
int rawGetDirEntries(char *pcStageFS)
Definition: rawProcUn.c:121
#define MAX_NODE
Definition: rawcommn.h:295
#define MAX_FILE_NO
Definition: rawcommn.h:287
#define MAX_FILE_SIZE
Definition: rawcommn.h:281
#define MAX_FULL_FILE
Definition: rawcommn.h:327
static const char * pcQM
Definition: rawdefn.h:65
static const char * pcPerc
Definition: rawdefn.h:66
static const char * pcStar
Definition: rawdefn.h:64
#define BUFSIZE
Definition: rawdefn.h:29
#define CMDLEN
Definition: rawdefn.h:28
int rawTestFileName(char *)
Definition: rawProcn.c:2659
char cFile[MAX_FULL_FILE]
Definition: rawcommn.h:483