diff --git a/buildd b/buildd index 74f4d57..6a0cb44 100755 --- a/buildd +++ b/buildd @@ -120,6 +120,20 @@ for m in re.finditer('"/ubuntu/\+source/%s/%s(/\+build/\d+)"[^\n]+\n\s*(\w+).*?< if op == 'status': sys.exit(0) +# Leaving operations may only be done by Ubuntu developers (retry) or buildd +# admins (rescore). Check if the proper permissions are in place. +if op == "rescore": teamNeeded = "launchpad-buildd-admins" +if op == "retry": teamNeeded = "ubuntu-dev" + +necessaryPrivs = common.isLPTeamMember(teamNeeded) + +if not necessaryPrivs: + print >> sys.stderr, "You cannot perform the %s operation as you are not " \ + "a member of the '%s' team on Launchpad." % (op, teamNeeded) + print "If this is incorrect, please log in to Launchpad using Firefox, " \ + "delete the ~/.lpcookie.txt file and rerun this script." + sys.exit(1) + for build, (arch, status) in buildstats.iteritems(): if oneArch and not options.architecture == arch: # Skip this architecture. diff --git a/common.py b/common.py index c04f2c5..86c8d27 100644 --- a/common.py +++ b/common.py @@ -202,3 +202,34 @@ def setupLaunchpadUrlOpener(cookie): urlopener.add_handler(urllib2.HTTPCookieProcessor(cj)) return urlopener + +def isLPTeamMember(team): + """ Checks if the user is a member of a certain team on Launchpad. + + We do this by opening the team page on Launchpad and checking if the + text "You are not a member of this team" is present using the + user's cookie file for authentication. + + If the user is a member of the team: return True. + If the user is not a member of the team: return False. + """ + + # TODO: Check if launchpadlib may be a better way of doing this. + + # Prepare cookie. + cookieFile = prepareLaunchpadCookie() + # Prepare URL opener. + urlopener = setupLaunchpadUrlOpener(cookieFile) + + # Try to open the Launchpad team page: + try: + lpTeamPage = urlopener.open("https://launchpad.net/~%s" % team).read() + except urllib2.HTTPError, error: + print >> sys.stderr, "Unable to connect to Launchpad. Received a %s." % error.code + sys.exit(1) + + # Check if text is present in page. + if ("You are not a member of this team") in lpTeamPage: + return False + + return True diff --git a/debian/changelog b/debian/changelog index fd1d841..aead7bc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,8 +4,13 @@ ubuntu-dev-tools (0.43ubuntu1) intrepid; urgency=low * common.py: - If loading a cookie file raises an exception exit. - Improve cookie file writing. - * requestsync: Return an error when the script is unable to connect to - packages.debian.org (LP: #261916). + - New function: isLPTeamMember() - checks if the user is a member of the + Launchpad team using cookies for authentication. + * requestsync: + - Return an error when the script is unable to connect to + packages.debian.org (LP: #261916). + - Adapt team checking with the function above. + * buildd: Adapt privilege checking code to the new function above. [ Ryan Kavanagh ] * dgetlp.1: New manpage diff --git a/requestsync b/requestsync index 304b25f..3dcaf77 100755 --- a/requestsync +++ b/requestsync @@ -62,20 +62,11 @@ def checkNeedsSponsorship(component): else: team = "ubuntu-dev" sponsor = "ubuntu-universe-sponsors" - - # 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." - sys.exit(1) - - # 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: + # Check if they are a member of the team. + teamMember = common.isLPTeamMember(team) + + if not teamMember: print "You are not a member (direct or indirect) of the '%s' " \ "team on Launchpad." % team print "Your sync request shall require an approval by a member of " \ @@ -87,6 +78,9 @@ def checkNeedsSponsorship(component): raw_input_exit_on_ctrlc() # Abort if necessary. return True # Sponsorship required. + # Is a team member, no sponsorship required. + return False + def cur_version_component(sourcepkg, release): '''Determine current package version in ubuntu.''' madison = subprocess.Popen(['rmadison', '-u', 'ubuntu', '-a', 'source', \