#! PERL # # add.pl CGI-Script to add a user in the LDAP directory so that it can # be enrolled automatically # # (c) 2001 Dr. Andreas Mueller, Beratung und Entwicklung # # $Id: add.pl.in,v 1.6 2001/05/16 23:18:47 afm Exp $ # $libdir = "LIBDIR"; $bindir = "BINDIR"; $sbindir = "SBINDIR"; $openscepdir = "OPENSCEPDIR"; $cacert = $openscepdir."/cacert.pem"; $pendingdir = $openscepdir."/pending"; $granteddir = $openscepdir."/granted"; $rejecteddir = $openscepdir."/rejected"; $scepgrant = $sbindir."/scepgrant"; $scepreject = $sbindir."/scepreject"; $scepconf = $bindir."/scepconf"; use CGI qw(param); # read through the openscep.cnf configuration file and extrat ldap parameters sub scepconf { local($cmd) = "${scepconf} ". join(' ', @_)." 2>/dev/null |"; open(CONF, $cmd) || die "cannot open scepconf: $!\n"; $value = ; chop $value; close(CONF); return $value; } $ldapmodify = &scepconf("ldap", "ldapmodify"); $ldaphost = &scepconf("ldap", "ldaphost"); $ldapport = &scepconf("ldap", "ldapport"); $ldapbase = &scepconf("ldap", "ldapbase"); $binddn = &scepconf("ldap", "binddn"); $bindpw = &scepconf("ldap", "bindpw"); $openssl = &scepconf("scepd", "openssl"); # parse info from request if (param("add") eq "Add") { $dntype = param("dntype"); $unstructuredName = param("unstructuredName"); $CN = param("CN"); $password1 = param("password1"); $password2 = param("password2"); if ($password1 ne $password2) { $failure = "passwords don't match"; goto skipit; } if ($dntype eq "unstructured") { $dn = "unstructuredName=".$unstructuredName.",".$ldapbase; } else { $dn = "CN=".$CN.",".$ldapbase; } $cmd = "$ldapmodify -a -D \"$binddn\" -w \"$bindpw\" -h ". "\"$ldaphost\" -p \"$ldapport\""; open(LDAP, "|$cmd >/dev/null 2>&1") || die "cannot connect to LDAP: $!\n"; printf(LDAP "dn: %s\n", $dn); printf(LDAP "objectClass: top\n"); printf(LDAP "objectClass: sCEPClient\n"); if (length($password1) > 0) { printf(LDAP "userPassword: %s\n", $password1); } printf(LDAP "\n"); if (close(LDAP)) { $success = "added client $dn"; } else { $failure = "failure closing LDAP: $!"; } } skipit: printf("Content-Type: text/html\n\n"); printf q( Add SCEP Client

Add SCEP Client

); #printf("command: %s\n", $cmd); if ($success) { printf("

%s\n

\n", $success); } if ($failure) { printf("

%s\n

\n", $failure); } $old_fh = select(STDOUT); $| = 1; select($old_fh); printf("
\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n", $ldapbase); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("
". "Subject:unstructuredName=
". "CN=,%s
". "Challenge Password:
(again)
\n"); printf("\n"); printf("
\n"); printf q(
© 2001 The OpenSCEP Project ); exit 0;