Your message dated Fri, 14 Oct 2022 03:15:20 +0200
with message-id <[email protected]>
and subject line Re: Bug#77828: dpkg: [PATCH]: users should be able to use 
update-alternatives (not only root)
has caused the Debian Bug report #77828,
regarding u-a: Users should be able to use u-a (not only root)
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
77828: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=77828
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
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 <directory>  --admindir <directory>
+          --localaltdir <directory>
 END
         || &quit("failed to write usage: $!");
 }
@@ -103,6 +104,9 @@
     } elsif (m/^--altdir$/) {
         @ARGV || &badusage("--altdir needs a <directory> argument");
         $altdir= shift(@ARGV);
+    } elsif (m/^--localaltdir$/) {
+        @ARGV || &badusage("--localaltdir needs a <directory> argument");
+        $localaltdir= shift(@ARGV);
     } elsif (m/^--admindir$/) {
         @ARGV || &badusage("--admindir needs a <directory> 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


--- End Message ---
--- Begin Message ---
Hi!

On Sun, 2008-07-06 at 17:49:25 +0200, Raphael Hertzog wrote:
> tags 77828 - patch
> tags 77828 + wontfix
> thanks

> On Sat, 25 Nov 2000, Martin Quinson wrote:
> > 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.
> 
> I'm not really inclined to support such a feature. I have yet to see a
> valid use case.
> 
> When the user wants to override a system-wide setting, there are already
> dozens of solutions going from using some environment variable to
> changing the PATH so that ~/bin/ is looked first. And ~/bin/ can contain
> symlinks corresponding to the various name of alternatives and have them
> point to their program of choice.

I do agree. As I see no point in keeping this around, I'll be closing
this request now. If this happens to be requested again then I guess
I'll create a FAQ entry.

Thanks,
Guillem

--- End Message ---

Reply via email to