Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[userids] Fix user ids to match the new ids in Mer.
Signed-off-by: Marko Saukko <marko.saukko@jollamobile.com>
  • Loading branch information
Marko Saukko committed Jun 11, 2013
1 parent 81c226d commit 2d1aa3f
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
65 changes: 65 additions & 0 deletions oneshot/correct-users
@@ -0,0 +1,65 @@
#!/bin/sh
# Copyright (C) 2013 Jolla Ltd.
# Contact: Islam Amer <islam.amer@jollamobile.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the <organization> nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# only works as root
[ $UID -eq 0 ] || exit 0

# requires old passwd and group files in /var/lib/misc
[ -f /var/lib/misc/passwd.old ] || exit 0
[ -f /var/lib/misc/group.old ] || exit 0

# Get system's default min gid and uid
GID_MIN=$(grep "^GID_MIN" /etc/login.defs | tr -s " " | cut -d " " -f2)
UID_MIN=$(grep "^UID_MIN" /etc/login.defs | tr -s " " | cut -d " " -f2)

# Get users that have a /home dir
for user in "$(grep "/home/" /etc/passwd)"; do
# get user's old info
uname=$(echo "$user" | cut -d: -f1)
old_uid=$(grep $uname /var/lib/misc/passwd.old | cut -d: -f3)
old_gid=$(grep $uname /var/lib/misc/passwd.old | cut -d: -f4)
gname=$(grep ":$old_gid:" /var/lib/misc/group.old | cut -d: -f1)

new_gid=$old_gid
# compare them to system's min gid and uid
if test $old_gid -lt $GID_MIN ; then
new_gid=$(( $old_gid + 99000 ))
fi

new_uid=$old_uid
if test $old_uid -lt $UID_MIN ; then
new_uid=$(( $old_uid + 99000 ))
fi

# correct user's uid and gid and reown it's files to it
if test \! "$new_uid" -eq "$old_uid" -o \! "$new_gid" -eq "$old_gid" ; then
groupmod -g $new_gid $gname
usermod -u $new_uid $uname
find / -xdev \( -group $old_gid -o -user $old_uid \) -exec chown -h $new_uid:$new_gid {} +
fi
done

33 changes: 33 additions & 0 deletions rpm/nemo-mobile-session.spec
Expand Up @@ -9,6 +9,12 @@ Source0: %{name}-%{version}.tar.gz
Requires: systemd >= 187
Requires: xorg-launch-helper
Obsoletes: uxlaunch
# mer release 0.20130605.1 changed login.defs
Requires: setup >= 2.8.56-1.1.33
BuildRequires: oneshot
Requires: oneshot
%{_oneshot_requires_post}
Requires(post): /bin/chgrp, /usr/sbin/groupmod

%description
Target for nemo systemd user session
Expand Down Expand Up @@ -64,6 +70,32 @@ ln -sf ../mthemedaemon.service %{buildroot}%{_libdir}/systemd/user/nemo-mobile-s
ln -sf ../ngfd.service %{buildroot}%{_libdir}/systemd/user/nemo-mobile-session.target.wants/
ln -sf ../ohm-session-agent.service %{buildroot}%{_libdir}/systemd/user/nemo-mobile-session.target.wants/

# login.defs
mkdir -p %{buildroot}/%{_oneshotdir}
install -D -m 755 oneshot/correct-users %{buildroot}/%{_oneshotdir}

%post
if [ $1 -gt 1 ] ; then
# known changes
if [ ! "$(grep audio %{_sysconfdir}/group | cut -d: -f3)" -eq 1005 ]; then
groupmod -g 1005 audio
fi
if [ ! "$(grep nobody %{_sysconfdir}/group | cut -d: -f3)" -eq 9999 ]; then
groupmod -g 9999 nobody
fi

[ -f /usr/bin/ssh-agent ] && chgrp nobody %{_bindir}/ssh-agent

# backup group and passwd
mkdir -p %{_sharedstatedir}/misc
[ ! -f %{_sharedstatedir}/misc/passwd.old ] && cp %{_sysconfdir}/passwd %{_sharedstatedir}/misc/passwd.old
[ ! -f %{_sharedstatedir}/misc/group.old ] && cp %{_sysconfdir}/group %{_sharedstatedir}/misc/group.old

# device specific changes
%{_bindir}/add-oneshot correct-users

fi

%files
%defattr(-,root,root,-)
%config /var/lib/environment/nemo/50-nemo-mobile-ui.conf
Expand All @@ -82,4 +114,5 @@ ln -sf ../ohm-session-agent.service %{buildroot}%{_libdir}/systemd/user/nemo-mob
%{_libdir}/startup/init-done
%{_libdir}/startup/killx
%{_sysconfdir}/systemd/system/runlevel4.target
%{_oneshotdir}/correct-users

0 comments on commit 2d1aa3f

Please sign in to comment.