Changeset 253 for trunk/src/sh_suidchk.c


Ignore:
Timestamp:
Oct 25, 2009, 9:11:25 AM (15 years ago)
Author:
katerina
Message:

Run SUID check in seperate thread (ticket #170).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_suidchk.c

    r252 r253  
    163163#endif
    164164
     165SH_MUTEX_STATIC(mutex_suid_check, PTHREAD_MUTEX_INITIALIZER);
     166
    165167extern unsigned long sh_files_maskof (int class);
    166168
     
    202204  if (depth > 99)
    203205    {
     206      SH_MUTEX_LOCK(mutex_thread_nolog);
    204207      sh_error_handle ((-1), FIL__, __LINE__, EINVAL,
    205208                       MSG_SUID_ERROR,
    206209                       _("do_truncate: max depth 99 exceeded"));
     210      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    207211      return -1;
    208212    }
     
    210214  if (path[0] != '/')
    211215    {
     216      SH_MUTEX_LOCK(mutex_thread_nolog);
    212217      sh_error_handle ((-1), FIL__, __LINE__, EINVAL,
    213218                       MSG_SUID_ERROR,
    214219                       _("do_truncate: not an absolute path"));
     220      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    215221      return -1;
    216222    }
     
    222228      if (0 != retry_lstat(FIL__, __LINE__, path, &one))
    223229        {
     230          SH_MUTEX_LOCK(mutex_thread_nolog);
    224231          sh_error_handle ((-1), FIL__, __LINE__, errno,
    225232                           MSG_SUID_ERROR,
    226233                           sh_error_message(errno, errbuf, sizeof(errbuf)));
     234          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    227235          *q = '/';
    228236          return -1;
     
    231239       
    232240        {
     241          SH_MUTEX_LOCK(mutex_thread_nolog);
    233242          sh_error_handle ((-1), FIL__, __LINE__, EINVAL,
    234243                           MSG_SUID_ERROR,
    235244                           _("Possible race: not a directory"));
     245          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    236246          *q = '/';
    237247          return -1;
     
    241251      if (0 != chdir(path))
    242252        {
     253          SH_MUTEX_LOCK(mutex_thread_nolog);
    243254          sh_error_handle ((-1), FIL__, __LINE__, errno,
    244255                           MSG_SUID_ERROR,
    245256                           sh_error_message(errno, errbuf, sizeof(errbuf)));
     257          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    246258          *q = '/';
    247259          return -1;
     
    259271          (!S_ISDIR(two.st_mode))/*@+usedef@*/)
    260272        {
     273          SH_MUTEX_LOCK(mutex_thread_nolog);
    261274          sh_error_handle ((-1), FIL__, __LINE__, EINVAL,
    262275                           MSG_SUID_ERROR,
    263276                           _("Possible race: lstat(dir) != lstat(.)"));
     277          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    264278          return -1;
    265279        }
     
    276290      if (0 != retry_lstat(FIL__, __LINE__, path, &one))
    277291        {
     292          SH_MUTEX_LOCK(mutex_thread_nolog);
    278293          sh_error_handle ((-1), FIL__, __LINE__, errno,
    279294                           MSG_SUID_ERROR,
    280295                           sh_error_message(errno, errbuf, sizeof(errbuf)));
     296          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    281297          return -1;
    282298        }
     
    284300      if (-1 == fd)
    285301        {
     302          SH_MUTEX_LOCK(mutex_thread_nolog);
    286303          sh_error_handle ((-1), FIL__, __LINE__, errno,
    287304                           MSG_SUID_ERROR,
    288305                           sh_error_message(errno, errbuf, sizeof(errbuf)));
     306          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    289307          return -1;
    290308        }
    291309      if (0 != retry_fstat(FIL__, __LINE__, fd, &two))
    292310        {
     311          SH_MUTEX_LOCK(mutex_thread_nolog);
    293312          sh_error_handle ((-1), FIL__, __LINE__, errno,
    294313                           MSG_SUID_ERROR,
    295314                           sh_error_message(errno, errbuf, sizeof(errbuf)));
     315          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    296316          (void) sl_close_fd(FIL__, __LINE__, fd);
    297317          return -1;
     
    300320          (one.st_ino != two.st_ino)/*@+usedef@*/)
    301321        {
     322          SH_MUTEX_LOCK(mutex_thread_nolog);
    302323          sh_error_handle ((-1), FIL__, __LINE__, EINVAL,
    303324                           MSG_SUID_ERROR,
    304325                           _("Possible race: lstat != fstat"));
     326          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    305327          (void) sl_close_fd(FIL__, __LINE__, fd);
    306328          return -1;
     
    308330      if (!S_ISREG(two.st_mode))
    309331        {
     332          SH_MUTEX_LOCK(mutex_thread_nolog);
    310333          sh_error_handle ((-1), FIL__, __LINE__, EINVAL,
    311334                           MSG_SUID_ERROR,
    312335                           _("Possible race: not a regular file"));
     336          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    313337          (void) sl_close_fd(FIL__, __LINE__, fd);
    314338          return -1;
     
    316340      if ((0 == (two.st_mode & S_ISUID)) && (0 == (two.st_mode & S_ISGID)))
    317341        {
     342          SH_MUTEX_LOCK(mutex_thread_nolog);
    318343          sh_error_handle ((-1), FIL__, __LINE__, EINVAL,
    319344                           MSG_SUID_ERROR,
    320345                           _("Possible race: not a suid/sgid file"));
     346          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    321347          (void) sl_close_fd(FIL__, __LINE__, fd);
    322348          return -1;
     
    331357          if (-1 == /*@-unrecog@*/fchmod(fd, two.st_mode)/*@+unrecog@*/)
    332358            {
     359              SH_MUTEX_LOCK(mutex_thread_nolog);
    333360              sh_error_handle ((-1), FIL__, __LINE__, errno,
    334361                               MSG_SUID_ERROR,
    335362                               sh_error_message(errno, errbuf, sizeof(errbuf)));
     363              SH_MUTEX_UNLOCK(mutex_thread_nolog);
    336364              (void) sl_close_fd(FIL__, __LINE__, fd);
    337365              return -1;
    338366            }
    339367#else
     368          SH_MUTEX_LOCK(mutex_thread_nolog);
    340369          sh_error_handle ((-1), FIL__, __LINE__, errno,
    341370                           MSG_SUID_ERROR,
    342371                           _("The fchmod() function is not available"));
     372          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    343373          (void) sl_close_fd(FIL__, __LINE__, fd);
    344374          return -1;
     
    346376          if (two.st_nlink > 1)
    347377            {
     378              SH_MUTEX_LOCK(mutex_thread_nolog);
    348379              sh_error_handle ((-1), FIL__, __LINE__, 0,
    349380                               MSG_SUID_ERROR,
    350381                               _("Not truncated because hardlink count gt 1"));
     382              SH_MUTEX_UNLOCK(mutex_thread_nolog);
    351383              (void) sl_close_fd(FIL__, __LINE__, fd);
    352384              return -1;
     
    356388          if (-1 == /*@-unrecog@*/ftruncate(fd, 0)/*@+unrecog@*/)
    357389            {
     390              SH_MUTEX_LOCK(mutex_thread_nolog);
    358391              sh_error_handle ((-1), FIL__, __LINE__, errno,
    359392                               MSG_SUID_ERROR,
    360393                               sh_error_message(errno, errbuf, sizeof(errbuf)));
     394              SH_MUTEX_UNLOCK(mutex_thread_nolog);
    361395              (void) sl_close_fd(FIL__, __LINE__, fd);
    362396              return -1;
     
    367401          if (-1 == retry_aud_unlink(FIL__, __LINE__, path))
    368402            {
     403              SH_MUTEX_LOCK(mutex_thread_nolog);
    369404              sh_error_handle ((-1), FIL__, __LINE__, errno,
    370405                               MSG_SUID_ERROR,
    371406                               sh_error_message(errno, errbuf, sizeof(errbuf)));
     407              SH_MUTEX_UNLOCK(mutex_thread_nolog);
    372408              (void) sl_close_fd(FIL__, __LINE__, fd);
    373409              return -1;
     
    381417static int do_truncate (const char * path_in)
    382418{
    383   int    caperr;
     419  volatile int    caperr;
    384420  int    result;
    385421  char * path;
     
    388424  if (0 != chdir("/"))
    389425    {
     426      SH_MUTEX_LOCK(mutex_thread_nolog);
    390427      sh_error_handle ((-1), FIL__, __LINE__, errno,
    391428                       MSG_SUID_ERROR,
    392429                       sh_error_message(errno, errbuf, sizeof(errbuf)));
     430      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    393431    }
    394432
    395433  if (0 != (caperr = sl_get_cap_qdel()))
    396434    {
     435      SH_MUTEX_LOCK(mutex_thread_nolog);
    397436      sh_error_handle((-1), FIL__, __LINE__, caperr, MSG_E_SUBGEN,
    398437                      sh_error_message (caperr, errbuf, sizeof(errbuf)),
    399438                      _("sl_get_cap_qdel"));
     439      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    400440    }
    401441
     
    406446  if (0 != (caperr = sl_drop_cap_qdel()))
    407447    {
     448      SH_MUTEX_LOCK(mutex_thread_nolog);
    408449      sh_error_handle((-1), FIL__, __LINE__, caperr, MSG_E_SUBGEN,
    409450                      sh_error_message (caperr, errbuf, sizeof(errbuf)),
    410451                      _("sl_drop_cap_qdel"));
     452      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    411453    }
    412454
    413455  if (0 != chdir("/"))
    414456    {
     457      SH_MUTEX_LOCK(mutex_thread_nolog);
    415458      sh_error_handle ((-1), FIL__, __LINE__, errno,
    416459                       MSG_SUID_ERROR,
    417460                       sh_error_message(errno, errbuf, sizeof(errbuf)));
     461      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    418462    }
    419463  return result;
    420464}
     465
     466/* This variable is not used anywhere. It only exists
     467 * to assign &dirlist to it, which keeps gcc from
     468 * putting it into a register, and avoids the 'clobbered
     469 * by longjmp' warning. And no, 'volatile' proved insufficient.
     470 */
     471static void * sh_dummy_tmp = NULL;
    421472
    422473static void sh_q_delete(const char * fullpath)
     
    426477  char * tmp;
    427478
     479  /* Take the address to keep gcc from putting it into a register.
     480   * Avoids the 'clobbered by longjmp' warning.
     481   */
     482  sh_dummy_tmp = (void*) &tmp;
     483
    428484  if (do_truncate (fullpath) == -1)
    429485    {
     
    435491                         _("Problem quarantining file.  File NOT quarantined.  errno = %ld"),
    436492                         status);
     493      SH_MUTEX_LOCK(mutex_thread_nolog);
    437494      sh_error_handle (ShSuidchkSeverity,
    438495                       FIL__, __LINE__,
     
    440497                       MSG_SUID_QREPORT, msg,
    441498                       tmp );
     499      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    442500      SH_FREE(tmp);
    443501      SH_FREE(msg);
     
    446504    {
    447505      tmp    = sh_util_safe_name(fullpath);
     506      SH_MUTEX_LOCK(mutex_thread_nolog);
    448507      sh_error_handle (ShSuidchkSeverity,
    449508                       FIL__, __LINE__, 0,
     
    451510                       _("Quarantine method applied"),
    452511                       tmp );
     512      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    453513      SH_FREE(tmp);
    454514    }
    455515  return;
    456516}
     517
     518/* This variable is not used anywhere. It only exists
     519 * to assign &dirlist to it, which keeps gcc from
     520 * putting it into a register, and avoids the 'clobbered
     521 * by longjmp' warning. And no, 'volatile' proved insufficient.
     522 */
     523static void * sh_dummy_mtmp = NULL;
     524static void * sh_dummy_mmsg = NULL;
    457525
    458526static void sh_q_move(const char * fullpath, file_type * theFile,
     
    460528                      const char * timestrm)
    461529{
    462   int           status;
     530  volatile int  status;
    463531  int           readFile  = -1;
    464   int           writeFile = -1;
     532  volatile int  writeFile = -1;
    465533  struct stat   fileInfo;
    466534  ssize_t       count;
     
    474542  FILE *        filePtr = NULL;
    475543
     544  /* Take the address to keep gcc from putting it into a register.
     545   * Avoids the 'clobbered by longjmp' warning.
     546   */
     547  sh_dummy_mtmp = (void*) &tmp;
     548  sh_dummy_mmsg = (void*) &msg;
     549
    476550  (void) sl_strlcpy (dir, DEFAULT_QDIR, PATH_MAX+1);
    477551
     
    487561                         _("Problem quarantining file.  File NOT quarantined.  errno = %ld (stat)"),
    488562                         status);
     563      SH_MUTEX_LOCK(mutex_thread_nolog);
    489564      sh_error_handle (ShSuidchkSeverity,
    490565                       FIL__, __LINE__,
     
    492567                       MSG_SUID_QREPORT, msg,
    493568                       tmp );
     569      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    494570      SH_FREE(tmp);
    495571      SH_FREE(msg);
     
    505581
    506582          (void) sl_snprintf(msg, SH_BUFSIZE, _("I/O error.  errno = %ld(stat)"), status);
     583          SH_MUTEX_LOCK(mutex_thread_nolog);
    507584          sh_error_handle (ShSuidchkSeverity,
    508585                           FIL__, __LINE__,
     
    510587                           MSG_SUID_QREPORT,
    511588                           msg, tmp );
     589          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    512590          SH_FREE(tmp);
    513591          SH_FREE(msg);
     
    535613
    536614              (void) sl_snprintf(msg, SH_BUFSIZE, _("Problem quarantining file.  File NOT quarantined.  errno = %ld (open)"), status);
     615              SH_MUTEX_LOCK(mutex_thread_nolog);
    537616              sh_error_handle (ShSuidchkSeverity,
    538617                               FIL__, __LINE__, status,
    539618                               MSG_SUID_QREPORT,
    540619                               msg, tmp );
     620              SH_MUTEX_UNLOCK(mutex_thread_nolog);
    541621              SH_FREE(tmp);
    542622              SH_FREE(msg);
     
    556636                      (void) sl_snprintf(msg, SH_BUFSIZE,
    557637                                         _("I/O error.  errno = %ld (write)"), status);
     638                      SH_MUTEX_LOCK(mutex_thread_nolog);
    558639                      sh_error_handle (ShSuidchkSeverity,
    559640                                       FIL__,
     
    562643                                       MSG_SUID_QREPORT,
    563644                                       msg, tmp );
     645                      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    564646                      SH_FREE(tmp);
    565647                      SH_FREE(msg);
     
    581663                                 _("Problem quarantining file.  File NOT quarantined.  errno = %ld"),
    582664                                 status);
     665              SH_MUTEX_LOCK(mutex_thread_nolog);
    583666              sh_error_handle (ShSuidchkSeverity,
    584667                               FIL__, __LINE__, status,
    585668                               MSG_SUID_QREPORT,
    586669                               msg, tmp );
     670              SH_MUTEX_UNLOCK(mutex_thread_nolog);
    587671              SH_FREE(tmp);
    588672              SH_FREE(msg);
     
    619703             
    620704              tmp    = sh_util_safe_name(fullpath);
     705              SH_MUTEX_LOCK(mutex_thread_nolog);
    621706              sh_error_handle (ShSuidchkSeverity,
    622707                               FIL__,__LINE__,
     
    624709                               _("Quarantine method applied"),
    625710                               tmp );
     711              SH_MUTEX_UNLOCK(mutex_thread_nolog);
    626712              SH_FREE(tmp);
    627713            }
     
    633719}
    634720
     721/* This variable is not used anywhere. It only exists
     722 * to assign &dirlist to it, which keeps gcc from
     723 * putting it into a register, and avoids the 'clobbered
     724 * by longjmp' warning. And no, 'volatile' proved insufficient.
     725 */
     726static void * sh_dummy_ctmp = NULL;
     727static void * sh_dummy_cmsg = NULL;
     728
    635729static void sh_q_changeperm(const char * fullpath)
    636730{
    637   int             caperr;
    638   int             status;
     731  volatile int    caperr;
     732  volatile int    status;
    639733  char          * msg;
    640734  char          * tmp;
     
    642736  struct stat     fileInfo_F;
    643737  int             cperm_status = 0;
    644   int             file_d       = -1;
     738  volatile int    file_d       = -1;
    645739  char errbuf[SH_ERRBUF_SIZE];
     740
     741  /* Take the address to keep gcc from putting it into a register.
     742   * Avoids the 'clobbered by longjmp' warning.
     743   */
     744  sh_dummy_ctmp = (void*) &tmp;
     745  sh_dummy_cmsg = (void*) &msg;
    646746
    647747  if (retry_lstat(FIL__, __LINE__, fullpath, &fileInfo) == -1)
     
    652752
    653753      (void) sl_snprintf(msg, SH_BUFSIZE, _("I/O error.  errno = %ld"), status);
     754      SH_MUTEX_LOCK(mutex_thread_nolog);
    654755      sh_error_handle (ShSuidchkSeverity,
    655756                       FIL__, __LINE__,
     
    657758                       MSG_SUID_QREPORT, msg,
    658759                       tmp );
     760      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    659761      SH_FREE(tmp);
    660762      SH_FREE(msg);
     
    666768      if (0 != (caperr = sl_get_cap_qdel()))
    667769        {
     770          SH_MUTEX_LOCK(mutex_thread_nolog);
    668771          sh_error_handle((-1), FIL__, __LINE__,
    669772                          caperr, MSG_E_SUBGEN,
    670773                          sh_error_message (caperr, errbuf, sizeof(errbuf)),
    671774                          _("sl_get_cap_qdel"));
     775          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    672776          cperm_status = -1;
    673777        }
     
    685789
    686790          (void) sl_snprintf(msg, SH_BUFSIZE, _("I/O error.  errno = %ld"), status);
     791          SH_MUTEX_LOCK(mutex_thread_nolog);
    687792          sh_error_handle (ShSuidchkSeverity,
    688793                           FIL__, __LINE__,
     
    690795                           MSG_SUID_QREPORT, msg,
    691796                           tmp );
     797          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    692798          SH_FREE(tmp);
    693799          SH_FREE(msg);
     
    706812          (void) sl_snprintf(msg, SH_BUFSIZE,
    707813                             _("I/O error.  errno = %ld"), status);
     814          SH_MUTEX_LOCK(mutex_thread_nolog);
    708815          sh_error_handle (ShSuidchkSeverity,
    709816                           FIL__, __LINE__,
     
    711818                           MSG_SUID_QREPORT, msg,
    712819                           tmp );
     820          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    713821          SH_FREE(tmp);
    714822          SH_FREE(msg);
     
    729837          (void) sl_snprintf(msg, SH_BUFSIZE,
    730838                             _("Race detected.  errno = %ld"), status);
     839          SH_MUTEX_LOCK(mutex_thread_nolog);
    731840          sh_error_handle (ShSuidchkSeverity,
    732841                           FIL__, __LINE__,
     
    734843                           MSG_SUID_QREPORT, msg,
    735844                           tmp );
     845          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    736846          SH_FREE(tmp);
    737847          SH_FREE(msg);
     
    756866                             _("Problem quarantining file.  File NOT quarantined.  errno = %ld"),
    757867                             status);
     868          SH_MUTEX_LOCK(mutex_thread_nolog);
    758869          sh_error_handle (ShSuidchkSeverity,
    759870                           FIL__, __LINE__,
     
    761872                           MSG_SUID_QREPORT,
    762873                           msg, tmp );
     874          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    763875          SH_FREE(tmp);
    764876          SH_FREE(msg);
     
    767879        {
    768880          tmp    = sh_util_safe_name(fullpath);
     881          SH_MUTEX_LOCK(mutex_thread_nolog);
    769882          sh_error_handle (ShSuidchkSeverity,
    770883                           FIL__, __LINE__,
     
    773886                           _("Quarantine method applied"),
    774887                           tmp );
     888          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    775889          SH_FREE(tmp);
    776890        }
     
    779893  if (0 != (caperr = sl_drop_cap_qdel()))
    780894    {
     895      SH_MUTEX_LOCK(mutex_thread_nolog);
    781896      sh_error_handle((-1), FIL__, __LINE__,
    782897                      caperr, MSG_E_SUBGEN,
    783898                      sh_error_message (caperr, errbuf, sizeof(errbuf)),
    784899                      _("sl_drop_cap_qdel"));
     900      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    785901    }
    786902 
     
    799915          (void) sl_snprintf(msg, SH_BUFSIZE,
    800916                             _("I/O error.  errno = %ld"), status);
     917          SH_MUTEX_LOCK(mutex_thread_nolog);
    801918          sh_error_handle (ShSuidchkSeverity,
    802919                           FIL__, __LINE__,
     
    804921                           MSG_SUID_QREPORT, msg,
    805922                           tmp );
     923          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    806924          SH_FREE(tmp);
    807925          SH_FREE(msg);
     
    836954  /*@+usedef@*/
    837955 
     956  SH_MUTEX_LOCK(mutex_thread_nolog);
    838957  sh_error_handle (ShSuidchkSeverity, FIL__, __LINE__,
    839958                   0, MSG_SUID_POLICY,
    840959                   _("suid/sgid file not in database"),
    841960                   tmp, msg );
     961  SH_MUTEX_UNLOCK(mutex_thread_nolog);
    842962  SH_FREE(tmp);
    843963  SH_FREE(msg);
    844964  return;
    845965}
     966
     967/* This variable is not used anywhere. It only exists
     968 * to assign &dirlist to it, which keeps gcc from
     969 * putting it into a register, and avoids the 'clobbered
     970 * by longjmp' warning. And no, 'volatile' proved insufficient.
     971 */
     972static void * sh_dummy_dirlist = NULL;
     973static void * sh_dummy_itmp    = NULL;
     974
    846975
    847976static
     
    856985  char            timestrm[32];
    857986  struct stat     buf;
    858   int             status;
     987  volatile int    status;
    859988  int             fflags;
    860989  char          * fs;
    861   long            sl_status;
     990  volatile long   sl_status;
    862991  file_type     * theFile = NULL;
    863992  char            fileHash[2*(KEY_LEN + 1)];
     
    869998  SL_ENTER(_("sh_suidchk_check_internal"));
    870999
     1000  /* Take the address to keep gcc from putting it into a register.
     1001   * Avoids the 'clobbered by longjmp' warning.
     1002   */
     1003  sh_dummy_dirlist = (void*) &dirlist;
     1004  sh_dummy_itmp    = (void*) &tmp;
     1005
    8711006  if (iname == NULL)
    8721007    {
     
    8851020      status = errno;
    8861021      tmp = sh_util_safe_name(iname);
     1022      SH_MUTEX_LOCK(mutex_thread_nolog);
    8871023      sh_error_handle (ShDFLevel[SH_ERR_T_DIR], FIL__, __LINE__, status,
    8881024                       MSG_E_OPENDIR,
    8891025                       sh_error_message (status, errbuf, sizeof(errbuf)), tmp);
     1026      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    8901027      SH_FREE(tmp);
    8911028      SL_RETURN( (-1), _("sh_suidchk_check_internal"));
     
    9541091      {
    9551092        tmp = sh_util_safe_name(tmpcat);
     1093        SH_MUTEX_LOCK(mutex_thread_nolog);
    9561094        sh_error_handle ((-1), FIL__, __LINE__, (int) sl_status,
    9571095                         MSG_E_SUBGPATH,
    9581096                         _("path too long"),
    9591097                         _("sh_suidchk_check_internal"), tmp );
     1098        SH_MUTEX_UNLOCK(mutex_thread_nolog);
    9601099        SH_FREE(tmp);
    9611100        SH_FREE(tmpcat);
     
    9851124    if (status != 0)
    9861125      {
    987         int elevel = SH_ERR_ERR;
     1126        volatile int elevel = SH_ERR_ERR;
    9881127        size_t tlen;
    9891128
     
    9931132        if (tlen >= 6 && 0 == strcmp(&tmp[tlen-6], _("/.gvfs")))
    9941133          elevel = SH_ERR_NOTICE;
     1134        SH_MUTEX_LOCK(mutex_thread_nolog);
    9951135        sh_error_handle (elevel, FIL__, __LINE__, status, MSG_ERR_LSTAT,
    9961136                         sh_error_message(status, errbuf, sizeof(errbuf)),
    9971137                         tmp );
     1138        SH_MUTEX_UNLOCK(mutex_thread_nolog);
    9981139        SH_FREE(tmp);
    9991140      }
     
    10581199            if (status != 0)
    10591200              {
     1201                SH_MUTEX_LOCK(mutex_thread_nolog);
    10601202                sh_error_handle (ShSuidchkSeverity, FIL__, __LINE__,
    10611203                                 0, MSG_E_SUBGPATH,
     
    10631205                                 _("sh_suidchk_check_internal"),
    10641206                                 tmp);
     1207                SH_MUTEX_UNLOCK(mutex_thread_nolog);
    10651208              }
    10661209            else
     
    10711214                      sh.flag.checkSum == SH_CHECK_CHECK))
    10721215                  {
     1216                    int compret;
     1217
    10731218                    /* Updating database. Report new files that
    10741219                     * are not in database already. Then compare
     
    10771222                    if (-1 == sh_hash_have_it (tmpcat))
    10781223                      {
     1224                        SH_MUTEX_LOCK(mutex_thread_nolog);
    10791225                        sh_error_handle ((-1), FIL__, __LINE__,
    10801226                                         0, MSG_SUID_FOUND, tmp );
     1227                        SH_MUTEX_UNLOCK(mutex_thread_nolog);
    10811228                      }
    10821229                    else
    10831230                      {
     1231                        SH_MUTEX_LOCK(mutex_thread_nolog);
    10841232                        sh_error_handle (SH_ERR_ALL, FIL__, __LINE__,
    10851233                                         0, MSG_SUID_FOUND, tmp );
     1234                        SH_MUTEX_UNLOCK(mutex_thread_nolog);
    10861235                      }
    10871236                   
    1088                     if (0 == sh_hash_compdata (SH_LEVEL_READONLY,
    1089                                                theFile, fileHash,
    1090                                                _("[SuidCheck]"),
    1091                                                ShSuidchkSeverity))
     1237                    SH_MUTEX_LOCK(mutex_thread_nolog);
     1238                    compret = sh_hash_compdata (SH_LEVEL_READONLY,
     1239                                                theFile, fileHash,
     1240                                                _("[SuidCheck]"),
     1241                                                ShSuidchkSeverity);
     1242                    SH_MUTEX_UNLOCK(mutex_thread_nolog);
     1243
     1244                    if (compret == 0)
    10921245                      {
    1093                         sh_hash_pushdata_memory (theFile, fileHash);
     1246                        sh_hash_pushdata_memory (theFile, fileHash); /* no call to sh_error_handle */
    10941247                      }
    10951248                   
    1096                     sh_hash_addflag(tmpcat, SH_FFLAG_SUIDCHK);
     1249                    sh_hash_addflag(tmpcat, SH_FFLAG_SUIDCHK); /* no call to sh_error_handle */
    10971250                   
    10981251                  }
     
    11031256                    /* Running init. Report on files detected.
    11041257                     */
    1105                     sh_hash_pushdata (theFile, fileHash);
     1258                    sh_hash_pushdata (theFile, fileHash); /* no call to sh_error_handle */
     1259                    SH_MUTEX_LOCK(mutex_thread_nolog);
    11061260                    sh_error_handle ((-1), FIL__, __LINE__,
    11071261                                     0, MSG_SUID_FOUND, tmp );
     1262                    SH_MUTEX_UNLOCK(mutex_thread_nolog);
    11081263                  }
    11091264               
     
    11131268                     * detected, and quarantine them.
    11141269                     */
     1270                    SH_MUTEX_LOCK(mutex_thread_nolog);
    11151271                    sh_error_handle (SH_ERR_ALL, FIL__, __LINE__,
    11161272                                     0, MSG_SUID_FOUND, tmp );
     1273                    SH_MUTEX_UNLOCK(mutex_thread_nolog);
    11171274                   
    1118                     fflags = sh_hash_getflags(tmpcat);
     1275                    fflags = sh_hash_getflags(tmpcat); /* no call to sh_error_handle */
    11191276                   
    11201277                    if ( (-1 == fflags) || (!SH_FFLAG_SUIDCHK_SET(fflags)))
     
    11441301                                break;
    11451302                              default:
     1303                                SH_MUTEX_LOCK(mutex_thread_nolog);
    11461304                                sh_error_handle (ShSuidchkSeverity, FIL__,
    11471305                                                 __LINE__, 0, MSG_SUID_QREPORT,
    11481306                                                 _("Bad quarantine method"), tmp);
     1307                                SH_MUTEX_UNLOCK(mutex_thread_nolog);
    11491308                                break;
    11501309                              }
     
    11541313                            /* 1.8.1 push file to in-memory database
    11551314                             */
     1315                            SH_MUTEX_LOCK(mutex_thread_nolog);
    11561316                            (void) sh_hash_compdata (SH_LEVEL_READONLY,
    11571317                                                     theFile, fileHash,
    11581318                                                     _("[SuidCheck]"),
    11591319                                                     ShSuidchkSeverity);
     1320                            SH_MUTEX_UNLOCK(mutex_thread_nolog);
    11601321                           
    1161                             sh_hash_addflag(tmpcat, SH_FFLAG_SUIDCHK);
     1322                            sh_hash_addflag(tmpcat, SH_FFLAG_SUIDCHK); /* no call to sh_error_handle */
    11621323                           
    11631324                          }
     
    11671328                        /* File exists. Check for modifications.
    11681329                         */
     1330                        SH_MUTEX_LOCK(mutex_thread_nolog);
    11691331                        (void) sh_hash_compdata (SH_LEVEL_READONLY,
    11701332                                                 theFile, fileHash,
    11711333                                                 _("[SuidCheck]"),
    11721334                                                 ShSuidchkSeverity);
    1173                        
    1174                         sh_hash_addflag(tmpcat, SH_FFLAG_SUIDCHK);
     1335                        SH_MUTEX_UNLOCK(mutex_thread_nolog);   
     1336                        sh_hash_addflag(tmpcat, SH_FFLAG_SUIDCHK); /* no call to sh_error_handle */
    11751337                       
    11761338                      }
     
    11921354          {
    11931355            status = errno;
     1356            SH_MUTEX_LOCK(mutex_thread_nolog);
    11941357            sh_error_handle ((-1), FIL__, __LINE__, status, MSG_E_SUBGEN,
    11951358                             _("Failed to release time slice"),
    11961359                             _("sh_suidchk_check_internal") );
     1360            SH_MUTEX_UNLOCK(mutex_thread_nolog);
    11971361          }
    11981362      }
     
    12161380int sh_suidchk_init (struct mod_type * arg)
    12171381{
     1382#ifndef HAVE_PTHREAD
    12181383  (void) arg;
     1384#endif
     1385
    12191386  if (ShSuidchkActive == S_FALSE)
    1220     return (-1);
     1387    return SH_MOD_FAILED;
     1388
     1389#ifdef HAVE_PTHREAD
     1390  if (arg != NULL && arg->initval < 0 &&
     1391      (sh.flag.isdaemon == S_TRUE || sh.flag.loop == S_TRUE))
     1392    {
     1393      if (0 == sh_pthread_create(sh_threaded_module_run, (void *)arg))
     1394        return SH_MOD_THREAD;
     1395      else
     1396        return SH_MOD_FAILED;
     1397    }
     1398#endif
    12211399
    12221400  return (0);
     
    12701448int sh_suidchk_check ()
    12711449{
    1272   int status;
     1450  volatile int status;
    12731451
    12741452  SL_ENTER(_("sh_suidchk_check"));
    12751453
     1454  if (ShSuidchkActive == S_FALSE)
     1455    SL_RETURN(-1, _("sh_suidchk_check"));
     1456
     1457  SH_MUTEX_LOCK(mutex_thread_nolog);
    12761458  sh_error_handle (SH_ERR_NOTICE, FIL__, __LINE__, EINVAL, MSG_E_SUBGEN,
    12771459                   _("Checking for SUID programs"),
    12781460                   _("suidchk_check") );
     1461  SH_MUTEX_UNLOCK(mutex_thread_nolog);
    12791462
    12801463  FileLimNow        = time(NULL);
     
    12891472#endif
    12901473
     1474  SH_MUTEX_LOCK(mutex_thread_nolog);
    12911475  sh_error_handle ((-1), FIL__, __LINE__, EINVAL, MSG_SUID_SUMMARY,
    12921476                   FileLimTotal,
    12931477                   (long) (time(NULL) - FileLimStart) );
     1478  SH_MUTEX_UNLOCK(mutex_thread_nolog);
    12941479
    12951480  SL_RETURN(status, _("sh_suidchk_check"));
     
    13461531int sh_suidchk_set_timer (const char * c)
    13471532{
    1348   long val;
     1533  volatile long val;
    13491534
    13501535  SL_ENTER(_("sh_suidchk_set_timer"));
     
    13521537  val = strtol (c, (char **)NULL, 10);
    13531538  if (val <= 0)
    1354     sh_error_handle ((-1), FIL__, __LINE__, EINVAL, MSG_EINVALS,
    1355                       _("suidchk timer"), c);
    1356 
     1539    {
     1540      SH_MUTEX_LOCK(mutex_thread_nolog);
     1541      sh_error_handle ((-1), FIL__, __LINE__, EINVAL, MSG_EINVALS,
     1542                       _("suidchk timer"), c);
     1543      SH_MUTEX_UNLOCK(mutex_thread_nolog);
     1544    }
    13571545  val = (val <= 0 ? 7200 : val);
    13581546
     
    13791567int sh_suidchk_reconf ()
    13801568{
     1569  SH_MUTEX_LOCK(mutex_suid_check);
    13811570  sh_suidchk_free_schedule();
    13821571  set_defaults();
     1572  SH_MUTEX_UNLOCK(mutex_suid_check);
    13831573  return 0;
    13841574}
     
    14241614int sh_suidchk_set_fps (const char * c)
    14251615{
    1426   long val;
     1616  volatile long val;
    14271617
    14281618  SL_ENTER(_("sh_suidchk_set_fps"));
     
    14301620  val = strtol (c, (char **)NULL, 10);
    14311621  if (val < 0)
    1432     sh_error_handle ((-1), FIL__, __LINE__, EINVAL, MSG_EINVALS,
    1433                       _("suidchk fps"), c);
    1434 
     1622    {
     1623      SH_MUTEX_LOCK(mutex_thread_nolog);
     1624      sh_error_handle ((-1), FIL__, __LINE__, EINVAL, MSG_EINVALS,
     1625                       _("suidchk fps"), c);
     1626      SH_MUTEX_UNLOCK(mutex_thread_nolog);
     1627    }
    14351628  val = (val < 0 ? 0 : val);
    14361629
     
    14861679int sh_suidchk_set_qmethod (const char * c)
    14871680{
    1488   long val;
    1489   int  ret = 0;
     1681  volatile long val;
     1682  volatile int  ret = 0;
    14901683  struct stat buf;
    14911684
     
    14951688  if (val < 0)
    14961689    {
     1690      SH_MUTEX_LOCK(mutex_thread_nolog);
    14971691      sh_error_handle ((-1), FIL__, __LINE__, EINVAL, MSG_EINVALS,
    14981692                       _("suidchk qmethod"), c);
     1693      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    14991694      ret = -1;
    15001695    }
     
    15141709              if (mkdir (DEFAULT_QDIR, 0750) == -1)
    15151710                {
     1711                  SH_MUTEX_LOCK(mutex_thread_nolog);
    15161712                  sh_error_handle ((-1), FIL__, __LINE__, EINVAL,
    15171713                                   MSG_SUID_ERROR,
    15181714                                   _("Unable to create quarantine directory"));
     1715                  SH_MUTEX_UNLOCK(mutex_thread_nolog);
    15191716                }
    15201717            }
     
    15221719          break;
    15231720        default:
     1721          SH_MUTEX_LOCK(mutex_thread_nolog);
    15241722          sh_error_handle ((-1), FIL__, __LINE__, EINVAL, MSG_EINVALS,
    15251723                           _("suidchk qmethod"), c);
     1724          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    15261725          ShSuidchkQMethod = -1;
    15271726          ret = -1;
     
    19722171}
    19732172
     2173/* This variable is not used anywhere. It only exists
     2174 * to assign &dirlist to it, which keeps gcc from
     2175 * putting it into a register, and avoids the 'clobbered
     2176 * by longjmp' warning. And no, 'volatile' proved insufficient.
     2177 */
     2178static void * sh_dummy_type = NULL;
     2179
     2180
    19742181/* Return a newly allocated string naming the type of filesystem that the
    19752182   file PATH, described by STATP, is on.
     
    19992206  if (mfp == NULL)
    20002207    {
     2208      SH_MUTEX_LOCK(mutex_thread_nolog);
    20012209      sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_E_SUBGEN,
    20022210                       _("setmntent() failed"),
    20032211                       _("filesystem_type_uncached") );
     2212      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    20042213      return NULL;
    20052214    }
     2215
     2216  /* Take the address to keep gcc from putting it into a register.
     2217   * Avoids the 'clobbered by longjmp' warning.
     2218   */
     2219  sh_dummy_type = (void*) &type;
    20062220
    20072221  /* Find the entry with the same device number as STATP, and return
     
    20412255            {
    20422256              char errmsg[256];
    2043               int  elevel = SH_ERR_ERR;
     2257              volatile int  elevel = SH_ERR_ERR;
    20442258              size_t tlen = strlen(mnt->mnt_dir);
    20452259              if (tlen >= 6 && 0 == strcmp(&((mnt->mnt_dir)[tlen-6]), _("/.gvfs")))
     
    20472261              sl_snprintf(errmsg, sizeof(errmsg), _("stat(%s) failed"),
    20482262                          mnt->mnt_dir);
     2263              SH_MUTEX_LOCK(mutex_thread_nolog);
    20492264              sh_error_handle (elevel, FIL__, __LINE__, 0, MSG_E_SUBGEN,
    20502265                               errmsg,
    20512266                               _("filesystem_type_uncached") );
     2267              SH_MUTEX_UNLOCK(mutex_thread_nolog);
    20522268              return NULL;
    20532269            }
     
    20722288  if (endmntent (mfp) == 0)
    20732289    {
     2290      SH_MUTEX_LOCK(mutex_thread_nolog);
    20742291      sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_E_SUBGEN,
    20752292                       _("endmntent() failed"),
    20762293                       _("filesystem_type_uncached") );
     2294      SH_MUTEX_UNLOCK(mutex_thread_nolog);
    20772295    }
    20782296#endif
     
    20852303    return NULL;
    20862304
     2305  /* Take the address to keep gcc from putting it into a register.
     2306   * Avoids the 'clobbered by longjmp' warning.
     2307   */
     2308  sh_dummy_type = (void*) &type;
     2309
    20872310  while (type == NULL
    20882311         && getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, 0) > 0)
     
    21002323    return NULL;
    21012324
     2325  /* Take the address to keep gcc from putting it into a register.
     2326   * Avoids the 'clobbered by longjmp' warning.
     2327   */
     2328  sh_dummy_type = (void*) &type;
     2329
    21022330  if (statfs (relpath, &fss, sizeof (struct statfs), 0) == -1)
    21032331    {
     
    21052333      if (errno != ENOENT)
    21062334        {
     2335          SH_MUTEX_LOCK(mutex_thread_nolog);
    21072336          sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
    21082337                           _("statfs() failed"),
    21092338                           _("filesystem_type_uncached") );
     2339          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    21102340          return NULL;
    21112341        }
     
    21202350  if (path == NULL || relpath == NULL)
    21212351    return NULL;
     2352
     2353  /* Take the address to keep gcc from putting it into a register.
     2354   * Avoids the 'clobbered by longjmp' warning.
     2355   */
     2356  sh_dummy_type = (void*) &type;
    21222357
    21232358  if (statvfs (relpath, &fss) == -1)
     
    21262361      if (errno != ENOENT)
    21272362        {
     2363          SH_MUTEX_LOCK(mutex_thread_nolog);
    21282364          sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
    21292365                           _("statvfs() failed"),
    21302366                           _("filesystem_type_uncached") );
     2367          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    21312368          return NULL;
    21322369        }
     
    21552392    return NULL;
    21562393
     2394  /* Take the address to keep gcc from putting it into a register.
     2395   * Avoids the 'clobbered by longjmp' warning.
     2396   */
     2397  sh_dummy_type = (void*) &type;
     2398
    21572399  if (S_ISLNK (statp->st_mode))
    21582400    p = sh_dirname (relpath);
     
    21662408      if (errno != ENOENT)
    21672409        {
     2410          SH_MUTEX_LOCK(mutex_thread_nolog);
    21682411          sh_error_handle ((-1), FIL__, __LINE__, errno, MSG_E_SUBGEN,
    21692412                           _("statfs() failed"),
    21702413                           _("filesystem_type_uncached") );
     2414          SH_MUTEX_UNLOCK(mutex_thread_nolog);
    21712415          return NULL;
    21722416        }
Note: See TracChangeset for help on using the changeset viewer.