LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   LFS /tools/bin/groups not displaying supplementary groups (https://www.linuxquestions.org/questions/linux-newbie-8/lfs-tools-bin-groups-not-displaying-supplementary-groups-812822/)

grail 06-08-2010 01:56 AM

LFS /tools/bin/groups not displaying supplementary groups
 
Always good to become the newbie again :)

So i am at the stage of about to install the basic system and am using a derivation of the package management provided by Matthias S. Benkmann.
To this end I am using his useradd and groupadd scripts to update the files:
/etc/passwd
/etc/group

My issue is that when I run the commands(created as part of temporary system when installing coreutils):
Code:

/tools/bin/su linux
#then as user
/tools/bin/groups

linux

(here linux is the name of the user)

This only returns the user being in the group named after user but not the additional group of 'install'

Also, prior to logging in as user, if I use this command as root:
Code:

/tools/bin/groups linux

linux install

This then returns that the user is in the correct groups.

Lines from relevant files look like:
Code:

#/etc/passwd
linux:x:10000:10000::/usr/src/build:/bin/bash

#/etc/group
install:x:1001:linux
linux:x:10000

Any help would be greatly appreciated as to which stupid error I have made :)

Cheers grail

Agrouf 06-09-2010 03:30 AM

Any pointer to Matthias S. Benkmann's scripts? What is the script code? What are they supposed to do, what did you expect them to do, and what is it actually doing?

business_kid 06-09-2010 03:32 AM

You're in the LFS book, chapter 5?
They say FBBG Follow Book - Book Good.
What page are you on? Or is this an external trick, in which case you're on your own.
I don't think you need users to start chapter 6. In chapter 6, you're in a chroot to /tools, so you don't see /tools

grail 06-09-2010 04:25 AM

@Agrouf - Yes I used "Matthias S. Benkmann's scripts" as a guideline.

useradd:
Code:

if [ $# -ne 11 -o z$1 != z-d -o z$3 != z-g -o z$5 != z-G -o z$7 != z-s -o z$9 != z-u ]; then
echo 1>&2 USAGE: useradd -d home -g maingroup -G addgroup -s shell -u uid login
exit 1
fi

#test if user already exists
grep "^${11}:.*" /etc/passwd
if [ $? -eq 0 ]; then
  echo 1>&2 $0: User does already exist
  exit 1
fi     

g=`grep ^${4}:.\* /etc/group | cut -d : -f 3 -`
if [ z${g} = z ]; then
  echo 1>&2 $0: Group ${4} does not exist!
  exit 1
fi

grep ^${6}:.\* /etc/group >/dev/null || \
{
  echo 1>&2 $0: Group ${6} does not exist!
  exit 1
}


cp /etc/passwd /tmp/passwd123456
echo "${11}:x:${10}:$g::$2:/bin/bash" \
| sort -t : -k3,3n -m /tmp/passwd123456 - > /etc/passwd


cp /etc/group /tmp/group123456
sed  -e 's/^\('"${6}"':[^:]*:[0-9]*:..*\)$/\1,'"${11}"'/' \
    -e 's/^\('"${6}"':[^:]*:[0-9]*\):$/\1:'"${11}"'/' \
                                                    /tmp/group123456 >/etc/group

groupadd:
Code:

if [ $# -ne 3 -o z$1 != z-g ]; then
echo 1>&2 USAGE: groupadd -g gid groupname
exit 1
fi

#test if group already exists
grep "^${3}:.*" /etc/group
if [ $? -eq 0 ]; then
  echo 1>&2 $0: Group does already exist
  exit 1
fi     

cp /etc/group /tmp/group123456
echo ${3}:x:${2}: | sort -t : -k3,3n -m /tmp/group123456 - > /etc/group

Both of these update the two corresponding files correctly.

@business_kid - I am on page 6.7 Linux-2.6.34 API Headers. Your following statement is not quite correct:
Quote:

I don't think you need users to start chapter 6. In chapter 6, you're in a chroot to /tools, so you don't see /tools
When you chroot you are in the top level of the mounted directory which does contain tools directory
eg.
Code:

export LFS=/mnt/lfs
mkdir -pv $LFS
mount -v -t ext3 /dev/<xxx> $LFS

mkdir -v $LFS/tools

So from this you can see that tools dir is under /mnt/lfs

Then the chroot is:
Code:

chroot "$LFS" /tools/bin/env -i \
    HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
    /tools/bin/bash --login +h

So here we have chrooted into /mnt/lfs

Upshot is, I am still stuck with root being able to get the right groups with the command but not a user who is being su'ed into.

Agrouf 06-09-2010 04:38 AM

Quote:

Originally Posted by grail (Post 3997610)
Upshot is, I am still stuck with root being able to get the right groups with the command but not a user who is being su'ed into.

Sorry, I read your posts 3 times and I still don't get what your problem is. Which command are you talking about in that sentence?
I understood you want linux in groups linux and install. It looks like /etc/group contains the right groups but /mnt/lfs/etc/group does not contain it?
Could you please post the commands you type one by one, the result you get and the result you expect?
something like that:


I type this:

$ ls
file1 file2 file3

And I expect this:

$ ls
file4

Agrouf 06-09-2010 04:51 AM

Sorry, I've reread a 4th time and I think I get it now.
Basically, you do this:
Code:

# /tools/bin/groups linux
linux install
# /tools/bin/su linux
$ /tools/bin/groups
linux

And you expect that:
Code:

# /tools/bin/groups linux
linux install
# /tools/bin/su linux
$ /tools/bin/groups
linux install

Correct?

Is /tools/etc/groups readable by everybody? It should be 644

grail 06-09-2010 04:54 AM

No probs :)

As root in chroot environment:
Code:

root# groups linux

linux : linux install

root# su linux

linux$ groups

linux


grail 06-09-2010 04:55 AM

Yes that's what I expect and yes it is readable.

grail 06-09-2010 09:57 PM

Ok ... so I have done some more testing and thought I would also explain why I thought this was necessary:

1. Extra testing - interestingly, even though when the user runs groups command on its own it does not display the extra group(s), if I submit the following:
Code:

linux$groups linux
I get:
Quote:

linux : linux install
Which is the output I expected???

2. Reason for query - i was installing another program, man-pages, and this is done as the man-pages user. As per the LFS instructions the install is very simply:
Code:

make install
This now runs the following for loop as per the Makefile contained in the package:
Code:

for i in man?; do \
    install -d -m 755 $(DESTDIR)$(MANDIR)/"$$i" || exit $$?; \
    install -m 644 "$$i"/* $(DESTDIR)$(MANDIR)/"$$i" || exit $$?; \
done;

Where DESTDIR is blank and MANDIR=/usr/share/man.

Now as part of LFS you create these directories already and also:
Quote:

/usr/share/man/man[1-8]
On my system there is an extra step where I change the group to be install and the permissions to be 775 so group can make changes.

On executing the first line in the "for" example above the script hits an error that permission is denied on changing the permissions, hence why I looked
to see what groups had been assigned to the user, in this case man-pages (linux was just shorter to type before), and on typing in the "groups" command
was told that man-pages (and later i found linux also) was not considered in the install group :(

I have since made a change to the Makefile to test if folder already exists and only then use the install -d -m line.

My question now I guess two fold:

1. Still why the erroneous output when submitting just the "groups" command as normal user?

2. Was this lack of acknowledgement of the install group the reason why the man-pages user was unable to execute the following example:
Code:

install -d -m 755 /usr/share/man/man1


All times are GMT -5. The time now is 02:19 PM.