Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_suidchk.c

    r30 r19  
    415415  long            sl_status = SL_ENONE;
    416416  struct stat     fileInfo;
    417   struct stat     fileInfo_F;
    418   int             file_d;
    419417
    420418  file_type       theFile;
    421419  char            fileHash[2*(KEY_LEN + 1)];
    422 
    423   mode_t          umask_old;
    424   int             cperm_status;
    425420
    426421  SL_ENTER(_("sh_suidchk_check_internal"));
     
    524519               */
    525520              fs = filesystem_type (tmpcat, tmpcat, &buf);
    526               if (fs != NULL
    527 #ifndef SH_SUIDTESTDIR
    528                   &&
    529                   0 != strncmp (_("afs"),     fs, 3) &&
     521              if (fs != NULL &&
     522                  0 != strncmp (_("nfs"),     fs, 3) &&
     523                  0 != strncmp (_("proc"),    fs, 4) &&
     524                  0 != strncmp (_("iso9660"), fs, 7) &&
     525                  0 != strncmp (_("vfat"),    fs, 4) &&
     526                  0 != strncmp (_("msdos"),   fs, 5) &&
    530527                  0 != strncmp (_("devfs"),   fs, 5) &&
    531                   0 != strncmp (_("iso9660"), fs, 7) &&
    532                   0 != strncmp (_("lustre"),  fs, 6) &&
    533                   0 != strncmp (_("mmfs"),    fs, 4) &&
    534                   0 != strncmp (_("msdos"),   fs, 5) &&
    535                   0 != strncmp (_("nfs"),     fs, 3) &&
    536                   0 != strncmp (_("nosuid"),  fs, 6) &&
    537                   0 != strncmp (_("proc"),    fs, 4) &&
    538                   0 != strncmp (_("vfat"),    fs, 4)
    539 #endif
     528                  0 != strncmp (_("nosuid"),  fs, 6)
    540529                  )
    541530                {
     
    677666                                    break;
    678667                                  case SH_Q_CHANGEPERM:
    679                                     cperm_status = 0;
    680                                     file_d = -1;
    681668                                    if (retry_lstat(FIL__, __LINE__, tmpcat, &fileInfo) == -1)
    682669                                      {
     
    690677                                                         tmp );
    691678                                        SH_FREE(msg);
    692                                         cperm_status = -1;
    693679                                      }
    694 
    695                                     if (cperm_status == 0)
     680                                    else
    696681                                      {
    697682                                        if (0 != (caperr = sl_get_cap_qdel()))
     
    701686                                                            sh_error_message (caperr),
    702687                                                            _("sl_get_cap_qdel"));
    703                                             cperm_status = -1;
    704688                                          }
    705                                       }
    706 
    707                                     if (cperm_status == 0)
    708                                       {
    709                                         file_d = aud_open (FIL__, __LINE__, SL_YESPRIV,
    710                                                            tmpcat, O_RDONLY, 0);
    711                                         if (-1 == file_d)
    712                                           {
    713                                             status = errno;
    714                                             msg = SH_ALLOC(SH_BUFSIZE);
    715                                             (void) sl_snprintf(msg, SH_BUFSIZE, _("I/O error.  errno = %ld"), status);
    716                                             sh_error_handle (ShSuidchkSeverity,
    717                                                              FIL__, __LINE__,
    718                                                              status,
    719                                                              MSG_SUID_QREPORT, msg,
    720                                                              tmp );
    721                                             SH_FREE(msg);
    722                                             cperm_status = -1;
    723                                           }
    724                                       }
    725 
    726                                     if (cperm_status == 0)
    727                                       {
    728                                         if (retry_fstat(FIL__, __LINE__, file_d, &fileInfo_F) == -1)
    729                                           {
    730                                             status = errno;
    731                                             msg = SH_ALLOC(SH_BUFSIZE);
    732                                             (void) sl_snprintf(msg, SH_BUFSIZE,
    733                                                                _("I/O error.  errno = %ld"), status);
    734                                             sh_error_handle (ShSuidchkSeverity,
    735                                                              FIL__, __LINE__,
    736                                                              status,
    737                                                              MSG_SUID_QREPORT, msg,
    738                                                              tmp );
    739                                             SH_FREE(msg);
    740                                             cperm_status = -1;
    741                                           }
    742                                       }
    743 
    744                                     if (cperm_status == 0)
    745                                       {
    746                                         if (fileInfo_F.st_ino  != fileInfo.st_ino ||
    747                                             fileInfo_F.st_dev  != fileInfo.st_dev ||
    748                                             fileInfo_F.st_mode != fileInfo.st_mode)
    749                                           {
    750                                             status = errno;
    751                                             msg = SH_ALLOC(SH_BUFSIZE);
    752                                             (void) sl_snprintf(msg, SH_BUFSIZE,
    753                                                                _("Race detected.  errno = %ld"), status);
    754                                             sh_error_handle (ShSuidchkSeverity,
    755                                                              FIL__, __LINE__,
    756                                                              status,
    757                                                              MSG_SUID_QREPORT, msg,
    758                                                              tmp );
    759                                             SH_FREE(msg);
    760                                             cperm_status = -1;
    761                                           }
    762                                       }
    763 
    764                                     if ((fileInfo.st_mode & S_ISUID) > 0)
    765                                       fileInfo.st_mode -= S_ISUID;
    766                                     if ((fileInfo.st_mode & S_ISGID) > 0)
    767                                       fileInfo.st_mode -= S_ISGID;
    768 
    769                                     if (cperm_status == 0)
    770                                       {
    771                                         if (fchmod(file_d, fileInfo.st_mode) == -1)
     689
     690                                        if ((fileInfo.st_mode & S_ISUID) > 0)
     691                                          fileInfo.st_mode -= S_ISUID;
     692                                        if ((fileInfo.st_mode & S_ISGID) > 0)
     693                                          fileInfo.st_mode -= S_ISGID;
     694                                        if (chmod(tmpcat, fileInfo.st_mode) == -1)
    772695                                          {
    773696                                            status = errno;
     
    790713                                                             tmp );
    791714                                          }
    792                                       }
    793 
    794                                     if (0 != (caperr = sl_drop_cap_qdel()))
    795                                       {
    796                                         sh_error_handle((-1), FIL__, __LINE__,
    797                                                         caperr, MSG_E_SUBGEN,
    798                                                         sh_error_message (caperr),
    799                                                         _("sl_drop_cap_qdel"));
    800                                       }
    801 
    802                                     if (file_d != -1)
    803                                       {
    804                                         do {
    805                                           status = close (file_d);
    806                                         } while (status == -1 && errno == EINTR);
    807 
    808                                         if (-1 == status)
     715                                        if (0 != (caperr = sl_drop_cap_qdel()))
    809716                                          {
    810                                             status = errno;
    811                                             msg = SH_ALLOC(SH_BUFSIZE);
    812                                             (void) sl_snprintf(msg, SH_BUFSIZE,
    813                                                                _("I/O error.  errno = %ld"), status);
    814                                             sh_error_handle (ShSuidchkSeverity,
    815                                                              FIL__, __LINE__,
    816                                                              status,
    817                                                              MSG_SUID_QREPORT, msg,
    818                                                              tmp );
    819                                             SH_FREE(msg);
    820                                             cperm_status = -1;
     717                                            sh_error_handle((-1), FIL__, __LINE__,
     718                                                            caperr, MSG_E_SUBGEN,
     719                                                            sh_error_message (caperr),
     720                                                            _("sl_drop_cap_qdel"));
    821721                                          }
    822722                                      }
     
    825725                                    dir = SH_ALLOC(PATH_MAX+1);
    826726                                    (void) sl_strlcpy (dir, DEFAULT_QDIR, PATH_MAX+1);
    827                                     if (retry_stat (FIL__, __LINE__, dir, &fileInfo) != 0)
     727                                    if (access (dir, F_OK) != 0)
    828728                                      {
    829729                                        status = errno;
    830730                                        msg = SH_ALLOC(SH_BUFSIZE);
    831                                         (void) sl_snprintf(msg, SH_BUFSIZE, _("Problem quarantining file.  File NOT quarantined.  errno = %ld (stat)"), status);
     731                                        (void) sl_snprintf(msg, SH_BUFSIZE, _("Problem quarantining file.  File NOT quarantined.  errno = %ld (access)"), status);
    832732                                        sh_error_handle (ShSuidchkSeverity,
    833733                                                         FIL__, __LINE__,
     
    915815                                                                   DEFAULT_QDIR,
    916816                                                                   basename(theFile.fullpath));
    917                                                 /*
    918                                                  * avoid chmod by setting umask
    919                                                  */
    920                                                 umask_old = umask (0077);
    921817                                                filePtr = fopen (filetmp, "w+");
    922818                                                /*@-usedef@*/
     
    932828                                                  }
    933829                                                /*@+usedef@*/
    934                                                 umask (umask_old);
    935830                                       
    936831                                                sh_error_handle (ShSuidchkSeverity,
     
    939834                                                                 _("Quarantine method applied"),
    940835                                                                 tmp );
     836                                                if (chmod(filetmp, S_IRUSR | S_IWUSR) == -1)
     837                                                  {
     838                                                    status = errno;
     839                                                    msg = SH_ALLOC(SH_BUFSIZE);
     840                                                    (void) sl_snprintf(msg, SH_BUFSIZE, _("Problem setting permissions on quarantined file.  errno = %ld"), status);
     841                                                    sh_error_handle (ShSuidchkSeverity,
     842                                                                     FIL__,__LINE__,
     843                                                                     status, MSG_SUID_QREPORT,
     844                                                                     msg, tmp );
     845                                                    SH_FREE(msg);
     846                                                  }
    941847                                              }
    942848                                            SH_FREE(filetmp);
     
    1070976  FileLimTotal      = 0;
    1071977
    1072 #ifdef SH_SUIDTESTDIR
    1073   status = sh_suidchk_check_internal (SH_SUIDTESTDIR);
    1074 #else
    1075978  status = sh_suidchk_check_internal ("/");
    1076 #endif
    1077979
    1078980  sh_error_handle ((-1), FIL__, __LINE__, EINVAL, MSG_SUID_SUMMARY,
     
    12671169  long val;
    12681170  int  ret = 0;
    1269   struct stat buf;
    12701171
    12711172  SL_ENTER(_("sh_suidchk_set_qmethod"));
     
    12891190          break;
    12901191        case SH_Q_MOVE:
    1291           if (retry_stat (FIL__, __LINE__, DEFAULT_QDIR, &buf) != 0)
     1192          if (access (DEFAULT_QDIR, F_OK) != 0)
    12921193            {
    12931194              if (mkdir (DEFAULT_QDIR, 0750) == -1)
Note: See TracChangeset for help on using the changeset viewer.