#1 Hides password if given on cmd line

closed-accepted
nobody
None
5
2008-10-18
2008-06-06
Anonymous
No

Hides the password if given using the -p switch on the command line.

Functional but not beautiful. Limited to a password length of 128 as in #DEFINE

--- main.c.orig 2008-06-06 10:49:39.000000000 +0100
+++ main.c 2008-06-06 11:43:06.000000000 +0100
@@ -49,6 +49,9 @@
} pwsrc;
} args;

+#define MAX_PASS_LENGTH 128
+char pass_space[MAX_PASS_LENGTH + 1];
+
static void show_help()
{
printf("Usage: " PACKAGE_NAME " -fdph command parameters\n"
@@ -98,7 +101,15 @@
VIRGIN_PWTYPE;

args.pwtype=PWT_PASS;
- args.pwsrc.password=optarg;
+ if (strlen(optarg) <= MAX_PASS_LENGTH ) {
+ strcpy (pass_space,optarg);
+ args.pwsrc.password=pass_space;
+ while (*optarg) *optarg++='x';
+ }
+ else {
+ // Cannot copy pass so cannot hide
+ args.pwsrc.password=optarg;
+ }
break;
case 'e':
VIRGIN_PWTYPE;

Discussion

  • Nobody/Anonymous

    Logged In: NO

    Actually, better this way.

    --- main.c.orig 2008-06-06 10:49:39.000000000 +0100
    +++ main.c 2008-06-06 15:38:42.000000000 +0100
    @@ -49,6 +49,8 @@
    } pwsrc;
    } args;

    +char *pass_space = NULL;
    +
    static void show_help()
    {
    printf("Usage: " PACKAGE_NAME " -fdph command parameters\n"
    @@ -98,7 +100,10 @@
    VIRGIN_PWTYPE;

    args.pwtype=PWT_PASS;
    - args.pwsrc.password=optarg;
    + pass_space = malloc(strlen(optarg) +1);
    + strcpy (pass_space,optarg);
    + args.pwsrc.password=pass_space;
    + while (*optarg) *optarg++='x';
    break;
    case 'e':
    VIRGIN_PWTYPE;
    @@ -131,6 +136,7 @@
    int main( int argc, char *argv[] )
    {
    int opt_offset=parse_options( argc, argv );
    + int ret;

    if( opt_offset<0 ) {
    // There was some error
    @@ -142,7 +148,11 @@
    return -opt_offset;
    }

    - return runprogram( argc-opt_offset, argv+opt_offset );
    + ret = runprogram( argc-opt_offset, argv+opt_offset );
    + if (pass_space != NULL) {
    + free (pass_space);
    + }
    + return ret;
    }

    int handleoutput( int fd );

     
  • Shachar Shemesh

    Shachar Shemesh - 2008-10-18

    Thank you for the patch. I ended up rewriting it, but it is duly appreciated.

    Please note for future reference that the right place to send these things is to the mailing list. The tracker is not as vigorously monitored.

    Thanks again
    Shachar

     
  • Shachar Shemesh

    Shachar Shemesh - 2008-10-18
    • status: open --> closed-accepted
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks