Move auth into function, remove duplicate header, misc bugfixes.

This commit is contained in:
Ricky Zhou (周家杰) 2009-03-13 23:26:08 -04:00
parent fb7cfecb01
commit 2623d77779

View file

@ -31,8 +31,6 @@ CACHE_DIR = '/srv/cache/lookaside/pkgs'
PACKAGER_GROUP = 'packager' PACKAGER_GROUP = 'packager'
def send_error(text): def send_error(text):
print 'Content-type: text/plain'
print
print text print text
sys.exit(1) sys.exit(1)
@ -44,21 +42,22 @@ def check_form(form, var):
send_error('Multiple values given for "%s". Aborting.' % var) send_error('Multiple values given for "%s". Aborting.' % var)
return ret return ret
def main(): def check_auth():
os.umask(002)
authenticated = False authenticated = False
if os.environ.has_key('SSL_CLIENT_S_DN_CN'): if os.environ.has_key('SSL_CLIENT_S_DN_CN'):
auth_username = os.environ['SSL_CLIENT_S_DN_CN'] auth_username = os.environ['SSL_CLIENT_S_DN_CN']
if auth_username in grp.getgrnam(PACKAGER_GROUP)[3]: if auth_username in grp.getgrnam(PACKAGER_GROUP)[3]:
authenticated = True authenticated = True
return authenticated
if not authenticated: def main():
os.umask(002)
if not check_auth():
print 'Status: 403 Forbidden' print 'Status: 403 Forbidden'
print 'Content-type: text/plain' print 'Content-type: text/plain'
print print
print 'You must be in the %s group to upload.' % PACKAGER_GROUP print 'You must connect with a valid certificate and be in the %s group to upload.' % PACKAGER_GROUP
sys.exit(0) sys.exit(0)
print 'Content-Type: text/plain' print 'Content-Type: text/plain'
@ -100,8 +99,7 @@ def main():
cvs_dir = os.path.join(CVSREPO, name) cvs_dir = os.path.join(CVSREPO, name)
if not os.path.isdir(cvs_dir): if not os.path.isdir(cvs_dir):
print >> sys.stderr, 'Unknown module: %s' % name print >> sys.stderr, 'Unknown module: %s' % name
print 'Module "%s" does not exist!' % name send_error('Module "%s" does not exist!' % name)
sys.exit(-9)
# try to see if we already have this file... # try to see if we already have this file...
dest_file = os.path.join(md5_dir, filename) dest_file = os.path.join(md5_dir, filename)
@ -116,7 +114,7 @@ def main():
sys.exit(0) sys.exit(0)
elif action == 'check': elif action == 'check':
print 'Missing' print 'Missing'
sys.exit(-9) sys.exit(0)
# check that all directories are in place # check that all directories are in place
if not os.path.isdir(module_dir): if not os.path.isdir(module_dir):