summaryrefslogtreecommitdiff
blob: 81052f508fef4cc477200860a2ec974bfb034230 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 67)
+++ ChangeLog	(revision 68)
@@ -1,3 +1,7 @@
+
+Tue Dec 7 2010 Valient Gough <vgough@pobox.com>
+	* add annotation option, patch by Werner Koch.
+
 Sun Sep 5 2010 Valient Gough <vgough@pobox.com>
 	* fix mount failures when using certain options, due to changes in
 	  option passing mechanism in 1.7
Index: encfs/FileUtils.cpp
===================================================================
--- encfs/FileUtils.cpp	(revision 67)
+++ encfs/FileUtils.cpp	(revision 68)
@@ -314,15 +314,33 @@
 	return path.substr(0, last);
 }
 
-bool userAllowMkdir( const char *path, mode_t mode )
+bool userAllowMkdir(const char *path, mode_t mode )
 {
+    return userAllowMkdir(0, path, mode);
+}
+
+bool userAllowMkdir(int promptno, const char *path, mode_t mode )
+{
     // TODO: can we internationalize the y/n names?  Seems strange to prompt in
     // their own language but then have to respond 'y' or 'n'.
     // xgroup(setup)
     cerr << autosprintf( _("The directory \"%s\" does not exist. Should it be created? (y,n) "), path );
     char answer[10];
-    char *res = fgets( answer, sizeof(answer), stdin );
+    char *res;
 
+    switch (promptno)
+    {
+      case 1:
+        cerr << endl << "$PROMPT$ create_root_dir" << endl;
+        break;
+      case 2:
+        cerr << endl << "$PROMPT$ create_mount_point" << endl;
+        break;
+      default:
+        break;
+    }
+    res = fgets( answer, sizeof(answer), stdin );
+
     if(res != 0 && toupper(answer[0]) == 'Y')
     {
 	int result = mkdir( path, mode );
@@ -976,6 +994,7 @@
     bool useStdin = opts->useStdin;
     bool reverseEncryption = opts->reverseEncryption;
     ConfigMode configMode = opts->configMode;
+    bool annotate = opts->annotate;
     
     RootPtr rootInfo;
 
@@ -994,6 +1013,9 @@
                 " anything else, or an empty line will select standard mode.\n"
                 "?> ");
     
+        if (annotate)
+            cerr << "$PROMPT$ config_option" << endl;
+
         char *res = fgets( answer, sizeof(answer), stdin );
 	(void)res;
         cout << "\n";
@@ -1179,7 +1201,11 @@
     CipherKey userKey;
     rDebug( "useStdin: %i", useStdin );
     if(useStdin)
+    {
+        if (annotate)
+            cerr << "$PROMPT$ new_passwd" << endl;
         userKey = config->getUserKey( useStdin );
+    }
     else if(!passwordProgram.empty())
         userKey = config->getUserKey( passwordProgram, rootDir );
     else
@@ -1618,6 +1644,8 @@
         if(opts->passwordProgram.empty())
         {
             rDebug( "useStdin: %i", opts->useStdin );
+            if (opts->annotate)
+                cerr << "$PROMPT$ passwd" << endl;
             userKey = config->getUserKey( opts->useStdin );
         } else
             userKey = config->getUserKey( opts->passwordProgram, opts->rootDir );
Index: encfs/main.cpp
===================================================================
--- encfs/main.cpp	(revision 67)
+++ encfs/main.cpp	(revision 68)
@@ -104,6 +104,7 @@
 	if(opts->forceDecode) ss << "(forceDecode) ";
 	if(opts->ownerCreate) ss << "(ownerCreate) ";
 	if(opts->useStdin) ss << "(useStdin) ";
+	if(opts->annotate) ss << "(annotate) ";
 	if(opts->reverseEncryption) ss << "(reverseEncryption) ";
 	if(opts->mountOnDemand) ss << "(mountOnDemand) ";
 	for(int i=0; i<fuseArgc; ++i)
@@ -196,6 +197,7 @@
     out->opts->forceDecode = false;
     out->opts->ownerCreate = false;
     out->opts->useStdin = false;
+    out->opts->annotate = false;
     out->opts->reverseEncryption = false;
  
     bool useDefaultFlags = true;
@@ -223,6 +225,7 @@
 	{"extpass", 1, 0, 'p'}, // external password program
 	// {"single-thread", 0, 0, 's'}, // single-threaded mode
 	{"stdinpass", 0, 0, 'S'}, // read password from stdin
+	{"annotate", 0, 0, 513}, // Print annotation lines to stderr
 	{"verbose", 0, 0, 'v'}, // verbose mode
 	{"version", 0, 0, 'V'}, //version
 	{"reverse", 0, 0, 'r'}, // reverse encryption
@@ -263,6 +266,9 @@
 	case 'S':
 	    out->opts->useStdin = true;
 	    break;
+        case 513:
+            out->opts->annotate = true;
+            break;
 	case 'f':
 	    out->isDaemon = false;
 	    // this option was added in fuse 2.x
@@ -411,13 +417,15 @@
 
     // check that the directories exist, or that we can create them..
     if(!isDirectory( out->opts->rootDir.c_str() ) && 
-	    !userAllowMkdir( out->opts->rootDir.c_str() ,0700))
+	    !userAllowMkdir( out->opts->annotate? 1:0,
+                             out->opts->rootDir.c_str() ,0700))
     {
 	rWarning(_("Unable to locate root directory, aborting."));
 	return false;
     }
     if(!isDirectory( out->mountPoint.c_str() ) && 
-	    !userAllowMkdir( out->mountPoint.c_str(),0700))
+	    !userAllowMkdir( out->opts->annotate? 2:0,
+                             out->mountPoint.c_str(),0700))
     {
 	rWarning(_("Unable to locate mount point, aborting."));
 	return false;
@@ -630,7 +638,10 @@
 	try
 	{
 	    time_t startTime, endTime;
-	   
+	  
+            if (encfsArgs->opts->annotate)
+                cerr << "$STATUS$ fuse_main_start" << endl;
+
 	    // FIXME: workaround for fuse_main returning an error on normal
 	    // exit.  Only print information if fuse_main returned
 	    // immediately..
@@ -642,6 +653,9 @@
 		    &encfs_oper, (void*)ctx);
 	    
 	    time( &endTime );
+            
+            if (encfsArgs->opts->annotate)
+                cerr << "$STATUS$ fuse_main_end" << endl;
 
 	    if(res == 0)
 		returnCode = EXIT_SUCCESS;
Index: encfs/encfsctl.cpp
===================================================================
--- encfs/encfsctl.cpp	(revision 67)
+++ encfs/encfsctl.cpp	(revision 68)
@@ -693,7 +693,7 @@
     return EXIT_SUCCESS;
 }
 
