]> git.pld-linux.org Git - packages/util-linux.git/blame - util-linux-losetup-getpass.patch
- added no_multiline patch... needed for gettext in gcc33
[packages/util-linux.git] / util-linux-losetup-getpass.patch
CommitLineData
0c76cfef
JB
1diff -Naur util-linux-2.11r-o/mount/lomount.c util-linux-2.11r/mount/lomount.c
2--- util-linux-2.11r-o/mount/lomount.c Mon Jul 9 16:10:58 2001
3+++ util-linux-2.11r/mount/lomount.c Mon Jul 9 16:19:24 2001
0f21b0bd
SZ
4@@ -6,6 +6,11 @@
5 * - added Native Language Support
6 * Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
7 * - fixed strerr(errno) in gettext calls
8+ * 2000-09-24 Marc Mutz <Marc@Mutz.com>
9+ * - added long option names and the --pass-fd option to pass
10+ * passphrases via fd's to losetup/mount. Used for encryption in
11+ * non-interactive environments. The idea behind xgetpass() is stolen
12+ * from GnuPG, v.1.0.3 (http://www.gnupg.org/).
13 */
14
15 #define PROC_DEVICES "/proc/devices"
16@@ -206,12 +211,50 @@
17 return 0;
18 }
19
20+/* A function to read the passphrase either from the terminal or from
21+ * an open file descriptor */
22+static char *
23+xgetpass (int pfd, const char *prompt)
24+{
25+ if (pfd < 0) /* terminal */
26+ return (getpass(prompt));
27+ else { /* file descriptor */
28+ char *pass = NULL;
29+ int buflen, i;
30+
31+ buflen=0;
32+ for (i=0; ; i++) {
33+ if (i >= buflen-1) {
34+ /* we're running out of space in the buffer.
35+ * Make it bigger: */
36+ char *tmppass = pass;
37+ buflen += 128;
38+ pass = realloc(tmppass,buflen);
39+ if (pass == NULL) {
40+ /* realloc failed. Stop reading _now_. */
41+ error("not enough memory while reading passphrase");
42+ pass = tmppass; /* the old buffer hasn't changed */
43+ break;
44+ }
45+ };
46+ if ( read(pfd,pass+i, 1) != 1 || pass[i] == '\n' )
47+ break;
48+ }
49+ if (pass == NULL)
50+ return "";
51+ else {
52+ pass[i] = 0;
53+ return pass;
54+ }
55+ }
56+}
57+
58 #define HASHLENGTH 20
59 #define PASSWDBUFFLEN 130 /* getpass returns only max. 128 bytes, see man getpass */
60
61 int
62 set_loop (const char *device, const char *file, int offset,
63- const char *encryption, int *loopro) {
64+ const char *encryption, int pfd, int *loopro) {
65 struct loop_info loopinfo;
66 int fd, ffd, mode, i;
67 int keylength;
68@@ -262,17 +305,19 @@
69 loopinfo.lo_encrypt_key_size = 0;
70 break;
71 case LO_CRYPT_XOR:
72- pass = getpass (_("Password: "));
73+ /* WARNING: xgetpass() can return massive amounts of data,
74+ * not only 128 bytes like the original getpass(3) */
75+ pass = xgetpass (pfd,_("Password: "));
76 xstrncpy (loopinfo.lo_encrypt_key, pass, LO_KEY_SIZE);
77 loopinfo.lo_encrypt_key_size = strlen(loopinfo.lo_encrypt_key);
78 break;
79 case LO_CRYPT_DES:
80 printf(_("WARNING: Use of DES is depreciated.\n"));
81- pass = getpass (_("Password: "));
82+ pass = xgetpass (pfd,_("Password: "));
83 strncpy (loopinfo.lo_encrypt_key, pass, 8);
84 loopinfo.lo_encrypt_key[8] = 0;
85 loopinfo.lo_encrypt_key_size = 8;
86- pass = getpass (_("Init (up to 16 hex digits): "));
87+ pass = xgetpass (pfd,_("Init (up to 16 hex digits): "));
88 for (i = 0; i < 16 && pass[i]; i++)
89 if (isxdigit (pass[i])) {
90 loopinfo.lo_init[i >> 3] |= (pass[i] > '9' ?
91@@ -293,7 +338,7 @@
92 case LO_CRYPT_RC6:
93 case LO_CRYPT_DES_EDE3:
94 case LO_CRYPT_DFC:
95- pass = getpass("Password :");
96+ pass = xgetpass(pfd,"Password :");
97 strncpy(passwdbuff+1,pass,PASSWDBUFFLEN-1);
98 passwdbuff[0] = 'A';
99 rmd160_hash_buffer(keybits,pass,strlen(pass));
100@@ -361,7 +406,7 @@
101
102 int
103 set_loop (const char *device, const char *file, int offset,
104- const char *encryption, int *loopro) {
105+ const char *encryption, int pfd, int *loopro) {
106 mutter();
107 return 1;
108 }
109@@ -390,20 +435,34 @@
110 int verbose = 0;
111 static char *progname;
112
113+static struct option longopts[] = {
114+ { "delete", 0, 0, 'd' },
115+ { "detach", 0, 0, 'd' },
116+ { "encryption", 1, 0, 'e' },
117+ { "help", 0, 0, 'h' },
118+ { "offset", 1, 0, 'o' },
119+ { "pass-fd", 1, 0, 'p' },
120+ { "verbose", 0, 0, 'v' },
121+ { NULL, 0, 0, 0 }
122+};
123+
124+
125 static void
126 usage(void) {
127- struct crypt_type_struct *c;
128 fprintf(stderr, _("usage:\n\
129 %s loop_device # give info\n\
130 %s -d loop_device # delete\n\
131- %s [ -e encryption ] [ -o offset ] loop_device file # setup\n"),
132+ %s [ options ] loop_device file # setup\n\
133+ where options include\n\
134+ --offset <num>, -o <num>\n\
135+ start at offset <num> into file.\n\
136+ --pass-fd <num>, -p <num>\n\
137+ read passphrase from file descriptor <num>\n\
138+ instead of the terminal.\n\
139+ --encryption <cipher>, -e <cipher>\n\
140+ encrypt with <cipher>.\n\
141+ Check /proc/crypto/cipher for available ciphers.\n"),
142 progname, progname, progname);
143- fprintf(stderr, " where encryption is one of:\n");
144- c = &crypt_type_tbl[0];
145- while(c->name) {
146- fprintf(stderr, " %s\n", c->name);
147- c++;
148- }
149 exit(1);
150 }
151
152@@ -436,8 +495,9 @@
153
154 int
155 main(int argc, char **argv) {
156- char *offset, *encryption;
157+ char *offset, *encryption, *passfd;
158 int delete,off,c;
159+ int pfd = -1;
160 int res = 0;
161 int ro = 0;
162
163@@ -446,9 +506,10 @@
164 textdomain(PACKAGE);
165
166 delete = off = 0;
167- offset = encryption = NULL;
0c76cfef 168+ offset = encryption = passfd = NULL;
0f21b0bd 169 progname = argv[0];
0c76cfef
JB
170- while ((c = getopt(argc,argv,"de:o:v")) != -1) {
171+ while ((c = getopt_long(argc,argv,"de:ho:p:v",
172+ longopts, NULL)) != -1) {
0f21b0bd
SZ
173 switch (c) {
174 case 'd':
175 delete = 1;
176@@ -459,6 +520,9 @@
177 case 'o':
178 offset = optarg;
179 break;
180+ case 'p':
181+ passfd = optarg;
182+ break;
183 case 'v':
184 verbose = 1;
185 break;
186@@ -467,7 +531,7 @@
187 }
188 }
189 if (argc == 1) usage();
190- if ((delete && (argc != optind+1 || encryption || offset)) ||
191+ if ((delete && (argc != optind+1 || encryption || offset || passfd)) ||
192 (!delete && (argc < optind+1 || argc > optind+2)))
193 usage();
194 if (argc == optind+1) {
195@@ -478,7 +542,9 @@
196 } else {
197 if (offset && sscanf(offset,"%d",&off) != 1)
198 usage();
199- res = set_loop(argv[optind],argv[optind+1],off,encryption,&ro);
200+ if (passfd && sscanf(passfd,"%d",&pfd) != 1)
201+ usage();
202+ res = set_loop(argv[optind],argv[optind+1],off,encryption,pfd,&ro);
203 }
204 return res;
205 }
206diff -Naur util-linux-2.11g-o/mount/lomount.h util-linux-2.11g/mount/lomount.h
207--- util-linux-2.11g-o/mount/lomount.h Fri Dec 8 19:08:02 2000
208+++ util-linux-2.11g/mount/lomount.h Mon Jul 9 16:11:38 2001
209@@ -1,5 +1,5 @@
210 extern int verbose;
211-extern int set_loop (const char *, const char *, int, const char *, int *);
212+extern int set_loop (const char *, const char *, int, const char *, int, int *);
213 extern int del_loop (const char *);
214 extern int is_loop_device (const char *);
215 extern char * find_unused_loop_device (void);
0f21b0bd
SZ
216diff -Naur util-linux-2.11g-o/mount/losetup.8 util-linux-2.11g/mount/losetup.8
217--- util-linux-2.11g-o/mount/losetup.8 Mon Jul 9 16:10:58 2001
218+++ util-linux-2.11g/mount/losetup.8 Mon Jul 9 16:11:38 2001
219@@ -10,6 +10,9 @@
220 ] [
221 .B \-o
222 .I offset
223+] [
224+.B \-p
225+.I num
226 ]
227 .I loop_device file
228 .br
229@@ -26,9 +29,9 @@
230 \fIloop_device\fP argument is given, the status of the corresponding loop
231 device is shown.
232 .SH OPTIONS
233-.IP \fB\-d\fP
234+.IP "\fB\-\-delete, \-\-detach, \-d\fP"
235 detach the file or device associated with the specified loop device.
236-.IP "\fB\-e \fIencryption\fP"
237+.IP "\fB\-\-encryption, \-e \fIencryption\fP"
238 .RS
239 enable data encryption. The following keywords are recognized:
240 .IP \fBNONE\fP
241@@ -79,9 +82,12 @@
242 enabled in the Crypto API.
243 .PD
244 .RE
245-.IP "\fB\-o \fIoffset\fP"
246+.IP "\fB\-\-offset, \-o \fIoffset\fP"
247 the data start is moved \fIoffset\fP bytes into the specified file or
248 device.
249+.IP "\fB\-\-pass-fd, \-p \fInum\fP"
250+read the passphrase from file descriptor \fInum\fP instead of the
251+terminal.
252 .SH RETURN VALUE
253 .B losetup
254 returns 0 on success, nonzero on failure. When
255diff -Naur util-linux-2.11g-o/mount/mount.8 util-linux-2.11g/mount/mount.8
256--- util-linux-2.11g-o/mount/mount.8 Wed Jun 27 01:19:12 2001
257+++ util-linux-2.11g/mount/mount.8 Mon Jul 9 16:11:38 2001
258@@ -248,6 +248,12 @@
259 .B \-v
260 Verbose mode.
261 .TP
262+.B \-p "\fInum\fP"
263+If the mount requires a passphrase to be entered, read it from file
264+descriptor
265+.IR num\fP
266+instead of from the terminal.
267+.TP
268 .B \-a
269 Mount all filesystems (of the given types) mentioned in
270 .IR fstab .
271@@ -1475,7 +1481,10 @@
272 .BR loop ", " offset " and " encryption ,
273 that are really options to
274 .BR losetup (8).
275-If no explicit loop device is mentioned
276+If the mount requires a passphrase, you will be prompted for one unless
277+you specify a file descriptor to read from instead with the
278+.BR \-\-pass-fd
279+option. If no explicit loop device is mentioned
280 (but just an option `\fB\-o loop\fP' is given), then
281 .B mount
282 will try to find some unused loop device and use that.
0c76cfef
JB
283diff -Naur util-linux-2.11r-o/mount/mount.c util-linux-2.11r/mount/mount.c
284--- util-linux-2.11r-o/mount/mount.c Fri Jun 8 01:24:28 2001
285+++ util-linux-2.11r/mount/mount.c Mon Jul 9 16:22:13 2001
0f21b0bd
SZ
286@@ -108,6 +108,9 @@
287 /* True if ruid != euid. */
288 static int suid = 0;
289
290+/* Contains the fd no. to read the passphrase from, if any */
291+static int pfd = -1;
292+
293 /* Map from -o and fstab option strings to the flag argument to mount(2). */
294 struct opt_map {
295 const char *opt; /* option name */
296@@ -587,7 +590,7 @@
297 if (verbose)
298 printf(_("mount: going to use the loop device %s\n"), *loopdev);
299 offset = opt_offset ? strtoul(opt_offset, NULL, 0) : 0;
300- if (set_loop (*loopdev, *loopfile, offset, opt_encryption, &loopro)) {
301+ if (set_loop (*loopdev, *loopfile, offset, opt_encryption, pfd, &loopro)) {
302 if (verbose)
303 printf(_("mount: failed setting up loop device\n"));
304 return EX_FAIL;
305@@ -1305,6 +1308,7 @@
306 { "read-write", 0, 0, 'w' },
307 { "rw", 0, 0, 'w' },
308 { "options", 1, 0, 'o' },
309+ { "pass-fd", 1, 0, 'p' },
74c0b1e2 310 { "test-opts", 1, 0, 'O' },
0f21b0bd
SZ
311 { "types", 1, 0, 't' },
312 { "bind", 0, 0, 128 },
0f21b0bd
SZ
313@@ -1337,7 +1341,7 @@
314 " mount --bind olddir newdir\n"
315 "A device can be given by name, say /dev/hda1 or /dev/cdrom,\n"
316 "or by label, using -L label or by uuid, using -U uuid .\n"
317- "Other options: [-nfFrsvw] [-o options].\n"
318+ "Other options: [-nfFrsvw] [-o options] [-p num].\n"
319 "For many more details, say man 8 mount .\n"
320 ));
321 /*
322@@ -1353,6 +1357,7 @@
323 int c, result = 0, specseen;
324 char *options = NULL, *spec, *node;
325 char *volumelabel = NULL;
326+ char *passfd = NULL;
327 char *uuid = NULL;
328 char *types = NULL;
329 struct mntentchn *mc;
330@@ -1374,7 +1379,7 @@
331 initproctitle(argc, argv);
332 #endif
333
74c0b1e2 334- while ((c = getopt_long (argc, argv, "afFhlL:no:O:rsU:vVwt:",
335+ while ((c = getopt_long (argc, argv, "afFhlL:no:O:p:rsU:vVwt:",
0c76cfef 336 longopts, NULL)) != -1) {
0f21b0bd
SZ
337 switch (c) {
338 case 'a': /* mount everything in fstab */
339@@ -1408,6 +1413,9 @@
340 readonly = 1;
341 readwrite = 0;
342 break;
343+ case 'p': /* read passphrase from given fd */
344+ passfd = optarg;
345+ break;
346 case 's': /* allow sloppy mount options */
347 sloppy = 1;
348 break;
349@@ -1491,6 +1499,9 @@
350 printf(_("mount: mounting %s\n"), spec);
351 } else
352 spec = NULL; /* just for gcc */
353+
354+ if (passfd && sscanf(passfd,"%d",&pfd) != 1)
355+ die (EX_USAGE, _("mount: argument to --pass-fd or -p must be a number"));
356
357 switch (argc+specseen) {
358 case 0:
This page took 0.45491 seconds and 4 git commands to generate.