git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #24331 from LumiGuide/ssmtp-AuthPassFile

ssmtp: use the authPassFile option instead of authPass

commitcb6d1fdfd98482c3a557dada9cceadfd4d603c62 authorJörg Thalheim <Mic92@users.noreply.github.com> dateSat 8 Apr 2017, 17:22 (10 years ago) parenta40600b21e3c2a
4 files changed+113−11
lib/maintainers.nix+1 nixos/modules/programs/ssmtp.nix+36−9 pkgs/tools/networking/ssmtp/default.nix+7−2 pkgs/tools/networking/ssmtp/ssmtp_support_AuthPassFile_parameter.patch+69
lib/maintainers.nix+1
@@ -60,6 +60,7 @@
6060 bachp = "Pascal Bach <pascal.bach@nextrem.ch>";
6161 badi = "Badi' Abdul-Wahid <abdulwahidc@gmail.com>";
6262 balajisivaraman = "Balaji Sivaraman<sivaraman.balaji@gmail.com>";
63+ basvandijk = "Bas van Dijk <v.dijk.bas@gmail.com>";
6364 Baughn = "Svein Ove Aas <sveina@gmail.com>";
6465 bcarrell = "Brandon Carrell <brandoncarrell@gmail.com>";
6566 bcdarwin = "Ben Darwin <bcdarwin@gmail.com>";
nixos/modules/programs/ssmtp.nix+36−9
@@ -39,7 +39,8 @@ in
3939 example = "mail.example.org";
4040 description = ''
4141 The host name of the default mail server to use to deliver
42− e-mail.
42+ e-mail. Can also contain a port number (ex: mail.example.org:587),
43+ defaults to port 25 if no port is given.
4344 '';
4445 };
4546
@@ -95,9 +96,28 @@ in
9596 example = "correctHorseBatteryStaple";
9697 description = ''
9798 Password used for SMTP auth. (STORED PLAIN TEXT, WORLD-READABLE IN NIX STORE)
99+
100+ It's recommended to use <option>authPassFile</option>
101+ which takes precedence over <option>authPass</option>.
102+ '';
103+ };
104+
105+ authPassFile = mkOption {
106+ type = types.nullOr types.str;
107+ default = null;
108+ example = "/run/keys/ssmtp-authpass";
109+ description = ''
110+ Path to a file that contains the password used for SMTP auth. The file
111+ should not contain a trailing newline, if the password does not contain one.
112+ This file should be readable by the users that need to execute ssmtp.
113+
114+ <option>authPassFile</option> takes precedence over <option>authPass</option>.
115+
116+ Warning: when <option>authPass</option> is non-empty <option>authPassFile</option>
117+ defaults to a file in the WORLD-READABLE Nix store containing that password.
98118 '';
99119 };
100−
120+
101121 setSendmail = mkOption {
102122 type = types.bool;
103123 default = true;
@@ -111,21 +131,28 @@ in
111131
112132 config = mkIf cfg.directDelivery {
113133
134+ networking.defaultMailServer.authPassFile = mkIf (cfg.authPass != "")
135+ (mkDefault (toString (pkgs.writeTextFile {
136+ name = "ssmtp-authpass";
137+ text = cfg.authPass;
138+ })));
139+
114140 environment.etc."ssmtp/ssmtp.conf".text =
141+ let yesNo = yes : if yes then "YES" else "NO"; in
115142 ''
116143 MailHub=${cfg.hostName}
117144 FromLineOverride=YES
118− ${if cfg.root != "" then "root=${cfg.root}" else ""}
119− ${if cfg.domain != "" then "rewriteDomain=${cfg.domain}" else ""}
120− UseTLS=${if cfg.useTLS then "YES" else "NO"}
121− UseSTARTTLS=${if cfg.useSTARTTLS then "YES" else "NO"}
145+ ${optionalString (cfg.root != "") "root=${cfg.root}"}
146+ ${optionalString (cfg.domain != "") "rewriteDomain=${cfg.domain}"}
147+ UseTLS=${yesNo cfg.useTLS}
148+ UseSTARTTLS=${yesNo cfg.useSTARTTLS}
122149 #Debug=YES
123− ${if cfg.authUser != "" then "AuthUser=${cfg.authUser}" else ""}
124− ${if cfg.authPass != "" then "AuthPass=${cfg.authPass}" else ""}
150+ ${optionalString (cfg.authUser != "") "AuthUser=${cfg.authUser}"}
151+ ${optionalString (!isNull cfg.authPassFile) "AuthPassFile=${cfg.authPassFile}"}
125152 '';
126153
127154 environment.systemPackages = [pkgs.ssmtp];
128−
155+
129156 services.mail.sendmailSetuidWrapper = mkIf cfg.setSendmail {
130157 program = "sendmail";
131158 source = "${pkgs.ssmtp}/bin/sendmail";
pkgs/tools/networking/ssmtp/default.nix+7−2
@@ -10,6 +10,10 @@ stdenv.mkDerivation {
1010 sha256 = "0dps8s87ag4g3jr6dk88hs9zl46h3790marc5c2qw7l71k4pvhr2";
1111 };
1212
13+ # A request has been made to merge this patch into ssmtp.
14+ # See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=858781
15+ patches = [ ./ssmtp_support_AuthPassFile_parameter.patch ];
16+
1317 configureFlags = "--sysconfdir=/etc ${if tlsSupport then "--enable-ssl" else ""}";
1418
1519 postConfigure =
@@ -27,7 +31,8 @@ stdenv.mkDerivation {
2731
2832 buildInputs = stdenv.lib.optional tlsSupport openssl;
2933
30− meta = {
31− platforms = stdenv.lib.platforms.linux;
34+ meta = with stdenv.lib; {
35+ platforms = platforms.linux;
36+ maintainers = with maintainers; [ basvandijk ];
3237 };
3338}
pkgs/tools/networking/ssmtp/ssmtp_support_AuthPassFile_parameter.patchnew file+69
@@ -0,0 +1,69 @@
1+diff -Naurb a/ssmtp.c b/ssmtp.c
2+--- a/ssmtp.c 2009-11-23 10:55:11.000000000 +0100
3++++ b/ssmtp.c 2017-03-25 03:00:26.508283016 +0100
4+@@ -57,6 +57,7 @@
5+ char arpadate[ARPADATE_LENGTH];
6+ char *auth_user = (char)NULL;
7+ char *auth_pass = (char)NULL;
8++char *auth_passfile = (char)NULL;
9+ char *auth_method = (char)NULL; /* Mechanism for SMTP authentication */
10+ char *mail_domain = (char)NULL;
11+ char *from = (char)NULL; /* Use this as the From: address */
12+@@ -1053,6 +1054,15 @@
13+ log_event(LOG_INFO, "Set AuthPass=\"%s\"\n", auth_pass);
14+ }
15+ }
16++ else if(strcasecmp(p, "AuthPassFile") == 0 && !auth_passfile) {
17++ if((auth_passfile = strdup(q)) == (char *)NULL) {
18++ die("parse_config() -- strdup() failed");
19++ }
20++
21++ if(log_level > 0) {
22++ log_event(LOG_INFO, "Set AuthPassFile=\"%s\"\n", auth_passfile);
23++ }
24++ }
25+ else if(strcasecmp(p, "AuthMethod") == 0 && !auth_method) {
26+ if((auth_method = strdup(q)) == (char *)NULL) {
27+ die("parse_config() -- strdup() failed");
28+@@ -1415,6 +1425,8 @@
29+ struct passwd *pw;
30+ int i, sock;
31+ uid_t uid;
32++ FILE *fp;
33++ char pass_buf[BUF_SZ+1];
34+ bool_t minus_v_save, leadingdot, linestart = True;
35+ int timeout = 0;
36+ int bufsize = sizeof(b)-1;
37+@@ -1433,6 +1445,17 @@
38+ log_event(LOG_INFO, "%s not found", config_file);
39+ }
40+
41++ if(auth_passfile != (char *)NULL) {
42++ if((fp = fopen(auth_passfile, "r")) == (FILE *)NULL) {
43++ die("Could not open the AuthPassFile %s", auth_passfile);
44++ }
45++ if (fgets(pass_buf, BUF_SZ, fp) == NULL) {
46++ die("Error while reading a line from the AuthPassFile %s, or it is empty", auth_passfile);
47++ }
48++ fclose(fp);
49++ auth_pass = strdup(pass_buf);
50++ }
51++
52+ if((p = strtok(pw->pw_gecos, ";,"))) {
53+ if((gecos = strdup(p)) == (char *)NULL) {
54+ die("ssmtp() -- strdup() failed");
55+diff -Naurb a/ssmtp.conf.5 b/ssmtp.conf.5
56+--- a/ssmtp.conf.5 2008-02-29 03:50:15.000000000 +0100
57++++ b/ssmtp.conf.5 2017-03-25 01:45:52.890165426 +0100
58+@@ -61,6 +61,11 @@
59+ .Pp
60+ .It Cm AuthPass
61+ The password to use for SMTP AUTH.
62++It is recommended to use AuthPassFile which also takes precedence over AuthPass.
63++.Pp
64++.It Cm AuthPassFile
65++A file that should contain the password to use for SMTP AUTH.
66++This takes precedence over AuthPass.
67+ .Pp
68+ .It Cm AuthMethod
69+ The authorization method to use.