Source

CUPS-PDF for Mac OS X / src / contrib / cups-pdf-dispatch-0.1 / examples / cups-pdf-dispatch-ldap.conf

# cups-pdf-dispatch.conf
# Configuration file for cups-pdf-dispatch.
# This file is interpreted by perl.
# This is (tested) example of using LDAP to fetch user info/e-mail.

#### LOCAL CODE ####
my %USERINFO_CACHE = ();
my $LDAP_HOST = 'localhost';
my $LDAP_BASE = 'ou=people,dc=avtomatikarus,dc=com';
my $LDAP_FILTER_FORMAT = '(&(objectClass=inetOrgPerson)(uid=%s))';
my $LDAP_TLS_CAFILE = '/etc/ldap/cacert.pem';
my $LDAP_TLS_VERIFY = 'require';
sub get_userinfo
{
	my( $username ) = @_;
	my $userinfo = {};

	use Net::LDAP;
	my $LDAP = new Net::LDAP( $LDAP_HOST, onerror => 'die' ) or
		die "$@\n";
	$LDAP->start_tls(
		verify	=> $LDAP_TLS_VERIFY,
		cafile => $LDAP_TLS_CAFILE
	);
	$LDAP->bind();
	my $msg = $LDAP->search(
		base	=> $LDAP_BASE,
		filter	=> sprintf( $LDAP_FILTER_FORMAT, $username ),
		attrs	=> [ 'cn', 'sn', 'mail' ]
	);
	my $entry = $msg->shift_entry();
	if( defined $entry ) {
		$userinfo->{realname} = sprintf(
			"%s %s",
			$entry->get_value( 'cn' ),
			$entry->get_value( 'sn' )
		);
		$userinfo->{mailaddr} =
			$entry->get_value( 'mail' );
	}

	$LDAP->unbind();

	return $userinfo;
}
#### END LOCAL CODE ####

# $GET_USER_MAILADDR_SUB
# Reference to a function which converts username to e-mail address.
# Arguments: username
# Returns: e-mail address
# $GET_USER_MAILADDR_SUB = sub{ $_[0]. '@'. hostname() };
#				# (i.e. user@hostname)
$GET_USER_MAILADDR_SUB = sub {
	unless( defined $USERINFO_CACHE{$_[0]} ) {
		$USERINFO_CACHE{$_[0]} = get_userinfo( $_[0] );
	}
	return $USERINFO_CACHE{$_[0]}->{mailaddr};
};

# $GET_USER_REALNAME_SUB
# Reference to a function which converts username to user's realname (used
# when constructing To: header).
# Arguments: username
# Returns: user's real name
# $GET_USER_REALNAME_SUB = sub{ (split( /,/, (getpwnam($_[0]))[6], 2 ))[0] };
#				# (i.e. user's real name from gecos)
$GET_USER_REALNAME_SUB = sub {
	unless( defined $USERINFO_CACHE{$_[0]} ) {
		$USERINFO_CACHE{$_[0]} = get_userinfo( $_[0] );
	}
	return $USERINFO_CACHE{$_[0]}->{realname};
};
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.