* requestsync: Fixes to permission checking.

* common.py: Change cookie file permissions to read and write only by user.
This commit is contained in:
Jonathan Patrick Davies 2008-08-12 18:18:11 +01:00
parent 575e8e76d4
commit b0528dd32e
3 changed files with 33 additions and 12 deletions

View File

@ -67,7 +67,11 @@ def prepareLaunchpadCookie():
ftstr = ["FALSE", "TRUE"] ftstr = ["FALSE", "TRUE"]
newLPCookie = open("%s/.lpcookie.txt" % os.environ.get('HOME'), 'w') # This shall be where our new cookie file lives - at ~/.lpcookie.txt
newLPCookieLocation = "%s/.lpcookie.txt" % os.environ.get('HOME')
# Open file for writing.
newLPCookie = open(newLPCookieLocation, 'w')
newLPCookie.write("# HTTP Cookie File.\n") # Header. newLPCookie.write("# HTTP Cookie File.\n") # Header.
for item in cur.fetchall(): for item in cur.fetchall():
@ -77,16 +81,20 @@ def prepareLaunchpadCookie():
ftstr[item[2]], item[3], item[4], item[5])) ftstr[item[2]], item[3], item[4], item[5]))
newLPCookie.write("\n") # New line. newLPCookie.write("\n") # New line.
newLPCookie.close() newLPCookie.close() # And close file.
# Check what we have written. # Check what we have written.
checkCookie = open("%s/.lpcookie.txt" % os.environ.get('HOME')).read() checkCookie = open(newLPCookieLocation).read()
if checkCookie == "# HTTP Cookie File.\n\n": if checkCookie == "# HTTP Cookie File.\n\n":
print >> sys.stderr, "No Launchpad cookies were written to file. " \ print >> sys.stderr, "No Launchpad cookies were written to file. " \
"Please visit and log into Launchpad and run this script again." "Please visit and log into Launchpad and run this script again."
os.remove("%s/.lpcookie.txt" % os.environ.get('HOME')) # Delete file. os.remove(newLPCookieLocation) # Delete file.
sys.exit(1) sys.exit(1)
# For security reasons, change file mode to write and read
# only by owner.
os.chmod(newLPCookieLocation, 0600)
launchpad_cookiefile = "%s/.lpcookie.txt" % os.environ.get('HOME') launchpad_cookiefile = "%s/.lpcookie.txt" % os.environ.get('HOME')
# Return the Launchpad cookie. # Return the Launchpad cookie.

1
debian/changelog vendored
View File

@ -3,6 +3,7 @@ ubuntu-dev-tools (0.38ubuntu1) intrepid; urgency=low
[ Jonathan Patrick Davies ] [ Jonathan Patrick Davies ]
* requestsync: Check if user is a member of ubuntu-core-dev if sync request * requestsync: Check if user is a member of ubuntu-core-dev if sync request
is for a package in main. is for a package in main.
* common.py: Change cookie file permissions to read and write only by user.
-- Jonathan Patrick Davies <jpds@ubuntu.com> Tue, 12 Aug 2008 14:52:34 +0100 -- Jonathan Patrick Davies <jpds@ubuntu.com> Tue, 12 Aug 2008 14:52:34 +0100

View File

@ -54,6 +54,7 @@ def checkNeedsSponsorship(component):
""" """
urlopener = common.setupLaunchpadUrlOpener(launchpad_cookiefile) urlopener = common.setupLaunchpadUrlOpener(launchpad_cookiefile)
# Check where the package is and assign the appropriate variables.
if component in ['main', 'restricted']: if component in ['main', 'restricted']:
team = "ubuntu-core-dev" team = "ubuntu-core-dev"
sponsor = "ubuntu-main-sponsors" sponsor = "ubuntu-main-sponsors"
@ -61,17 +62,28 @@ def checkNeedsSponsorship(component):
team = "ubuntu-dev" team = "ubuntu-dev"
sponsor = "ubuntu-universe-sponsors" sponsor = "ubuntu-universe-sponsors"
teamLPPage = urlopener.open('https://launchpad.net/~%s' % team).read() # Try and open up Launchpad.
try: teamLPPage = urlopener.open('https://launchpad.net/~%s' % team).read()
except urllib2.HTTPError:
print >> sys.stderr, "Unable to connect to Launchpad."
if 'You are not a member of this team:' in teamLPPage: # Check if they are a member of the team.
if "You are an indirect member of this team:" in teamLPPage or \
"You are a member of this team." in teamLPPage:
return False # Sponsorship not required.
# Check if they are not.
if "You are not a member of this team" in teamLPPage:
print "You are not a member (direct or indirect) of the '%s' " \ print "You are not a member (direct or indirect) of the '%s' " \
"team on Launchpad." % team "team on Launchpad." % team
print "Your sync request shall require an approval by a member of " \ print "Your sync request shall require an approval by a member of " \
"the %s team." % sponsor "the '%s'\nteam, who shall be subscribed to this bug report." % sponsor
print "before it is processed by a member of the Ubuntu Archive admins." print "This must be done before it can be processed by a member of " \
"the Ubuntu Archive team."
print "Should the above be incorrect, please press Control-C now to " \
"stop this script now\nand check the cookie file at:", launchpad_cookiefile
raw_input_exit_on_ctrlc() # Abort if necessary.
return True # Sponsorship required. return True # Sponsorship required.
else:
return False # Sponsorship not required.
def cur_version_component(sourcepkg, release): def cur_version_component(sourcepkg, release):
'''Determine current package version in ubuntu.''' '''Determine current package version in ubuntu.'''