Welcome
Welcome to refracta

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!

change-username and kde4

Refracta Development, Scripts, etc.

change-username and kde4

Postby fsmithred » Sat Jun 23, 2012 12:23 pm

The change-username script seems to work the first time I run it on the primary user, but if I try to change that user's name a second time, I run into problems. It hangs on the sed command to change /home/$oldname to /home/$newname in the user's config files (in /home/user/.confi).

Sorry, this is kind of scattered testing. I created a second user and then tried to change that user's name when they were logged in. Got errors when trying to log in as that new user. (something like Cannot open ConsoleKit session... Failed to connect to socket /var/run/debus/system_bus_socket). The following was in .xsession_errors:
Code: Select all
./.xsession-errors:Error: "/home/buford/.kde/tmp-refwheezy" points to "/tmp/kde-phred" instead of "/tmp/kde-buford".
./.xsession-errors:Error: "/home/buford/.kde/cache-refwheezy" points to "/var/tmp/kdecache-phred" instead of "/var/tmp/kdecache-buford".
./.xsession-errors:Error: "/home/buford/.kde/socket-refwheezy" points to "/tmp/ksocket-phred" instead of "/tmp/ksocket-buford".
./.xsession-errors:kded(3923) LayoutMemoryPersister::restoreFromFile: Failed to open layout memory xml file for reading "/home/buford/.kde/share/apps/kded/session/keyboard/layout_memory.xml" error: 5
./.xsession-errors:I/O warning : failed to load external entity "/home/buford/.qalculate/eurofxref-daily.xml"
./.xsession-errors:I/O warning : failed to load external entity "/home/buford/.qalculate/eurofxref-daily.xml"


And at some point, I figured out that there are a bunch of references to $oldname in ~/.local/share/akonadi. Trying to run sed on that didn't work. Will have to investigate that further.

If anyone reading this can stand to use kde4 long enough to do some testing, please step up to the plate.


f"aptitudepurgekdeplasmadesktop"smithred
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Re: change-username and kde4

Postby dzz » Tue Jun 26, 2012 1:01 am

f"aptitudepurgekdeplasmadesktop"smithred


Sums it up well! I tried to get to like it (as I was told i should) but I and my machine failed. Purging it was not that simple though.

Seriously, it's good to see refracta and snapshot support other DE's (and distros) but no spare €$£ here for new hardware to run unwanted glitz, to test it.

Maybe the user should not be logged in to do that,,, then system connection PID's would be closed... (wild guess)
dzz
 
Posts: 629
Joined: Wed Apr 27, 2011 11:53 am
Location: Devon, England

Re: change-username and kde4

Postby fsmithred » Tue Jun 26, 2012 2:33 pm

Oh, I wasn't clear about the user being logged in - the script logs the user out by stopping the display manager and also by running /sbin/killall5. That works as expected.

Entries in the config files for /home/$oldname have to be changed to /home/$newname. The following code seems to do that correctly now.
Code: Select all
if [[ -d /home/"$oldname"/.kde/share ]] ; then
   sed -i "s/\/home\/$oldname/\/home\/$newname/g" /home/$newname/.kde/share/apps/kfileplaces/bookmarks.xml
   sed -i "s/\/home\/$oldname/\/home\/$newname/g" /home/$newname/.kde/share/config/startupconfigfiles
   sed -i "s/\/home\/$oldname/\/home\/$newname/g" /home/$newname/.kde/share/config/ksmserverrc
fi


And if I restart dbus before restarting kdm at the end of the script, I don't get the ConsoleKit error.

There are entries for /home/$oldname in .local, but the script hangs if I try to replace those. They're in a mysql database, I think. Then mysql hangs when I log into the desktop. If I don't try to replace those, it seems to work. Uh, no, that's not right. I just looked, and mysqld is using 80% of CPU after the last run. Make that 98%.

I just killed mysqld and restarted kdm again, and it seems like it's ok.

Another piece that needs to be solved. Currently, there's some code to let you disable sudo mode for gksu. I need to know how kde handles sudo, and does kde now use gksu? I tried to install or at least find kdesu, and all I could come up with was kdesudo. Won't do me any good right now, because I don't have sudo set up.

And that brings up another discussion - keep sudo the way it is with full, no password root privileges with sudo, or limit it to a few commands, such as halt, reboot, start/stop network and maybe a few other things?
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Re: change-username and kde4

Postby dzz » Wed Jun 27, 2012 3:51 pm

I do use and know quite well Trinity Desktop (kde3 fork). Many configs in 4x are actually similar. The following is true for 3x and might still apply:

The file ~/.kde/share/config/kdesurc (might be /.kde4/share/config/kdesurc or similar) controls if sudo gets used. It may not exist by default. Reads something like:
Code: Select all
[super-user-command]
super-user-command=sudo

kdesu is part of kdelibs and a binary in /usr/bin, not an independent package. If kdesudo is installed, far as I know it makes a divert from /usr/bin/kdesu to /usr/bin/kdesudo depending what the config file says.

For live-image building where there may be no preconfigured user nor root password set, you need sudo. Ubuntu-style universal passwordless sudo in a Debian installation, if that is really what is wanted, should be by deliberate user action only..
dzz
 
Posts: 629
Joined: Wed Apr 27, 2011 11:53 am
Location: Devon, England

Re: change-username and kde4

Postby fsmithred » Fri Jun 29, 2012 10:47 am

No kdesurc.
No usr - bin - kdesu (or kdesudo)
'apt-file search kdesu' shows only kdesudo.
'aptitude search kdelibs' shows that kdelibs-bin, kdelibs5-data and kdelibs5-plugins are installed. Only the dbg and dev packages are not installed.

