Fossil SCM

If the FOSSIL_PWREADER environment variable is set to the name of a program, then use that program to prompt and read passwords and passphrases from the user when required, in place of the getpass() library routine.

drh 2016-06-07 15:27 trunk
Commit 55f3f3d42d546182eea390ad0af7026a4739f996
1 file changed +39 -1
+39 -1
--- src/user.c
+++ src/user.c
@@ -89,15 +89,53 @@
8989
fputs("\n", stderr);
9090
return pwd;
9191
}
9292
#endif
9393
94
+#if defined(_WIN32) || defined(WIN32)
95
+# include <io.h>
96
+# include <fcntl.h>
97
+# undef popen
98
+# define popen _popen
99
+# undef pclose
100
+# define pclose _pclose
101
+#endif
102
+
94103
/*
95104
** Do a single prompt for a passphrase. Store the results in the blob.
105
+**
106
+** If the FOSSIL_PWREADER environment variable is set, then it will
107
+** be the name of a program that prompts the user for their password/
108
+** passphrase in a secure manner. The program should take one or more
109
+** arguments which are the prompts and should output the acquired
110
+** passphrase as a single line on stdout. This function will read the
111
+** output using popen().
112
+**
113
+** If FOSSIL_PWREADER is not set, or if it is not the name of an
114
+** executable, then use the C-library getpass() routine.
115
+**
116
+** The return value is a pointer to a static buffer that is overwritten
117
+** on subsequent calls to this same routine.
96118
*/
97119
static void prompt_for_passphrase(const char *zPrompt, Blob *pPassphrase){
98
- char *z = getpass(zPrompt);
120
+ char *z;
121
+ const char *zProg = fossil_getenv("FOSSIL_PWREADER");
122
+ if( zProg && zProg[0] ){
123
+ static char zPass[100];
124
+ Blob cmd;
125
+ FILE *in;
126
+ blob_zero(&cmd);
127
+ blob_appendf(&cmd, "%s \"Fossil Passphrase\" \"%s\"", zProg, zPrompt);
128
+ zPass[0] = 0;
129
+ in = popen(blob_str(&cmd), "r");
130
+ fgets(zPass, sizeof(zPass), in);
131
+ pclose(in);
132
+ blob_reset(&cmd);
133
+ z = zPass;
134
+ }else{
135
+ z = getpass(zPrompt);
136
+ }
99137
strip_string(pPassphrase, z);
100138
}
101139
102140
/*
103141
** Prompt the user for a password. Store the result in the pPassphrase
104142
--- src/user.c
+++ src/user.c
@@ -89,15 +89,53 @@
89 fputs("\n", stderr);
90 return pwd;
91 }
92 #endif
93
 
 
 
 
 
 
 
 
 
94 /*
95 ** Do a single prompt for a passphrase. Store the results in the blob.
 
 
 
 
 
 
 
 
 
 
 
 
 
96 */
97 static void prompt_for_passphrase(const char *zPrompt, Blob *pPassphrase){
98 char *z = getpass(zPrompt);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99 strip_string(pPassphrase, z);
100 }
101
102 /*
103 ** Prompt the user for a password. Store the result in the pPassphrase
104
--- src/user.c
+++ src/user.c
@@ -89,15 +89,53 @@
89 fputs("\n", stderr);
90 return pwd;
91 }
92 #endif
93
94 #if defined(_WIN32) || defined(WIN32)
95 # include <io.h>
96 # include <fcntl.h>
97 # undef popen
98 # define popen _popen
99 # undef pclose
100 # define pclose _pclose
101 #endif
102
103 /*
104 ** Do a single prompt for a passphrase. Store the results in the blob.
105 **
106 ** If the FOSSIL_PWREADER environment variable is set, then it will
107 ** be the name of a program that prompts the user for their password/
108 ** passphrase in a secure manner. The program should take one or more
109 ** arguments which are the prompts and should output the acquired
110 ** passphrase as a single line on stdout. This function will read the
111 ** output using popen().
112 **
113 ** If FOSSIL_PWREADER is not set, or if it is not the name of an
114 ** executable, then use the C-library getpass() routine.
115 **
116 ** The return value is a pointer to a static buffer that is overwritten
117 ** on subsequent calls to this same routine.
118 */
119 static void prompt_for_passphrase(const char *zPrompt, Blob *pPassphrase){
120 char *z;
121 const char *zProg = fossil_getenv("FOSSIL_PWREADER");
122 if( zProg && zProg[0] ){
123 static char zPass[100];
124 Blob cmd;
125 FILE *in;
126 blob_zero(&cmd);
127 blob_appendf(&cmd, "%s \"Fossil Passphrase\" \"%s\"", zProg, zPrompt);
128 zPass[0] = 0;
129 in = popen(blob_str(&cmd), "r");
130 fgets(zPass, sizeof(zPass), in);
131 pclose(in);
132 blob_reset(&cmd);
133 z = zPass;
134 }else{
135 z = getpass(zPrompt);
136 }
137 strip_string(pPassphrase, z);
138 }
139
140 /*
141 ** Prompt the user for a password. Store the result in the pPassphrase
142

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button