Dear Danny, The cgi that I wrote is attached. To my knowledge it is fully functional. It was developed on a rh6.1 box using perl 5.005_03. You might have to modify the locations of the path for the user homedir (currently / because the first guy to ask for the script wanted that (DON"T ASK ME!)). and the path to useradd and /etc/passwd. Basically, it takes form input (username,password) and checks to see if the username is in the password file. If the username already exists, then it will error out with a message to the browser. If not, it will create a hash of the password using the crypt() function and then call system() to use useradd to create the account. You will have to use suid perl. My apologies on the 'only take about 17 lines' thing. ;) #include <stddisclaimer.h>; Good luck with the script and have a great week! Sincerely, Mike Cathey([EMAIL PROTECTED]) P.S. If you use if for a commercial purpose, please consider compensation. I won't demand it. I love the OSS model. Please feel free to modify/clean up the code. I know that this could be done 10000 different other ways. I wrote it this way because I was on a time schedule. Danny H wrote: > I am doing something simlar for my private intranet. Can you show me > examples of the code please. > > >It would only take about 17 lines of perl. However, how strongly are you > >going to protect this page? I wouldn't even consider this unless this page > >will be accessible behind a firewall and htaccess protected. If you need > >example code let me know. I can even write it without using CGI.pm if you > >want. Have a great week! > > > >Sincerely, > > > >Mike Cathey([EMAIL PROTECTED]) > >Voyager Online, LLC
#!/usr/bin/perl ########################################################### # This program is Copyright under the GPL (yada yada yada) # Abuse it at your will just email me any improvements # please! --Mike Cathey ([EMAIL PROTECTED]) # The purpose of this script is farily self explanatory. # It calls useradd and passwd to change the name of a user. # It also checks to see if a user by the requested username # already exists on the system. ########################################################### # We have to define where the system utils are first. # because it is the easiest and quickest way that I can # think of, I am going to parse through /etc/passwd (please # use shadow passwds) to find out if the username requested # is already in use. # # NOTE: I am not implementing any kind of username check # (eg. username/password limit). You might want # to add that if you expect to have problems in that # area. $path_to_homedir = "/"; # path to create home directories $useradd = "/usr/sbin/useradd"; # path to useradd $userlist = "</etc/passwd"; # open readonly # now we parse the form input $formdata=<STDIN>; $formdata=~s/\s+$//; foreach (split(/&/, $formdata)) { ($name, $value)=split(/=/, $_); $name=~s/\+/ /g; $name=~s/%([0-9|A-F]{2})/pack(C,hex($1))/eg; $value=~s/\+/ /g; $value=~s/%([0-9|A-F]{2})/pack(C,hex($1))/eg; if ($value eq "") { &exit($name); } push (@print, $name); $data{$name}=$value; } $username = $data{'username'}; $password = $data{'password'}; # create a 'random' salt and then use # the crypt function to creat the hashed password $salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]; $passwordhash = crypt($password,$salt); open(ULIST,"$userlist") || die "Error can't open: $!"; @userlist = <ULIST>; foreach $line (@userlist) { if ($line =~ /.*$username.*/i) { $name = "user exists"; &exit($name); } } system("$useradd $username -m -d $path_to_homedir$username -p $passwordhash"); # then we print the success page print "Content-type: text/html\n\n"; print "<html>\n<head>\n<title>Done!</title>\n</head>\n<body bgcolor=\"ffffff\">\n"; print "The username $username was added<br>\n"; print "with the password $password.<br>\n"; print "</body>\n</html>\n"; sub exit { local ($name)=@_; print "Content-type: text/html\n\n"; print "<html>\n<head>\n<title>Error!</title>\n</head>\n<body bgcolor=\"ffffff\">\n"; if ($name eq "user exists") { print "This username is already taken.<br>\n"; print "Please return back and enter<br>\n"; print "another username.<br>\n"; } else { print "Your must fill in the $name field to process this form.<br>\n"; print " Please return back and do it. Thank you.<br>\n"; } print "</body>\n</html>\n"; }