As Data coming into the script I'd be inclined to validate the username beyond lower-casing. Also I have included character class checking as usually usernames are not allowed to have a number (and possibly underscore too, would have to check that) as the first character. The \W would allow that as the first character.

Performing the untainting prior to calling system validation functions may also prevent badly constructed usernames getting passed through to system in functions such as getpwnam

my $un = shift; unless( $un ~= s/\A([_A-Za-z][_A-Za-z0-9]+)\Z/$1/ ){ # Log/Warn(L4/5); #? exit &ask_user_to_resubmit_request; } $un = lc($un); ... unless($<){..}

I'd likely suggest restricting user removal solely to root, but that is probably fine as long as admin priveleges are in place.

update:splitting the uid check from the user retrieval may even be better. We first see if administrator is calling the script before pulling in and untainting the user supplied data, then call the process body.

#uid check unless($< == 0){ # Log attempt and exit; }else{ print "Sue! How do you do?\nWe've been rooting for you" } #untaint and foldcase user data my $un = shift; unless( $un ~= s/\A([A-Za-z]\W+)\Z/$1/ ){ # Log attempt exit &ask_user_to_resubmit_request; } $un = lc($un); #carry on if(defined(getpwnam $un)){ .. }

In reply to Re: Script for SFTP users not deleting accounts automatically by Don Coyote
in thread Script for SFTP users not deleting accounts automatically by C18ANT

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.