def get_log_path(client_name): if portable.is_admin(): log_path = os.path.join(LOG_DIR, client_name) else: user_name = portable.get_username() log_path = os.path.join(LOG_DIR, client_name + "_" + user_name) return log_path
def install(self, pkgplan, orig): """Client-side method that installs a directory.""" path = self.attrs["path"] mode = int(self.attrs["mode"], 8) owner, group = self.get_uid_gid(pkgplan.image) if orig: omode = int(orig.attrs["mode"], 8) oowner = pkgplan.image.get_user_by_name( orig.attrs["owner"]) ogroup = pkgplan.image.get_group_by_name( orig.attrs["group"]) path = os.path.normpath(os.path.sep.join( (pkgplan.image.get_root(), path))) # XXX Hack! (See below comment.) if not portable.is_admin(): mode |= 0200 if not orig: try: self.makedirs(path, mode = mode) except OSError, e: if e.errno != errno.EEXIST: raise
def testerrorlevelIsCorrect(self): p = pkgtarfile.PkgTarFile(self.tarfile, 'r') # "read-only" folders on Windows are not actually read-only so # the test below doesn't cause the exception to be raised if portable.is_admin() or portable.util.get_canonical_os_type( ) == "windows": self.assert_(p.errorlevel == 2) p.close() return extractpath = os.path.join(self.tpath, "foo/bar") os.makedirs(extractpath) os.chmod(extractpath, 0o555) self.assertRaises(IOError, p.extract, "foo/bar/baz", self.tpath) p.close() os.chmod(extractpath, 0o777)
def testerrorlevelIsCorrect(self): p = pkgtarfile.PkgTarFile(self.tarfile, 'r') # "read-only" folders on Windows are not actually read-only so # the test below doesn't cause the exception to be raised if portable.is_admin() or portable.util.get_canonical_os_type() == "windows": self.assert_(p.errorlevel == 2) p.close() return extractpath = os.path.join(self.tpath, "foo/bar") os.makedirs(extractpath) os.chmod(extractpath, 0555) self.assertRaises(IOError, p.extract, "foo/bar/baz", self.tpath) p.close() os.chmod(extractpath, 777)
def install(self, pkgplan, orig): """Client-side method that installs a directory.""" path = self.attrs["path"] mode = int(self.attrs["mode"], 8) owner, group = self.get_uid_gid(pkgplan.image) if orig: omode = int(orig.attrs["mode"], 8) oowner = pkgplan.image.get_user_by_name(orig.attrs["owner"]) ogroup = pkgplan.image.get_group_by_name(orig.attrs["group"]) path = os.path.normpath( os.path.sep.join((pkgplan.image.get_root(), path))) # XXX Hack! (See below comment.) if not portable.is_admin(): mode |= 0200 if not orig: try: self.makedirs(path, mode=mode) except OSError, e: if e.errno != errno.EEXIST: raise
def testAdmin(self): if os.name == 'posix' and os.getuid() == 0: self.assert_(portable.is_admin()) if os.name == 'posix' and os.getuid() != 0: self.assert_(not portable.is_admin())
def testAdmin(self): if os.name == 'posix' and os.getuid() == 0: self.assertTrue(portable.is_admin()) if os.name == 'posix' and os.getuid() != 0: self.assertTrue(not portable.is_admin())
def install(self, pkgplan, orig): """Client-side method that installs a directory.""" mode = None try: mode = int(self.attrs.get("mode", None), 8) except (TypeError, ValueError): # Mode isn't valid, so let validate raise a more # informative error. self.validate(fmri=pkgplan.destination_fmri) omode = oowner = ogroup = None owner, group = self.get_fsobj_uid_gid(pkgplan, pkgplan.destination_fmri) if orig: try: omode = int(orig.attrs.get("mode", None), 8) except (TypeError, ValueError): # Mode isn't valid, so let validate raise a more # informative error. orig.validate(fmri=pkgplan.origin_fmri) oowner, ogroup = orig.get_fsobj_uid_gid(pkgplan, pkgplan.origin_fmri) path = os.path.normpath(os.path.sep.join(( pkgplan.image.get_root(), self.attrs["path"]))) # Don't allow installation through symlinks. self.fsobj_checkpath(pkgplan, path) # XXX Hack! (See below comment.) if not portable.is_admin(): mode |= stat.S_IWUSR if not orig: try: self.makedirs(path, mode=mode, fmri=pkgplan.destination_fmri) except OSError, e: if e.filename != path: # makedirs failed for some component # of the path. raise fs = os.lstat(path) fs_mode = stat.S_IFMT(fs.st_mode) if e.errno == errno.EROFS: # Treat EROFS like EEXIST if both are # applicable, since we'll end up with # EROFS instead. if stat.S_ISDIR(fs_mode): return raise elif e.errno != errno.EEXIST: raise if stat.S_ISLNK(fs_mode): # User has replaced directory with a # link, or a package has been poorly # implemented. It isn't safe to # simply re-create the directory as # that won't restore the files that # are supposed to be contained within. err_txt = _("Unable to create " "directory %s; it has been " "replaced with a link. To " "continue, please remove the " "link or restore the directory " "to its original location and " "try again.") % path raise apx.ActionExecutionError( self, details=err_txt, error=e, fmri=pkgplan.destination_fmri) elif stat.S_ISREG(fs_mode): # User has replaced directory with a # file, or a package has been poorly # implemented. Salvage what's there, # and drive on. pkgplan.salvage(path) os.mkdir(path, mode) elif stat.S_ISDIR(fs_mode): # The directory already exists, but # ensure that the mode matches what's # expected. os.chmod(path, mode)
def install(self, pkgplan, orig): """Client-side method that installs a directory.""" mode = None try: mode = int(self.attrs.get("mode", None), 8) except (TypeError, ValueError): # Mode isn't valid, so let validate raise a more # informative error. self.validate(fmri=pkgplan.destination_fmri) omode = oowner = ogroup = None owner, group = self.get_fsobj_uid_gid(pkgplan, pkgplan.destination_fmri) if orig: try: omode = int(orig.attrs.get("mode", None), 8) except (TypeError, ValueError): # Mode isn't valid, so let validate raise a more # informative error. orig.validate(fmri=pkgplan.origin_fmri) oowner, ogroup = orig.get_fsobj_uid_gid(pkgplan, pkgplan.origin_fmri) path = self.get_installed_path(pkgplan.image.get_root()) # Don't allow installation through symlinks. self.fsobj_checkpath(pkgplan, path) # XXX Hack! (See below comment.) if not portable.is_admin(): mode |= stat.S_IWUSR if not orig: self.__create_directory(pkgplan, path, mode) # The downside of chmodding the directory is that as a non-root # user, if we set perms u-w, we won't be able to put anything in # it, which is often not what we want at install time. We save # the chmods for the postinstall phase, but it's always possible # that a later package install will want to place something in # this directory and then be unable to. So perhaps we need to # (in all action types) chmod the parent directory to u+w on # failure, and chmod it back aftwards. The trick is to # recognize failure due to missing file_dac_write in contrast to # other failures. Or can we require that everyone simply have # file_dac_write who wants to use the tools. Probably not. elif mode != omode: try: os.chmod(path, mode) except Exception as e: if e.errno != errno.EPERM and e.errno != \ errno.ENOSYS: # Assume chmod failed due to a # recoverable error. self.__create_directory(pkgplan, path, mode) omode = oowner = ogroup = None # if we're salvaging contents, move 'em now. # directories with "salvage-from" attribute # set will scavenge any available contents # that matches specified directory and # move it underneath itself on install or update. # This is here to support directory rename # when old directory has unpackaged contents, or # consolidation of content from older directories. for salvage_from in self.attrlist("salvage-from"): pkgplan.salvage_from(salvage_from, path) if not orig or oowner != owner or ogroup != group: try: portable.chown(path, owner, group) except OSError as e: if e.errno != errno.EPERM and \ e.errno != errno.ENOSYS: # Assume chown failed due to a # recoverable error. self.__create_directory(pkgplan, path, mode, uid=owner, gid=group)
if __name__ == "__main__": client = gconf.client_get_default() use_http_proxy = client.get_bool(HTTP_PROXY_USE) if use_http_proxy: http_proxy = get_http_proxy() if os.getenv(HTTP_PROXY_VARIABLE) == None: os.putenv(HTTP_PROXY_VARIABLE, http_proxy) if os.getenv(HTTPS_PROXY_VARIABLE) == None: os.putenv(HTTPS_PROXY_VARIABLE, http_proxy) # If /usr/bin/packagemanager was checked for instead, that would make # testing (especially automated) impossible for web links. allow_links = False args = sys.argv[1:] if args[0].find("packagemanager") != -1 and not portable.is_admin(): allow_links = True args.append("--allow-links") args = ["/usr/bin/gksu", " ".join(args)] proc = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True) # Reap the defunct gksu now rather than wait for kernel to do it. proc.wait() if not allow_links: # Nothing to do for other programs. sys.exit() # XXX PackageManager should not run as a privileged process!
if __name__ == "__main__": client = gconf.client_get_default() use_http_proxy = client.get_bool(HTTP_PROXY_USE) if use_http_proxy: http_proxy = get_http_proxy() if os.getenv(HTTP_PROXY_VARIABLE) == None: os.putenv(HTTP_PROXY_VARIABLE, http_proxy) if os.getenv(HTTPS_PROXY_VARIABLE) == None: os.putenv(HTTPS_PROXY_VARIABLE, http_proxy) # If /usr/bin/packagemanager was checked for instead, that would make # testing (especially automated) impossible for web links. allow_links = False args = sys.argv[1:] if args[0].find("packagemanager") != -1 and not portable.is_admin(): allow_links = True args.append("--allow-links") args = ["/usr/bin/gksu", " ".join(args)] proc = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True) # Reap the defunct gksu now rather than wait for kernel to do it. proc.wait() if not allow_links: # Nothing to do for other programs. sys.exit() # XXX PackageManager should not run as a privileged process! # This rather convoluted solution allows packagemanager to open links
def install(self, pkgplan, orig): """Client-side method that installs a directory.""" mode = None try: mode = int(self.attrs.get("mode", None), 8) except (TypeError, ValueError): # Mode isn't valid, so let validate raise a more # informative error. self.validate(fmri=pkgplan.destination_fmri) omode = oowner = ogroup = None owner, group = self.get_fsobj_uid_gid(pkgplan, pkgplan.destination_fmri) if orig: try: omode = int(orig.attrs.get("mode", None), 8) except (TypeError, ValueError): # Mode isn't valid, so let validate raise a more # informative error. orig.validate(fmri=pkgplan.origin_fmri) oowner, ogroup = orig.get_fsobj_uid_gid(pkgplan, pkgplan.origin_fmri) path = os.path.normpath(os.path.sep.join(( pkgplan.image.get_root(), self.attrs["path"]))) # Don't allow installation through symlinks. self.fsobj_checkpath(pkgplan, path) # XXX Hack! (See below comment.) if not portable.is_admin(): mode |= stat.S_IWUSR if not orig: try: self.makedirs(path, mode=mode, fmri=pkgplan.destination_fmri) except OSError, e: if e.filename != path: # makedirs failed for some component # of the path. raise fs = os.lstat(path) fs_mode = stat.S_IFMT(fs.st_mode) if e.errno == errno.EROFS: # Treat EROFS like EEXIST if both are # applicable, since we'll end up with # EROFS instead. if stat.S_ISDIR(fs_mode): return raise elif e.errno != errno.EEXIST: raise if stat.S_ISLNK(fs_mode): # User has replaced directory with a # link, or a package has been poorly # implemented. It isn't safe to # simply re-create the directory as # that won't restore the files that # are supposed to be contained within. err_txt = _("Unable to create " "directory %s; it has been " "replaced with a link. To " "continue, please remove the " "link or restore the directory " "to its original location and " "try again.") % path raise apx.ActionExecutionError( self, details=err_txt, error=e, fmri=pkgplan.destination_fmri) elif stat.S_ISREG(fs_mode): # User has replaced directory with a # file, or a package has been poorly # implemented. Salvage what's there, # and drive on. pkgplan.image.salvage(path) os.mkdir(path, mode) elif stat.S_ISDIR(fs_mode): # The directory already exists, but # ensure that the mode matches what's # expected. os.chmod(path, mode)