[X2Go-Dev] Forwarding based on group membership

John Sigurd Skogtvedt jss at linuxavdelingen.no
Mon Oct 14 14:05:34 CEST 2013


Hello, for FreeNX we implemented a hack for forwarding users to certain
servers based on LDAP group membership. To do this we wrote a
nxcheckload script which returns a different value depending on if a
user is member of a group "belonging to" a server. I have attached the
script for reference.

Is it possible to achieve the same with x2go, forwarding based on group
membership?


Regards,

John.
-------------- next part --------------
#!/usr/bin/python
import os
import sys
import grp

def main(args):
	if len(args) != 2:
		print >>sys.stderr, 'Usage: %s hostname' % args[0]
		return 1
	groupmap = {}
	f = open('/etc/nxserver/groupmap', 'r')
	for line in f:
		try:
			host, groups = line.split(None, 2)
			groups = groups.split(',')
			groupmap[host] = groups
		except ValueError:
			pass
	f.close()

	user = os.environ['USER']
	host = args[1]
	try:
		for group in groupmap[host]:
			if user in grp.getgrnam(group)[3]:
				print '1'
				return 0
	except KeyError:
		pass

	print '0'
	return 0

if __name__ == '__main__':
	sys.exit(main(sys.argv))



More information about the x2go-dev mailing list