svn commit: r333292 - user/des/fbce/db
Dag-Erling Smørgrav
des at FreeBSD.org
Sun May 6 11:21:33 UTC 2018
Author: des
Date: Sun May 6 11:21:32 2018
New Revision: 333292
URL: https://svnweb.freebsd.org/changeset/base/333292
Log:
Add gjb@'s LDAP-snarfing scripts.
Added:
user/des/fbce/db/genuserlist.pl (contents, props changed)
user/des/fbce/db/genuserlist.sh (contents, props changed)
Added: user/des/fbce/db/genuserlist.pl
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/des/fbce/db/genuserlist.pl Sun May 6 11:21:32 2018 (r333292)
@@ -0,0 +1,72 @@
+#!/usr/bin/env perl
+#
+# $Id$
+#
+
+my $file = "$ARGV[0]";
+my $haveuid = 0;
+my $havekey = 0;
+my $uid = '';
+
+sub usage() {
+ print "Usage: $ARGV[0] /path/to/ldap/data\n";
+ exit (1);
+}
+
+sub main() {
+ if (!$ARGV[0]) {
+ &usage();
+ }
+ open(FILE, $file) or die("Could not open $file\n");
+ while(<FILE>) {
+ chomp($_);
+
+ # Skip commented lines.
+ if ($_ =~ m/^#/) {
+ next;
+ }
+
+ # Skip empty lines, reset vars.
+ if ($_ =~ m/^$/) {
+ $haveuid = 0;
+ $uid = '';
+ $havekey = 0;
+ next;
+ }
+
+ # Found the uid field. Make sure it is not empty, then set
+ # haveuid=1.
+ if ($_ =~ m/^uid: /) {
+ $_ =~ s/^uid: //;
+ # The one unfortunate account *with* an ssh key.
+ if ($_ =~ m/backup/) {
+ next;
+ }
+ $uid = $_;
+ $haveuid = 1;
+ }
+
+ # No need to search for a key if haveuid=0.
+ if ($haveuid eq 1) {
+ # Have the key.
+ if ($_ =~ m/^sshPublicKey::? /) {
+ $_ =~ s/^sshPublicKey::? //;
+ # It should not happen, but if a key datafield exists
+ # without a key, bail.
+ if ($_ =~ m//) {
+ $haveuid = 0;
+ next;
+ }
+ # Great. We have found a key for the UID. Since they
+ # have login access, they can vote. Good for them.
+ $havekey = 1;
+ print "$uid\n";
+ $haveuid = 0;
+ }
+ }
+ }
+ close(FILE);
+}
+
+&main();
+
Added: user/des/fbce/db/genuserlist.sh
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/des/fbce/db/genuserlist.sh Sun May 6 11:21:32 2018 (r333292)
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+set -e
+
+users=
+tmpfile="$(mktemp $HOME/tmp.XXXXXXXXXX)"
+
+main() {
+ cd $(realpath $(dirname $(basename ${0})))
+ userlist="$(ldapsearch -x -b \
+ ou=users,dc=freebsd,dc=org \
+ -s children \
+ '(&(objectClass=freebsdAccount)(cn=*)(uid=*)(sshPublicKey=*)(loginShell=*)(!(loginShell=/usr/sbin/nologin))(!(uid=*test))(!(uid=socsvn-import)))' \
+ uid uidNumber loginShell sshPublicKey)"
+ printf "${userlist}" > ${tmpfile}
+ echo "Output written to: ${tmpfile}"
+
+ ./genuserlist.pl ${tmpfile} > ./users.txt
+
+ echo "Final output written to: users.txt"
+
+}
+
+main "$@"
More information about the svn-src-user
mailing list