GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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  * rawGetFSEntries: get number of entries in FS (via scandir)
15  * rawGetFSfree: get free space in specified filesystem (via ls)
16  * rawGetFSSpace: get space statistics of file system (via statfs)
17  * rawGetFileAttr: get file attributes
18  * rawGetFileList: get/enhance file list from generic input
19  * rawGetHostConn: get network connection type of client host
20  * rawGetUserid: get user identification
21  *********************************************************************
22  * 4. 2.1998, H.G.: new entry rawGetFSfree
23  * 6. 2.1998, H.G.: rawGetFSfree: ex shell-cmd via system()
24  * 13. 4.1999, H.G.: mod. declaration of rawGetFileAttr
25  * 22. 2.2000, H.G.: rawGetFileAttr: fix occurence of pipe message:
26  * '\nYour .kshrc is not executable!'
27  * 28. 7.2000, H.G.: rawGetFileList: ls -pdL -> ls
28  * 18. 6.2001, H.G.: rawGetFileList: check upper case in names
29  * 21. 6.2001, H.G.: rawGetFileList: control acceptance of upper case
30  * 31.10.2001, H.G.: rawGetFSfree added
31  * 26. 2.2002, H.G.: rawGetFSSpace added
32  * 6. 6.2002, H.G.: rawGetDirEntries, rawGetFSEntries added
33  * 29.10.2002, H.G.: rawGetFileList: MAX_FILE_NO -> MAX_STAGE_FILE_NO
34  * 31. 1.2003, H.G.: use rawdefn.h
35  * 25. 6.2003, H.G.: handle offset of old files in filelist
36  * rename rawGetFilelist -> rawGetFileList
37  * 9. 7.2003, H.G.: rawGetFileList: ignore directories
38  * 16. 7.2003, H.G.: rawGetFileList: avoid duplicate file names
39  * 6. 8.2004, H.G.: ported to Lynx
40  * 1. 2.2005, H.G.: ported to Linux and gcc322
41  * 2. 2.2007, H.G.: two steps for char ptr increments (gcc 3.3.5)
42  * 9. 5.2008, H.G.: remove (client header) file rawclin.h
43  * 22. 9.2008, H.G.: rawGetFileList: suppress subdir contents
44  * 12.11.2008, H.G.: add suggestions of Hakan
45  * 10. 2.2009, H.G.: rawGetFileList: don't stop scan if ls output
46  * buffer starts with '\n'
47  * 11. 2.2009, H.G.: rawGetFileList: stop scanning subdirs
48  * DDD for recursive filelist: remove stop + ident files
49  * 22. 6.2008, H.G.: replace long->int if 64bit client (ifdef SYSTEM64)
50  * 3. 9.2009, H.G.: rawGetFileList: MAX_STAGE_FILE_NO -> MAX_FILE_NO
51  * 29. 1.2010, H.G.: rawGetFileList, cBuf: MAX_FILE -> MAX_FULL_FILE
52  * rawGetFSfree, cTempFile: 128 -> MAX_FULL_FILE
53  * 24. 6.2010, H.G.: new entry rawGetDirEntryList
54  * 12. 8.2010, H.G.: rawGetDirEntryList: increase filelist, if too small
55  * 16. 8.2010, H.G.: rawGetDirEntryList: handle (xfs) filesystems
56  * providing entry type "DT_UNKNOWN"
57  * 23. 8.2010, H.G.: rawGetFileAttr, rawGetFileList:
58  * remove SYSTEM64 (allow "long")
59  * rawGetUserid: lr: long -> int
60  * 5.11.2010, H.G.: replace perror by strerror(errno),
61  * reset errno after error
62  * 26.11.2010, H.G.: rawGetFileAttr, rawGetFileList:
63  * reset errno after successful!! pclose
64  *********************************************************************
65  */
66 
67 #include <stdio.h>
68 #include <string.h>
69 #include <unistd.h>
70 #include <ctype.h>
71 #include <stdlib.h>
72 #include <time.h>
73 #include <errno.h>
74 #include <fnmatch.h>
75 
76 #ifndef Lynx
77 #include <sys/types.h>
78 #include <sys/statfs.h>
79 #include <sys/stat.h>
80 #include <sys/dir.h>
81 #endif
82 
83 #include "rawcommn.h"
84 #include "rawdefn.h"
85 #include "rawentn.h"
86 
87 extern FILE *fLogFile;
88 
89 static int iFileList = sizeof(srawFileList);
90 
91 #define BUFSIZE_SMALL 80
92 
93 #ifndef Lynx
94 /********************************************************************
95  * rawGetDirEntries:
96  * get number of entries in file system (via opendir/readdir)
97  *
98  * created 6. 6.2002, Horst Goeringer
99  ********************************************************************/
100 
101 int rawGetDirEntries(char *pcStageFS)
102 {
103  char cModule[32]="rawGetDirEntries";
104  int iDebug = 0;
105 
106  int iRC;
107  int iEntries = 0;
108 
109  DIR *pDir;
110  struct dirent *pEntry;
111 
112  if (iDebug) fprintf(fLogFile,
113  "\n-D- begin %s: FS %s\n", cModule, pcStageFS);
114 
115  pDir = opendir(pcStageFS);
116  if (pDir == NULL)
117  {
118  fprintf(fLogFile,
119  "-E- %s: cannot open directory %s\n", cModule, pcStageFS);
120  if (errno)
121  {
122  fprintf(fLogFile, " %s\n", strerror(errno));
123  errno = 0;
124  }
125 
126  return -1;
127  }
128 
129  while ( (pEntry = readdir(pDir)) != NULL)
130  {
131  if ( (strcmp(pEntry->d_name, ".") == 0) ||
132  (strcmp(pEntry->d_name, "..") == 0) )
133  continue;
134 
135  iEntries++;
136 
137  if (iDebug)
138  fprintf(fLogFile, " %d: %s\n", iEntries, pEntry->d_name);
139  }
140 
141  iRC = closedir(pDir);
142 
143  if (iDebug)
144  fprintf(fLogFile, " rc(closedir) = %d\n-D- end %s\n\n", iRC, cModule);
145 
146  return(iEntries);
147 
148 } /* rawGetDirEntries */
149 #endif
150 
151 #ifndef Lynx
152 /*********************************************************************
153  * rawGetDirEntryList:
154  * get/enhance list of matching entries in file system
155  * created 23.6.2010, Horst Goeringer
156  *********************************************************************
157  */
158 
160  char *pcDirName,
161  char *pcEntryMask, /* entry name mask */
162  int iEntryType,
163  /* = 0: all entries (in FileList)
164  = 1: all files (in FileList)
165  = 2: all subdirectories (in DirList)
166  =10: all entries, but files only if matching with mask
167  =11: all files, but only if matching with mask
168  =12: all subdirs, but only if matching with mask */
169  int iEntryLoop, /* = 1: in loop, append new entries
170  = 2: recursive, append new entries */
171  int iPrefixDir, /* = 1: prefix files in list with cur path */
172  char **ppFileList, /* ptr to entry list ptr */
173  char **ppDirList) /* ptr to dir list ptr */
174 {
175  char cModule[32] = "rawGetDirEntryList";
176  int iDebug = 0; /* =1: verbose, =2: entry details */
177  int iRC = 0;
178  int iRCE = 0;
179  int ilen, iloc, ii, jj;
180  char cTemp[MAX_FULL_FILE] = "";
181 
182  int iTypeFound = 0;
183  /* keep entry type, if DT_UNKNOWN (xfs): =1: reg file, =2: dir */
184  char cEntryType[32] = "";
185  int iEntries = 0; /* no. of entries in specified file system */
186  int iEntriesMatch = 0; /* no. of matching entries in specified FS */
187 
188  int iFileEntryMax = 0; /* max. no. of file names in buffer */
189  int iFileEntryRem = 0; /* remaining no. of file names in buffer */
190  int iFileEntries = 0;
191  int iFileEntriesOld = 0;
192  int iFileEntriesNew = 0;
193  int *piFileNo; /* points to no. of entries in file list */
194  int *piFileList; /* points to first file name */
195  srawFileList *psFileList; /* points to current file name */
196  srawFileList *psFileList0; /* points to first file name */
197 
198  char *pcFileList2;
199  int *piFileList2; /* points to first file in reallocated filelist */
200 
201  int iDirEntryMax = 0; /* max. no. of subdir names in buffer */
202  int iDirEntryRem = 0; /* remaining no. of subdir names in buffer */
203  int iDirEntries = 0;
204  int iDirEntriesOld = 0;
205  int iDirEntriesNew = 0;
206  int *piDirNo; /* points to no. of subdirs in entrylist */
207  int *piDirList; /* points to first subdir name */
208  srawFileList *psDirList; /* points to current subdir name */
209  srawFileList *psDirList0; /* points to first subdir name */
210 
211  int iMatch = 0; /* = 1: handle only entries matching with mask */
212  int iStore = 0; /* =1: cur entry will be stored in list */
213  int iCheck = 0; /* =1: cur entry must be compared with mask */
214 
215  DIR *pDir;
216  struct dirent *pEntry;
217 
218  struct stat sEntryStatus, *pEntryStatus;
219 
220  if (iDebug)
221  fprintf(fLogFile, "\n-D- begin %s\n", cModule);
222 
223  pEntryStatus = &sEntryStatus;
224 
225  if (strlen(pcDirName) <= 0)
226  {
227  fprintf(fLogFile, "-E- %s: empty directory name\n", cModule);
228 
229  iRCE = -1;
230  goto gEndDirEntryList;
231  }
232 
233  if (iEntryType >= 10)
234  {
235  if (strlen(pcEntryMask) <= 0)
236  {
237  fprintf(fLogFile,
238  "-E- %s: empty mask for entry name\n", cModule);
239 
240  iRCE = -1;
241  goto gEndDirEntryList;
242  }
243 
244  iEntryType -= 10;
245 
246  if (strcmp(pcEntryMask, "*") != 0)
247  iMatch = 1;
248  }
249 
250  if (iEntryType == 0)
251  strcpy(cEntryType, "entries");
252  else if (iEntryType == 1)
253  strcpy(cEntryType, "files");
254  else if (iEntryType == 2)
255  strcpy(cEntryType, "subdirs");
256  else
257  {
258  fprintf(fLogFile,
259  "-E- %s: invalid EntryType %d (allowed 0-2, 10-12)\n",
260  cModule, iEntryType);
261 
262  iRCE = -1;
263  goto gEndDirEntryList;
264  }
265 
266  /* handle files */
267  if ( (iEntryType == 0) || (iEntryType == 1) )
268  {
269  if (ppFileList == NULL)
270  {
271  fprintf(fLogFile,
272  "-E- %s: invalid pointer for entry list\n", cModule);
273 
274  iRCE = -1;
275  goto gEndDirEntryList;
276  }
277 
278  piFileNo = (int *) *ppFileList;
279  piFileList = piFileNo;
280  iFileEntriesOld = *piFileNo;
281 
282  if (iEntryLoop)
283  {
284  if (iDebug)
285  {
286  if (iFileEntriesOld) fprintf(fLogFile,
287  " %d files already available in list:\n",
288  iFileEntriesOld);
289  else fprintf(fLogFile,
290  " still no files in list\n");
291  if (iEntryLoop == 2)
292  fprintf(fLogFile, " recursive file handling\n");
293  }
294  }
295  else
296  {
297  if (iFileEntriesOld) fprintf(fLogFile,
298  "-W- %s: no entry loop, but %d files already available in list\n",
299  cModule, iFileEntriesOld);
300  }
301 
302  piFileList++;
303  psFileList = (srawFileList *) piFileList;
304  psFileList0 = psFileList;
305 
306  if (iDebug)
307  {
308  if (iFileEntriesOld)
309  {
310  fprintf(fLogFile, "old files:\n");
311  for (ii=1; ii<=iFileEntriesOld; ii++)
312  {
313  fprintf(fLogFile, " %d: %s\n", ii, psFileList->cFile);
314  psFileList++;
315  }
316  }
317  }
318  else
319  psFileList += iFileEntriesOld;
320 
321  iFileEntries = iFileEntriesOld;
322  iFileEntryMax = MAX_FILE_NO;
323  /* iFileEntryMax = 2; DDDMax */
324 
325  /* already add. space allocated */
326  if (iFileEntriesOld > iFileEntryMax)
327  {
328  ii = iFileEntriesOld / iFileEntryMax;
329  ii++;
330  iFileEntryMax *= ii;
331  }
332  iFileEntryRem = iFileEntryMax - iFileEntriesOld;
333 
334  if (iDebug) fprintf(fLogFile,
335  " space available for %d file entries (max %d)\n",
336  iFileEntryRem, iFileEntryMax);
337 
338  } /* (iEntryType == 0 || 1) */
339 
340  /* handle subdirectories */
341  if ( (iEntryType == 0) || (iEntryType == 2) )
342  {
343  if (ppDirList == NULL)
344  {
345  fprintf(fLogFile,
346  "-E- %s: invalid pointer for subdir list\n", cModule);
347 
348  iRCE = -1;
349  goto gEndDirEntryList;
350  }
351 
352  piDirNo = (int *) *ppDirList;
353  piDirList = piDirNo;
354  iDirEntriesOld = *piDirNo;
355 
356  if (iEntryLoop)
357  {
358  if (iDebug)
359  {
360  if (iDirEntriesOld) fprintf(fLogFile,
361  " %d subdirectories already available in list:\n",
362  iDirEntriesOld);
363  else fprintf(fLogFile,
364  " still no subdirectories in list\n");
365  }
366  }
367  else if (iDirEntriesOld) fprintf(fLogFile,
368  "-W- %s: no entry loop, but %d subdirectories available in list\n",
369  cModule, iDirEntriesOld);
370 
371  piDirList++;
372  psDirList = (srawFileList *) piDirList;
373  psDirList0 = psDirList;
374 
375  for (ii=1; ii<=iDirEntriesOld; ii++)
376  {
377  if (iDebug)
378  {
379  if (ii == 1)
380  fprintf(fLogFile, "previous subdirs:\n");
381  fprintf(fLogFile, " %d: %s\n", ii, psDirList->cFile);
382  }
383 
384  psDirList++;
385  }
386 
387  iDirEntries = iDirEntriesOld;
388  iDirEntryMax = MAX_FILE_NO;
389 
390  /* already add. space allocated */
391  if (iDirEntriesOld > iDirEntryMax)
392  {
393  ii = iDirEntriesOld / iDirEntryMax;
394  ii++;
395  iDirEntryMax *= ii;
396  }
397  iDirEntryRem = iDirEntryMax - iDirEntriesOld;
398 
399  if (iDebug) fprintf(fLogFile,
400  " space available for %d subdir entries (max %d)\n",
401  iDirEntryRem, iDirEntryMax);
402 
403  } /* (iEntryType == 0 || 2) */
404 
405  if (iDebug)
406  {
407  if ( (iEntryType == 0) && (iMatch) )
408  {
409  fprintf(fLogFile,
410  " provide all files matching with %s and all subdirs in directory %s\n",
411  pcEntryMask, pcDirName);
412  }
413  else
414  {
415  fprintf(fLogFile, " provide all %s", cEntryType);
416  if (iMatch) fprintf(fLogFile,
417  " matching with %s", pcEntryMask);
418  fprintf(fLogFile, " in directory %s\n", pcDirName);
419  }
420  }
421 
422  pDir = opendir(pcDirName);
423  if (pDir == NULL)
424  {
425  fprintf(fLogFile,
426  "-E- %s: cannot open directory %s\n", cModule, pcDirName);
427  if (errno)
428  {
429  fprintf(fLogFile, "%s\n", strerror(errno));
430  errno = 0;
431  }
432 
433  iRCE = -1;
434  goto gEndDirEntryList;
435  }
436 
437  while ( (pEntry = readdir(pDir)) != NULL)
438  {
439  if ( (strcmp(pEntry->d_name, ".") == 0) ||
440  (strcmp(pEntry->d_name, "..") == 0) )
441  continue;
442 
443  iEntries++;
444  iCheck = 0;
445  iStore = 0;
446 
447  /* for xfs */
448  if (pEntry->d_type == DT_UNKNOWN)
449  {
450  if ( (iEntries == 1) && (iDebug) ) fprintf(fLogFile,
451  " %s: of type DT_UNKNOWN (1st entry)\n",
452  pEntry->d_name);
453 
454  strcpy(cTemp, pcDirName);
455  strcat(cTemp, "/");
456  strcat(cTemp, pEntry->d_name);
457 
458  iRC = stat(cTemp, pEntryStatus);
459  if (iRC)
460  {
461  if (errno)
462  {
463  fprintf(fLogFile, "-E- stat %s: %s\n",
464  cTemp, strerror(errno));
465 
466  /* only valid for 32 bit OS */
467  if (strcmp(strerror(errno),
468  "Value too large for defined data type") == 0)
469  {
470  fprintf(fLogFile,
471  "-E- %s: filesize of %s > 2 GByte: use 64 bit gStore client\n",
472  cModule, cTemp);
473 
474  errno = 0;
475  return -99;
476  }
477  errno = 0;
478  }
479  else fprintf(fLogFile,
480  "-W- %s: entry %s unavailable\n", cModule, pEntry->d_name);
481 
482  continue;
483  }
484 
485  if (S_ISREG(pEntryStatus->st_mode))
486  iTypeFound = 1;
487  else if (S_ISDIR(pEntryStatus->st_mode))
488  iTypeFound = 2;
489  else
490  {
491  fprintf(fLogFile,
492  "-W- %s: entry %s neither file nor directory, ignored\n",
493  cModule, pEntry->d_name);
494 
495  continue;
496  }
497  } /* (pEntry->d_type == DT_UNKNOWN) */
498  else
499  iTypeFound = 0;
500 
501  /* check in which cases entry could be stored */
502  if ( (pEntry->d_type == DT_REG) || (iTypeFound == 1) )
503  {
504  if ( (iEntryType == 0) || (iEntryType == 1) )
505  {
506  if (iMatch)
507  iCheck = 1;
508  else
509  iStore = 1;
510  }
511  }
512  else if ( (pEntry->d_type == DT_DIR) || (iTypeFound == 2) )
513  {
514  if ( (iEntryType == 0) || (iEntryType == 2) )
515  {
516  if ( (iMatch) && (iEntryType == 2) )
517  iCheck = 1;
518  else
519  iStore = 1;
520  }
521  }
522 
523  if (iDebug == 2) fprintf(fLogFile,
524  " %d: entry %s (check %d, store %d, type %d) \n",
525  iEntries, pEntry->d_name, iCheck, iStore, pEntry->d_type);
526 
527  /* check if matching with input mask */
528  if (iCheck)
529  {
530  /* last arg FNM_FILE_NAME: not resolved! 0 seems okay */
531  if (fnmatch(pcEntryMask, pEntry->d_name, 0) == 0)
532  {
533  iStore = 1; /* match, store this entry */
534  iEntriesMatch++;
535  }
536  else
537  iStore = 0;
538  }
539 
540  if (iStore)
541  {
542  /* store new file names */
543  if ( (pEntry->d_type == DT_REG) ||
544  (pEntry->d_type == DT_UNKNOWN) )
545  {
546  if (iPrefixDir)
547  {
548  strcpy(psFileList->cFile, pcDirName);
549  strcat(psFileList->cFile, "/");
550  strcat(psFileList->cFile, pEntry->d_name);
551  }
552  else
553  strcpy(psFileList->cFile, pEntry->d_name);
554 
555  iFileEntries++;
556  iFileEntriesNew++;
557 
558  if (iDebug)
559  {
560  if (iFileEntriesNew == 1)
561  fprintf(fLogFile, "new files:\n");
562  fprintf(fLogFile, " %d(%d): %s\n",
563  iFileEntriesNew, iFileEntries, psFileList->cFile);
564  }
565 
566  if (iFileEntryRem <= 0)
567  {
568  /* if (iEntryLoop == 2)
569  {
570  fprintf(fLogFile,
571  "-W- recursive file search: max size of file list buffer reached (%d entries)\n",
572  iFileEntryMax);
573  goto gEndDirEntryClose;
574  }
575 
576  */ iFileEntryMax += MAX_FILE_NO;
577  /* iFileEntryMax += 2; DDDMax */
578 
579  ii = sizeof(int) + iFileEntryMax*iFileList;
580  if ((pcFileList2 = (char *) calloc((unsigned) ii, 1)) == NULL)
581  {
582  fprintf(fLogFile,
583  "-E- %s: allocating new filelist buffer (%d byte, %d entries)\n",
584  cModule, ii, iFileEntryMax);
585  if (errno)
586  {
587  fprintf(fLogFile, " %s\n", strerror(errno));
588  errno = 0;
589  }
590 
591  iRCE = -1;
592  goto gEndDirEntryList;
593  }
594 
595  if (iDebug) fprintf(fLogFile,
596  " new filelist buffer allocated (%d byte, %d entries)\n",
597  ii, iFileEntryMax);
598 
599  iFileEntryRem = iFileEntryMax - iFileEntries;
600  piFileList2 = (int *) pcFileList2;
601  *piFileList2 = iFileEntries;
602  *ppFileList = (char *) piFileList2;
603  piFileList2++;
604 
605  ii = iFileEntries*iFileList;
606  memcpy(piFileList2, piFileList, ii);
607 
608  psFileList = (srawFileList *) piFileList2;
609  psFileList0 = psFileList;
610 
611  if (iDebug) fprintf(fLogFile,
612  " %d filelist entries copied, first %s\n",
613  iFileEntries, psFileList->cFile);
614  fflush(fLogFile);
615 
616  psFileList += iFileEntries;
617  piFileList = piFileList2;
618  piFileList2--;
619  piFileNo = piFileList2;
620 
621  } /* (iFileEntryRem <= 0) */
622  else
623  psFileList++;
624 
625  iFileEntryRem--;
626 
627  } /* files */
628 
629  /* store new subdirectory names */
630  if (pEntry->d_type == DT_DIR)
631  {
632  strcpy(psDirList->cFile, pEntry->d_name);
633  iDirEntries++;
634  iDirEntriesNew++;
635  iDirEntryRem--;
636 
637  if (iDebug)
638  {
639  if (iDirEntriesNew == 1)
640  fprintf(fLogFile, "new subdirs:\n");
641  fprintf(fLogFile, " %d(%d): %s\n",
642  iDirEntriesNew, iDirEntries, psDirList->cFile);
643  }
644 
645  if (iDirEntryRem <= 0)
646  {
647  fprintf(fLogFile, "DDD2 new space must be allocated\n");
648  }
649 
650  psDirList++;
651 
652  } /* subdirs */
653  } /* current entry matches and is of requested type */
654  }
655 
656 gEndDirEntryClose:
657  iRC = closedir(pDir);
658 
659  if (iDebug)
660  fprintf(fLogFile, " rc(closedir) = %d\n", iRC);
661 
662  if ( (iDebug) || (iEntryLoop != 2) ) /* if recursive only if debug */
663  {
664  fprintf(fLogFile,
665  " %d entries in directory %s found\n",
666  iEntries, pcDirName);
667  if (iMatch) fprintf(fLogFile,
668  " %d matching with %s\n", iEntriesMatch, pcEntryMask);
669  }
670 
671  if (iDebug)
672  {
673  if (iFileEntries) fprintf(fLogFile,
674  " thereof %d files (%d new)\n",
675  iFileEntries, iFileEntriesNew);
676  if (iDirEntries) fprintf(fLogFile,
677  " thereof %d subdirectories (%d new)\n",
678  iDirEntries, iDirEntriesNew);
679  }
680 
681  if ( (iEntryType == 0) || (iEntryType == 1) )
682  *piFileNo = iFileEntries;
683  if ( (iEntryType == 0) || (iEntryType == 2) )
684  *piDirNo = iDirEntries;
685 
686  if (iDebug)
687  {
688  if (iFileEntries) fprintf(fLogFile,
689  " %d files provided in list, first %s\n",
690  iFileEntries, psFileList0->cFile);
691  else if ( (iEntryType == 0) || (iEntryType == 1) )
692  {
693  fprintf(fLogFile, " no files in %s found",
694  pcDirName);
695  if (iMatch) fprintf(fLogFile,
696  " matching with %s\n", pcEntryMask);
697  else
698  fprintf(fLogFile, "\n");
699  }
700 
701  if (iDirEntries) fprintf(fLogFile,
702  " %d subdirs provided in list, first %s\n",
703  iDirEntries, psDirList0->cFile);
704  else if ( (iEntryType == 0) || (iEntryType == 2) )
705  {
706  fprintf(fLogFile, " no subdirs in %s found",
707  pcDirName);
708  if ( (iMatch) && (iEntryType == 2) ) fprintf(fLogFile,
709  " matching with %s\n", pcEntryMask);
710  else
711  fprintf(fLogFile, "\n");
712  }
713  }
714 
715 gEndDirEntryList:
716 
717  if (iDebug)
718  fprintf(fLogFile, "\n-D- end %s\n\n", cModule);
719 
720  if (iRCE)
721  return iRCE;
722 
723  if (iMatch)
724  return iEntriesMatch;
725  return iEntries;
726 
727 } /* rawGetDirEntryList */
728 #endif
729 
730 #ifndef Lynx
731 /********************************************************************
732  * rawGetFSEntries:
733  * get number of entries in file system (via scandir)
734  *
735  * created 6. 6.2002, Horst Goeringer
736  ********************************************************************/
737 
738 int rawGetFSEntries(char *pcStageFS)
739  /* struct dirent *(fEntryList[]) */
740 {
741  char cModule[32]="rawGetFSEntries";
742  int iDebug = 0;
743 
744  int iRC;
745  int ii = 0;
746 
747  int iEntries = 0;
748  struct dirent **fEntryList;
749 
750  if (iDebug) fprintf(fLogFile,
751  "\n-D- begin %s: FS %s\n", cModule, pcStageFS);
752 
753  iRC = scandir(pcStageFS, &fEntryList, NULL, NULL);
754  if (iRC < 0 )
755  {
756  fprintf(fLogFile,
757  "-E- %s: calling system function scandir, rc=%d\n",
758  cModule, iRC);
759  if (errno)
760  {
761  fprintf(fLogFile, " %s\n", strerror(errno));
762  errno = 0;
763  }
764 
765  return -1;
766  }
767 
768  iEntries = 0;
769  for (ii=0; ii<iRC; ii++)
770  {
771  if (iDebug) fprintf(fLogFile,
772  " %d: %s\n", ii, fEntryList[ii]->d_name);
773 
774  if ( (strcmp(fEntryList[ii]->d_name, ".") == 0) ||
775  (strcmp(fEntryList[ii]->d_name, "..") == 0) )
776  continue;
777 
778  iEntries++;
779  }
780 
781  if (iDebug)
782  fprintf(fLogFile, "-D- end %s\n\n", cModule);
783 
784  return(iEntries);
785 
786 } /* rawGetFSEntries*/
787 #endif
788 
789 /********************************************************************
790  * rawGetFSfree: get free space (bytes) in specified filesystem
791  *
792  * created 4.2.98, Horst Goeringer
793  ********************************************************************/
794 
795 int rawGetFSfree(char *pcStageFS)
796 {
797  char cModule[32]="rawGetFSfree";
798  int iDebug = 0;
799 
800  int iRC;
801  unsigned int itemsize, itemno;
802  int iFree = 0;
803 
804  FILE *fPipe;
805  int iBuf;
806  char cName[BUFSIZE_SMALL] = "", *pName;
807  char cBuf[BUFSIZE_SMALL] = "", *pBuf;
808  char cTempFile[MAX_FULL_FILE] = "";
809  char cCmd[256] = "/home/rawserv/rawdf.sh ";
810 
811  time_t tTime;
812  pid_t pstr;
813 
814  pBuf = &cBuf[0];
815  pName = &cName[0];
816  strcpy(cTempFile, pcStageFS);
817 
818  tTime = time(NULL);
819  pstr = getpid();
820  sprintf(cName, "/size.t%d.p%d", (int) tTime, pstr);
821  strcat(cTempFile, pName);
822 
823  strcat(cCmd, pcStageFS);
824  strcat(cCmd, " ");
825  strcat(cCmd, cTempFile);
826 
827  if (iDebug)
828  fprintf(fLogFile, "\n-D- begin %s: execute\n '%s'\n",
829  cModule, cCmd);
830 
831  if (system(NULL))
832  {
833  iRC = system(cCmd);
834  if (iRC)
835  {
836  fprintf(fLogFile, "-W- %s: system() failed, rc = %d\n",
837  cModule, iRC);
838  return -1;
839  }
840  else
841  {
842  if (iDebug)
843  fprintf(fLogFile,
844  " shell command successfully executed\n");
845  }
846  }
847  else
848  {
849  fprintf(fLogFile, "-W- %s: system() not available\n",
850  cModule);
851  return -1;
852  }
853 
854  fPipe = NULL;
855  fPipe = fopen(cTempFile, "r");
856  if (fPipe == NULL)
857  {
858  fprintf(fLogFile, "-E- %s: opening file %s\n",
859  cModule, cTempFile);
860  if (errno)
861  {
862  fprintf(fLogFile, " %s\n", strerror(errno));
863  errno = 0;
864  }
865 
866  return -1;
867  }
868 
869  if (iDebug)
870  fprintf(fLogFile, " file %s opened\n", cTempFile);
871 
872  itemsize = sizeof(char);
873  itemno = BUFSIZE_SMALL;
874  iBuf = fread(pBuf, itemsize, itemno, fPipe);
875  if (iBuf <= 0)
876  {
877  fprintf(fLogFile, "-E- %s: fread, rc = %d\n", cModule, iBuf);
878  if (errno)
879  {
880  fprintf(fLogFile, " %s\n", strerror(errno));
881  errno = 0;
882  }
883 
884  fprintf(fLogFile, " NO status buffer sent\n");
885 
886  } /* (iBuf <= 0) */
887  else
888  {
889  iFree = atoi(pBuf);
890  if (iDebug)
891  {
892  fprintf(fLogFile, " %d bytes in file: %s", iBuf, pBuf);
893  fprintf(fLogFile, " free kB: %d\n", iFree);
894  }
895  }
896 
897  iRC = fclose(fPipe);
898  if (iRC)
899  {
900  fprintf(fLogFile, "-E- %s: rc = %d closing file\n",
901  cModule, iRC);
902  if (errno)
903  {
904  fprintf(fLogFile, " %s\n", strerror(errno));
905  errno = 0;
906  }
907 
908  return(-1);
909  }
910 
911  if (iDebug)
912  fprintf(fLogFile, " file %s closed\n", cTempFile);
913 
914  iRC = remove(cTempFile);
915  if (iRC)
916  {
917  fprintf(fLogFile, "-E- %s: rc = %d removing file %s\n",
918  cModule, iRC, cTempFile);
919  if (errno)
920  {
921  fprintf(fLogFile, " %s\n", strerror(errno));
922  errno = 0;
923  }
924 
925  return -1;
926  }
927  if (iDebug)
928  fprintf(fLogFile, " file %s removed\n", cTempFile);
929 
930  if (iDebug)
931  fprintf(fLogFile, "-D- end %s\n\n", cModule);
932 
933  if (iBuf <= 0)
934  return -1;
935  else
936  return(iFree);
937 
938 } /* rawGetFSfree */
939 
940 #ifndef Lynx
941 /**********************************************************************
942  * rawGetFSSpace
943  * get file size (bytes)
944  * created 19.2.2002, Horst Goeringer
945  **********************************************************************
946  */
947 
948 int rawGetFSSpace(char *pcFileSystem,
949  int *piSizeAll,
950  int *piSizeAvail,
951  int *piNodeAll,
952  int *piNodeAvail)
953 {
954  char cModule[32] = "rawGetFSSpace";
955  int iDebug = 0;
956 
957  int iRC;
958  int iBlockSize = 4; /* kB */
959  int iSizeAll = 0;
960  int iSizeFree = 0;
961  int iSizeAvail = 0;
962  int iNodeAll = 0;
963  int iNodeAvail = 0;
964 
965  struct statfs sFSstatus, *pFSstatus;
966 
967  if (iDebug) fprintf(fLogFile,
968  "\n-D- begin %s: FS %s\n", cModule, pcFileSystem);
969 
970  pFSstatus = &sFSstatus;
971 
972  iRC = statfs(pcFileSystem, pFSstatus);
973  if (iRC)
974  {
975  fprintf(fLogFile,
976  "-E- %s: calling system function statfs, rc=%d\n",
977  cModule, iRC);
978  if (errno)
979  {
980  fprintf(fLogFile, " %s\n", strerror(errno));
981  errno = 0;
982  }
983 
984  return -1;
985  }
986 
987  iBlockSize = (int) pFSstatus->f_bsize;
988  if (iBlockSize == 0)
989  {
990  fprintf(fLogFile,
991  "-W- unexpected blocksize found: 0 byte\n");
992  return 1;
993  }
994  else
995  {
996  if (iDebug) fprintf(fLogFile,
997  " blocksize found %d byte\n", iBlockSize);
998  if (iBlockSize >= 1024)
999  iBlockSize /= 1024;
1000  else
1001  {
1002  fprintf(fLogFile,
1003  "-W- unexpected blocksize found: %d byte\n", iBlockSize);
1004  return 1;
1005  }
1006  }
1007 
1008  /* convert to MByte */
1009  iSizeAll = (int) (pFSstatus->f_blocks/1000)*iBlockSize;
1010  iSizeFree = (int) (pFSstatus->f_bfree/1000)*iBlockSize;
1011  iSizeAvail = (int) (pFSstatus->f_bavail/1000)*iBlockSize;
1012 
1013  iNodeAll = (int) pFSstatus->f_files;
1014  iNodeAvail = (int) pFSstatus->f_ffree;
1015 
1016  if (iDebug)
1017  {
1018  fprintf(fLogFile,
1019  " overall space %d MB, free %d MB, available %d MB\n",
1020  iSizeAll, iSizeFree, iSizeAvail);
1021  fprintf(fLogFile,
1022  " overall file nodes %d, available %d\n",
1023  iNodeAll, iNodeAvail);
1024  }
1025 
1026  *piSizeAll = iSizeAll;
1027  *piSizeAvail = iSizeAvail;
1028  *piNodeAll = iNodeAll;
1029  *piNodeAvail = iNodeAvail;
1030 
1031  if (iDebug)
1032  fprintf(fLogFile, "-D- end %s\n\n", cModule);
1033 
1034  return 0;
1035 
1036 } /* rawGetFSSpace */
1037 #endif
1038 
1039 /**********************************************************************/
1040 /* rawGetFileAttr: get file attributes (size in bytes) */
1041 /* utilize shell command output via pipes */
1042 /* created 17.4.96, Horst Goeringer */
1043 /**********************************************************************/
1044 
1045 int rawGetFileAttr(char *pcFile, unsigned long *plFileSize)
1046 {
1047  char cModule[32] = "rawGetFileAttr";
1048  int iDebug = 0;
1049 
1050  FILE *f_ifile;
1051  int iRC;
1052  unsigned long lFileSize;
1053  unsigned long lr;
1054  int iReclen;
1055 
1056  int ilocSize = 5; /* token no. 5 contains file size */
1057  int ilocFile = 9; /* token no. 9 contains file name (check) */
1058  int ii, ilen, iloc;
1059 
1060  char cCmd[CMDLEN] = "ls -l ";
1061  char *pCmd;
1062  const char *pType = "r";
1063  char *pBuf, *pBuf0;
1064  const char *pcDollar = "$"; /* requ. spec. treatment in file name */
1065  char *pcc, *ploc;
1066 
1067  char *pctoken;
1068  const char *pcblank = " ";
1069  /* char ctoken[20]; */
1070  int icount = 0;
1071 
1072 /******************** end of declarations *****************/
1073 
1074  if (iDebug)
1075  {
1076  fprintf(fLogFile,
1077  "\n-D- begin %s: file %s\n", cModule, pcFile);
1078  fflush(fLogFile);
1079  }
1080 
1081  iReclen = 0; /* not available in Unix system */
1082 
1083  /* treat $ in file name */
1084  ploc = strchr(pcFile, *pcDollar);
1085  if (ploc != NULL)
1086  {
1087  if (iDebug)
1088  {
1089  fprintf(fLogFile, "-D- $ in file name found: %s\n", pcFile);
1090  fflush(fLogFile);
1091  }
1092  ilen = strlen(pcFile);
1093  pcc = pcFile;
1094  for (ii = 1; ii <= ilen; ii++)
1095  {
1096  iloc = strncmp(pcc, pcDollar, 1);
1097  if (iloc == 0) strcat(cCmd, "\\"); /* $ found */
1098  strncat(cCmd, pcc++, 1);
1099  }
1100  } /* ploc != NULL, $ in file name */
1101  else strcat(cCmd, pcFile);
1102 
1103  if (iDebug)
1104  {
1105  fprintf(fLogFile, "-D- %s: ex '%s'\n", cModule, cCmd);
1106  fflush(fLogFile);
1107  }
1108 
1109  pCmd = &cCmd[0];
1110  f_ifile = popen(pCmd, pType);
1111  if (f_ifile == NULL)
1112  {
1113  fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
1114  return -1;
1115  }
1116  if (iDebug)
1117  {
1118  fprintf(fLogFile, " %s: pipe opened\n", cModule);
1119  fflush(fLogFile);
1120  }
1121 
1122  if ( !(pBuf0 = (char *) malloc(BUFSIZE)) )
1123  {
1124  fprintf(fLogFile, "-E- %s: allocation buffer failed\n", cModule);
1125  pclose(f_ifile);
1126  return(-1);
1127  }
1128  if (iDebug)
1129  {
1130  fprintf(fLogFile, " %s: buffer allocated\n", cModule);
1131  fflush(fLogFile);
1132  }
1133 
1134  pBuf = pBuf0;
1135  lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
1136  if (lr <= 0)
1137  {
1138  fprintf(fLogFile, "-E- %s: reading from pipe failed\n", cModule);
1139  pclose(f_ifile);
1140  return(-1);
1141  }
1142 
1143  pBuf += (lr-1);
1144  strncpy(pBuf, "\0", 1); /* overwrite newline character */
1145 
1146  if (iDebug)
1147  {
1148  fprintf(fLogFile, " %s: complete string: (%lu bytes): \n%s\n",
1149  cModule, lr, pBuf0);
1150  fflush(fLogFile);
1151  }
1152 
1153  pBuf = pBuf0;
1154  while ( (pctoken = strtok(pBuf, pcblank)) != NULL)
1155  {
1156  icount++;
1157  if (iDebug)
1158  {
1159  fprintf(fLogFile, " token %d: %s\n", icount, pctoken);
1160  fflush(fLogFile);
1161  }
1162 
1163  if (icount == 2)
1164  {
1165  /* check for leading string:
1166  '\nYour .kshrc is not executable!' */
1167  iRC = strcmp(pctoken, ".kshrc");
1168  if (iRC == 0)
1169  {
1170  fprintf(fLogFile, " %s: token %d: %s found\n",
1171  cModule, icount, pctoken);
1172  ilocSize += 4;
1173  ilocFile += 4;
1174  }
1175  }
1176 
1177  if (icount == ilocSize)
1178  {
1179  /* test large file size DDD
1180  strcpy(ctoken, "2000000000");
1181  pctoken = &ctoken;
1182  */
1183  if ( ( iRC = sscanf( pctoken, "%lu", &lFileSize) ) <= 0 )
1184  {
1185  fprintf(fLogFile, "-E- %s: filesize %lu (%s) invalid\n",
1186  cModule, lFileSize, pctoken);
1187  if (errno)
1188  {
1189  fprintf(fLogFile, " %s\n", strerror(errno));
1190  errno = 0;
1191  }
1192  pclose(f_ifile);
1193 
1194  return(-1);
1195  }
1196  if (iDebug)
1197  {
1198  fprintf(fLogFile, " file size %lu\n", lFileSize);
1199  fflush(fLogFile);
1200  }
1201 
1202  if ( (lFileSize == 0) && (iDebug) )
1203  fprintf(fLogFile, " file %s empty\n", pcFile);
1204 
1205  if (lFileSize > MAX_FILE_SIZE)
1206  {
1207  fprintf(fLogFile,
1208  "-E- %s: file %s too large (%lu byte), max allowed 2GB -1\n",
1209  cModule, pcFile, lFileSize);
1210  pclose(f_ifile);
1211  return(-1);
1212  }
1213  }
1214 
1215  if (icount == ilocFile)
1216  {
1217  if ( (iRC = strcmp(pctoken, pcFile) ) != 0)
1218  {
1219  fprintf(fLogFile,
1220  "-E- %s: file name check: %s\n", cModule, pctoken);
1221  pclose(f_ifile);
1222  return(-1);
1223  }
1224  }
1225 
1226  pBuf = NULL;
1227 
1228  } /* while ... */
1229 
1230  pclose(f_ifile);
1231 
1232  /* pclose provides "No child processes" only if iRC=0 */
1233  if (errno)
1234  errno = 0;
1235 
1236  *plFileSize = lFileSize;
1237  if (iDebug)
1238  {
1239  fprintf(fLogFile, "-D- end %s\n\n", cModule);
1240  fflush(fLogFile);
1241  }
1242 
1243  return 0;
1244 
1245 } /* rawGetFileAttr */
1246 
1247 /**********************************************************************/
1248 /* rawGetFileList: execute shell cmd ls and get file list vector */
1249 /* created 19.2.96, Horst Goeringer */
1250 /**********************************************************************/
1251 
1252 int rawGetFileList( char *pcFile,
1253  int iAccept, /* = 0: only lower case files
1254  = 1: also upper case files
1255  = 2: also directories */
1256  int iEntryLoop,
1257  char **ppFileList)
1258 {
1259  char cModule[32] = "rawGetFileList";
1260  int iDebug = 0;
1261 
1262  int iRC = 0;
1263  int iRCE = 0;
1264  int iIgnore = 0; /* =1: new file already in list */
1265  int ilen, iloc, ii, jj;
1266  int ird, ipc, ipc1, irem, grem = 0;
1267  int iFileno, iFilenoo;
1268  int *piFileno; /* points to no. of files in filelist */
1269  int *piFileList; /* points to first file in filelist */
1270 
1271  char *pcc, *pcc0, *ploc;
1272  unsigned long lr;
1273 
1274  FILE *f_ifile;
1275 
1276  char cCmd[CMDLEN] = "ls -L ";
1277  /* mark directory names with / to skip them */
1278  /* char cCmd[CMDLEN] = "ls "; was valid from 28.7.2000-18.6.2001 */
1279  char *pCmd;
1280  char *pBuf;
1281  char cBuf[MAX_FULL_FILE]; /* temp buffer for incompl file names */
1282  const char *pcDollar = "$"; /* requ. spec. treatment in file name */
1283 
1284  srawFileList *psFileList, /* points to actual file in filelist */
1285  *psFileList0, /* points to first file in filelist */
1286  *psFileList0c; /* current file in old filelist */
1287 
1288  /******************************************************************/
1289 
1290  if (iDebug)
1291  fprintf(fLogFile, "\n-D- begin %s\n", cModule);
1292 
1293  ploc = strchr(pcFile, *pcDollar);
1294  if (ploc != NULL)
1295  {
1296  if (iDebug)
1297  fprintf(fLogFile, " '$' in file name found: %s\n", pcFile);
1298  ilen = strlen(pcFile);
1299  pcc = pcFile;
1300  for (ii=1; ii<=ilen; ii++)
1301  {
1302  iloc = strncmp(pcc, pcDollar, 1);
1303  if (iloc == 0) strcat(cCmd, "\\"); /* $ found */
1304  strncat(cCmd, pcc++, 1);
1305  }
1306  } /* ploc != NULL, $ in file name */
1307  else strcat(cCmd, pcFile);
1308  strcat(cCmd, " 2>/dev/null");
1309 
1310  if (iDebug)
1311  fprintf(fLogFile, " command: %s\n", cCmd);
1312 
1313  piFileList = (int *) *ppFileList; /* pointer to file list buffer */
1314  piFileno = piFileList++; /* points to no. of files, updated later */
1315  iFilenoo = *piFileno;
1316  psFileList = (srawFileList *) piFileList;
1317  psFileList0 = psFileList; /* points now to first file name */
1318 
1319  if (iFilenoo) /* skip files from previous calls */
1320  {
1321  if (iDebug) fprintf(fLogFile,
1322  " %d old files in list\n", iFilenoo);
1323 
1324  for (ii=1; ii<=iFilenoo; ii++)
1325  {
1326  if (iDebug == 1) fprintf(fLogFile,
1327  " %d (old): %s\n", ii, psFileList->cFile);
1328  psFileList++;
1329  }
1330  }
1331 
1332  pCmd = &cCmd[0];
1333  f_ifile = popen(pCmd, "r");
1334  if (f_ifile == NULL)
1335  {
1336  fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
1337  return(-1);
1338  }
1339  if (iDebug) fprintf(fLogFile, " pipe opened\n");
1340 
1341  if ( !(pBuf = (char *) malloc(BUFSIZE)) )
1342  {
1343  fprintf(fLogFile,
1344  "-E- %s: allocation buffer failed\n", cModule);
1345  pclose(f_ifile);
1346  return(-1);
1347  }
1348  if (iDebug)
1349  fprintf(fLogFile, " buffer allocated\n");
1350 
1351  memset(&cBuf[0], '\0', MAX_FULL_FILE);
1352  lr = 1;
1353  iFileno = 0;
1354  while (lr > 0)
1355  {
1356 gRead:
1357  memset(pBuf, '\0', BUFSIZE);
1358  lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
1359  if (lr > 0)
1360  {
1361  pcc0 = pBuf;
1362  pcc = pBuf;
1363  ird = lr; /* meaningful bytes */
1364 
1365  if (iDebug == 2)
1366  fprintf(fLogFile, "-D- received %d bytes:\n", ird);
1367 
1368  while(ird > 0)
1369  {
1370  if (iDebug == 2)
1371  fprintf(fLogFile, " '%s'", pcc0);
1372  ipc = strcspn(pcc0, "\n");
1373  irem = strlen(pcc0);
1374  pcc = strchr(pcc0, '\n');
1375  if (iDebug == 2) fprintf(fLogFile,
1376  "\n first length %d, total %d, remainder %d\n",
1377  ipc, irem, grem);
1378 
1379  if (grem) /* incompl. file name from previous buffer */
1380  {
1381  if (ipc > 0)
1382  {
1383  strncat(cBuf, pcc0, (unsigned) ipc);
1384  if (iDebug == 2) fprintf(fLogFile,
1385  " last concatenated: %s\n", cBuf);
1386  }
1387 
1388  ii = strlen(cBuf);
1389 
1390  /* after file names: subdir (marked by trailing ":") */
1391  if (strncmp(&(cBuf[ii-1]), ":", 1) == 0)
1392  {
1393  if (iDebug) fprintf(fLogFile,
1394  "\n stop checking, ignore subdirectory %s\n",
1395  cBuf);
1396  lr = 0;
1397  break;
1398  }
1399 
1400  if ( (strcmp(cBuf, "./")) && /* ignore "./" */
1401  (ii) && /* ignore empty string */
1402  (strncmp(&(cBuf[ii-1]), ":", 1)) )
1403  /* ignore subdir (trailing ":") */
1404  {
1405  iRC = rawTestFileName(cBuf);
1406  if ( (iRC == 0) ||
1407  ( (iRC == 1) && (iAccept >= 1) ) )
1408  {
1409  if (iFilenoo)
1410  {
1411  psFileList0c = psFileList0; /* first old file */
1412 
1413  /* compare new name with old ones */
1414  for (jj=1; jj<=iFilenoo; jj++)
1415  {
1416  iRC = strcmp(cBuf, psFileList0c->cFile);
1417  if (iRC == 0)
1418  {
1419  iIgnore = 1;
1420  if (iDebug) fprintf(fLogFile,
1421  " entry %s already available(1)\n",
1422  cBuf);
1423  break;
1424  }
1425  psFileList0c++;
1426  }
1427  } /* (iFilenoo) */
1428 
1429  if (iIgnore == 0)
1430  {
1431  strcpy(psFileList->cFile, cBuf);
1432  iFileno++;
1433  if (iDebug) fprintf(fLogFile,
1434  " %s stored(1), addr %p\n",
1435  psFileList->cFile, psFileList);
1436 
1437  psFileList++;
1438  }
1439  else
1440  iIgnore = 0;
1441 
1442  if (iFileno >= MAX_FILE_NO)
1443  {
1444  fprintf(fLogFile,
1445  "-E- %s: List of files for archive/retrieve currently limited to %d entries\n",
1446  cModule, --iFileno);
1447  fprintf(fLogFile,
1448  " %s: NOT ALL files handled\n",
1449  cModule);
1450  goto gFinishList;
1451  }
1452  }
1453  else
1454  {
1455  if (iRC == 1)
1456  {
1457  fprintf(fLogFile,
1458  "-W- file name %s has uppercase letters - ignored\n",
1459  cBuf);
1460  iRCE = 1; /* client ends with error code */
1461  }
1462  if (iRC == 2) /* no error code */
1463  {
1464  fprintf(fLogFile,
1465  "-W- directory %s ignored\n", cBuf);
1466  }
1467  }
1468  }
1469 
1470  memset(&cBuf, '\0', strlen(cBuf));
1471  grem = 0;
1472  } /* if (grem) */
1473  else
1474  {
1475  strncpy(cBuf, pcc0, (unsigned) ipc);
1476  strcat(cBuf, "\0");
1477  if (irem - ipc == 0) /* current file name incomplete */
1478  {
1479  ipc1 = strlen(cBuf);
1480  if (iDebug == 2) fprintf(fLogFile,
1481  " grem set, cBuf: %s (%d byte) \n", cBuf, ipc1);
1482  grem = 1;
1483  }
1484  else
1485  {
1486  ii = strlen(cBuf);
1487 
1488  /* after file names: subdir (marked by trailing ":") */
1489  if (strncmp(&(cBuf[ii-1]), ":", 1) == 0)
1490  {
1491  if (iDebug) fprintf(fLogFile,
1492  "\n stop checking, ignore subdirectory %s\n",
1493  cBuf);
1494  lr = 0;
1495  break;
1496  }
1497 
1498  if ( (strcmp(cBuf, "./")) && /* ignore "./" */
1499  (ii) && /* ignore empty string */
1500  (strncmp(&(cBuf[ii-1]), ":", 1)) )
1501  /* ignore subdir (trailing ":") */
1502  {
1503  iRC = rawTestFileName(cBuf);
1504  if ( (iRC == 0) ||
1505  ( (iRC == 1) && (iAccept >= 1) ) )
1506  {
1507  if (iFilenoo)
1508  {
1509  psFileList0c = psFileList0;/* 1st old file */
1510 
1511  /* compare new name with old ones */
1512  for (jj=1; jj<=iFilenoo; jj++)
1513  {
1514  if (ipc == (int) strlen(psFileList0c->cFile))
1515  {
1516  iRC = strncmp(cBuf,
1517  psFileList0c->cFile,
1518  (unsigned) ipc);
1519  if (iRC == 0)
1520  {
1521  iIgnore = 1;
1522  if (iDebug) fprintf(fLogFile,
1523  " entry %s already available(2)\n",
1524  cBuf);
1525  break;
1526  }
1527  }
1528  psFileList0c++;
1529  }
1530  } /* (iFilenoo) */
1531 
1532  if (iIgnore == 0)
1533  {
1534  strncpy(psFileList->cFile, cBuf, (unsigned) ipc);
1535  iFileno++;
1536 
1537  if (iDebug) fprintf(fLogFile,
1538  " %s stored(2), addr %p\n",
1539  psFileList->cFile, psFileList);
1540  psFileList++;
1541  }
1542  else
1543  iIgnore = 0;
1544 
1545  if (iFileno >= MAX_FILE_NO)
1546  {
1547  fprintf(fLogFile,
1548  "-E- %s: List of files for archive/retrieve currently limited to %d entries\n",
1549  cModule, --iFileno);
1550  fprintf(fLogFile,
1551  " %s: NOT ALL files handled\n",
1552  cModule);
1553  goto gFinishList;
1554  }
1555  }
1556  else
1557  {
1558  if (iRC == 1)
1559  {
1560  fprintf(fLogFile,
1561  "-W- file name %s has uppercase letters - ignored\n",
1562  cBuf);
1563  iRCE = 1; /* client ends with error code */
1564  }
1565  if (iRC == 2) /* no error code */
1566  fprintf(fLogFile,
1567  "-W- directory %s ignored\n", cBuf);
1568  }
1569  }
1570 
1571  memset(&cBuf, '\0', strlen(cBuf));
1572  }
1573 
1574  } /* if (!grem) */
1575 
1576  pcc0 = ++pcc;
1577  ird -= (ipc+1);
1578  } /* while(ird > 0) */
1579 
1580  } /* if(lr > 0) */
1581 
1582  } /* while(lr > 0) */
1583 
1584 gFinishList:
1585  if (iEntryLoop)
1586  {
1587  if (iFileno == 0)
1588  fprintf(fLogFile, "-I- no (new) files found\n");
1589  else if (iFileno > 1)
1590  fprintf(fLogFile, "-I- %d (new) files found\n", iFileno);
1591  }
1592 
1593  if ( (iDebug) && (iFileno) )
1594  {
1595  psFileList = (srawFileList *) piFileList;
1596  /* points now to first file name */
1597  for (ii=1; ii<=iFilenoo; ii++)
1598  {
1599  if (iDebug == 1) fprintf(fLogFile,
1600  " %d (old): %s\n", ii, psFileList->cFile); psFileList++;
1601  }
1602  for (ii=iFilenoo+1; ii<=iFilenoo+iFileno; ii++)
1603  {
1604  if (iDebug == 1) fprintf(fLogFile,
1605  " %d: %s\n", ii, psFileList->cFile); psFileList++;
1606  }
1607  }
1608 
1609  iFileno += iFilenoo; /* total no. of files found */
1610  piFileno[0] = iFileno; /* pass total no. of files found */
1611 
1612  iRC = pclose(f_ifile);
1613  if (iDebug)
1614  {
1615  if (iRC)
1616  {
1617  fprintf(fLogFile, "-E- %s: iRC = %d closing pipe\n",
1618  cModule, iRC);
1619  if (errno)
1620  {
1621  fprintf(fLogFile, " %s\n", strerror(errno));
1622  errno = 0;
1623  }
1624  }
1625  else
1626  fprintf(fLogFile, " pipe closed\n");
1627 
1628  fprintf(fLogFile, "-D- end %s\n\n", cModule);
1629  }
1630 
1631  /* pclose provides "No child processes" only if iRC=0 */
1632  if (errno)
1633  errno = 0;
1634 
1635  if (iRCE)
1636  return iRCE;
1637  else
1638  return 0;
1639 
1640 } /* rawGetFileList */
1641 
1642 /**********************************************************************
1643  * rawGetHostConn: get network connection type of client host
1644  * created 19.3.98, Horst Goeringer
1645  **********************************************************************/
1646 
1648 {
1649  char cModule[32] = "rawGetHostConn";
1650  int iDebug = 0;
1651 
1652  int iRC;
1653  int ii;
1654  int iBuf = 0;
1655  int iCol = 0; /* no. of columns in cmd output */
1656  int iType = 0; /* network connection type
1657  = 1: ethernet (slow)
1658  = 2: ethernet (fast, nodes linux*
1659  = 3: fddi
1660  = 4: SP switch */
1661  char *pcc;
1662  char cToken[16] = "", *pToken;
1663  char cheadName[16], *pheadName;
1664  char cheadMtu[16] = "mtu", *pheadMtu;
1665  char cName[16] = "", *pName;
1666  char cMtu[16] = "", *pMtu;
1667  char cNameRef1[16] = "";
1668  char cNameRef2[16] = "";
1669 
1670  char cCmd[CMDLEN] = "netstat -i", *pCmd;
1671  char cBuf[1024] = "", *pBuf;
1672  char cNode[MAX_NODE] = "";
1673 
1674  FILE *f_ifile;
1675 
1676  if (iDebug)
1677  fprintf(fLogFile, "\n-D- in %s\n", cModule);
1678 
1679 #ifdef _AIX
1680  strcpy(cheadName, "name");
1681 #else
1682  strcpy(cheadName, "iface");
1683 #endif
1684 
1685  iRC = gethostname(cNode, MAX_NODE);
1686  if (iRC)
1687  {
1688  fprintf(fLogFile,
1689  "-E- %s: getting client host name: %s\n",
1690  cModule, strerror(iRC));
1691  return(1);
1692  }
1693  if (iDebug) fprintf(fLogFile,
1694  " %s: client host %s\n", cModule, cNode);
1695 
1696  if (strncmp(cNode, "lx", 2) == 0) /* fast ethernet */
1697  return(2);
1698  if (strncmp(cNode, "linux", 5) == 0) /* fast ethernet */
1699  return(2);
1700  if (strncmp(cNode, "sp2", 3) == 0) /* fddi */
1701  return(4);
1702 
1703  pToken = &cToken[0];
1704  pheadName = &cheadName[0];
1705  pheadMtu = &cheadMtu[0];
1706  pName = &cName[0];
1707  pMtu = &cMtu[0];
1708  pCmd = &cCmd[0];
1709  pBuf = &cBuf[0];
1710 
1711  f_ifile = popen(pCmd, "r");
1712  if (f_ifile == NULL)
1713  {
1714  fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
1715  return(-1);
1716  }
1717  if (iDebug)
1718  fprintf(fLogFile, " %s: pipe opened\n", cModule);
1719 
1720  iBuf = fread(pBuf, sizeof(char), 1024, f_ifile);
1721  if (iBuf <= 0)
1722  {
1723  fprintf(fLogFile, "-E- %s: reading from pipe failed\n", cModule);
1724  goto gError;
1725  }
1726 
1727  if (iDebug == 2)
1728  fprintf(fLogFile, " %s command output: \n%s", cModule, cBuf);
1729 
1730  pToken = strtok(pBuf, " \n");
1731  pcc = pToken;
1732  while (*pcc != '\0')
1733  {
1734  *pcc = tolower(*pcc);
1735  pcc++; /* gcc 3.3.5: need two steps, else string corrupted */
1736  }
1737 
1738  if (strcmp(pToken, pheadName))
1739  {
1740  fprintf(fLogFile, "-E- %s: invalid name heading (%s, expected %s)\n",
1741  cModule, pToken, pheadName);
1742  goto gError;
1743  }
1744 
1745  pToken = strtok(NULL, " \n");
1746  pcc = pToken;
1747  while (*pcc != '\0')
1748  {
1749  *pcc = tolower(*pcc);
1750  pcc++; /* gcc 3.3.5: need two steps, else string corrupted */
1751  }
1752 
1753  if (strcmp(pToken, pheadMtu))
1754  {
1755  fprintf(fLogFile, "-E- %s: invalid mtu heading (%s, expected %s)\n",
1756  cModule, pToken, pheadMtu);
1757  goto gError;
1758  }
1759 
1760 #ifdef _AIX
1761  iCol = 9;
1762  strcpy(cNameRef1, "en0");
1763  strcpy(cNameRef2, "fi0");
1764 #endif
1765 #ifdef Linux
1766  iCol = 12;
1767  strcpy(cNameRef1, "eth0");
1768  strcpy(cNameRef2, "fdd0");
1769 #endif
1770 
1771  for (ii=1; ii<=iCol-2; ii++) /* skip other headings */
1772  { pToken = strtok(NULL, " \n"); }
1773 
1774  for (;;) /* loop over command output words */
1775  {
1776  pToken = strtok(NULL, " \n");
1777  if (pToken == NULL) break; /* EOF */
1778  pcc = pToken;
1779  while (*pcc != '\0')
1780  {
1781  *pcc = tolower(*pcc);
1782  pcc++; /* gcc 3.3.5: need two steps, else string corrupted */
1783  }
1784 
1785  if (iDebug == 2)
1786  fprintf(fLogFile, "DDD %s: %s\n", cModule, pToken);
1787 
1788  if (strcmp(pToken, cNameRef1) == 0)
1789  {
1790  iType = 1;
1791  if (iDebug)
1792  fprintf(fLogFile, " %s: ethernet available\n", cModule);
1793  }
1794  else if (strcmp(pToken, cNameRef2) == 0)
1795  {
1796  iType = 3; /* fddi */
1797  break;
1798  }
1799  } /* loop over command output lines */
1800 
1801  pclose(f_ifile);
1802  if ( (iType != 3) && (iType != 1) )
1803  {
1804  fprintf(fLogFile,
1805  "-E- %s: invalid network connection type (%d)\n",
1806  cModule, iType);
1807  goto gError;
1808  }
1809  else if (iDebug)
1810  fprintf(fLogFile, "-D- end %s: network connection type %d\n\n",
1811  cModule, iType);
1812  goto gEnd;
1813 
1814 gError:
1815  iType = -1;
1816 
1817 gEnd:
1818  return(iType);
1819 
1820 } /* rawGetHostConn */
1821 
1822 /**********************************************************************/
1823 /* rawGetUserid get user identification */
1824 /* created 22.3.96, Horst Goeringer */
1825 /**********************************************************************/
1826 
1828 {
1829  char cModule[32] = "rawGetUserid";
1830  int iDebug = 0;
1831 
1832  unsigned int lr;
1833  FILE *f_ifile;
1834 
1835  char cCmd[CMDLEN] = "whoami";
1836  char *pCmd;
1837  char *pBuf, *pBuf0;
1838 
1839  pCmd = &cCmd[0];
1840  f_ifile = popen(pCmd, "r");
1841  if (f_ifile == NULL)
1842  {
1843  fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
1844  return(NULL);
1845  }
1846  if (iDebug)
1847  fprintf(fLogFile, " %s: pipe opened\n", cModule);
1848 
1849  if ( !(pBuf0 = (char *) malloc(BUFSIZE)) )
1850  {
1851  fprintf(fLogFile, "-E- %s: allocation buffer failed\n", cModule);
1852  pclose(f_ifile);
1853  return(NULL);
1854  }
1855  if (iDebug)
1856  fprintf(fLogFile, " %s: buffer allocated\n", cModule);
1857 
1858  pBuf = pBuf0;
1859  lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
1860  if (lr <= 0)
1861  {
1862  fprintf(fLogFile, "-E- %s: reading from pipe failed\n", cModule);
1863  pclose(f_ifile);
1864  return(NULL);
1865  }
1866 
1867  pBuf += (lr-1);
1868  strncpy(pBuf, "\0", 1); /* overwrite newline character */
1869 
1870  pclose(f_ifile);
1871 
1872  if (iDebug) fprintf(fLogFile, "-D- %s: user name (%u bytes): %s\n", cModule, lr, pBuf0);
1873 
1874  return(pBuf0);
1875 
1876 } /* rawGetUserid */
int rawGetDirEntryList(char *pcDirName, char *pcEntryMask, int iEntryType, int iEntryLoop, int iPrefixDir, char **ppFileList, char **ppDirList)
Definition: rawProcUn.c:159
int rawTestFileName(char *)
Definition: rawProcn.c:2188
int rawGetHostConn()
Definition: rawProcUn.c:1647
#define MAX_FILE_SIZE
Definition: rawcommn.h:218
static int iFileList
Definition: rawProcUn.c:89
char * rawGetUserid()
Definition: rawProcUn.c:1827
int rawGetFileAttr(char *pcFile, unsigned long *plFileSize)
Definition: rawProcUn.c:1045
#define CMDLEN
Definition: rawdefn.h:28
int rawGetFileList(char *pcFile, int iAccept, int iEntryLoop, char **ppFileList)
Definition: rawProcUn.c:1252
int rawGetFSSpace(char *pcFileSystem, int *piSizeAll, int *piSizeAvail, int *piNodeAll, int *piNodeAvail)
Definition: rawProcUn.c:948
#define MAX_NODE
Definition: rawcommn.h:225
#define MAX_FULL_FILE
Definition: rawcommn.h:255
#define BUFSIZE
Definition: rawdefn.h:29
char cFile[MAX_FULL_FILE]
Definition: rawcommn.h:392
FILE * fLogFile
Definition: rawapin.c:185
int rawGetFSEntries(char *pcStageFS)
Definition: rawProcUn.c:738
int rawGetDirEntries(char *pcStageFS)
Definition: rawProcUn.c:101
int rawGetFSfree(char *pcStageFS)
Definition: rawProcUn.c:795
#define MAX_FILE_NO
Definition: rawcommn.h:220
#define BUFSIZE_SMALL
Definition: rawProcUn.c:91