Launchpadlib support in Ubuntu Developer Tools
Kees Cook
kees at ubuntu.com
Thu Jan 15 00:48:44 GMT 2009
On Thu, Jan 15, 2009 at 12:23:13AM +0000, Colin Watson wrote:
> On Wed, Jan 14, 2009 at 11:18:35AM -0800, Kees Cook wrote:
> > launchpad.credentials.save(open(credfile,"w",0600))
>
> Isn't the third argument to Python's open() the buffer size, not the
> file mode? That's what the documentation says, anyway.
UUuurg, this is what I get for switching languages so much. :) Thanks for
catching that. (Luckily my mkdir worked as expected, which makes the
latter goof less of an issue.)
> I think you need:
>
> launchpad = Launchpad.get_token_and_login(sys.argv[0], EDGE_SERVICE_ROOT, cachedir)
> credfd = open(credfile, "w")
> os.chmod(credfile, 0600)
> launchpad.credentials.save(credfd)
> credfd.close()
>
> Python didn't have fchmod until 2.6 so this is a little awkward, but it
> does the job.
Now I have to redeem my embarrassment by suggesting this as a way to avoid
the create/chmod race when fchmod is unavailable:
credfd = tempfile.NamedTemporaryFile(dir=os.path.dirname(credfile))
launchpad.credentials.save(credfd)
os.link(credfd.name, credfile)
credfd.close()
The link will fail if the target exists, and the close will clean up the
original file. Wheee :)
--
Kees Cook
Ubuntu Security Team
More information about the ubuntu-devel
mailing list