-
Notifications
You must be signed in to change notification settings - Fork 256
/
ua_label.c
715 lines (645 loc) · 21.7 KB
/
ua_label.c
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2003-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2013 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
/*
* BAREOS Director -- Tape labeling commands
*
* Kern Sibbald, April MMIII
*/
#include "bareos.h"
#include "dird.h"
/* Forward referenced functions */
static void label_from_barcodes(UAContext *ua, int drive, bool label_encrypt);
static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
POOL_DBR *pr, bool relabel, bool media_record_exists,
int drive);
static bool generate_new_encryption_key(UAContext *ua, MEDIA_DBR *mr);
/* External functions */
extern DIRRES *director;
/*
* Check if this is a cleaning tape by comparing the Volume name
* with the Cleaning Prefix. If they match, this is a cleaning
* tape.
*/
static inline bool is_cleaning_tape(UAContext *ua, MEDIA_DBR *mr, POOL_DBR *pr)
{
bool retval;
/*
* Find Pool resource
*/
ua->jcr->res.pool = (POOLRES *)GetResWithName(R_POOL, pr->Name);
if (!ua->jcr->res.pool) {
ua->error_msg(_("Pool \"%s\" resource not found for volume \"%s\"!\n"),
pr->Name, mr->VolumeName);
return false;
}
retval = bstrncmp(mr->VolumeName,
ua->jcr->res.pool->cleaning_prefix,
strlen(ua->jcr->res.pool->cleaning_prefix));
Dmsg4(100, "CLNprefix=%s: Vol=%s: len=%d bstrncmp=%s\n",
ua->jcr->res.pool->cleaning_prefix, mr->VolumeName,
strlen(ua->jcr->res.pool->cleaning_prefix),
retval ? "true" : "false");
return retval;
}
/*
* Common routine for both label and relabel
*/
static int do_label(UAContext *ua, const char *cmd, bool relabel)
{
USTORERES store;
BSOCK *sd;
char dev_name[MAX_NAME_LENGTH];
MEDIA_DBR mr, omr;
POOL_DBR pr;
bool print_reminder = true;
bool label_barcodes = false;
bool label_encrypt = false;
int ok = FALSE;
int i, j;
int drive;
bool media_record_exists = false;
static const char *barcode_keywords[] = {
"barcode",
"barcodes",
NULL
};
if (!open_client_db(ua)) {
return 1;
}
memset(&pr, 0, sizeof(pr));
memset(&mr, 0, sizeof(mr));
memset(&omr, 0, sizeof(omr));
/*
* Look for one of the barcode keywords
*/
if (!relabel && (i = find_arg_keyword(ua, barcode_keywords)) >= 0) {
/*
* Now find the keyword in the list
*/
if ((j = find_arg(ua, barcode_keywords[i])) > 0) {
*ua->argk[j] = 0; /* zap barcode keyword */
}
label_barcodes = true;
}
/*
* Look for the encrypt keyword
*/
if ((i = find_arg(ua, "encrypt")) > 0) {
*ua->argk[i] = 0; /* zap encrypt keyword */
label_encrypt = true;
}
store.store = get_storage_resource(ua, true, label_barcodes);
if (!store.store) {
return 1;
}
switch (store.store->Protocol) {
case APT_NDMPV2:
case APT_NDMPV3:
case APT_NDMPV4:
/*
* See if the user selected a NDMP storage device but its
* handled by a native Bareos storage daemon e.g. we have
* a paired_storage pointer.
*/
if (store.store->paired_storage) {
store.store = store.store->paired_storage;
} else {
ua->warning_msg(_("Storage has non-native protocol.\n"));
return 1;
}
break;
default:
break;
}
pm_strcpy(store.store_source, _("command line"));
set_wstorage(ua->jcr, &store);
drive = get_storage_drive(ua, store.store);
if (label_barcodes) {
label_from_barcodes(ua, drive, label_encrypt);
return 1;
}
/*
* If relabel get name of Volume to relabel
*/
if (relabel) {
/*
* Check for oldvolume=name
*/
i = find_arg_with_value(ua, "oldvolume");
if (i >= 0) {
bstrncpy(omr.VolumeName, ua->argv[i], sizeof(omr.VolumeName));
if (db_get_media_record(ua->jcr, ua->db, &omr)) {
goto checkVol;
}
ua->error_msg("%s", db_strerror(ua->db));
}
/*
* No keyword or Vol not found, ask user to select
*/
if (!select_media_dbr(ua, &omr)) {
return 1;
}
/*
* Require Volume to be Purged or Recycled
*/
checkVol:
if (!bstrcmp(omr.VolStatus, "Purged") && !bstrcmp(omr.VolStatus, "Recycle")) {
ua->error_msg(_("Volume \"%s\" has VolStatus %s. It must be Purged or Recycled before relabeling.\n"),
omr.VolumeName, omr.VolStatus);
return 1;
}
}
/*
* Check for volume=NewVolume
*/
i = find_arg_with_value(ua, "volume");
if (i >= 0) {
pm_strcpy(ua->cmd, ua->argv[i]);
goto checkName;
}
/*
* Get a new Volume name
*/
for ( ;; ) {
media_record_exists = false;
if (!get_cmd(ua, _("Enter new Volume name: "))) {
return 1;
}
checkName:
if (!is_volume_name_legal(ua, ua->cmd)) {
continue;
}
/*
* Search by Media name so set VolumeName and clear MediaId.
*/
mr.MediaId = 0;
bstrncpy(mr.VolumeName, ua->cmd, sizeof(mr.VolumeName));
/*
* If VolBytes are zero the Volume is not labeled
*/
if (db_get_media_record(ua->jcr, ua->db, &mr)) {
if (mr.VolBytes != 0) {
ua->error_msg(_("Media record for new Volume \"%s\" already exists.\n"),
mr.VolumeName);
continue;
}
media_record_exists = true;
}
break; /* Got it */
}
/*
* If autochanger, request slot
*/
i = find_arg_with_value(ua, "slot");
if (i >= 0) {
mr.Slot = atoi(ua->argv[i]);
if (mr.Slot < 0) {
mr.Slot = 0;
}
mr.InChanger = mr.Slot > 0; /* if slot give assume in changer */
} else if (store.store->autochanger) {
if (!get_pint(ua, _("Enter slot (0 or Enter for none): "))) {
return 1;
}
mr.Slot = ua->pint32_val;
if (mr.Slot < 0) {
mr.Slot = 0;
}
mr.InChanger = mr.Slot > 0; /* if slot give assume in changer */
}
set_storageid_in_mr(store.store, &mr);
bstrncpy(mr.MediaType, store.store->media_type, sizeof(mr.MediaType));
/*
* Must select Pool if not already done
*/
if (pr.PoolId == 0) {
memset(&pr, 0, sizeof(pr));
if (!select_pool_dbr(ua, &pr)) {
return 1;
}
}
/*
* See if we need to generate a new passphrase for hardware encryption.
*/
if (label_encrypt) {
ua->info_msg(_("Generating new hardware encryption key\n"));
if (!generate_new_encryption_key(ua, &mr)) {
return 1;
}
}
ok = send_label_request(ua, &mr, &omr, &pr, relabel, media_record_exists, drive);
if (ok) {
sd = ua->jcr->store_bsock;
if (relabel) {
/*
* Delete the old media record
*/
if (!db_delete_media_record(ua->jcr, ua->db, &omr)) {
ua->error_msg(_("Delete of Volume \"%s\" failed. ERR=%s"),
omr.VolumeName, db_strerror(ua->db));
} else {
ua->info_msg(_("Old volume \"%s\" deleted from catalog.\n"),
omr.VolumeName);
/*
* Update the number of Volumes in the pool
*/
pr.NumVols--;
if (!db_update_pool_record(ua->jcr, ua->db, &pr)) {
ua->error_msg("%s", db_strerror(ua->db));
}
}
}
if (ua->automount) {
bstrncpy(dev_name, store.store->dev_name(), sizeof(dev_name));
ua->info_msg(_("Requesting to mount %s ...\n"), dev_name);
bash_spaces(dev_name);
sd->fsend("mount %s drive=%d", dev_name, drive);
unbash_spaces(dev_name);
/*
* We use bget_dirmsg here and not bnet_recv because as part of
* the mount request the stored can request catalog information for
* any plugin who listens to the bsdEventLabelVerified event.
* As we don't want to loose any non protocol data e.g. errors
* without a 3xxx prefix we set the allow_any_message of
* bget_dirmsg to true and as such is behaves like a normal
* bnet_recv for any non protocol messages.
*/
while (bget_dirmsg(sd, true) >= 0) {
ua->send_msg("%s", sd->msg);
/*
* Here we can get
* 3001 OK mount. Device=xxx or
* 3001 Mounted Volume vvvv
* 3002 Device "DVD-Writer" (/dev/hdc) is mounted.
* 3906 is cannot mount non-tape
* So for those, no need to print a reminder
*/
if (bstrncmp(sd->msg, "3001 ", 5) ||
bstrncmp(sd->msg, "3002 ", 5) ||
bstrncmp(sd->msg, "3906 ", 5)) {
print_reminder = false;
}
}
}
}
if (print_reminder) {
ua->info_msg(_("Do not forget to mount the drive!!!\n"));
}
close_sd_bsock(ua);
return 1;
}
/*
* Request SD to send us the slot:barcodes, then wiffle through them all labeling them.
*/
static void label_from_barcodes(UAContext *ua, int drive, bool label_encrypt)
{
STORERES *store = ua->jcr->res.wstore;
POOL_DBR pr;
MEDIA_DBR mr;
vol_list_t *vl;
dlist *vol_list = NULL;
bool media_record_exists;
char *slot_list;
int max_slots;
memset(&mr, 0, sizeof(mr));
max_slots = get_num_slots_from_SD(ua);
if (max_slots <= 0) {
ua->warning_msg(_("No slots in changer to scan.\n"));
return;
}
slot_list = (char *)malloc(nbytes_for_bits(max_slots));
clear_all_bits(max_slots, slot_list);
if (!get_user_slot_list(ua, slot_list, "slots", max_slots)) {
goto bail_out;
}
vol_list = get_vol_list_from_SD(ua, store, false /* no listall */ , false /*no scan*/);
if (!vol_list) {
ua->warning_msg(_("No Volumes found to label, or no barcodes.\n"));
goto bail_out;
}
/*
* Display list of Volumes and ask if he really wants to proceed
*/
ua->send_msg(_("The following Volumes will be labeled:\n"
"Slot Volume\n"
"==============\n"));
foreach_dlist(vl, vol_list) {
if (!vl->VolName || !bit_is_set(vl->Slot - 1, slot_list)) {
continue;
}
ua->send_msg("%4d %s\n", vl->Slot, vl->VolName);
}
if (!get_yesno(ua, _("Do you want to label these Volumes? (yes|no): ")) ||
(ua->pint32_val == 0)) {
goto bail_out;
}
/*
* Select a pool
*/
memset(&pr, 0, sizeof(pr));
if (!select_pool_dbr(ua, &pr)) {
goto bail_out;
}
/*
* Fire off the label requests
*/
foreach_dlist(vl, vol_list) {
if (!vl->VolName || !bit_is_set(vl->Slot - 1, slot_list)) {
continue;
}
memset(&mr, 0, sizeof(mr));
bstrncpy(mr.VolumeName, vl->VolName, sizeof(mr.VolumeName));
media_record_exists = false;
if (db_get_media_record(ua->jcr, ua->db, &mr)) {
if (mr.VolBytes != 0) {
ua->warning_msg(_("Media record for Slot %d Volume \"%s\" already exists.\n"),
vl->Slot, mr.VolumeName);
mr.Slot = vl->Slot;
mr.InChanger = mr.Slot > 0; /* if slot give assume in changer */
set_storageid_in_mr(store, &mr);
if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
ua->error_msg(_("Error setting InChanger: ERR=%s"), db_strerror(ua->db));
}
continue;
}
media_record_exists = true;
}
mr.InChanger = mr.Slot > 0; /* if slot give assume in changer */
set_storageid_in_mr(store, &mr);
/*
* Deal with creating cleaning tape here. Normal tapes created in send_label_request() below
*/
if (is_cleaning_tape(ua, &mr, &pr)) {
if (media_record_exists) { /* we update it */
mr.VolBytes = 1; /* any bytes to indicate it exists */
bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus));
mr.MediaType[0] = 0;
set_storageid_in_mr(store, &mr);
if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
ua->error_msg("%s", db_strerror(ua->db));
}
} else { /* create the media record */
if (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) {
ua->error_msg(_("Maximum pool Volumes=%d reached.\n"), pr.MaxVols);
goto bail_out;
}
set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus));
mr.MediaType[0] = 0;
set_storageid_in_mr(store, &mr);
if (db_create_media_record(ua->jcr, ua->db, &mr)) {
ua->send_msg(_("Catalog record for cleaning tape \"%s\" successfully created.\n"),
mr.VolumeName);
pr.NumVols++; /* this is a bit suspect */
if (!db_update_pool_record(ua->jcr, ua->db, &pr)) {
ua->error_msg("%s", db_strerror(ua->db));
}
} else {
ua->error_msg(_("Catalog error on cleaning tape: %s"), db_strerror(ua->db));
}
}
continue; /* done, go handle next volume */
}
bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
/*
* See if we need to generate a new passphrase for hardware encryption.
*/
if (label_encrypt) {
if (!generate_new_encryption_key(ua, &mr)) {
continue;
}
}
mr.Slot = vl->Slot;
send_label_request(ua, &mr, NULL, &pr, false, media_record_exists, drive);
}
bail_out:
free(slot_list);
if (vol_list) {
free_vol_list(vol_list);
}
close_sd_bsock(ua);
return;
}
/*
* Label a tape
*
* label storage=xxx volume=vvv
*/
int label_cmd(UAContext *ua, const char *cmd)
{
return do_label(ua, cmd, false); /* standard label */
}
int relabel_cmd(UAContext *ua, const char *cmd)
{
return do_label(ua, cmd, true); /* relabel tape */
}
/*
* Check if the Volume name has legal characters
* If ua is non-NULL send the message
*/
bool is_volume_name_legal(UAContext *ua, const char *name)
{
int len;
const char *p;
const char *accept = ":.-_/";
if (name[0] == '/') {
if (ua) {
ua->error_msg(_("Volume name can not start with \"/\".\n"));
}
return 0;
}
/*
* Restrict the characters permitted in the Volume name
*/
for (p=name; *p; p++) {
if (B_ISALPHA(*p) || B_ISDIGIT(*p) || strchr(accept, (int)(*p))) {
continue;
}
if (ua) {
ua->error_msg(_("Illegal character \"%c\" in a volume name.\n"), *p);
}
return 0;
}
len = strlen(name);
if (len >= MAX_NAME_LENGTH) {
if (ua) {
ua->error_msg(_("Volume name too long.\n"));
}
return 0;
}
if (len == 0) {
if (ua) {
ua->error_msg(_("Volume name must be at least one character long.\n"));
}
return 0;
}
return 1;
}
/*
* NOTE! This routine opens the SD socket but leaves it open
*/
static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
POOL_DBR *pr, bool relabel, bool media_record_exists,
int drive)
{
BSOCK *sd;
char dev_name[MAX_NAME_LENGTH];
bool ok = false;
uint64_t VolBytes = 0;
if (!(sd=open_sd_bsock(ua))) {
return false;
}
bstrncpy(dev_name, ua->jcr->res.wstore->dev_name(), sizeof(dev_name));
bash_spaces(dev_name);
bash_spaces(mr->VolumeName);
bash_spaces(mr->MediaType);
bash_spaces(pr->Name);
if (relabel) {
bash_spaces(omr->VolumeName);
sd->fsend("relabel %s OldName=%s NewName=%s PoolName=%s "
"MediaType=%s Slot=%d drive=%d MinBlocksize=%d MaxBlocksize=%d",
dev_name, omr->VolumeName, mr->VolumeName, pr->Name,
mr->MediaType, mr->Slot, drive,
/*
* if relabeling, keep blocksize settings
*/
omr->MinBlocksize, omr->MaxBlocksize);
ua->send_msg(_("Sending relabel command from \"%s\" to \"%s\" ...\n"),
omr->VolumeName, mr->VolumeName);
} else {
sd->fsend("label %s VolumeName=%s PoolName=%s MediaType=%s "
"Slot=%d drive=%d MinBlocksize=%d MaxBlocksize=%d",
dev_name, mr->VolumeName, pr->Name, mr->MediaType,
mr->Slot, drive,
/*
* If labeling, use blocksize defined in pool
*/
pr->MinBlocksize, pr->MaxBlocksize);
ua->send_msg(_("Sending label command for Volume \"%s\" Slot %d ...\n"),
mr->VolumeName, mr->Slot);
Dmsg8(100, "label %s VolumeName=%s PoolName=%s MediaType=%s "
"Slot=%d drive=%d MinBlocksize=%d MaxBlocksize=%d\n",
dev_name, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot, drive,
pr->MinBlocksize, pr->MaxBlocksize);
}
/*
* We use bget_dirmsg here and not bnet_recv because as part of
* the label request the stored can request catalog information for
* any plugin who listens to the bsdEventLabelVerified event.
* As we don't want to loose any non protocol data e.g. errors
* without a 3xxx prefix we set the allow_any_message of
* bget_dirmsg to true and as such is behaves like a normal
* bnet_recv for any non protocol messages.
*/
while (bget_dirmsg(sd, true) >= 0) {
ua->send_msg("%s", sd->msg);
if (sscanf(sd->msg, "3000 OK label. VolBytes=%llu ", &VolBytes) == 1) {
ok = true;
}
}
unbash_spaces(mr->VolumeName);
unbash_spaces(mr->MediaType);
unbash_spaces(pr->Name);
mr->LabelDate = time(NULL);
mr->set_label_date = true;
if (ok) {
if (media_record_exists) { /* we update it */
mr->VolBytes = VolBytes;
mr->InChanger = mr->Slot > 0; /* if slot give assume in changer */
set_storageid_in_mr(ua->jcr->res.wstore, mr);
if (!db_update_media_record(ua->jcr, ua->db, mr)) {
ua->error_msg("%s", db_strerror(ua->db));
ok = false;
}
} else { /* create the media record */
set_pool_dbr_defaults_in_media_dbr(mr, pr);
mr->VolBytes = VolBytes;
mr->InChanger = mr->Slot > 0; /* if slot give assume in changer */
mr->Enabled = 1;
set_storageid_in_mr(ua->jcr->res.wstore, mr);
if (db_create_media_record(ua->jcr, ua->db, mr)) {
ua->info_msg(_("Catalog record for Volume \"%s\", Slot %d successfully created.\n"),
mr->VolumeName, mr->Slot);
/*
* Update number of volumes in pool
*/
pr->NumVols++;
if (!db_update_pool_record(ua->jcr, ua->db, pr)) {
ua->error_msg("%s", db_strerror(ua->db));
}
} else {
ua->error_msg("%s", db_strerror(ua->db));
ok = false;
}
}
} else {
ua->error_msg(_("Label command failed for Volume %s.\n"), mr->VolumeName);
}
return ok;
}
/*
* Generate a new encryption key for use in volume encryption.
* We don't ask the user for a encryption key but generate a semi
* random passphrase of the wanted length which is way stronger.
* When the config has a wrap key we use that to wrap the newly
* created passphrase using RFC3394 aes wrap and always convert
* the passphrase into a base64 encoded string. This key is
* stored in the database and is passed to the storage daemon
* when needed. The storage daemon has the same wrap key per
* director so it can unwrap the passphrase for use.
*
* Changing the wrap key will render any previously created
* crypto keys useless so only change the wrap key after initial
* setting when you know what you are doing and always store
* the old key somewhere save so you can use bscrypto to
* convert them for the new wrap key.
*/
static bool generate_new_encryption_key(UAContext *ua, MEDIA_DBR *mr)
{
int length;
char *passphrase;
passphrase = generate_crypto_passphrase(DEFAULT_PASSPHRASE_LENGTH);
if (!passphrase) {
ua->error_msg(_("Failed to generate new encryption passphrase for Volume %s.\n"), mr->VolumeName);
return false;
}
/*
* See if we need to wrap the passphrase.
*/
if (me->keyencrkey.value) {
char *wrapped_passphrase;
length = DEFAULT_PASSPHRASE_LENGTH + 8;
wrapped_passphrase = (char *)malloc(length);
memset(wrapped_passphrase, 0, length);
aes_wrap((unsigned char *)me->keyencrkey.value,
DEFAULT_PASSPHRASE_LENGTH / 8,
(unsigned char *)passphrase,
(unsigned char *)wrapped_passphrase);
free(passphrase);
passphrase = wrapped_passphrase;
} else {
length = DEFAULT_PASSPHRASE_LENGTH;
}
/*
* The passphrase is always base64 encoded.
*/
bin_to_base64(mr->EncrKey, sizeof(mr->EncrKey), passphrase, length, true);
free(passphrase);
return true;
}