Text   |  XML   |  ReML   |   Visible Warnings:

Ignored Return Value  at restrict-access.c:293

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

restrict_access_by_env

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/restrict-access.c)expand/collapse
Show more  
 252  void restrict_access_by_env(bool disallow_root)
 253  {
 254          const char *env;
 255          uid_t uid;
 256          bool is_root, have_root_group, preserve_groups = FALSE;
 257          bool allow_root_gid;
 258   
 259          is_root = geteuid() == 0;
 260   
 261          /* set the primary/privileged group */
 262          env = getenv("RESTRICT_SETGID");
 263          process_primary_gid = env == NULL || *env == '\0' ? (gid_t)-1 :
 264                  (gid_t)strtoul(env, NULL, 10);
 265          env = getenv("RESTRICT_SETGID_PRIV");
 266          process_privileged_gid = env == NULL || *env == '\0' ? (gid_t)-1 :
 267                  (gid_t)strtoul(env, NULL, 10);
 268   
 269          have_root_group = process_primary_gid == 0;
 270          if (process_primary_gid != (gid_t)-1 ||
 271              process_privileged_gid != (gid_t)-1) {
 272                  if (process_primary_gid == (gid_t)-1)
 273                          process_primary_gid = getegid();
 274                  restrict_init_groups(process_primary_gid,
 275                                       process_privileged_gid);
 276          } else {
 277                  if (process_primary_gid == (gid_t)-1)
 278                          process_primary_gid = getegid();
 279          }
 280   
 281          /* set system user's groups */
 282          env = getenv("RESTRICT_USER");
 283          if (env != NULL && *env != '\0' && is_root) {
 284                  if (initgroups(env, process_primary_gid) < 0) {
 285                          i_fatal("initgroups(%s, %s) failed: %m",
 286                                  env, get_gid_str(process_primary_gid));
 287                  }
 288                  preserve_groups = TRUE;
 289          }
 290   
 291          /* add extra groups. if we set system user's groups, drop the
 292             restricted groups at the same time. */
 293          env = getenv("RESTRICT_SETEXTRAGROUPS");
 294          if (is_root) T_BEGIN {
 295                  fix_groups_list(env, preserve_groups, &have_root_group);
 296          } T_END;
 297   
 298          /* chrooting */
 299          env = getenv("RESTRICT_CHROOT");
 300          if (env != NULL && *env != '\0') {
 301                  /* kludge: localtime() must be called before chroot(),
 302                     or the timezone isn't known */
 303                  const char *home = getenv("HOME");
 304                  time_t t = 0;
 305                  (void)localtime(&t);
 306   
 307                  if (chroot(env) != 0)
 308                          i_fatal("chroot(%s) failed: %m", env);
 309   
 310                  if (home != NULL) {
 311                          if (chdir(home) < 0) {
 312                                  i_error("chdir(%s) failed: %m", home);
 313                                  home = NULL;
 314                          }
 315                  }
 316                  if (home == NULL) {
 317                          if (chdir("/") != 0)
 318                                  i_fatal("chdir(/) failed: %m");
 319                  }
 320          }
 321   
 322          /* uid last */
 323          env = getenv("RESTRICT_SETUID");
 324          uid = env == NULL || *env == '\0' ? 0 : (uid_t)strtoul(env, NULL, 10);
 325          if (uid != 0) {
 326                  if (setuid(uid) != 0) {
 327                          i_fatal("setuid(%s) failed with euid=%s: %m",
 328                                  get_uid_str(uid), get_uid_str(geteuid()));
 329                  }
 330          }
 331   
 332          /* verify that we actually dropped the privileges */
 333          if (uid != 0 || disallow_root) {
 334                  if (setuid(0) == 0) {
 335                          if (uid == 0)
 336                                  i_fatal("Running as root isn't permitted");
 337                          i_fatal("We couldn't drop root privileges");
 338                  }
 339          }
 340   
 341          env = getenv("RESTRICT_GID_FIRST");
 342          if (env != NULL && atoi(env) != 0)
 343                  allow_root_gid = FALSE;
 344          else if (process_primary_gid == 0 || process_privileged_gid == 0)
 345                  allow_root_gid = TRUE;
 346          else 
 347                  allow_root_gid = FALSE;
 348   
 349          if (!allow_root_gid && uid != 0) {
 350                  if (getgid() == 0 || getegid() == 0 || setgid(0) == 0) {
 351                          if (process_primary_gid == 0)
 352                                  i_fatal("GID 0 isn't permitted");
 353                          i_fatal("We couldn't drop root group privileges "
 354                                  "(wanted=%s, gid=%s, egid=%s)",
 355                                  get_gid_str(process_primary_gid),
 356                                  get_gid_str(getgid()), get_gid_str(getegid()));
 357                  }
 358          }
 359   
 360          /* clear the environment, so we don't fail if we get back here */
 361          env_put("RESTRICT_USER=");
 362          env_put("RESTRICT_CHROOT=");
 363          env_put("RESTRICT_SETUID=");
 364          if (process_privileged_gid == (gid_t)-1) {
 365                  /* if we're dropping privileges before executing and 
 366                     a privileged group is set, the groups must be fixed 
 367                     after exec */
 368                  env_put("RESTRICT_SETGID=");
 369                  env_put("RESTRICT_SETGID_PRIV=");
 370          }
 371          env_put("RESTRICT_SETEXTRAGROUPS=");
 372          env_put("RESTRICT_GID_FIRST=");
 373          env_put("RESTRICT_GID_LAST=");
 374  }
Show more  




Change Warning 8188.26099 : Ignored Return Value

Priority:
State:
Finding:
Owner:
Note: