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

📄 security-server,v

📁 Perfession Linux Programming examples
💻
字号:
head	1.1;
access;
symbols;
locks
	cbbrowne:1.1; strict;
comment	@# @;


1.1
date	2000.06.09.12.32.50;	author cbbrowne;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Initial revision
@
text
@#!/usr/bin/env python
import CORBA
import sys
import regex
import string
from string import split, strip
class USERAUTH:   # interface
	def validate(self, user, capability):
		if capabilities.has_key(user):
			caplist = split(capabilities[user], ',')
			if (caplist.occurrences(capability) == 0):
				raise USERAUTH.NOTAUTHENTICATED
			if not tokens.has_key(user):
				raise USERAUTH.NOTAUTHENTICATED
	def login (self, user, password):
		if pwtable.has_key(user):
			if (password == pwtable[user]):
				print "Authenticated", user
				tokens[user] = currtoken
				currtoken = currtoken * 2 + 533
				if currtoken > 12000:
					currtoken = currtoken - 12000
				print "Latest token:", currtoken
				return tokens[user]
			else:
				print "Bad password!"
				print "ID:", user, "PW:", password
				raise USERAUTH.NOTAUTHENTICATED
		else:
			print "Bad user!"
			print "ID:", user, "PW:", password
			raise USERAUTH.NOTAUTHENTICATED
	def submit(self, msg):
		print "Message Received from:", msg.fr
		print "Message for:", msg.to
		for line in msg.body:
			print line
		self.msgs = self.msgs + 1
		print "Messages: ", self.msgs

## First, load in the IDs.
f=open("/brownes/knuth/local/src/ORBit/others/dvdcorba/server/ids.txt")
pwtable={}
tokens={}
capabilities={}
currtoken=252
while 1:
	line=f.readline()
	if not line: break
	if not (line[0] == "#"):
		(id, password, caps) = split( line, ':')
		id=strip(id)
		pwtable[id] = strip(password)
		capabilities[id]=strip(caps)
for id in pwtable.keys():
	print "ID:", id, " --> ", pwtable[id]

CORBA.load_idl("security.idl")
CORBA.load_idl("/usr/share/idl/name-service.idl")
orb = CORBA.ORB_init((), CORBA.ORB_ID)
poa = orb.resolve_initial_references("RootPOA")

servant = POA.SECURITY.USERAUTH(USERAUTH())
poa.activate_object(servant)
ref = poa.servant_to_reference(servant)
open("./security-server.ior", "w").write(orb.object_to_string(ref))

poa.the_POAManager.activate()
orb.run()
@

⌨️ 快捷键说明

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