⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sql2ldif.pl

📁 GForge 3.0 协作开发平台 支持CVS, mailing lists, bug tracking, message boards/forums, task management, perman
💻 PL
字号:
#!/usr/bin/perl##  Convert SQL user database to LDIF format (for SourceForge LDAP schema)#  by pfalcon@users.sourceforge.net 2000-10-17##  ./sql2ldif.pl	: Dump only top-level ou map#  ./sql2ldif.pl --full : Dump full database (ouch!)##  $Id: sql2ldif.pl,v 1.3 2003/02/13 17:58:46 lo-lan-do Exp $# use DBI;#require("base64.pl");  # Include all the predefined functionsrequire("/usr/lib/gforge/lib/include.pl");  # Include all the predefined functions$chroot="/var/lib/gforge/chroot";&db_connect;dump_header();# if (!($#ARGV+1)) {# 	exit;# }##  Dump user entries (ou=People)## We give user maximum of privileges assigned to one by groups ;-(my $query = "SELECT user_name,realname,shell,unix_pw,unix_uid,MAX(cvs_flags),emailFROM users,user_groupWHERE unix_status='A'      AND users.user_id=user_group.user_idGROUP BY user_name,realname,shell,unix_pw,unix_uid,email";my $rel = $dbh->prepare($query);$rel->execute();#print "$sys_ldap_host\n";#print "$sys_ldap_base_dn\n";@cvs_flags2shell=('/dev/null','/bin/cvssh','/bin/bash');while(my ($username, $realname, $shell, $pw, $uid, $cvs_flags, $email) = $rel->fetchrow()) {	print "dn: uid=$username,ou=People,$sys_ldap_base_dn\n";	#CB# To have the same id than generated by new_parse	$uid += $uid_add;	print "uid: $username\n";	if (!$realname) { $realname='?'; }	$realname=~tr#\x80-\xff#?#;  # it should be UTF-8 encoded, we just drop non-ascii chars	print "cn: $realnameobjectClass: accountobjectClass: posixAccountobjectClass: topobjectClass: shadowAccountobjectClass: debSfAccount";	#CB# gid was 100, i replace with $gid=$uid	$gid = $uid;	print "userPassword: {crypt}$pwshadowLastChange: 10879shadowMax: 99999shadowWarning: 7loginShell: $shelldebSfCvsShell: $cvs_flags2shell[$cvs_flags]uidNumber: $uidgidNumber: $gidhomeDirectory: $chroot/home/users/$usernamegecos: $realnamedebSfForwardEmail: $email";	#CB# To have the same id than generated by new_parse	#CB# A group per user	print "dn: cn=$username,ou=Group,$sys_ldap_base_dnobjectClass: posixGroupobjectClass: topcn: $usernameuserPassword: {crypt}xgidNumber: $gid";}##  Dump group entries (ou=Group)#my $query = "SELECT group_id,unix_group_nameFROM groupsWHERE status='A'";my $rel = $dbh->prepare($query);$rel->execute();while(my ($gid, $groupname) = $rel->fetchrow()) {	my $query = "SELECT user_nameFROM users,user_groupWHERE group_id=$gid      AND users.user_id=user_group.user_id";	my $rel = $dbh->prepare($query);	$rel->execute();	#CB# To have the same id than generated by new_parse	$gid += $gid_add;	print "dn: cn=$groupname,ou=Group,$sys_ldap_base_dnobjectClass: posixGroupobjectClass: topcn: $groupnameuserPassword: {crypt}xgidNumber: $gid";	while(my ($username) = $rel->fetchrow()) {		print "memberUid: $username\n";	}	print "\n";}##  Dump mailing-lists entries (ou=mailingList)#$query = "SELECT mail_group_list.group_list_id,                 mail_group_list.list_name,                 users.user_name,                 mail_group_list.password,                 mail_group_list.description          FROM mail_group_list, users          WHERE mail_group_list.status = 3                AND mail_group_list.list_admin = users.user_id" ;$rel = $dbh->prepare($query);$rel->execute();while(my ($group_list_id, $listname, $user_name, $password, $description) = $rel->fetchrow()) {	print "dn: cn=$listname,ou=mailingList,$sys_ldap_base_dnobjectClass: debSfMailingListobjectClass: topdebSfListPostAddress: \"|/var/lib/mailman/mail/mailman post $listname\"debSfListOwnerAddress: \"|/var/lib/mailman/mail/mailman mailowner $listname\"debSfListRequestAddress: \"|/var/lib/mailman/mail/mailman mailcmd $listname\"debSfListAdminAddress: \"|/var/lib/mailman/mail/mailman admin $listname\"debSfListBouncesAddress: \"|/var/lib/mailman/mail/mailman bounces $listname\"debSfListConfirmAddress: \"|/var/lib/mailman/mail/mailman confirm $listname\"debSfListJoinAddress: \"|/var/lib/mailman/mail/mailman join $listname\"debSfListLeaveAddress: \"|/var/lib/mailman/mail/mailman leave $listname\"debSfListSubscribeAddress: \"|/var/lib/mailman/mail/mailman subscribe $listname\"debSfListUnsubscribeAddress: \"|/var/lib/mailman/mail/mailman unsubscribe $listname\"";	print "\n";}##  Dump CVS group entries (ou=cvsGroup)#my $query = "SELECT group_id,unix_group_nameFROM groupsWHERE status='A'";my $rel = $dbh->prepare($query);$rel->execute();while(my ($gid, $groupname) = $rel->fetchrow()) {	my $query = "SELECT user_nameFROM users,user_groupWHERE group_id=$gidAND users.user_id=user_group.user_idAND user_group.cvs_flags > 0";	my $rel = $dbh->prepare($query);	$rel->execute();	#CB from 2.6# virtual member for anoncvs access	$uid=$gid+$anoncvs_uid_add;	$gid += $gid_add;	print "\ndn: uid=anoncvs_$groupname,ou=People,$sys_ldap_base_dnuid: anoncvs_$groupnamecn: anoncvsobjectClass: accountobjectClass: posixAccountobjectClass: topobjectClass: shadowAccountobjectClass: debSfAccountuserPassword: {crypt}xshadowLastChange: 1shadowMax: 99999shadowWarning: 7loginShell: /bin/falsedebSfCvsShell: /bin/falseuidNumber: $uidgidNumber: $gidhomeDirectory: $chroot/home/users/anoncvs_$groupnamegecos: anoncvs";	#CB# To have the same id than generated by new_parse	#CB# CVS group itself	print "\ndn: cn=$groupname,ou=cvsGroup,$sys_ldap_base_dnobjectClass: posixGroupobjectClass: topcn: $groupnameuserPassword: {crypt}xgidNumber: $gid";	while(my ($username) = $rel->fetchrow()) {		print "memberUid: $username\n";	}	print "\n";}##  Auxilary functions#sub dump_header {	print "dn: $sys_ldap_base_dndc: sourceforgeobjectClass: topobjectClass: domainobjectClass: domainRelatedObjectassociatedDomain: $sys_default_domaindn: ou=Hosts,$sys_ldap_base_dnou: HostsobjectClass: topobjectClass: organizationalUnitobjectClass: domainRelatedObjectassociatedDomain: $sys_default_domaindn: ou=People,$sys_ldap_base_dnou: PeopleobjectClass: topobjectClass: organizationalUnitobjectClass: domainRelatedObjectassociatedDomain: $sys_default_domaindn: ou=Aliases,$sys_ldap_base_dnou: AliasesobjectClass: topobjectClass: organizationalUnitobjectClass: domainRelatedObjectassociatedDomain: $sys_default_domaindn: ou=Group,$sys_ldap_base_dnou: GroupobjectClass: topobjectClass: organizationalUnitobjectClass: domainRelatedObjectassociatedDomain: $sys_default_domaindn: ou=cvsGroup,$sys_ldap_base_dnou: cvsGroupobjectClass: topobjectClass: organizationalUnitobjectClass: domainRelatedObjectassociatedDomain: $sys_default_domaindn: ou=mailingList,$sys_ldap_base_dnou: mailingListobjectClass: topobjectClass: organizationalUnitobjectClass: domainRelatedObjectassociatedDomain: $sys_lists_hostdn: uid=dummy,ou=People,$sys_ldap_base_dnuid: dummycn: Dummy UserobjectClass: accountobjectClass: posixAccountobjectClass: topobjectClass: shadowAccountobjectClass: debSfAccountuserPassword: {crypt}xshadowLastChange: 10879shadowMax: 99999shadowWarning: 7loginShell: /bin/falsedebSfCvsShell: /bin/falseuidNumber: $dummy_uidgidNumber: $dummy_uidhomeDirectory: $chroot/home/users/dummygecos: Dummy User";}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -