# HG changeset patch # User Timo Sirainen # Date 1191163885 -10800 # Node ID 9b71007b70c72db496fd3af7a361fe7d13b347f0 # Parent 4e92a6c44b44950d8e287b1c3f3630ca8d630a1c Another try, -d is now destination user as originally and -a is now destination address. diff -r 4e92a6c44b44 -r 9b71007b70c7 src/deliver/deliver.c --- a/src/deliver/deliver.c Sun Sep 30 17:38:31 2007 +0300 +++ b/src/deliver/deliver.c Sun Sep 30 17:51:25 2007 +0300 @@ -511,7 +511,7 @@ static void print_help(void) { printf( -"Usage: deliver [-c ] [-a ] [-d ]\n" +"Usage: deliver [-c ] [-a
] [-d ]\n" " [-f ] [-m ] [-n] [-e] [-k]\n"); } @@ -590,7 +590,7 @@ const char *envelope_sender = DEFAULT_ENVELOPE_SENDER; const char *mailbox = "INBOX"; const char *auth_socket; - const char *home, *destaddr, *authuser, *value, *error; + const char *home, *destaddr, *user, *value, *error; ARRAY_TYPE(string) extra_fields; struct mail_namespace *ns, *mbox_ns; struct mail_storage *storage; @@ -602,6 +602,7 @@ pool_t namespace_pool; bool stderr_rejection = FALSE; bool keep_environment = FALSE; + bool user_auth = FALSE; bool *input_first; int i, ret; @@ -619,24 +620,21 @@ lib_signals_ignore(SIGXFSZ, TRUE); #endif - destaddr = authuser = NULL; + destaddr = user = NULL; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-a") == 0) { - /* destination auth user */ - i++; - if (i == argc) { - i_fatal_status(EX_USAGE, - "Missing auth user argument"); - } - authuser = argv[i]; - } else if (strcmp(argv[i], "-d") == 0) { /* destination address */ i++; - if (i == argc) { - i_fatal_status(EX_USAGE, - "Missing destination argument"); - } + if (i == argc) + i_fatal_status(EX_USAGE, "Missing -a argument"); destaddr = argv[i]; + } else if (strcmp(argv[i], "-d") == 0) { + /* destination user */ + i++; + if (i == argc) + i_fatal_status(EX_USAGE, "Missing -d argument"); + user = argv[i]; + user_auth = TRUE; } else if (strcmp(argv[i], "-e") == 0) { stderr_rejection = TRUE; } else if (strcmp(argv[i], "-c") == 0) { @@ -652,10 +650,8 @@ } else if (strcmp(argv[i], "-m") == 0) { /* destination mailbox */ i++; - if (i == argc) { - i_fatal_status(EX_USAGE, - "Missing mailbox argument"); - } + if (i == argc) + i_fatal_status(EX_USAGE, "Missing -m argument"); /* Ignore -m "". This allows doing -m ${extension} in Postfix to handle user+mailbox */ if (*argv[i] != '\0') @@ -666,10 +662,8 @@ } else if (strcmp(argv[i], "-f") == 0) { /* envelope sender address */ i++; - if (i == argc) { - i_fatal_status(EX_USAGE, - "Missing envelope argument"); - } + if (i == argc) + i_fatal_status(EX_USAGE, "Missing -f argument"); envelope_sender = argv[i]; explicit_envelope_sender = argv[i]; } else if (argv[i][0] != '\0') { @@ -683,16 +677,15 @@ deliver_env_clean(); process_euid = geteuid(); - if (destaddr != NULL) { - if (authuser == NULL) - authuser = destaddr; - } else if (process_euid != 0) { + if (user_auth) + ; + else if (process_euid != 0) { /* we're non-root. get our username and possibly our home. */ struct passwd *pw; pw = getpwuid(process_euid); if (pw != NULL) { - authuser = t_strdup(pw->pw_name); + user = t_strdup(pw->pw_name); if (getenv("HOME") == NULL) env_put(t_strconcat("HOME=", pw->pw_dir, NULL)); } else { @@ -705,7 +698,7 @@ } config_file_init(config_path); - open_logfile(authuser); + open_logfile(user); if (getenv("MAIL_DEBUG") != NULL) env_put("DEBUG=1"); @@ -726,21 +719,21 @@ } t_array_init(&extra_fields, 64); - if (authuser != NULL) { + if (user_auth) { auth_socket = getenv("AUTH_SOCKET_PATH"); if (auth_socket == NULL) auth_socket = DEFAULT_AUTH_SOCKET_PATH; ret = auth_client_lookup_and_restrict(ioloop, auth_socket, - authuser, process_euid, + user, process_euid, &extra_fields); if (ret != 0) return ret; - } else { - destaddr = authuser; } + if (destaddr == NULL) + destaddr = user; - expand_envs(authuser); + expand_envs(user); putenv_extra_fields(&extra_fields); /* If possible chdir to home directory, so that core file @@ -755,7 +748,7 @@ } } - env_put(t_strconcat("USER=", authuser, NULL)); + env_put(t_strconcat("USER=", user, NULL)); value = getenv("UMASK"); if (value == NULL || sscanf(value, "%i", &i) != 1 || i < 0) @@ -789,12 +782,12 @@ module_dir_init(modules); namespace_pool = pool_alloconly_create("namespaces", 1024); - if (mail_namespaces_init(namespace_pool, authuser, &ns) < 0) + if (mail_namespaces_init(namespace_pool, user, &ns) < 0) exit(EX_TEMPFAIL); mbox_ns = mail_namespaces_init_empty(namespace_pool); mbox_ns->flags |= NAMESPACE_FLAG_INTERNAL; - if (mail_storage_create(mbox_ns, "mbox", "/tmp", authuser, + if (mail_storage_create(mbox_ns, "mbox", "/tmp", user, 0, FILE_LOCK_METHOD_FCNTL, &error) < 0) i_fatal("Couldn't create internal mbox storage: %s", error); input = create_mbox_stream(0, envelope_sender, &input_first); @@ -867,7 +860,7 @@ fprintf(stderr, "%s\n", error_string); return EX_NOPERM; } - ret = mail_send_rejection(mail, authuser, error_string); + ret = mail_send_rejection(mail, user, error_string); if (ret != 0) return ret < 0 ? EX_TEMPFAIL : ret; /* ok, rejection sent */