2
* Copyright (C) 2006 International Business Machines
3
* Author(s): Trevor Highland <tshighla@us.ibm.com>
4
* Theresa Nelson <tmnelson@us.ibm.com>
5
* Tyler Hicks <tyhicks@ou.edu>
7
* I/O functions for mount helper
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License as
11
* published by the Free Software Foundation; either version 2 of the
12
* License, or (at your option) any later version.
14
* This program is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35
static int disable_echo(struct termios *saved_settings)
37
struct termios current_settings;
40
rc = tcgetattr(0, ¤t_settings);
43
*saved_settings = current_settings;
44
current_settings.c_lflag &= ~ECHO;
45
rc = tcsetattr(0, TCSANOW, ¤t_settings);
49
static int enable_echo(struct termios *saved_settings)
51
return tcsetattr(0, TCSANOW, saved_settings);
63
int get_string_stdin(char **val, char *prompt, int echo)
65
#define DEFAULT_STRING_LENGTH 16
67
struct termios saved_settings;
68
int length = DEFAULT_STRING_LENGTH;
72
printf("%s: ", prompt);
73
temp = malloc(length);
80
rc = disable_echo(&saved_settings);
85
if (count == length) {
86
temp = malloc(length * 2);
91
memcpy(temp, *val, length);
92
memset(*val, 0, length);
97
(*val)[count] = mygetchar();
99
} while((*val)[count-1] != '\n');
100
(*val)[count - 1] = '\0';
103
rc = enable_echo(&saved_settings);
109
int get_string(char *val, int len, int echo)
112
struct termios saved_settings;
115
if (echo == ECRYPTFS_ECHO_OFF) {
116
rc = disable_echo(&saved_settings);
121
val[count] = mygetchar();
123
} while(val[count-1] != '\n' && (count < len));
127
val[count - 1] = '\0';
128
if (echo == ECRYPTFS_ECHO_OFF) {
130
rc = enable_echo(&saved_settings);
136
static inline int munch_newline(void)
138
if (mygetchar() == '\n')
140
while (mygetchar() != '\n');
144
int manager_menu(void)
149
printf("\neCryptfs key management menu\n");
150
printf("-------------------------------\n");
151
printf("\t%d. Add passphrase key to keyring\n", MME_MOUNT_PASSPHRASE);
152
printf("\t%d. Add public key to keyring\n", MME_MOUNT_PUBKEY);
153
printf("\t%d. Generate new public/private keypair\n", MME_GEN_PUBKEY);
154
printf("\t%d. Exit\n", MME_ABORT);
156
printf("\nMake selection: ");
157
str[0] = mygetchar();
158
if (munch_newline()) {
159
printf("Invalid selection\n");
162
str[strlen(str)] = '\0';
163
selection = atoi(str);
165
case MME_MOUNT_PASSPHRASE:
166
case MME_MOUNT_PUBKEY:
171
printf("Invalid selection\n");
177
int read_passphrase_salt(char *pass, char *salt)
179
char *confirmed_pass;
182
confirmed_pass = malloc(ECRYPTFS_MAX_PASSWORD_LENGTH);
183
if (!confirmed_pass) {
185
ecryptfs_syslog(LOG_ERR, "Failed to allocate memory\n");
188
mlock(confirmed_pass, ECRYPTFS_MAX_PASSWORD_LENGTH);
189
printf("\n\tMount-wide passphrase: ");
190
rc = get_string(pass, ECRYPTFS_MAX_PASSWORD_LENGTH, ECRYPTFS_ECHO_OFF);
193
if (pass[0] == '\0') {
194
printf("Invalid passphrase. Aborting mount.\n");
198
printf("\tConfirm passphrase: ");
199
rc = get_string(confirmed_pass, ECRYPTFS_MAX_PASSWORD_LENGTH,
202
ecryptfs_syslog(LOG_ERR, "Failed to read passphrase\n");
205
if (strcmp(pass, confirmed_pass) != 0) {
206
printf("Passphrase mismatch. Aborting mount\n");
210
printf("\tUsing the default salt value\n");
212
memset(confirmed_pass, 0, ECRYPTFS_MAX_PASSWORD_LENGTH);
213
free(confirmed_pass);
217
int ecryptfs_select_key_mod(struct ecryptfs_key_mod **key_mod,
218
struct ecryptfs_ctx *ctx)
223
struct ecryptfs_key_mod *curr;
225
int default_key_mod = 1;
229
curr = ctx->key_mod_list_head.next;
236
printf("\nThe following PKI modules are available:\n");
238
printf("\t%i. %s\n", count, curr->alias);
242
printf("\nSelect desired key module [%d]: ", default_key_mod);
243
fgets(str, 4, stdin);
245
str[strlen(str)] = '\0';
247
key_mod_type = default_key_mod;
249
key_mod_type = atoi(str);
250
if (key_mod_type < 1 || key_mod_type >= count) {
251
char *pch = strstr(str, "\n");
253
printf("Invalid selection\n");
257
while ((ch = mygetchar()) != '\n');
261
curr = ctx->key_mod_list_head.next;
262
while(key_mod_type > 1) {