Received: (at submit) by bugs.debian.org; 23 Nov 2000 14:55:33 +0000 From mquinson@pixies.ens-lyon.fr Thu Nov 23 08:55:32 2000 Return-path: Received: from pixies.ens-lyon.fr (pixies) [140.77.13.230] (mail) by master.debian.org with esmtp (Exim 3.12 1 (Debian)) id 13yxmd-0007GO-00; Thu, 23 Nov 2000 08:55:31 -0600 Received: from mquinson by pixies with local (Exim 3.16 #1 (Debian)) id 13zgnH-0008MG-00; Sat, 25 Nov 2000 15:59:11 +0100 From: Martin Quinson Subject: dpkg: [PATCH]: users should be able to use update-alternatives (not only root) To: submit@bugs.debian.org X-Mailer: bug 3.3.7 Message-Id: Date: Sat, 25 Nov 2000 15:59:11 +0100 Delivered-To: submit@bugs.debian.org Package: dpkg Version: 1.7.1 Severity: wishlist Hello, Here is an (unified) patch against update-alternatives.pl as found today in the CVS. Its purpose is to allow the users to manage an "alternative" system on their account. But, don't dream, anything is not possible for users. They can just call update-alternatives for actions "--display", "--config" or "--install". So, they can't add new alternative neither remove old ones. (Doing so, I don't have to manage a DB for users) Second problem, users who want to use it will have to add to their .bashrc something like: PATH=$HOME/etc/alternatives:$PATH MANPATH=$HOME/etc/alternatives:$PATH The problem is that anything (binaries and man pages) will be mixed up in this directory (good news in the bad new: you can change the dir used). Third problem: so far, the programm is located in /usr/sbin So, you'll have to change that to give the users the ability to use it. Enough with problems. How does it work ? When you run the programm as user (uid != 0), /etc/alternatives is not changed (sure, I do not have the right to do so). It's the ~/etc/altenatives which changes. When I (as user) put an alternative to "auto", it removes the corresponding link from my subdir, putting the setting to the system-wide one by the same occasion. When I (as user) run display, I got information about my own personal setting, and about the system-wide one. When I (as user) run config, and if I got a personnal setting for this alternative, this is the default one, and it is marked by a '@'. (so, we have three column: '@' on first one for the user settings (not visible when root) '*' on second one for system-wide one '+' on third one for 'best' one Ok, I've just read that I can't make attachements to bug repports because the system dislikes MIME, so I dumbly copy/paste my patch here... >>>>>>>>>>>>>>> BEGIN OF PATCH --- DEBIAN/dpkg/scripts/update-alternatives.pl Sat Nov 25 09:58:52 2000 +++ update-alternatives.pl Sat Nov 25 15:49:00 2000 @@ -45,6 +45,7 @@ Options: --verbose|--quiet --test --help --version --altdir --admindir + --localaltdir END || &quit("failed to write usage: $!"); } @@ -103,6 +104,9 @@ } elsif (m/^--altdir$/) { @ARGV || &badusage("--altdir needs a argument"); $altdir= shift(@ARGV); + } elsif (m/^--localaltdir$/) { + @ARGV || &badusage("--localaltdir needs a argument"); + $localaltdir= shift(@ARGV); } elsif (m/^--admindir$/) { @ARGV || &badusage("--admindir needs a argument"); $admindir= shift(@ARGV); @@ -115,6 +119,19 @@ $aslavelinkcount{$alink} && &badusage("link $link is both primary and slave"); $mode || &badusage("need --display, --config, --install, --remove or --auto"); +if (getpwnam(getpwuid($<))) { # check if user is root + $mode eq "auto" || $mode eq "config" || $mode eq "display" + || &badusage("If you're not root, you're only allowed to run --config, --auto or --display"); + $localaltdir=$ENV{"HOME"}.$altdir unless $localaltdir; + $localaltdir || &quit("Unable to determine localaltdir. Giving up"); + &pr("Any changes will apply to $localaltdir.") + if $verbosemode > 0; + -e $localaltdir || &quit("$localaltdir does not exist. Please create it."); + $rootaltdir=$altdir;$altdir=$localaltdir; +} else { + $rootaltdir=''; + $localaltdir && &badusage("You can't specify a localaltdir option when running as root"); +} $mode eq 'install' || !%slavelink || &badusage("--slave only allowed with --install"); if (open(AF,"$admindir/$name")) { @@ -159,10 +176,20 @@ if ($mode eq 'display') { if (!$dataread) { - &pr("No alternatives for $name."); + &pr("No alternatives for $name."); } else { - &pr("$name - status is $manual."); - if (defined($linkname= readlink("$altdir/$name"))) { + if (getpwnam(getpwuid($<))) { + if (defined($linkname= readlink("$altdir/$name"))) { + &pr("$name - user alternative link currently points to $linkname"); + } elsif ($! == &ENOENT) { + &pr("$name - using system-wide settings"); + } + } + $tmp=getpwnam(getpwuid($<))? "\nSystem wide":"$name - "; + $tmp2=getpwnam(getpwuid($<))? " BUT DISCARDED in flavor of user settings":""; + &pr("$tmp status is $manual$tmp2."); + if ((getpwnam(getpwuid($<))&& defined($linkname = readlink("$rootaltdir/$name"))) + || defined($linkname= readlink("$altdir/$name"))) { &pr(" link currently points to $linkname"); } elsif ($! == &ENOENT) { &pr(" link currently absent"); @@ -225,6 +252,22 @@ # all independent if ($mode eq 'auto') { + if (getpwnam(getpwuid($<)) != 0) { # check if user is root + &pr("Setting up selection of $name to site setting.") + if $verbosemode > 0; + &quit("$name already set to site setting. Nothing done") + unless -e "$altdir/$name"; + &pr("You are not root: I won't change the system wide settings, but only yours.\n"); + unlink("$altdir/$name") || $! == &ENOENT || + &quit("unable to remove $altdir/$name"); + for ($j=0; $j<=$#slavenames; $j++) { + &pr("Discarding obsolete slave link $slavenames[$j] ($slavelinks[$j]).") + if $verbosemode > 0; + unlink("$altdir/$slavenames[$j]") || $! == &ENOENT || + &quit("unable to remove $slavenames[$j]: $!"); + } + exit 0; + } &pr("Setting up automatic selection of $name.") if $verbosemode > 0; unlink("$altdir/$name.dpkg-tmp") || $! == &ENOENT || @@ -366,6 +409,7 @@ # state=unexpected => manual=manual # manual=auto => state!=expected-inprogress && state!=unexpected +exit 0 if (getpwnam(getpwuid($<))); # non-root don't save the DB open(AF,">$admindir/$name.dpkg-new") || &quit("unable to open $admindir/$name.dpkg-new for write: $!"); &paf($manual); @@ -482,15 +526,32 @@ return; } printf(STDOUT "\nThere are %s programs which provide \`$name'.\n\n", $#versions+1); - printf(STDOUT " Selection Command\n"); + printf(STDOUT " Selection Command\n"); printf(STDOUT "-----------------------------------------------\n"); + $userfixed=0; for ($i=0; $i<=$#versions; $i++) { - printf(STDOUT "%s%s %s %s\n", - (readlink("$altdir/$name") eq $versions[$i]) ? '*' : ' ', + $userfixed = $userfixed || + (-e "$altdir/$name" && (readlink("$altdir/$name") eq $versions[$i])); + printf(STDOUT "%s%s%s %s %s\n", + (getpwnam(getpwuid($<)) ? #non root + (-e "$altdir/$name" && (readlink("$altdir/$name") eq $versions[$i]) ? '@' : ' ') + : # root => no user specified + ' '), + (getpwnam(getpwuid($<)) ? #non root + ((readlink("$rootaltdir/$name") eq $versions[$i]) ? '*' : ' ') + : # root + (readlink("$altdir/$name") eq $versions[$i]) ? '*' : ' '), ($best eq $versions[$i]) ? '+' : ' ', $i+1, $versions[$i]); } - printf(STDOUT "\nEnter to keep the default[*], or type selection number: "); + &pr("\n"); + + &pr("(You are not root: I won't change the system wide settings, but only yours)\n") + if (getpwnam(getpwuid($<))); + + printf(STDOUT "Enter to keep the %sdefault[%s], or type selection number: ", + (getpwnam(getpwuid($<)) ? ($userfixed ? "user-specified " : "system-wide ") : ""), + (getpwnam(getpwuid($<)) ? ($userfixed ? "@" : "*") : "*")); } sub config_alternatives { @@ -559,3 +620,8 @@ exit(0); # vim: nowrap ts=8 sw=4 + + + + + <<<<<<<<<<<<<< END OF PATCH When this is the wrong way to give a patch, please say it, and I'll resend it. Bye, Mt. -- System Information Debian Release: woody Kernel Version: Linux pixies 2.2.17 #1 Thu Sep 21 17:08:01 CEST 2000 i686 unknown Versions of the packages dpkg depends on: ii libc6 2.2-1 GNU C Library: Shared libraries and Timezone ii libncurses5 5.0-7 Shared libraries for terminal handling ii libstdc++2.10- 2.95.2-17 The GNU stdc++ library