Text   |  XML   |  ReML   |   Visible Warnings:

Ignored Return Value  at deliver.c:1215

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

main

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/deliver/deliver.c)expand/collapse
Show more  
 885  int main(int argc, char *argv[])
 886  {
 887          const char *config_path = DEFAULT_CONFIG_FILE;
 888          const char *mailbox = "INBOX";
 889          const char *auth_socket;
 890          const char *home, *destaddr, *user, *value, *errstr, *path, *orig_user;
 891          ARRAY_TYPE(const_string) extra_fields = ARRAY_INIT;
 892          struct mail_user *mail_user, *raw_mail_user;
 893          struct mail_namespace *raw_ns;
 894          struct mail_storage *storage;
 895          struct mailbox *box;
 896          struct raw_mailbox *raw_box;
 897          struct istream *input;
 898          struct mailbox_transaction_context *t;
 899          struct mailbox_header_lookup_ctx *headers_ctx;
 900          struct mail *mail;
 901          char cwd[PATH_MAX];
 902          uid_t process_euid;
 903          bool stderr_rejection = FALSE;
 904          bool keep_environment = FALSE;
 905          bool user_auth = FALSE;
 906          time_t mtime;
 907          int i, ret;
 908          pool_t userdb_pool = NULL;
 909          string_t *str;
 910          enum mail_error error;
 911   
 912          if (getuid() != geteuid() && geteuid() == 0) {
 913                  /* running setuid - don't allow this if deliver is 
 914                     executable by anyone */
 915                  struct stat st;
 916   
 917                  if (stat(argv[0], &st) < 0) {
 918                          fprintf(stderr, "stat(%s) failed: %s\n",
 919                                  argv[0], strerror(errno));
 920                          return EX_CONFIG;
 921                  } else if ((st.st_mode & 1) != 0) {
 922                          fprintf(stderr, "%s must not be both world-executable "
 923                                  "and setuid-root. This allows root exploits. "
 924                                  "See http://wiki.dovecot.org/LDA#multipleuids\n",
 925                                  argv[0]);
 926                          return EX_CONFIG;
 927                  }
 928          }
 929   
 930          i_set_failure_exit_callback(failure_exit_callback);
 931   
 932          lib_init();
 933          ioloop = io_loop_create();
 934   
 935          lib_signals_init();
 936          lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
 937          lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
 938          lib_signals_ignore(SIGPIPE, TRUE);
 939          lib_signals_ignore(SIGALRM, FALSE);
 940  #ifdef SIGXFSZ 
 941          lib_signals_ignore(SIGXFSZ, TRUE);
 942  #endif
 943   
 944          deliver_set = i_new(struct deliver_settings, 1);
 945          deliver_set->mailbox_autocreate = TRUE;
 946   
 947          destaddr = user = path = NULL;
 948          for (i = 1; i < argc; i++) {
 949                  if (strcmp(argv[i], "-a") == 0) {
 950                          /* destination address */
 951                          i++;
 952                          if (i == argc)
 953                                  i_fatal_status(EX_USAGE, "Missing -a argument");
 954                          destaddr = argv[i];
 955                  } else if (strcmp(argv[i], "-d") == 0) {
 956                          /* destination user */
 957                          i++;
 958                          if (i == argc)
 959                                  i_fatal_status(EX_USAGE, "Missing -d argument");
 960                          user = argv[i];
 961                          user_auth = TRUE;
 962                  } else if (strcmp(argv[i], "-p") == 0) {
 963                          /* input path */
 964                          i++;
 965                          if (i == argc)
 966                                  i_fatal_status(EX_USAGE, "Missing -p argument");
 967                          path = argv[i];
 968                          if (*path != '/') {
 969                                  /* expand relative paths before we chdir */
 970                                  if (getcwd(cwd, sizeof(cwd)) == NULL)
 971                                          i_fatal("getcwd() failed: %m");
 972                                  path = t_strconcat(cwd, "/", path, NULL);
 973                          }
 974                  } else if (strcmp(argv[i], "-e") == 0) {
 975                          stderr_rejection = TRUE;
 976                  } else if (strcmp(argv[i], "-c") == 0) {
 977                          /* config file path */
 978                          i++;
 979                          if (i == argc) {
 980                                  i_fatal_status(EX_USAGE,
 981                                          "Missing config file path argument");
 982                          }
 983                          config_path = argv[i];
 984                  } else if (strcmp(argv[i], "-k") == 0) {
 985                          keep_environment = TRUE;
 986                  } else if (strcmp(argv[i], "-m") == 0) {
 987                          /* destination mailbox */
 988                          i++;
 989                          if (i == argc)
 990                                  i_fatal_status(EX_USAGE, "Missing -m argument");
 991                          /* Ignore -m "". This allows doing -m ${extension}
 992                             in Postfix to handle user+mailbox */
 993                          if (*argv[i] != '\0') {
 994                                  str = t_str_new(256);
 995                                  if (imap_utf8_to_utf7(argv[i], str) < 0) {
 996                                          i_fatal("Mailbox name not UTF-8: %s",
 997                                                  mailbox);
 998                                  }
 999                                  mailbox = str_c(str);
 1000                          }
 1001                  } else if (strcmp(argv[i], "-n") == 0) {
 1002                          deliver_set->mailbox_autocreate = FALSE;
 1003                  } else if (strcmp(argv[i], "-s") == 0) {
 1004                          deliver_set->mailbox_autosubscribe = TRUE;
 1005                  } else if (strcmp(argv[i], "-f") == 0) {
 1006                          /* envelope sender address */
 1007                          i++;
 1008                          if (i == argc)
 1009                                  i_fatal_status(EX_USAGE, "Missing -f argument");
 1010                          explicit_envelope_sender =
 1011                                  i_strdup(address_sanitize(argv[i]));
 1012                  } else if (argv[i][0] != '\0') {
 1013                          print_help();
 1014                          i_fatal_status(EX_USAGE,
 1015                                         "Unknown argument: %s", argv[i]);
 1016                  }
 1017          }
 1018   
 1019          if (user == NULL)
 1020                  user = getenv("USER");
 1021          if (!keep_environment)
 1022                  deliver_env_clean(!user_auth);
 1023   
 1024          process_euid = geteuid();
 1025          if (user_auth)
 1026                  ;
 1027          else if (process_euid != 0) {
 1028                  /* we're non-root. get our username and possibly our home. */
 1029                  struct passwd *pw;
 1030   
 1031                  home = getenv("HOME");
 1032                  if (user != NULL && home != NULL) {
 1033                          /* no need for a pw lookup */
 1034                  } else if ((pw = getpwuid(process_euid)) != NULL) {
 1035                          user = t_strdup(pw->pw_name);
 1036                          if (home == NULL)
 1037                                  env_put(t_strconcat("HOME=", pw->pw_dir, NULL));
 1038                  } else if (user == NULL) {
 1039                          i_fatal_status(EX_USAGE,
 1040                                         "Couldn't lookup our username (uid=%s)",
 1041                                         dec2str(process_euid));
 1042                  }
 1043          } else {
 1044                  i_fatal_status(EX_USAGE,
 1045                          "destination user parameter (-d user) not given");
 1046          }
 1047   
 1048          T_BEGIN {
 1049                  config_file_init(config_path);
 1050          } T_END;
 1051          open_logfile(user);
 1052   
 1053          if (getenv("MAIL_DEBUG") != NULL)
 1054                  env_put("DEBUG=1");
 1055   
 1056          if (getenv("MAIL_PLUGINS") == NULL)
 1057                  modules = NULL;
 1058          else {
 1059                  const char *plugin_dir = getenv("MAIL_PLUGIN_DIR");
 1060                  const char *version;
 1061   
 1062                  if (plugin_dir == NULL)
 1063                          plugin_dir = MODULEDIR"/lda";
 1064   
 1065                  version = getenv("VERSION_IGNORE") != NULL ?
 1066                          NULL : PACKAGE_VERSION;
 1067                  modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
 1068                                            TRUE, version);
 1069          }
 1070   
 1071          if (user_auth) {
 1072                  auth_socket = getenv("AUTH_SOCKET_PATH");
 1073                  if (auth_socket == NULL) {
 1074                          const char *base_dir = getenv("BASE_DIR");
 1075                          if (base_dir == NULL)
 1076                                  base_dir = PKG_RUNDIR;
 1077                          auth_socket = t_strconcat(base_dir, "/auth-master",
 1078                                                    NULL);
 1079                  }
 1080   
 1081                  userdb_pool = pool_alloconly_create("userdb lookup replys", 512);
 1082                  orig_user = user;
 1083                  ret = auth_client_lookup_and_restrict(auth_socket,
 1084                                                        &user, process_euid,
 1085                                                        userdb_pool,
 1086                                                        &extra_fields);
 1087                  if (ret != 0)
 1088                          return ret;
 1089   
 1090                  if (strcmp(user, orig_user) != 0) {
 1091                          /* auth lookup changed the user. */
 1092                          if (getenv("DEBUG") != NULL)
 1093                                  i_info("userdb changed username to %s", user);
 1094                          i_set_failure_prefix(t_strdup_printf("deliver(%s): ",
 1095                                                               user));
 1096                  }
 1097                  /* if user was changed, it was allocated from userdb_pool 
 1098                     which we'll free soon. */
 1099                  user = t_strdup(user);
 1100          }
 1101   
 1102          expand_envs(user);
 1103          if (userdb_pool != NULL) {
 1104                  putenv_extra_fields(&extra_fields);
 1105                  pool_unref(&userdb_pool);
 1106          }
 1107   
 1108          /* Fix namespaces with empty locations */
 1109          for (i = 1;; i++) {
 1110                  value = getenv(t_strdup_printf("NAMESPACE_%u", i));
 1111                  if (value == NULL)
 1112                          break;
 1113   
 1114                  if (*value == '\0') {
 1115                          env_put(t_strdup_printf("NAMESPACE_%u=%s", i,
 1116                                                  getenv("MAIL")));
 1117                  }
 1118          }
 1119   
 1120          /* If possible chdir to home directory, so that core file
 1121             could be written in case we crash. */
 1122          home = getenv("HOME");
 1123          if (home != NULL) {
 1124                  if (chdir(home) < 0) {
 1125                          if (errno != ENOENT)
 1126                                  i_error("chdir(%s) failed: %m", home);
 1127                          else if (getenv("DEBUG") != NULL)
 1128                                  i_info("Home dir not found: %s", home);
 1129                  }
 1130          }
 1131   
 1132          env_put(t_strconcat("USER=", user, NULL));
 1133          (void)umask(0077);
 1134   
 1135          deliver_set->hostname = getenv("HOSTNAME");
 1136          if (deliver_set->hostname == NULL)
 1137                  deliver_set->hostname = my_hostname;
 1138          deliver_set->postmaster_address = getenv("POSTMASTER_ADDRESS");
 1139          if (deliver_set->postmaster_address == NULL) {
 1140                  i_fatal_status(EX_CONFIG,
 1141                                 "postmaster_address setting not given");
 1142          }
 1143          deliver_set->sendmail_path = getenv("SENDMAIL_PATH");
 1144          if (deliver_set->sendmail_path == NULL)
 1145                  deliver_set->sendmail_path = DEFAULT_SENDMAIL_PATH;
 1146          deliver_set->rejection_subject = getenv("REJECTION_SUBJECT");
 1147          if (deliver_set->rejection_subject == NULL)
 1148                  deliver_set->rejection_subject = DEFAULT_MAIL_REJECTION_SUBJECT;
 1149          deliver_set->rejection_reason = getenv("REJECTION_REASON");
 1150          if (deliver_set->rejection_reason == NULL) {
 1151                  deliver_set->rejection_reason =
 1152                          DEFAULT_MAIL_REJECTION_HUMAN_REASON;
 1153          }
 1154          deliver_set->log_format = getenv("DELIVER_LOG_FORMAT");
 1155          if (deliver_set->log_format == NULL)
 1156                  deliver_set->log_format = DEFAULT_LOG_FORMAT;
 1157   
 1158          dict_drivers_register_builtin();
 1159          duplicate_init();
 1160          mail_users_init(getenv("AUTH_SOCKET_PATH"), getenv("DEBUG") != NULL);
 1161          mail_storage_init();
 1162          mail_storage_register_all();
 1163          mailbox_list_register_all();
 1164   
 1165          module_dir_init(modules);
 1166   
 1167          mail_user = mail_user_init(user);
 1168          mail_user_set_home(mail_user, home);
 1169          if (mail_namespaces_init(mail_user) < 0)
 1170                  i_fatal("Namespace initialization failed");
 1171   
 1172          /* create a separate mail user for the internal namespace */
 1173          raw_mail_user = mail_user_init(user);
 1174          mail_user_set_home(raw_mail_user, NULL);
 1175          raw_ns = mail_namespaces_init_empty(raw_mail_user);
 1176          raw_ns->flags |= NAMESPACE_FLAG_NOQUOTA | NAMESPACE_FLAG_NOACL;
 1177   
 1178          if (mail_storage_create(raw_ns, "raw", "/tmp",
 1179                                  MAIL_STORAGE_FLAG_FULL_FS_ACCESS,
 1180                                  FILE_LOCK_METHOD_FCNTL, &errstr) < 0)
 1181                  i_fatal("Couldn't create internal raw storage: %s", errstr);
 1182          if (path == NULL) {
 1183                  input = create_raw_stream(mail_user, 0, &mtime);
 1184                  box = mailbox_open(&raw_ns->storage, "Dovecot Delivery Mail",
 1185                                     input, MAILBOX_OPEN_NO_INDEX_FILES);
 1186                  i_stream_unref(&input);
 1187          } else {
 1188                  mtime = (time_t)-1;
 1189                  box = mailbox_open(&raw_ns->storage, path, NULL,
 1190                                     MAILBOX_OPEN_NO_INDEX_FILES);
 1191          }
 1192          if (box == NULL) {
 1193                  i_fatal("Can't open delivery mail as raw: %s",
 1194                          mail_storage_get_last_error(raw_ns->storage, &error));
 1195          }
 1196          if (mailbox_sync(box, 0, 0, NULL) < 0) {
 1197                  i_fatal("Can't sync delivery mail: %s",
 1198                          mail_storage_get_last_error(raw_ns->storage, &error));
 1199          }
 1200          raw_box = (struct raw_mailbox *)box;
 1201          raw_box->envelope_sender = explicit_envelope_sender != NULL ?
 1202                  explicit_envelope_sender : DEFAULT_ENVELOPE_SENDER;
 1203          raw_box->mtime = mtime;
 1204   
 1205          t = mailbox_transaction_begin(box, 0);
 1206          headers_ctx = mailbox_header_lookup_init(box, wanted_headers);
 1207          mail = mail_alloc(t, 0, headers_ctx);
 1208          mail_set_seq(mail, 1);
 1209   
 1210          if (destaddr == NULL) {
 1211                  destaddr = deliver_get_address(mail, "Envelope-To");
 1212                  if (destaddr == NULL) {
 1213                          destaddr = strchr(user, '@') != NULL ? user :
 1214                                  t_strconcat(user, "@",
 1215                                              deliver_set->hostname, NULL);
 1216                  }
 1217          }
 1218   
 1219          storage = NULL;
 1220          default_mailbox_name = mailbox;
 1221          if (deliver_mail == NULL)
 1222                  ret = -1;
 1223          else {
 1224                  if (deliver_mail(mail_user->namespaces, &storage, mail,
 1225                                   destaddr, mailbox) <= 0) {
 1226                          /* if message was saved, don't bounce it even though
 1227                             the script failed later. */
 1228                          ret = saved_mail ? 0 : -1;
 1229                  } else {
 1230                          /* success. message may or may not have been saved. */
 1231                          ret = 0;
 1232                  }
 1233          }
 1234   
 1235          if (ret < 0 && !tried_default_save) {
 1236                  /* plugins didn't handle this. save into the default mailbox. */
 1237                  ret = deliver_save(mail_user->namespaces,
 1238                                     &storage, mailbox, mail, 0, NULL);
 1239          }
 1240          if (ret < 0 && strcasecmp(mailbox, "INBOX") != 0) {
 1241                  /* still didn't work. try once more to save it
 1242                     to INBOX. */
 1243                  ret = deliver_save(mail_user->namespaces,
 1244                                     &storage, "INBOX", mail, 0, NULL);
 1245          }
 1246   
 1247          if (ret < 0 ) {
 1248                  const char *error_string;
 1249                  enum mail_error error;
 1250   
 1251                  if (storage == NULL) {
 1252                          /* This shouldn't happen */
 1253                          i_error("BUG: Saving failed for unknown storage");
 1254                          return EX_TEMPFAIL;
 1255                  }
 1256   
 1257                  error_string = mail_storage_get_last_error(storage, &error);
 1258   
 1259                  if (stderr_rejection) {
 1260                          /* write to stderr also for tempfails so that MTA 
 1261                             can log the reason if it wants to. */
 1262                          fprintf(stderr, "%s\n", error_string);
 1263                  }
 1264   
 1265                  if (error != MAIL_ERROR_NOSPACE ||
 1266                      getenv("QUOTA_FULL_TEMPFAIL") != NULL) {
 1267                          /* Saving to INBOX should always work unless 
 1268                             we're over quota. If it didn't, it's probably a
 1269                             configuration problem. */
 1270                          return EX_TEMPFAIL;
 1271                  }
 1272   
 1273                  /* we'll have to reply with permanent failure */
 1274                  deliver_log(mail, "rejected: %s",
 1275                              str_sanitize(error_string, 512));
 1276   
 1277                  if (stderr_rejection)
 1278                          return EX_NOPERM;
 1279                  ret = mail_send_rejection(mail, user, error_string);
 1280                  if (ret != 0)
 1281                          return ret < 0 ? EX_TEMPFAIL : ret;
 1282                  /* ok, rejection sent */
 1283          }
 1284          i_free(explicit_envelope_sender);
 1285   
 1286          mail_free(&mail);
 1287          mailbox_header_lookup_unref(&headers_ctx);
 1288          mailbox_transaction_rollback(&t);
 1289          mailbox_close(&box);
 1290   
 1291          mail_user_unref(&mail_user);
 1292          mail_user_unref(&raw_mail_user);
 1293   
 1294          module_dir_unload(&modules);
 1295          mail_storage_deinit();
 1296          mail_users_deinit();
 1297   
 1298          duplicate_deinit();
 1299          dict_drivers_unregister_builtin();
 1300          lib_signals_deinit();
 1301   
 1302          io_loop_destroy(&ioloop);
 1303          lib_deinit();
 1304   
 1305          return EX_OK;
 1306  }
Show more  




Change Warning 8168.26092 : Ignored Return Value

Because they are very similar, this warning shares annotations with warnings 8168.26097 and 8168.26098.

Priority:
State:
Finding:
Owner:
Note: