I am stumped. I have created a script to add a linux user, and it works fine. I have it owned by root, and setuid. It works fine until I want to add the users first and last name to the command. Here is the code that works:
system ("$useradd -d /home/sites/site$site_count/users/$username -g si +te$site_count -G site-adm$site_count -p $password -s /bin/false -u $u +id $username");
Here is the code that doesn't work:
system ("$useradd -c \"$fullname\" -d /home/sites/site$site_count/user +s/$username -g site$site_count -G site-adm$site_count -p $password -s + /bin/false -u $uid $username");
It also works fine if I take out the \" and just make sure that $fullname is only one word. Otherwise, that causes problems too. The non-working line works fine on the command line when run by root. Why are the quotes causing an error? The error I get is:
useradd: unable to lock password file
and more specifically with strace on(last few lines):
open("/var/nis/NIS_COLD_START", O_RDONLY) = -1 ENOENT (No such file or + directory) open("/etc/.pwd.lock", O_WRONLY|O_CREAT, 0600) = -1 EACCES (Permission + denied) write(2, "useradd: unable to lock password"..., 38useradd: unable to l +ock password file
Do the quotes cause part of the useradd command to be run as the web user without setuid? How do I get around this? Any suggestions would be greatly appreciated.

Thanks,
Rick Guyer
DualTech Services, Inc.

In reply to Using doublequotes in a system call by rguyer

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.