268
248
for (i = 0; i < current->num_transitions; i++) {
269
249
struct transition_node *tn = ¤t->tl[i];
271
if (tn->val && strcmp("default", tn->val) == 0) {
251
if (tn->val && strcmp("default", tn->val) == 0){
272
252
int trans_func_tok_id = NULL_TOK;
274
254
if (tn->trans_func)
275
255
trans_func_tok_id =
276
256
tn->trans_func(ctx, current,
277
257
mnt_params, foo);
278
if (trans_func_tok_id == WRONG_VALUE &&
280
(current->flags & STDIN_REQUIRED))) {
284
if (trans_func_tok_id == MOUNT_ERROR ||
285
trans_func_tok_id < 0)
258
if (trans_func_tok_id == MOUNT_ERROR)
286
259
return trans_func_tok_id;
287
260
if ((*next = tn->next_token))
289
262
else return -EINVAL;
296
269
* Try to find one of the aliases for this node in the list of
297
270
* name-value pairs. If found, set the value from that element in the
300
* Returns non-zero on error condition
302
static int retrieve_val(int *value_retrieved,
303
struct ecryptfs_name_val_pair *nvp_head,
273
static int retrieve_val(struct ecryptfs_name_val_pair *nvp_head,
304
274
struct param_node *node)
306
276
int i = node->num_mnt_opt_names;
309
278
if (ecryptfs_verbosity)
310
279
syslog(LOG_INFO, "%s: Called on node [%s]\n", __FUNCTION__,
311
280
node->mnt_opt_names[0]);
312
(*value_retrieved) = 0;
314
282
struct ecryptfs_name_val_pair *temp = nvp_head->next;
370
329
char *verify_prompt;
378
if (ecryptfs_verbosity)
379
syslog(LOG_INFO, "%s: Called on node->mnt_opt_names[0] = [%s]",
380
__FUNCTION__, node->mnt_opt_names[0]);
382
if (ecryptfs_verbosity)
383
syslog(LOG_INFO, "%s: node->val already set to [%s]\n",
384
__FUNCTION__, node->val);
387
rc = retrieve_val(&value_retrieved, nvp_head, node);
389
syslog(LOG_ERR, "%s: Error attempting to retrieve value; "
390
"rc = [%d]\n", __FUNCTION__, rc);
393
if (value_retrieved) {
394
if (ecryptfs_verbosity)
396
"%s: Value retrieved from default_val or from "
397
"parameter list; returning\n",
399
if (!(node->flags & ECRYPTFS_ALLOW_IMPLICIT_TRANSITION
400
&& node->flags & ECRYPTFS_IMPLICIT_OVERRIDE_DEFAULT))
403
if (node->flags & ECRYPTFS_ALLOW_IMPLICIT_TRANSITION
404
&& !(node->flags & ECRYPTFS_NO_AUTO_TRANSITION)) {
405
for (i = 0; i < node->num_transitions; i++) {
406
if (node->tl[i].next_token)
407
rc = retrieve_val(&value_retrieved, nvp_head,
408
node->tl[i].next_token);
410
syslog(LOG_ERR, "%s: Error attempting to "
411
"retrieve value; rc = [%d]\n",
415
if (value_retrieved) {
416
if (ecryptfs_verbosity)
418
"%s: Value retrieved from "
419
"default_val or from parameter "
420
"list for successive "
421
"node at transition slot [%d]; "
422
"returning\n", __FUNCTION__, i);
423
rc = asprintf(&node->val, "%s",
424
node->tl[i].next_token->mnt_opt_names[0]);
434
if (node->flags & ECRYPTFS_PARAM_FLAG_NO_VALUE) {
435
if (ecryptfs_verbosity)
437
"%s: ECRYPTFS_PARAM_FLAG_NO_VALUE set\n",
441
if (ctx->verbosity == 0 && !(node->flags & STDIN_REQUIRED)) {
442
if (ecryptfs_verbosity)
443
syslog(LOG_INFO, "%s: ctx->verbosity == 0 and "
444
"STDIN_REQUIRED not set\n", __FUNCTION__);
447
if ((node->flags & PARAMETER_SET) && !(node->flags & STDIN_REQUIRED)) {
448
if (ecryptfs_verbosity)
449
syslog(LOG_INFO, "%s: PARAMETER_SET and "
450
"STDIN_REQUIRED not set\n", __FUNCTION__);
334
if (!retrieve_val(nvp_head, node))
336
if (node->flags & ECRYPTFS_PARAM_FLAG_NO_VALUE)
338
if (ctx->verbosity == 0 && !(node->flags & STDIN_REQUIRED))
340
if ((node->flags & PARAMETER_SET) && !(node->flags & STDIN_REQUIRED))
453
342
if (ctx->get_string) {
454
if (ecryptfs_verbosity)
455
syslog(LOG_INFO, "%s: ctx->get_string defined\n",
457
343
if (node->flags & DISPLAY_TRANSITION_NODE_VALS) {
458
struct prompt_elem pe_head;
459
struct prompt_elem *pe;
345
int node_prompt_len = strlen(node->prompt);
346
int default_val_len = 0;
464
if (ecryptfs_verbosity)
465
syslog(LOG_INFO, "%s: DISPLAY_TRANSITION_NODE_"
466
"VALS set\n", __FUNCTION__);
467
memset(&pe_head, 0, sizeof(pe_head));
469
if ((node->num_transitions == 1)
350
if (node->default_val)
351
default_val_len = strlen(node->default_val);
352
len = node_prompt_len + default_val_len + 32;
353
if (node->num_transitions == 1
471
355
& ECRYPTFS_PARAM_FORCE_DISPLAY_NODES)) {
472
356
if (asprintf(&(node->val), "%s",
473
node->tl[0].val) == -1) {
480
pe->next = malloc(sizeof(*pe));
486
memset(pe, 0, sizeof(*pe));
487
rc = asprintf(&pe->str, "%s: \n", node->prompt);
357
node->tl[0].val) == -1)
361
for (i = 0; i < node->num_transitions; i++)
362
len += (strlen(node->tl[i].val) + 5);
363
prompt = malloc(len);
366
memcpy(prompt, node->prompt, node_prompt_len);
367
prompt[node_prompt_len] = ':';
368
strpos = node_prompt_len + 1;
369
prompt[strpos++] = '\n';
493
370
for (i = 0; i < node->num_transitions; i++) {
494
pe->next = malloc(sizeof(*pe));
500
memset(pe, 0, sizeof(*pe));
501
if (node->flags & ECRYPTFS_DISPLAY_PRETTY_VALS)
502
rc = asprintf(&pe->str, " %d) %s\n",
504
node->tl[i].pretty_val);
506
rc = asprintf(&pe->str, " %d) %s\n",
515
pe->next = malloc(sizeof(*pe));
521
memset(pe, 0, sizeof(*pe));
522
if (node->suggested_val)
523
rc = asprintf(&pe->str, "Selection [%s]",
524
node->suggested_val);
525
else if (node->default_val)
526
rc = asprintf(&pe->str, "Selection [%s]",
529
rc = asprintf(&pe->str, "Selection");
535
/* Convert prompt_elem linked list into
536
* single prompt string */
540
prompt_len += strlen(pe->str);
545
prompt = malloc(prompt_len);
552
struct prompt_elem *pe_tmp;
554
memcpy(&prompt[i], pe->str, strlen(pe->str));
555
i += strlen(pe->str);
371
prompt[strpos++] = ' ';
372
prompt[strpos++] = '0' + (char)(i + 1);
373
prompt[strpos++] = ')';
374
prompt[strpos++] = ' ';
375
memcpy(&prompt[strpos], node->tl[i].val,
376
strlen(node->tl[i].val));
377
strpos += strlen(node->tl[i].val);
378
prompt[strpos++] = '\n';
380
memcpy(&prompt[strpos], "Selection", 9);
382
if (node->suggested_val) {
383
memcpy(&prompt[strpos], " [", 2);
385
memcpy(&prompt[strpos], node->default_val,
387
strpos += default_val_len;
388
memcpy(&prompt[strpos], "]", 1);
390
} else if (node->default_val) {
391
memcpy(&prompt[strpos], " [", 2);
393
memcpy(&prompt[strpos], node->default_val,
395
strpos += default_val_len;
396
memcpy(&prompt[strpos], "]", 1);
399
prompt[strpos] = '\0';
563
401
rc = (ctx->get_string)
564
402
(&(node->val), prompt,
567
405
val = atoi(node->val);
568
406
if (val > 0 && val <= node->num_transitions) {
570
if (asprintf(&(node->val), "%s",
571
node->tl[val - 1].val) == -1) {
408
asprintf(&(node->val), "%s",
409
node->tl[val - 1].val);
578
if (node->val[0] == '\0') {
579
if (!node->suggested_val)
581
rc = asprintf(&node->val, "%s",
582
node->suggested_val);
590
for (i = 0; i < node->num_transitions; i++) {
591
if (strcmp(node->val, node->tl[i].val)
605
if (ecryptfs_verbosity)
606
syslog(LOG_INFO, "%s: DISPLAY_TRANSITION_NODE_"
607
"VALS not set\n", __FUNCTION__);
609
if (++tries > 3) return EINVAL;
610
419
if (node->suggested_val)
611
rc = asprintf(&prompt, "%s [%s]", node->prompt,
420
asprintf(&prompt, "%s [%s]", node->prompt,
612
421
node->suggested_val);
614
rc = asprintf(&prompt, "%s", node->prompt);
423
asprintf(&prompt, "%s", node->prompt);
620
424
if (ecryptfs_verbosity)
622
"%s: node->mnt_opt_names[0] = [%s]\n; "
426
"node->mnt_opt_names[0] = [%s]\n; "
623
427
"node->flags = [0x%.8x]\n",
625
428
node->mnt_opt_names[0], node->flags);
626
429
rc = (ctx->get_string)
627
430
(&(node->val), prompt,
629
432
& ECRYPTFS_PARAM_FLAG_ECHO_INPUT));
630
if (node->val[0] == '\0' &&
631
(node->flags & ECRYPTFS_NONEMPTY_VALUE_REQUIRED)) {
632
fprintf(stderr,"Wrong input, non-empty value "
637
434
if (node->flags & VERIFY_VALUE) {
638
435
rc = asprintf(&verify_prompt, "Verify %s",