-static int do_chpasswd( bool useStdin, int argc, char **argv )
+static int do_chpasswd( bool useStdin, bool annotate, int argc, char **argv )
 {
     (void)argc;
     string rootDir = argv[1];
@@ -721,6 +721,8 @@
 
     // ask for existing password
     cout << _("Enter current Encfs password\n");
+    if (annotate)
+        cerr << "$PROMPT$ passwd" << endl;
     CipherKey userKey = config->getUserKey( useStdin );
     if(!userKey)
 	return EXIT_FAILURE;
@@ -742,7 +744,11 @@
     config->kdfIterations = 0; // generate new
 
     if( useStdin )
+    {
+        if (annotate)
+            cerr << "$PROMPT$ new_passwd" << endl;
         userKey = config->getUserKey( true );
+    }
     else
         userKey = config->getNewUserKey();
 
@@ -781,12 +787,12 @@
 
 static int chpasswd( int argc, char **argv )
 {
-    return do_chpasswd( false, argc, argv );
+    return do_chpasswd( false, false, argc, argv );
 }
 
 static int chpasswdAutomaticly( int argc, char **argv )
 {
-    return do_chpasswd( true, argc, argv );
+    return do_chpasswd( true, false, argc, argv );
 }
 
 
Index: encfs/FileUtils.h
===================================================================
--- encfs/FileUtils.h	(revision 67)
+++ encfs/FileUtils.h	(revision 68)
@@ -36,7 +36,8 @@
 
 // ask the user for permission to create the directory.  If they say ok, then
 // do it and return true.
-bool userAllowMkdir( const char *dirPath, mode_t mode );
+bool userAllowMkdir(const char *dirPath, mode_t mode );
+bool userAllowMkdir(int promptno, const char *dirPath, mode_t mode );
 
 class Cipher;
 class DirNode;
@@ -72,6 +73,7 @@
 
     std::string passwordProgram; // path to password program (or empty)
     bool useStdin; // read password from stdin rather then prompting
+    bool annotate; // print annotation line prompt to stderr.
 
     bool ownerCreate; // set owner of new files to caller
 
@@ -87,6 +89,7 @@
         checkKey = true;
         forceDecode = false;
         useStdin = false;
+        annotate = false;
         ownerCreate = false;
         reverseEncryption = false;
         configMode = Config_Prompt;