00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #include <stdio.h>
00058 #include <sys/types.h>
00059 #include <string.h>
00060 #include <sys/statfs.h>
00061 #include <sys/dir.h>
00062
00063 #include "rawcommn.h"
00064 #include "rawclin.h"
00065 #include "rawdefn.h"
00066
00067 extern FILE *fLogFile;
00068
00069 #define BUFSIZE_SMALL 80
00070
00071
00072
00073
00074
00075
00076
00077
00078 int rawGetDirEntries(char *pcStageFS)
00079 {
00080 int iDebug = 0;
00081 char cModule[32]="rawGetDirEntries";
00082 int iRC;
00083 int iEntries = 0;
00084
00085 DIR *pDir;
00086 struct dirent *pEntry;
00087
00088 if (iDebug) fprintf(fLogFile,
00089 "\n-D- begin %s: FS %s\n", cModule, pcStageFS);
00090
00091 pDir = opendir(pcStageFS);
00092 if (pDir == NULL)
00093 {
00094 fprintf(fLogFile,
00095 "-E- cannot open directory %s\n", pcStageFS);
00096 perror(" ");
00097 return -1;
00098 }
00099
00100 while ( (pEntry = readdir(pDir)) != NULL)
00101 {
00102 if ( (strcmp(pEntry->d_name, ".") == 0) ||
00103 (strcmp(pEntry->d_name, "..") == 0) )
00104 continue;
00105
00106 iEntries++;
00107
00108 if (iDebug)
00109 fprintf(fLogFile, " %d: %s\n", iEntries, pEntry->d_name);
00110 }
00111
00112 iRC = closedir(pDir);
00113
00114 if (iDebug)
00115 fprintf(fLogFile, " rc(closedir) = %d\n-D- end %s\n\n", iRC, cModule);
00116
00117 return(iEntries);
00118
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128 int rawGetFSEntries(char *pcStageFS)
00129
00130 {
00131 int iDebug = 0;
00132 char cModule[32]="rawGetFSEntries";
00133 int iRC;
00134 int ii = 0;
00135
00136 int iEntries = 0;
00137 struct dirent **fEntryList;
00138
00139 if (iDebug) fprintf(fLogFile,
00140 "\n-D- begin %s: FS %s\n", cModule, pcStageFS);
00141
00142 iRC = scandir(pcStageFS, &fEntryList, NULL, NULL);
00143 if (iRC < 0 )
00144 {
00145 fprintf(fLogFile,
00146 "-E- calling system function scandir, rc=%d\n", iRC);
00147 perror(" ");
00148 return -1;
00149 }
00150
00151 iEntries = 0;
00152 for (ii=0; ii<iRC; ii++)
00153 {
00154 if (iDebug) fprintf(fLogFile,
00155 " %d: %s\n", ii, fEntryList[ii]->d_name);
00156
00157 if ( (strcmp(fEntryList[ii]->d_name, ".") == 0) ||
00158 (strcmp(fEntryList[ii]->d_name, "..") == 0) )
00159 continue;
00160
00161 iEntries++;
00162 }
00163
00164 if (iDebug)
00165 fprintf(fLogFile, "-D- end %s\n\n", cModule);
00166
00167 return(iEntries);
00168
00169 }
00170
00171
00172
00173
00174
00175
00176
00177 int rawGetFSfree(char *pcStageFS)
00178 {
00179 int iDebug = 0;
00180 char cModule[32]="rawGetFSfree";
00181 int iRC;
00182 unsigned int itemsize, itemno;
00183 int iFree, *piFree;
00184 int iSleep = 0;
00185
00186 FILE *fPipe;
00187 int iBuf;
00188 char cName[BUFSIZE_SMALL] = "", *pName;
00189 char cBuf[BUFSIZE_SMALL] = "", *pBuf;
00190 char cTempFile[128] = "";
00191 char cCmd[256] = "/home/rawserv/rawdf.sh ", *pCmd;
00192
00193 time_t tTime;
00194 pid_t pstr;
00195
00196 pBuf = &cBuf[0];
00197 pName = &cName[0];
00198 strcpy(cTempFile, pcStageFS);
00199
00200 tTime = time(NULL);
00201 pstr = getpid();
00202 sprintf(cName, "/size.t%d.p%d", tTime, pstr);
00203 strcat(cTempFile, pName);
00204
00205 strcat(cCmd, pcStageFS);
00206 strcat(cCmd, " ");
00207 strcat(cCmd, cTempFile);
00208
00209 if (iDebug)
00210 fprintf(fLogFile, "\n-D- begin %s: execute\n '%s'\n",
00211 cModule, cCmd);
00212
00213 if (system(NULL))
00214 {
00215 iRC = system(cCmd);
00216 if (iRC)
00217 {
00218 fprintf(fLogFile, "-W- %s: system() failed, rc = %d\n",
00219 cModule, iRC);
00220 return -1;
00221 }
00222 else
00223 {
00224 if (iDebug)
00225 fprintf(fLogFile,
00226 " shell command successfully executed\n");
00227 }
00228 }
00229 else
00230 {
00231 fprintf(fLogFile, "-W- %s: system() not available\n",
00232 cModule);
00233 return -1;
00234 }
00235
00236 fPipe = NULL;
00237 fPipe = fopen(cTempFile, "r");
00238 if (fPipe == NULL)
00239 {
00240 fprintf(fLogFile, "-W- %s: opening file %s\n",
00241 cModule, cTempFile);
00242 perror(" ");
00243 return -1;
00244 }
00245 if (iDebug)
00246 fprintf(fLogFile, " file %s opened\n", cTempFile);
00247
00248 itemsize = sizeof(char);
00249 itemno = BUFSIZE_SMALL;
00250 iBuf = fread(pBuf, itemsize, itemno, fPipe);
00251 if (iBuf <= 0)
00252 {
00253 fprintf(fLogFile, "-W- %s: fread, rc = %d\n", cModule, iBuf);
00254 perror(" ");
00255 fprintf(fLogFile, " NO status buffer sent\n");
00256 }
00257 else
00258 {
00259 iFree = atoi(pBuf);
00260 if (iDebug)
00261 {
00262 fprintf(fLogFile, " %d bytes in file: %s", iBuf, pBuf);
00263 fprintf(fLogFile, " free kB: %d\n", iFree);
00264 }
00265 }
00266
00267 iRC = fclose(fPipe);
00268 if (iRC)
00269 {
00270 fprintf(fLogFile, "-W- %s: rc = %d closing file\n",
00271 cModule, iRC);
00272 if (ferror) perror(" ");
00273 return(-1);
00274 }
00275 if (iDebug)
00276 fprintf(fLogFile, " file %s closed\n", cTempFile);
00277
00278 iRC = remove(cTempFile);
00279 if (iRC)
00280 {
00281 fprintf(fLogFile, "-W- %s: rc = %d removing file %s\n",
00282 cModule, iRC, cTempFile);
00283 if (ferror) perror(" ");
00284 return -1;
00285 }
00286 if (iDebug)
00287 fprintf(fLogFile, " file %s removed\n", cTempFile);
00288
00289 if (iDebug)
00290 fprintf(fLogFile, "-D- end %s\n\n", cModule);
00291
00292 if (iBuf <= 0) return -1;
00293 else return(iFree);
00294
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304 int rawGetFSSpace(char *pcFileSystem,
00305 int *piSizeAll,
00306 int *piSizeAvail,
00307 int *piNodeAll,
00308 int *piNodeAvail)
00309 {
00310 char cModule[32] = "rawGetFSSpace";
00311 int iDebug = 0;
00312
00313 int iRC;
00314 int iBlockSize = 4;
00315 int iSizeAll = 0;
00316 int iSizeFree = 0;
00317 int iSizeAvail = 0;
00318 int iNodeAll = 0;
00319 int iNodeAvail = 0;
00320
00321 struct statfs sFSstatus, *pFSstatus;
00322
00323 if (iDebug) fprintf(fLogFile,
00324 "\n-D- begin %s: FS %s\n", cModule, pcFileSystem);
00325
00326 pFSstatus = &sFSstatus;
00327
00328 iRC = statfs(pcFileSystem, pFSstatus);
00329 if (iRC)
00330 {
00331 fprintf(fLogFile,
00332 "-E- calling system function statfs, rc=%d\n", iRC);
00333 perror(" ");
00334 return -1;
00335 }
00336
00337 iBlockSize = (int) pFSstatus->f_bsize;
00338 if (iBlockSize == 0)
00339 {
00340 fprintf(fLogFile,
00341 "-W- unexpected blocksize found: 0 byte\n");
00342 return 1;
00343 }
00344 else
00345 {
00346 if (iDebug) fprintf(fLogFile,
00347 " blocksize found %d byte\n", iBlockSize);
00348 if (iBlockSize >= 1024)
00349 iBlockSize /= 1024;
00350 else
00351 {
00352 fprintf(fLogFile,
00353 "-W- unexpected blocksize found: %d byte\n", iBlockSize);
00354 return 1;
00355 }
00356 }
00357
00358
00359 iSizeAll = (int) (pFSstatus->f_blocks/1000)*iBlockSize;
00360 iSizeFree = (int) (pFSstatus->f_bfree/1000)*iBlockSize;
00361 iSizeAvail = (int) (pFSstatus->f_bavail/1000)*iBlockSize;
00362
00363 iNodeAll = (int) pFSstatus->f_files;
00364 iNodeAvail = (int) pFSstatus->f_ffree;
00365
00366 if (iDebug)
00367 {
00368 fprintf(fLogFile,
00369 " overall space %d MB, free %d MB, available %d MB\n",
00370 iSizeAll, iSizeFree, iSizeAvail);
00371 fprintf(fLogFile,
00372 " overall file nodes %d, available %d\n",
00373 iNodeAll, iNodeAvail);
00374 }
00375
00376 *piSizeAll = iSizeAll;
00377 *piSizeAvail = iSizeAvail;
00378 *piNodeAll = iNodeAll;
00379 *piNodeAvail = iNodeAvail;
00380
00381 if (iDebug)
00382 fprintf(fLogFile, "-D- end %s\n\n", cModule);
00383
00384 return 0;
00385
00386 }
00387
00388
00389
00390
00391
00392
00393
00394 int rawGetFileAttr(char *pcFile,
00395 unsigned long *piFileSize)
00396 {
00397 int iDebug = 0;
00398 char cModule[32] = "rawGetFileAttr";
00399 FILE *f_ifile, *f_ofile;
00400 int iRC;
00401 unsigned long iFileSize, iiu;
00402 int iReclen;
00403
00404 int ilocSize = 5;
00405 int ilocFile = 9;
00406
00407 int ii, ilen, iloc;
00408 unsigned long lr;
00409
00410 char cCmd[CMDLEN] = "ls -l ";
00411 char *pCmd;
00412 char *pType = "r";
00413 char *pBuf, *pBuf0;
00414 char *pcDollar = "$";
00415 char *pc, *ploc;
00416
00417 char *pctoken, *pcblank = " ";
00418 char ctoken[20];
00419 int icount = 0;
00420
00421
00422
00423 if (iDebug)
00424 fprintf(fLogFile, "-D- Begin %s\n", cModule);
00425
00426 iReclen = 0;
00427
00428
00429 ploc = strchr(pcFile, *pcDollar);
00430 if (ploc != NULL)
00431 {
00432 if (iDebug)
00433 fprintf(fLogFile, "-D- $ in file name found: %s\n", pcFile);
00434 ilen = strlen(pcFile);
00435 pc = pcFile;
00436 for (ii = 1; ii <= ilen; ii++)
00437 {
00438 iloc = strncmp(pc, pcDollar, 1);
00439 if (iloc == 0) strncat(cCmd, "\\", 1);
00440 strncat(cCmd, pc++, 1);
00441 }
00442 }
00443 else strcat(cCmd, pcFile);
00444
00445 if (iDebug)
00446 fprintf(fLogFile, "-D- %s: ex '%s'\n", cModule, cCmd);
00447
00448 pCmd = &cCmd[0];
00449 f_ifile = popen(pCmd, pType);
00450 if (f_ifile == NULL)
00451 {
00452 fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
00453 return(-1);
00454 }
00455 if (iDebug)
00456 fprintf(fLogFile, " %s: pipe opened\n", cModule);
00457
00458 if ( !(pBuf0 = (char *) malloc(BUFSIZE)) )
00459 {
00460 fprintf(fLogFile,
00461 "-E- %s: allocation buffer failed\n", cModule);
00462 pclose(f_ifile);
00463 return(-1);
00464 }
00465 if (iDebug)
00466 fprintf(fLogFile, " %s: buffer allocated\n", cModule);
00467
00468 pBuf = pBuf0;
00469 lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
00470 if (lr <= 0)
00471 {
00472 fprintf(fLogFile,
00473 "-E- %s: reading from pipe failed\n", cModule);
00474 pclose(f_ifile);
00475 return(-1);
00476 }
00477
00478 pBuf += (lr-1);
00479 strncpy(pBuf, "\0", 1);
00480
00481 if (iDebug)
00482 fprintf(fLogFile, "-D- %s: complete string: (%d bytes): \n%s\n",
00483 cModule, lr, pBuf0);
00484
00485 pBuf = pBuf0;
00486 while ( (pctoken = strtok(pBuf, pcblank)) != NULL)
00487 {
00488 icount++;
00489 if (iDebug)
00490 fprintf(fLogFile, " token %d: %s\n", icount, pctoken);
00491
00492 if (icount == 2)
00493 {
00494
00495
00496 iRC = strcmp(pctoken, ".kshrc");
00497 if (iRC == 0)
00498 {
00499 fprintf(fLogFile, " %s: token %d: %s found\n",
00500 cModule, icount, pctoken);
00501 ilocSize += 4;
00502 ilocFile += 4;
00503 }
00504 }
00505
00506 if (icount == ilocSize)
00507 {
00508
00509 if ( ( iRC = sscanf( pctoken, "%u", &iFileSize) ) <= 0 )
00510 {
00511 fprintf(fLogFile,
00512 "-E- %s: file size %d (%s) invalid\n",
00513 cModule, iFileSize, pctoken);
00514 perror(" ");
00515 pclose(f_ifile);
00516 return(-1);
00517 }
00518 if (iDebug)
00519 fprintf(fLogFile, " file size %u\n", iFileSize);
00520
00521 if ( (iFileSize == 0) && (iDebug) )
00522 fprintf(fLogFile, " file %s empty\n", pcFile);
00523
00524 if ( (iFileSize > MAX_FILE_SIZE) ||
00525 (iFileSize < 0) )
00526 {
00527 fprintf(fLogFile, "-E- file %s too large\n", pcFile);
00528 if (iFileSize > 0)
00529 fprintf(fLogFile,
00530 " file size %u > 2 GBbyte - 1\n", iFileSize);
00531 else
00532 fprintf(fLogFile, " file size > 2 GBbyte - 1\n");
00533 pclose(f_ifile);
00534 return(-1);
00535 }
00536 }
00537
00538 if (icount == ilocFile)
00539 {
00540 if ( (iRC = strcmp(pctoken, pcFile) ) != 0)
00541 {
00542 fprintf(fLogFile,
00543 "-E- %s: file name check: %s\n", cModule, pctoken);
00544 pclose(f_ifile);
00545 return(-1);
00546 }
00547 }
00548
00549 pBuf = NULL;
00550
00551 }
00552
00553 pclose(f_ifile);
00554 *piFileSize = iFileSize;
00555 if (iDebug)
00556 fprintf(fLogFile, "-D- End %s\n", cModule);
00557
00558 return 0;
00559
00560 }
00561
00562
00563
00564
00565
00566
00567 int rawGetFileList( char *pcFile,
00568 int iAccept,
00569
00570
00571 int iEntryLoop,
00572 char **pFilelist)
00573 {
00574 char cModule[32] = "rawGetFileList";
00575 int iDebug = 0;
00576 int iRC = 0;
00577 int iRCE = 0;
00578 int iIgnore = 0;
00579 int ilen, iloc, ii, jj;
00580 int ird, ipc, ipc1, irem, grem = 0;
00581 int iSize;
00582 int iFileno, iFilenoo;
00583 int *piFileno;
00584 int *piFilelist;
00585
00586 char *pc, *pc0, *ploc;
00587 unsigned long lr;
00588
00589 FILE *f_ifile;
00590
00591 char cCmd[CMDLEN] = "ls -L ";
00592
00593
00594 char *pCmd;
00595 char *pBuf;
00596 char cBuf[MAX_FILE];
00597 char *pcDollar = "$";
00598
00599 srawArchList *psArchList,
00600 *psArchList0,
00601 *psArchList0c;
00602
00603
00604
00605 if (iDebug)
00606 fprintf(fLogFile, "\n-D- begin %s\n", cModule);
00607
00608 ploc = strchr(pcFile, *pcDollar);
00609 if (ploc != NULL)
00610 {
00611 if (iDebug)
00612 fprintf(fLogFile, " '$' in file name found: %s\n", pcFile);
00613 ilen = strlen(pcFile);
00614 pc = pcFile;
00615 for (ii=1; ii<=ilen; ii++)
00616 {
00617 iloc = strncmp(pc, pcDollar, 1);
00618 if (iloc == 0) strncat(cCmd, "\\", 1);
00619 strncat(cCmd, pc++, 1);
00620 }
00621 }
00622 else strcat(cCmd, pcFile);
00623 strcat(cCmd, " 2>/dev/null");
00624
00625 if (iDebug)
00626 fprintf(fLogFile, " command: %s\n", cCmd);
00627
00628 piFilelist = (int *) *pFilelist;
00629 piFileno = piFilelist++;
00630 iFilenoo = *piFileno;
00631 psArchList = (srawArchList *) piFilelist;
00632 psArchList0 = psArchList;
00633
00634 if (iFilenoo)
00635 {
00636 if (iDebug) fprintf(fLogFile,
00637 " %d old files in list\n", iFilenoo);
00638
00639 for (ii=1; ii<=iFilenoo; ii++)
00640 {
00641 if (iDebug == 1) fprintf(fLogFile,
00642 " %d (old): %s\n", ii, psArchList->cFile);
00643 psArchList++;
00644 }
00645 }
00646
00647 pCmd = &cCmd[0];
00648 f_ifile = popen(pCmd, "r");
00649 if (f_ifile == NULL)
00650 {
00651 fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
00652 return(-1);
00653 }
00654 if (iDebug) fprintf(fLogFile, " pipe opened\n");
00655
00656 if ( !(pBuf = (char *) malloc(BUFSIZE)) )
00657 {
00658 fprintf(fLogFile,
00659 "-E- %s: allocation buffer failed\n", cModule);
00660 pclose(f_ifile);
00661 return(-1);
00662 }
00663 if (iDebug) fprintf(fLogFile, " buffer allocated\n");
00664
00665 memset(&cBuf, '\0', MAX_FILE);
00666 lr = 1;
00667 iFileno = 0;
00668 while (lr > 0)
00669 {
00670 gRead:
00671 lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
00672 if (lr > 0)
00673 {
00674 ird = lr;
00675 pc0 = pBuf;
00676 pc = pBuf;
00677 pc += ird;
00678 *(pc) = '\0';
00679
00680 if (iDebug == 2)
00681 fprintf(fLogFile, "-D- received %d bytes:\n", ird);
00682
00683 pc = pBuf;
00684 while(ird > 0)
00685 {
00686 if (iDebug == 2)
00687 fprintf(fLogFile, " '%s'", pc0);
00688 ipc = strcspn(pc0, "\n");
00689 irem = strlen(pc0);
00690 pc = strchr(pc0, '\n');
00691 if (iDebug == 2)
00692 fprintf(fLogFile, " first length %d, total %d\n",
00693 ipc, irem);
00694
00695 if (grem)
00696 {
00697 if (ipc > 0)
00698 {
00699 strncat(cBuf, pc0, ipc);
00700 if (iDebug == 2)
00701 fprintf(fLogFile, " last concatenated: %s\n",
00702 cBuf);
00703 }
00704
00705 ii = strlen(cBuf);
00706 if ( (strcmp(cBuf, "./")) && (ii) &&
00707 (strncmp(&(cBuf[ii-1]), ":", 1)) )
00708 {
00709 iRC = rawTestFileName(cBuf);
00710 if ( (iRC == 0) ||
00711 ( (iRC == 1) && (iAccept >= 1) ) )
00712 {
00713 if (iFilenoo)
00714 {
00715 psArchList0c = psArchList0;
00716
00717
00718 for (jj=1; jj<=iFilenoo; jj++)
00719 {
00720 iRC = strcmp(cBuf, psArchList0c->cFile);
00721 if (iRC == 0)
00722 {
00723 iIgnore = 1;
00724 if (iDebug) fprintf(fLogFile,
00725 " entry %s already available(1)\n",
00726 cBuf);
00727 break;
00728 }
00729 psArchList0c++;
00730 }
00731 }
00732
00733 if (iIgnore == 0)
00734 {
00735 strcpy(psArchList->cFile, cBuf);
00736 iFileno++;
00737 if (iDebug == 1) fprintf(fLogFile,
00738 " %s stored(1), addr %d\n",
00739 psArchList->cFile, psArchList);
00740
00741 psArchList++;
00742 }
00743 else
00744 iIgnore = 0;
00745
00746 if (iFileno >= MAX_STAGE_FILE_NO)
00747 {
00748 fprintf(fLogFile,
00749 "-E- %s: List of files for archive/retrieve currently limited to %d entries\n",
00750 cModule, --iFileno);
00751 fprintf(fLogFile,
00752 " %s: NOT ALL files handled\n",
00753 cModule);
00754 goto gFinishList;
00755 }
00756 }
00757 else
00758 {
00759 if (iRC == 1)
00760 {
00761 fprintf(fLogFile,
00762 "-W- file name %s has uppercase letters - ignored\n",
00763 cBuf);
00764 iRCE = 1;
00765 }
00766 if (iRC == 2)
00767 {
00768 fprintf(fLogFile,
00769 "-W- directory %s ignored\n", cBuf);
00770 }
00771 }
00772 }
00773
00774 memset(&cBuf, '\0', strlen(cBuf));
00775 grem = 0;
00776 }
00777 else
00778 {
00779 strncpy(cBuf, pc0, ipc);
00780 strcat(cBuf, "\0");
00781 if (irem - ipc == 0)
00782 {
00783 ipc1 = strlen(cBuf);
00784 if (iDebug == 2) fprintf(fLogFile,
00785 " grem set, cBuf: %s (%d byte) \n", cBuf, ipc1);
00786 grem = 1;
00787 }
00788 else
00789 {
00790 ii = strlen(cBuf);
00791 if ( (strcmp(cBuf, "./")) && (ii) &&
00792 (strncmp(&(cBuf[ii-1]), ":", 1)) )
00793 {
00794 iRC = rawTestFileName(cBuf);
00795 if ( (iRC == 0) ||
00796 ( (iRC == 1) && (iAccept >= 1) ) )
00797 {
00798 if (iFilenoo)
00799 {
00800 psArchList0c = psArchList0;
00801
00802
00803 for (jj=1; jj<=iFilenoo; jj++)
00804 {
00805 if (ipc == strlen(psArchList0c->cFile))
00806 {
00807 iRC = strncmp(cBuf,
00808 psArchList0c->cFile,
00809 ipc);
00810 if (iRC == 0)
00811 {
00812 iIgnore = 1;
00813 if (iDebug) fprintf(fLogFile,
00814 " entry %s already available(2)\n",
00815 cBuf);
00816 break;
00817 }
00818 }
00819 psArchList0c++;
00820 }
00821 }
00822
00823 if (iIgnore == 0)
00824 {
00825 strncpy(psArchList->cFile, cBuf, ipc);
00826 iFileno++;
00827
00828 if (iDebug == 1) fprintf(fLogFile,
00829 " %s stored, addr %d\n",
00830 psArchList->cFile, psArchList);
00831 psArchList++;
00832 }
00833 else
00834 iIgnore = 0;
00835
00836 if (iFileno >= MAX_STAGE_FILE_NO)
00837 {
00838 fprintf(fLogFile,
00839 "-E- %s: List of files for archive/retrieve currently limited to %d entries\n",
00840 cModule, --iFileno);
00841 fprintf(fLogFile,
00842 " %s: NOT ALL files handled\n",
00843 cModule);
00844 goto gFinishList;
00845 }
00846 }
00847 else
00848 {
00849 if (iRC == 1)
00850 {
00851 fprintf(fLogFile,
00852 "-W- file name %s has uppercase letters - ignored\n",
00853 cBuf);
00854 iRCE = 1;
00855 }
00856 if (iRC == 2)
00857 fprintf(fLogFile,
00858 "-W- directory %s ignored\n", cBuf);
00859 }
00860 }
00861
00862 memset(&cBuf, '\0', strlen(cBuf));
00863 }
00864
00865 }
00866
00867 pc0 = ++pc;
00868 ird -= (ipc+1);
00869 }
00870
00871 }
00872
00873 }
00874
00875 gFinishList:
00876 if (iEntryLoop)
00877 {
00878 if (iFileno == 0)
00879 fprintf(fLogFile, "-I- no (new) files found\n");
00880 else
00881 fprintf(fLogFile, "-I- %d (new) files found\n", iFileno);
00882 }
00883
00884 if ( (iDebug) && (iFileno) )
00885 {
00886 psArchList = (srawArchList *) piFilelist;
00887
00888 for (ii=1; ii<=iFilenoo; ii++)
00889 {
00890 if (iDebug == 1) fprintf(fLogFile,
00891 " %d (old): %s\n", ii, psArchList->cFile); psArchList++;
00892 }
00893 for (ii=iFilenoo+1; ii<=iFilenoo+iFileno; ii++)
00894 {
00895 if (iDebug == 1) fprintf(fLogFile,
00896 " %d: %s\n", ii, psArchList->cFile); psArchList++;
00897 }
00898 }
00899
00900 iFileno += iFilenoo;
00901 piFileno[0] = iFileno;
00902
00903 iRC = pclose(f_ifile);
00904 if (iDebug)
00905 {
00906 if (iRC)
00907 {
00908 fprintf(fLogFile, "-E- %s: iRC = %d closing pipe\n",
00909 cModule, iRC);
00910 perror(" ");
00911 }
00912 else
00913 fprintf(fLogFile, " pipe closed\n", iRC);
00914
00915 fprintf(fLogFile, "-D- end %s\n\n", cModule);
00916 }
00917
00918 if (iRCE) return iRCE;
00919 else return 0;
00920
00921 }
00922
00923
00924
00925
00926
00927
00928 int rawGetHostConn()
00929 {
00930 int iDebug = 0;
00931 char cModule[32] = "rawGetHostConn";
00932 int iRC;
00933 int ii;
00934 int iBuf = 0;
00935 int iCol = 0;
00936 int iType = 0;
00937
00938
00939
00940
00941 char *pc;
00942 char cToken[16] = "", *pToken;
00943 char cheadName[16], *pheadName;
00944 char cheadMtu[16] = "mtu", *pheadMtu;
00945 char cName[16] = "", *pName;
00946 char cMtu[16] = "", *pMtu;
00947 char cNameRef1[16] = "";
00948 char cNameRef2[16] = "";
00949 char cMtuRef1[16] = "";
00950
00951 char cCmd[CMDLEN] = "netstat -i", *pCmd;
00952 char cBuf[1024] = "", *pBuf;
00953 char cNode[MAX_NODE] = "";
00954
00955 FILE *f_ifile;
00956
00957 if (iDebug)
00958 printf("\n-D- in %s\n", cModule);
00959
00960 #ifdef _AIX
00961 strcpy(cheadName, "name");
00962 #else
00963 strcpy(cheadName, "iface");
00964 #endif
00965
00966 iRC = gethostname(cNode, MAX_NODE);
00967 if (iRC)
00968 {
00969 fprintf(fLogFile,
00970 "-E- %s: getting client host name: %s\n",
00971 cModule, strerror(iRC));
00972 return(1);
00973 }
00974 if (iDebug)
00975 printf(" %s: client host %s\n", cModule, cNode);
00976
00977 if (strncmp(cNode, "lx", 2) == 0)
00978 return(2);
00979 if (strncmp(cNode, "linux", 5) == 0)
00980 return(2);
00981 if (strncmp(cNode, "sp2", 3) == 0)
00982 return(4);
00983
00984 pToken = &cToken[0];
00985 pheadName = &cheadName[0];
00986 pheadMtu = &cheadMtu[0];
00987 pName = &cName[0];
00988 pMtu = &cMtu[0];
00989 pCmd = &cCmd[0];
00990 pBuf = &cBuf[0];
00991
00992 f_ifile = popen(pCmd, "r");
00993 if (f_ifile == NULL)
00994 {
00995 fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
00996 return(-1);
00997 }
00998 if (iDebug) printf(" %s: pipe opened\n", cModule);
00999
01000 iBuf = fread(pBuf, sizeof(char), 1024, f_ifile);
01001 if (iBuf <= 0)
01002 {
01003 fprintf(fLogFile, "-E- %s: reading from pipe failed\n", cModule);
01004 goto gError;
01005 }
01006
01007 if (iDebug == 2)
01008 printf(" %s command output: \n%s", cModule, cBuf);
01009
01010 pToken = strtok(pBuf, " \n");
01011 pc = pToken;
01012 while (*pc != '\0') { *pc++ = tolower(*pc); }
01013 if (strcmp(pToken, pheadName))
01014 {
01015 fprintf(fLogFile, "-E- %s: invalid name heading (%s, expected %s)\n",
01016 cModule, pToken, pheadName);
01017 goto gError;
01018 }
01019
01020 pToken = strtok(NULL, " \n");
01021 pc = pToken;
01022 while (*pc != '\0') { *pc++ = tolower(*pc); }
01023 if (strcmp(pToken, pheadMtu))
01024 {
01025 fprintf(fLogFile, "-E- %s: invalid mtu heading (%s, expected %s)\n",
01026 cModule, pToken, pheadMtu);
01027 goto gError;
01028 }
01029
01030 #ifdef _AIX
01031 iCol = 9;
01032 strcpy(cNameRef1, "en0");
01033 strcpy(cNameRef2, "fi0");
01034 #endif
01035 #ifdef Linux
01036 iCol = 12;
01037 strcpy(cNameRef1, "eth0");
01038 strcpy(cNameRef2, "fdd0");
01039 #endif
01040
01041 for (ii=1; ii<=iCol-2; ii++)
01042 { pToken = strtok(NULL, " \n"); }
01043
01044 for (;;)
01045 {
01046 pToken = strtok(NULL, " \n");
01047 if (pToken == NULL) break;
01048 pc = pToken;
01049 while (*pc != '\0') { *pc++ = tolower(*pc); }
01050 if (iDebug == 2)
01051 printf("DDD %s: %s\n", cModule, pToken);
01052
01053 if (strcmp(pToken, cNameRef1) == 0)
01054 {
01055 iType = 1;
01056 if (iDebug)
01057 printf(" %s: ethernet available\n", cModule);
01058 }
01059 else if (strcmp(pToken, cNameRef2) == 0)
01060 {
01061 iType = 3;
01062 break;
01063 }
01064 }
01065
01066 pclose(f_ifile);
01067 if ( (iType != 3) && (iType != 1) )
01068 {
01069 fprintf(fLogFile,
01070 "-E- %s: invalid network connection type (%d)\n",
01071 cModule, iType);
01072 goto gError;
01073 }
01074 else if (iDebug)
01075 printf("-D- end %s: network connection type %d\n\n",
01076 cModule, iType);
01077 goto gEnd;
01078
01079 gError:
01080 iType = -1;
01081
01082 gEnd:
01083 return(iType);
01084
01085 }
01086
01087
01088
01089
01090
01091
01092 char *rawGetUserid()
01093 {
01094 int iDebug = 0;
01095 char cModule[32] = "rawGetUserid";
01096 unsigned long lr;
01097 FILE *f_ifile;
01098
01099 char cCmd[CMDLEN] = "whoami";
01100 char *pCmd;
01101 char *pBuf, *pBuf0;
01102
01103 pCmd = &cCmd[0];
01104 f_ifile = popen(pCmd, "r");
01105 if (f_ifile == NULL)
01106 {
01107 fprintf(fLogFile, "-E- %s: opening pipe\n", cModule);
01108 return(NULL);
01109 }
01110 if (iDebug) printf(" %s: pipe opened\n", cModule);
01111
01112 if ( !(pBuf0 = (char *) malloc(BUFSIZE)) )
01113 {
01114 fprintf(fLogFile, "-E- %s: allocation buffer failed\n", cModule);
01115 pclose(f_ifile);
01116 return(NULL);
01117 }
01118 if (iDebug) printf(" %s: buffer allocated\n", cModule);
01119
01120 pBuf = pBuf0;
01121 lr = fread(pBuf, sizeof(char), BUFSIZE, f_ifile);
01122 if (lr <= 0)
01123 {
01124 fprintf(fLogFile, "-E- %s: reading from pipe failed\n", cModule);
01125 pclose(f_ifile);
01126 return(NULL);
01127 }
01128
01129 pBuf += (lr-1);
01130 strncpy(pBuf, "\0", 1);
01131
01132 pclose(f_ifile);
01133
01134 if (iDebug)
01135 printf("-D- %s: user name (%d bytes): %s\n", cModule, lr, pBuf0);
01136
01137 return(pBuf0);
01138
01139 }
01140
01141
01142
01143