Changeset 481 for trunk/src/slib.c


Ignore:
Timestamp:
Jul 18, 2015, 5:06:52 PM (9 years ago)
Author:
katerina
Message:

Enhancements and fixes for tickets #374, #375, #376, #377, #378, and #379.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/slib.c

    r476 r481  
    587587
    588588
     589#if !defined (VA_COPY)
     590#if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
     591#define VA_COPY(ap1, ap2)     (*(ap1) = *(ap2))
     592#elif defined (VA_COPY_AS_ARRAY)
     593#define VA_COPY(ap1, ap2)     memmove ((ap1), (ap2), sizeof (va_list))
     594#else /* va_list is a pointer */
     595#define VA_COPY(ap1, ap2)     ((ap1) = (ap2))
     596#endif
     597#endif
     598
    589599#if !defined(HAVE_VSNPRINTF) || defined(HAVE_BROKEN_VSNPRINTF)
    590600static
     
    774784  str[n-1] = '\0';
    775785#else
    776   va_copy(vl2, vl);                      /* save the argument list           */
     786  VA_COPY (vl2, vl);                     /* save the argument list           */
    777787  total = sl_printf_count (format, vl);
    778788  len = (int) total;
     
    820830  str[n-1] = '\0';
    821831#else
    822   va_copy(vl2, vl);                    /* save the argument list           */
     832  VA_COPY (vl2, vl);                   /* save the argument list           */
    823833  total = sl_printf_count (format, vl);
    824834  if (total < n)
     
    11411151static   gid_t   rgid_orig;
    11421152
    1143 static   int     uids_are_stored = SL_FALSE;
    1144 static   int     suid_is_set     = SL_TRUE;
     1153static   int     uids_are_stored = S_FALSE;
     1154static   int     suid_is_set     = S_TRUE;
    11451155
    11461156#ifdef HAVE_SETRESUID
     
    11561166int sl_is_suid()
    11571167{
    1158   if (uids_are_stored == SL_FALSE)
     1168  if (uids_are_stored == S_FALSE)
    11591169    {
    11601170      if (getuid() == geteuid() && getgid() == getegid())
     
    11791189{
    11801190  SL_ENTER(_("sl_get_euid"));
    1181   /* SL_REQUIRE(uids_are_stored == SL_TRUE, _("uids_are_stored == SL_TRUE"));*/
    1182   if (uids_are_stored == SL_TRUE)
     1191  /* SL_REQUIRE(uids_are_stored == S_TRUE, _("uids_are_stored == S_TRUE"));*/
     1192  if (uids_are_stored == S_TRUE)
    11831193    *ret = euid;
    11841194  else
     
    11891199uid_t sl_ret_euid()
    11901200{
    1191   /* SL_REQUIRE(uids_are_stored == SL_TRUE, _("uids_are_stored == SL_TRUE"));*/
    1192   if (uids_are_stored == SL_TRUE)
     1201  /* SL_REQUIRE(uids_are_stored == S_TRUE, _("uids_are_stored == S_TRUE"));*/
     1202  if (uids_are_stored == S_TRUE)
    11931203    return (euid);
    11941204  else
     
    12031213{
    12041214  SL_ENTER(_("sl_get_egid"));
    1205   /* SL_REQUIRE(uids_are_stored == SL_TRUE, _("uids_are_stored == SL_TRUE"));*/
    1206   if (uids_are_stored == SL_TRUE)
     1215  /* SL_REQUIRE(uids_are_stored == S_TRUE, _("uids_are_stored == S_TRUE"));*/
     1216  if (uids_are_stored == S_TRUE)
    12071217    *ret = egid;
    12081218  else
     
    12181228{
    12191229  SL_ENTER(_("sl_get_ruid"));
    1220   /* SL_REQUIRE(uids_are_stored == SL_TRUE, _("uids_are_stored == SL_TRUE"));*/
    1221   if (uids_are_stored == SL_TRUE)
     1230  /* SL_REQUIRE(uids_are_stored == S_TRUE, _("uids_are_stored == S_TRUE"));*/
     1231  if (uids_are_stored == S_TRUE)
    12221232    *ret = ruid;
    12231233  else
     
    12331243{
    12341244  SL_ENTER(_("sl_get_rgid"));
    1235   /* SL_REQUIRE(uids_are_stored == SL_TRUE, _("uids_are_stored == SL_TRUE"));*/
    1236   if (uids_are_stored == SL_TRUE)
     1245  /* SL_REQUIRE(uids_are_stored == S_TRUE, _("uids_are_stored == S_TRUE"));*/
     1246  if (uids_are_stored == S_TRUE)
    12371247    *ret = rgid;
    12381248  else
     
    12481258{
    12491259  SL_ENTER(_("sl_get_ruid_orig"));
    1250   /* SL_REQUIRE(uids_are_stored == SL_TRUE, _("uids_are_stored == SL_TRUE"));*/
    1251   if (uids_are_stored == SL_TRUE)
     1260  /* SL_REQUIRE(uids_are_stored == S_TRUE, _("uids_are_stored == S_TRUE"));*/
     1261  if (uids_are_stored == S_TRUE)
    12521262    *ret = ruid_orig;
    12531263  else
     
    12631273{
    12641274  SL_ENTER(_("sl_get_rgid_orig"));
    1265   /* SL_REQUIRE(uids_are_stored == SL_TRUE, _("uids_are_stored == SL_TRUE"));*/
    1266   if (uids_are_stored == SL_TRUE)
     1275  /* SL_REQUIRE(uids_are_stored == S_TRUE, _("uids_are_stored == S_TRUE"));*/
     1276  if (uids_are_stored == S_TRUE)
    12671277    *ret = rgid_orig;
    12681278  else
     
    12891299  SL_ENTER(_("sl_set_suid"));
    12901300
    1291   if (uids_are_stored == SL_FALSE)
     1301  if (uids_are_stored == S_FALSE)
    12921302    {
    12931303      SL_IRETURN(SL_ENONE, _("sl_set_suid"));
    12941304    }
    12951305
    1296   SL_REQUIRE(uids_are_stored == SL_TRUE, _("uids_are_stored == SL_TRUE")); 
     1306  SL_REQUIRE(uids_are_stored == S_TRUE, _("uids_are_stored == S_TRUE")); 
    12971307
    12981308  if (ruid == euid && rgid == egid)
    12991309    {
    1300       suid_is_set = SL_TRUE;
     1310      suid_is_set = S_TRUE;
    13011311      SL_IRETURN(SL_ENONE, _("sl_set_suid"));
    13021312    } 
    1303   SL_REQUIRE(suid_is_set     == SL_FALSE, _("suid_is_set == SL_FALSE")); 
     1313  SL_REQUIRE(suid_is_set     == S_FALSE, _("suid_is_set == S_FALSE")); 
    13041314
    13051315#if defined(HAVE_SETRESUID)
     
    13301340
    13311341  SL_REQUIRE(retval == 0, _("retval == 0"));
    1332   suid_is_set = SL_TRUE;
     1342  suid_is_set = S_TRUE;
    13331343  SL_IRETURN(SL_ENONE, _("sl_set_suid"));
    13341344}
     
    13441354  SL_ENTER(_("sl_unset_suid"));
    13451355
    1346   if (uids_are_stored == SL_FALSE)
     1356  if (uids_are_stored == S_FALSE)
    13471357    {
    13481358      SL_IRETURN(SL_ENONE, _("sl_unset_suid"));
    13491359    }
    13501360
    1351   SL_REQUIRE(uids_are_stored == SL_TRUE, _("uids_are_stored == SL_TRUE"));
     1361  SL_REQUIRE(uids_are_stored == S_TRUE, _("uids_are_stored == S_TRUE"));
    13521362
    13531363  if (ruid == euid && rgid == egid)
    13541364    {
    1355       suid_is_set = SL_FALSE;
     1365      suid_is_set = S_FALSE;
    13561366      SL_IRETURN(SL_ENONE, _("sl_unset_suid"));
    13571367    } 
    1358   SL_REQUIRE(suid_is_set     == SL_TRUE, _("suid_is_set == SL_TRUE")); 
     1368  SL_REQUIRE(suid_is_set     == S_TRUE, _("suid_is_set == S_TRUE")); 
    13591369
    13601370#if defined(HAVE_SETRESUID)
     
    13841394
    13851395  SL_REQUIRE(retval == 0, _("retval == 0"));
    1386   suid_is_set = SL_FALSE;
     1396  suid_is_set = S_FALSE;
    13871397  SL_IRETURN(SL_ENONE, _("sl_unset_suid"));
    13881398}
     
    13951405{
    13961406  SL_ENTER(_("sl_save_uids"));
    1397   if (uids_are_stored == SL_TRUE)
     1407  if (uids_are_stored == S_TRUE)
    13981408    SL_IRETURN(SL_EREPEAT, _("sl_save_uids"));
    13991409
     
    14041414  ruid = ruid_orig;
    14051415  rgid = rgid_orig;
    1406   uids_are_stored = SL_TRUE;
     1416  uids_are_stored = S_TRUE;
    14071417
    14081418  SL_IRETURN(SL_ENONE, _("sl_save_uids"));
     
    14171427{
    14181428  SL_ENTER(_("sl_drop_privileges"));
    1419   SL_REQUIRE(uids_are_stored == SL_TRUE, _("uids_are_stored == SL_TRUE"));
     1429  SL_REQUIRE(uids_are_stored == S_TRUE, _("uids_are_stored == S_TRUE"));
    14201430
    14211431  SL_REQUIRE(setgid(rgid_orig) == 0, _("setgid(rgid_orig) == 0"));
     
    14421452{
    14431453  SL_ENTER(_("sl_policy_get_root"));
    1444   SL_REQUIRE(uids_are_stored == SL_FALSE, _("uids_are_stored == SL_FALSE"));
     1454  SL_REQUIRE(uids_are_stored == S_FALSE, _("uids_are_stored == S_FALSE"));
    14451455
    14461456  SL_REQUIRE (sl_save_uids() == SL_ENONE, _("sl_save_uids() == SL_ENONE"));
     
    14551465      rgid = egid;
    14561466    }
    1457   suid_is_set = SL_TRUE;
     1467  suid_is_set = S_TRUE;
    14581468  if (euid == 0)
    14591469    {
     
    14741484{
    14751485  SL_ENTER(_("sl_policy_get_real"));
    1476   SL_REQUIRE(uids_are_stored == SL_FALSE, _("uids_are_stored == SL_FALSE"));
     1486  SL_REQUIRE(uids_are_stored == S_FALSE, _("uids_are_stored == S_FALSE"));
    14771487  SL_REQUIRE (sl_save_uids() == SL_ENONE, _("sl_save_uids() == SL_ENONE"));
    14781488
     
    15071517              _("sl_drop_privileges() == SL_ENONE"));
    15081518
    1509   suid_is_set = SL_TRUE;
     1519  suid_is_set = S_TRUE;
    15101520  SL_IRETURN(SL_ENONE, _("sl_policy_get_real"));
    15111521}
     
    15221532
    15231533  SL_REQUIRE(user != NULL, _("user != NULL"));
    1524   SL_REQUIRE(uids_are_stored == SL_FALSE, _("uids_are_stored == SL_FALSE"));
     1534  SL_REQUIRE(uids_are_stored == S_FALSE, _("uids_are_stored == S_FALSE"));
    15251535  SL_REQUIRE (sl_save_uids() == SL_ENONE, _("sl_save_uids() == SL_ENONE"));
    15261536
     
    17781788  ofiles[fd]->content = NULL;
    17791789  ofiles[fd]->stream  = stream;
    1780   ofiles[fd]->flush   = SL_FALSE;
     1790  ofiles[fd]->flush   = S_FALSE;
    17811791
    17821792  sl_strlcpy(ofiles[fd]->ofile, ofile, SL_OFILE_SIZE);
     
    20582068  ofiles[fd]->content = NULL;
    20592069  ofiles[fd]->stream  = NULL;
    2060   ofiles[fd]->flush   = SL_FALSE;
     2070  ofiles[fd]->flush   = S_FALSE;
    20612071
    20622072  sl_strlcpy(ofiles[fd]->ofile, ofile, SL_OFILE_SIZE);
     
    21822192#endif
    21832193
    2184 static int sl_drop_cache = SL_FALSE;
     2194static int sl_drop_cache = S_FALSE;
    21852195
    21862196int sl_set_drop_cache(const char * str)
     
    22032213#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) && defined(POSIX_FADV_DONTNEED)
    22042214
    2205   if (SL_FALSE != sl_drop_cache && !SL_ISERROR(status))
     2215  if (S_FALSE != sl_drop_cache && !SL_ISERROR(status))
    22062216    {
    22072217      int fd = get_the_fd(status);
     
    22092219        {
    22102220          if (0 == sl_check_mincore(fd))
    2211             ofiles[fd]->flush = SL_TRUE;
     2221            ofiles[fd]->flush = S_TRUE;
    22122222        }
    22132223    }
     
    23452355    {
    23462356#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) && defined(POSIX_FADV_DONTNEED)
    2347       if (ofiles[fd]->flush == SL_TRUE)
     2357      if (ofiles[fd]->flush == S_TRUE)
    23482358        {
    23492359          posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
     
    25692579  extern volatile int sig_termfast;
    25702580 
    2571   if (is_nonblocking == SL_FALSE)
     2581  if (is_nonblocking == S_FALSE)
    25722582    {
    25732583      /* set to non-blocking mode
     
    26202630                {
    26212631                  error = errno;
    2622                   if (is_nonblocking == SL_FALSE)
     2632                  if (is_nonblocking == S_FALSE)
    26232633                      retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
    26242634                  TPT(( 0, FIL__, __LINE__, _("msg=<read error>")));
     
    26372647      else if (retval == 0)
    26382648        {
    2639           if (is_nonblocking == SL_FALSE)
     2649          if (is_nonblocking == S_FALSE)
    26402650              retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
    26412651          TPT(( 0, FIL__, __LINE__, _("msg=<timeout>")));
     
    26482658        {
    26492659          error = errno;
    2650           if (is_nonblocking == SL_FALSE)
     2660          if (is_nonblocking == S_FALSE)
    26512661              retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
    26522662          TPT(( 0, FIL__, __LINE__, _("msg=<timeout>")));
     
    26572667      if (sig_termfast == 1)
    26582668        {
    2659           if (is_nonblocking == SL_FALSE)
     2669          if (is_nonblocking == S_FALSE)
    26602670              retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
    26612671          TPT(( 0, FIL__, __LINE__, _("msg=<terminated>")));
     
    26692679      if (tdiff > timeout)
    26702680        {
    2671           if (is_nonblocking == SL_FALSE)
     2681          if (is_nonblocking == S_FALSE)
    26722682              retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
    26732683          TPT(( 0, FIL__, __LINE__, _("msg=<timeout>")));
     
    26792689    }
    26802690
    2681   if (is_nonblocking == SL_FALSE)
     2691  if (is_nonblocking == S_FALSE)
    26822692    retry_fcntl(FIL__, __LINE__, fd, F_SETFL, sflags);
    26832693  return ((int) bytes);
     
    28882898
    28892899extern uid_t rootonly[];
    2890 extern int   EUIDSLOT;
    2891 extern int   ORIG_EUIDSLOT;
     2900extern unsigned int   EUIDSLOT;
     2901extern unsigned int   ORIG_EUIDSLOT;
    28922902
    28932903extern char  tf_path[MAXFILENAME];      /* Error path for trust function. */
     
    29983008int  sl_trust_purge_user (void)
    29993009{
    3000   int i;
     3010  unsigned int i;
    30013011
    30023012  EUIDSLOT = ORIG_EUIDSLOT;
     
    30743084{
    30753085  long          status;
    3076   static time_t old = 0;
    3077   static time_t now;
     3086  static size_t old = 0;
     3087  static size_t now;
    30783088
    30793089  SL_ENTER(_("sl_trustfile_euid"));
     
    30843094
    30853095  now = time(NULL);
     3096
    30863097  if (now < (old + 300))
    30873098    {
     
    31193130{
    31203131  if ((b == 0) || (a >= (INT_MIN / b) && a <= (INT_MAX / b)))
    3121     return SL_TRUE; /* no overflow */
    3122   return SL_FALSE;
     3132    return S_TRUE; /* no overflow */
     3133  return S_FALSE;
    31233134}
    31243135
     
    31263137{
    31273138  if ((b == 0) || (a <= (SIZE_MAX / b)))
    3128     return SL_TRUE; /* no overflow */
    3129   return SL_FALSE;
     3139    return S_TRUE; /* no overflow */
     3140  return S_FALSE;
    31303141}
    31313142
     
    31343145  (void) a;
    31353146  if (b != 0)
    3136     return SL_TRUE; /* no overflow */
    3137   return SL_FALSE;
     3147    return S_TRUE; /* no overflow */
     3148  return S_FALSE;
    31383149}
    31393150
     
    31433154    {
    31443155      if (a <= (INT_MAX - b))
    3145         return SL_TRUE; /* no overflow */
     3156        return S_TRUE; /* no overflow */
    31463157      else
    3147         return SL_FALSE;
     3158        return S_FALSE;
    31483159    }
    31493160  else if (a < 0 && b < 0)
    31503161    {
    31513162      if (a >= (INT_MIN - b))
    3152         return SL_TRUE; /* no overflow */
     3163        return S_TRUE; /* no overflow */
    31533164      else
    3154         return SL_FALSE;
    3155     }
    3156   return SL_TRUE;
     3165        return S_FALSE;
     3166    }
     3167  return S_TRUE;
    31573168}
    31583169
     
    31603171{
    31613172  if (a <= (SIZE_MAX - b))
    3162     return SL_TRUE; /* no overflow */
     3173    return S_TRUE; /* no overflow */
    31633174  else
    3164     return SL_FALSE;
     3175    return S_FALSE;
    31653176}
    31663177
     
    31703181    {
    31713182      if (a <= (INT_MAX + b))
    3172         return SL_TRUE; /* no overflow */
     3183        return S_TRUE; /* no overflow */
    31733184      else
    3174         return SL_FALSE;
     3185        return S_FALSE;
    31753186    }
    31763187  else if (a < 0 && b >= 0)
    31773188    {
    31783189      if (a >= (INT_MIN + b))
    3179         return SL_TRUE; /* no overflow */
     3190        return S_TRUE; /* no overflow */
    31803191      else
    3181         return SL_FALSE;
    3182     }
    3183   return SL_TRUE;
    3184 }
     3192        return S_FALSE;
     3193    }
     3194  return S_TRUE;
     3195}
Note: See TracChangeset for help on using the changeset viewer.