@@ -127,11 +127,15 @@ char *sedopal_get_password(char *prompt)
127127 return NULL ;
128128
129129 len = strlen (pass );
130- if (len < SEDOPAL_MIN_PASSWORD_LEN )
130+ if (len < SEDOPAL_MIN_PASSWORD_LEN ) {
131+ fprintf (stderr , "Error: password is not long enough\n" );
131132 return NULL ;
133+ }
132134
133- if (len > SEDOPAL_MAX_PASSWORD_LEN )
135+ if (len > SEDOPAL_MAX_PASSWORD_LEN ) {
136+ fprintf (stderr , "Error: password is too long\n" );
134137 return NULL ;
138+ }
135139
136140 return pass ;
137141}
@@ -425,8 +429,12 @@ static int sedopal_revert_psid(int fd)
425429 rc = sedopal_set_key (& key );
426430 if (rc == 0 ) {
427431 rc = ioctl (fd , IOC_OPAL_PSID_REVERT_TPR , & key );
428- if (rc != 0 )
429- fprintf (stderr , "PSID_REVERT_TPR rc %d\n" , rc );
432+ if (rc != 0 ) {
433+ if (rc == EPERM )
434+ fprintf (stderr , "Error: incorrect password\n" );
435+ else
436+ fprintf (stderr , "PSID_REVERT_TPR rc %d\n" , rc );
437+ }
430438 }
431439
432440 return rc ;
@@ -457,6 +465,7 @@ int sedopal_cmd_revert(int fd)
457465#ifdef IOC_OPAL_REVERT_LSP
458466 struct opal_revert_lsp revert_lsp ;
459467 uint8_t locking_state ;
468+ char * revert = "LSP" ;
460469
461470 locking_state = sedopal_locking_state (fd );
462471
@@ -481,19 +490,28 @@ int sedopal_cmd_revert(int fd)
481490
482491 rc = ioctl (fd , IOC_OPAL_REVERT_LSP , & revert_lsp );
483492 if (rc == 0 ) {
493+ revert = "TPER" ;
484494 /*
485495 * TPER must also be reverted.
486496 */
487497 rc = ioctl (fd , IOC_OPAL_REVERT_TPR , & revert_lsp .key );
488498 if (rc != 0 )
489499 fprintf (stderr , "Error: revert TPR - %d\n" , rc );
490500 }
501+
502+ if (rc != 0 ) {
503+ if (rc == EPERM )
504+ fprintf (stderr , "Error: incorrect password\n" );
505+ else
506+ fprintf (stderr , "Error: revert %s - %d\n" ,
507+ revert , rc );
508+ }
491509#else
492510 rc = - EOPNOTSUPP ;
493511#endif
494512 }
495513
496- if (rc != 0 )
514+ if (( rc != 0 ) && ( rc != EPERM ) )
497515 fprintf (stderr , "Error: failed reverting drive - %d\n" , rc );
498516
499517 return rc ;
@@ -533,7 +551,10 @@ int sedopal_cmd_password(int fd)
533551 */
534552 rc = ioctl (fd , IOC_OPAL_SET_PW , & new_pw );
535553 if (rc != 0 ) {
536- fprintf (stderr , "Error: failed setting password - %d\n" , rc );
554+ if (rc == EPERM )
555+ fprintf (stderr , "Error: incorrect password\n" );
556+ else
557+ fprintf (stderr , "Error: setting password - %d\n" , rc );
537558 return rc ;
538559 }
539560
@@ -542,8 +563,12 @@ int sedopal_cmd_password(int fd)
542563 * set sid password
543564 */
544565 rc = ioctl (fd , IOC_OPAL_SET_SID_PW , & new_pw );
545- if (rc != 0 )
546- fprintf (stderr , "Error: failed setting SID password - %d\n" , rc );
566+ if (rc != 0 ) {
567+ if (rc == EPERM )
568+ fprintf (stderr , "Error: incorrect password\n" );
569+ else
570+ fprintf (stderr , "Error: setting SID pw - %d\n" , rc );
571+ }
547572#endif
548573
549574 return rc ;
0 commit comments