Googling for "What happened to kdesu?" gets me a thread by the same name at the kubuntu forum. Apparently, kdesu has been replace with kdesudo. Well, that's great if you have sudo configured. Lucky for me, gksu works in kde. I was worried about changing the dependencies for refractainstaller to list kdesu as an alternate to gksu, but I guess I don't need to do that.

So, I installed kdesudo. There's no kdesudorc file, and there are no files with "conf" in the name. The only things in etc - kde4 all have to do with X. Running 'kdesudo kwrite' from the desktop brings up a dialog box. Entering the user's password as requested results in silent failure. Entering the root password brings up a 'wrong-password' box. I'm beginning to feel the way I did during the two days I tried to add a launcher to the panel. (and I mean a launcher that allows me to select the command and the icon.)

OK, it's now usr - lib - kde4 - libexec - kdesu
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Re: change-username and kde4

Postby fsmithred » Fri Jun 29, 2012 10:49 am

About that posting problem...

Apparently, we can't post anything with paths. I removed all the slashes in my previous post, after trying to post it for a couple of days, and getting the error, "Forbidden, you don't have permission..."
http://www.phpbb.com/community/viewtopi ... 6&t=417546
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Re: change-username and kde4

Postby meandean » Fri Jun 29, 2012 6:23 pm

I am using wheezy, kde4, and kdm

I used this https://gist.github.com/3011914



------------------------------------------------------------------------------------------------------
I log out, switch to tty2, login as root and run the script.
I do not bother with the sudo changes or the password changes.
Logging in as any user on the system I get a "cannot open consolekit" error.
If I reboot and then login the error message no longer appears.
------------------------------------------------------------------------------------------------------------
If I am logged in as the user I am trying to change then I get dropped to a tty when the xserver/loginmanager is killed and nothing.
---------------------------------------------------------------------------------------------------------
If I am logged in as a different user than the one I am trying to change then I get dropped to a tty when the xserver/loginmanager is killed and nothing.
----------------------------------------------------------------------------------------------------------




MODIFIED SCRIPT (modified version of the script that does not kill the xserver/loginmanager)
-----------------------------------------------------------------------------------------------------------
I log out, switch to tty2, login as root and run the script.
I do not bother with the sudo changes or the password changes.
I log in as the new user.
No errors.
-------------------------------------------------------------------------------------------------------
I am logged in as a different user than the one I am changing. I switch to tty2, login as root and run the script.
I do not bother with the sudo changes or the password changes.
I log out of the current user and login as the new user.
No errors.
---------------------------------------------------------------------------------------------------------
I am logged in as a different user than the one I am changing. I open a terminal, su to root, and run the script.
I do not bother with the sudo changes or the password changes.
I log out of the current user and login as the new user.
No errors.
---------------------------------------------------------------------------------------------------------


I do see some info in xsession-errors about some links pointing to the wrong place but it appears they are updated correctly and point to the correct places. Seems harmless to me.
User avatar
meandean
 
Posts: 392
Joined: Wed Mar 09, 2011 5:16 am

Re: change-username and kde4

Postby fsmithred » Sun Jul 01, 2012 12:39 pm

Thanks for testing. I tried it from a root console on tty1, on tty2 and from a terminal inside another user's session, without killing the dm or using killall5, and it exits on a usermod error, saying that the old user is still using a process - gnome-keyring. (why gnome-keyring in kde4?) Tried it again after a reboot, without ever logging in the old user, and it mostly worked. (see below)

Found another problem - redirecting errors to a log file is bad - it hides the prompts for a new password. I know a way around this, but for now, I commented out the error log in the gist. If you get stuck at this point, hit ctrl-d, and the script will proceed without changing the password.

Can log in as the new user (with the old user's password) and no console-kit error.
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Re: change-username and kde4

Postby fsmithred » Sun Jul 01, 2012 1:23 pm

I changed the section that kills $oldname's processes (lines 67-88 in the linked gist) so that it just kills processes owned by $oldname, instead of killing the dm and (almost) everything else. It looks like this, and it seems to work. (purging gnome-keyring was another solution that worked.)
Code: Select all
while true; do
echo "
    $oldname must not be logged in if you want to proceed.
    If you answer \"yes\", this script will stop the display manager and
    kill any processes owned by $oldname. Say \"no\" if you want to exit
    the script and go back to manually close any running programs.
   
    Kill ${oldname}'s processes now? (y or n)
   
    "
    read ans
    case $ans in
      [Yy]*) for i in $(pgrep -u $oldname) ; do
                   kill $i
               done
break ;;
      [Nn]*) exit 0
    esac
done


Other thing I need to do is ASK if you want to restart the dm when the script is done.

Oh, one other possibility would be to change "kill $i" to "kill -9 $i".
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Re: change-username and kde4

Postby fsmithred » Sun Jul 01, 2012 3:03 pm

Updated version - https://gist.github.com/3028674

Works if root is logged into console.
Works if you run it from a root terminal inside another user's graphical session (with or without restarting kdm).
If you run it from a terminal inside xsession owned by the user whose name you're changing, it drops you to a kdm login screen.

Problems:
1. If the user whose name you're changing is logged into console, that process won't be killed, and the script will exit with a usermod error. Changing 'kill $i' to 'kill -9 $i' fixes this, but my gut tells me not to do that. Anyone who logs their user into console should be able to figure out that they need to return to the console and log out.

2. There were a couple of times I ran the script from a root console, and when it killed the user's processes, I was bumped to a different tty. I think this happened once when I was in tty1, and I got bumped to tty2 and once the other direction. This didn't happen the last several times I ran it, so maybe something I did fixed it.
User avatar
fsmithred
 
Posts: 1987
Joined: Wed Mar 09, 2011 9:13 pm

Next

Return to Discuss

Who is online

Users browsing this forum: No registered users and 0 guests

suspicion-preferred