Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
autologin user on startup without dm (consolekit "obstacle")
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
hal2050
n00b
n00b


Joined: 19 Jul 2008
Posts: 33

PostPosted: Wed Jan 19, 2011 1:25 pm    Post subject: autologin user on startup without dm (consolekit "obsta Reply with quote

hi all,

based on my consolekit odyssey (http://forums.gentoo.org/viewtopic-t-858504.html) i started a new thread.
i'm using my system as a dedicated htpc. for convenience i have to autologin my user and do not use a keyboard or mouse.

requirements:
- no dm usage because i try to keep my system as slim as possible.
- global xsession to prevent the user to accidentially delete the contents in ~/
- therefore no ~/.xinitrc or ~/.bash_profile solution
- respawn the session in case xbmc or x crashes (i used to use a while loop for that kind of jobs)

already tried:
- autologin via sudo or su does not respect consolkit and results in unactive sessions
- does not make any difference whether or not one takes this approach over /etc/inittab or /etc/init.d/local

does anybody know or recommend a way to accomplish this task while taking consolekit into consideration to maintain the privileges to mount, reboot, shutdown, etc. the system?

thanks for you help && regards,
hal2050
Back to top
View user's profile Send private message
fat_chris
n00b
n00b


Joined: 16 Jan 2008
Posts: 10

PostPosted: Wed Jan 19, 2011 3:44 pm    Post subject: Reply with quote

Check out nodm, ebuilds at http://bugs.gentoo.org/show_bug.cgi?id=327105

I'm about to try it out myself for this very purpose.
Back to top
View user's profile Send private message
ssuominen
Developer
Developer


Joined: 30 Sep 2005
Posts: 2129
Location: Finland

PostPosted: Wed Jan 19, 2011 8:36 pm    Post subject: Reply with quote

$ eix qingy
Back to top
View user's profile Send private message
fat_chris
n00b
n00b


Joined: 16 Jan 2008
Posts: 10

PostPosted: Wed Jan 19, 2011 9:54 pm    Post subject: Reply with quote

Turns out nodm didn't play well with consolekit either.

But I'm now using slim with auto-login where consolekit works great so I can shutdown, reboot, etc. from within xbmc.
Back to top
View user's profile Send private message
hal2050
n00b
n00b


Joined: 19 Jul 2008
Posts: 33

PostPosted: Thu Jan 20, 2011 10:35 am    Post subject: Reply with quote

hehe. indeed!

i installed nodm last night and after the first reboot my system hung pretty early in start up procedure where the system deps are getting cached, (chaching system dependencies) producing errors in an infinite loop about net.eth0 and sth else i can't remember right now. chrooting, uninstalling nodm and running

Code:
/lib/rc/bin/rc-depend -u


fixed it.

now i'm heading over to qingy. :)

edit:

right now qingy basically works. but again i don't get an active session with consolekit. below you can find my setup:

cat /etc/env.d/90xsession
Code:
 
XSESSION="XBMCsession"


cat /etc/X11/Sessions/XBMCsession
Code:

#!/bin/bash

while true; do

    ck-launch-session /usr/lib/xbmc/xbmc.bin --standalone --nolirc
    sleep 1

done


cat /etc/pam.d/system-login
Code:

auth      required   pam_shells.so
auth      required   pam_nologin.so
auth      include      system-auth
             
account      required   pam_access.so
account      required   pam_nologin.so
account      include      system-auth
 
password   include      system-auth
 
session         optional        pam_loginuid.so
session      required   pam_env.so
session      include      system-auth
session      optional   pam_ck_connector.so


cat /etc/inittab
Code:
#
# /etc/inittab:  This file describes how the INIT process should set up
#                the system in a certain run-level.
#
# Author:  Miquel van Smoorenburg, <miquels@cistron.nl>
# Modified by:  Patrick J. Volkerding, <volkerdi@ftp.cdrom.com>
# Modified by:  Daniel Robbins, <drobbins@gentoo.org>
# Modified by:  Martin Schlemmer, <azarah@gentoo.org>
# Modified by:  Mike Frysinger, <vapier@gentoo.org>
# Modified by:  Robin H. Johnson, <robbat2@gentoo.org>
#
# $Header: /var/cvsroot/gentoo-x86/sys-apps/sysvinit/files/inittab-2.87,v 1.1 2010/01/08 16:55:07 williamh Exp $

# Default runlevel.
id:3:initdefault:

# System initialization, mount local filesystems, etc.
si::sysinit:/sbin/rc sysinit

# Further system initialization, brings up the boot runlevel.
rc::bootwait:/sbin/rc boot

l0:0:wait:/sbin/rc shutdown
l0s:0:wait:/sbin/halt -dhp
l1:1:wait:/sbin/rc single
l2:2:wait:/sbin/rc nonetwork
l3:3:wait:/sbin/rc default
l4:4:wait:/sbin/rc default
l5:5:wait:/sbin/rc default
l6:6:wait:/sbin/rc reboot
l6r:6:wait:/sbin/reboot -dk
#z6:6:respawn:/sbin/sulogin

# new-style single-user
su0:S:wait:/sbin/rc single
su1:S:wait:/sbin/sulogin

# TERMINALS
# c1:12345:respawn:/sbin/agetty 38400 tty1 linux
# c2:2345:respawn:/sbin/agetty 38400 tty2 linux
# c3:2345:respawn:/sbin/agetty 38400 tty3 linux
# c4:2345:respawn:/sbin/agetty 38400 tty4 linux
# c5:2345:respawn:/sbin/agetty 38400 tty5 linux
# c6:2345:respawn:/sbin/agetty 38400 tty6 linux

# Qingy Login
c1:12345:respawn:/sbin/qingy tty1
c2:12345:respawn:/sbin/qingy tty2
c3:12345:respawn:/sbin/qingy tty3
c4:12345:respawn:/sbin/qingy tty4
c5:12345:respawn:/sbin/qingy tty5
c6:2345:respawn:/sbin/agetty 38400 tty6 linux

# SERIAL CONSOLES
#s0:12345:respawn:/sbin/agetty 9600 ttyS0 vt100
#s1:12345:respawn:/sbin/agetty 9600 ttyS1 vt100

# What to do at the "Three Finger Salute".
ca:12345:ctrlaltdel:/sbin/shutdown -r now

# Used by /etc/init.d/xdm to control DM startup.
# Read the comments in /etc/init.d/xdm for more
# info. Do NOT remove, as this will start nothing
# extra at boot if /etc/init.d/xdm is not added
# to the "default" runlevel.
x:a:once:/etc/X11/startDM.sh


cat /etc/qingy/settings
Code:
 
# Directory containing X sessions
x_sessions = "/etc/X11/Sessions/"

# Directory containing text mode sessions
text_sessions = "/etc/qingy/sessions/"

# Directory where qingy should put its temporary files
temp_files_dir = "/var/lib/misc"

# Full path to the X server
x_server = "/usr/bin/Xorg"
# Full path to the 'xinit' executable
xinit = "/usr/bin/xinit"

# Parameter we should pass to the X server
x_args = "-nolisten tcp -novtswitch +bs -nocursor -br -deferglyphs all -quiet -allowMouseOpenFail"

# How verbose should qingy be?
# Possible values are debug, error
# Default value is error
log_level = error

# Where should qingy messages be logged?
# Values can be one or more of the following:
# console, file, syslog
# Default value is console
# log_facilities = console, file
log_facilities = console, file

# Offset to search for an available X server number.
# This number affects the DISPLAY env variable.
# Default is 1, setting it to 0 will make buggy OpenGL implementations
# (like the ATI one) work with qingy, but it will also make it impossible
# to start an X server from console using startx without passing it
# extra parameters.
x_server_offset = 1

# Where should we start the X server?
# Accepted values are:
#   qingy_tty (default) to start it in the same tty qingy is running in
#   unused_tty to start it into an unused tty
x_server_tty = unused_tty

# Scripts that should be executed just before/after qingy GUI is fired up/shut down
#pre_gui_script  = "/path/to/pre_guiscript.sh"
#post_gui_script = "/path/to/post_gui_script.sh"

# Where are the screen savers?
screensavers_dir = "/usr/lib/qingy/screensavers"

# How much should we wait (in minutes) before the screen saver is fired up?
# A value of 0 disables screensaver completely.
screensaver_timeout = 0

# How much should we wait (in minutes) before the screen enters power saving mode?
# A value of 0 disables the feature
screen_powersaving_timeout = 0

#screensaver "pixel"
# screensaver "running_time"#="%H:%S:%M"

# Where are the themes?
themes_dir = "/usr/share/qingy/themes"

# What theme do you want (you can also specify 'random')
# theme = random
theme = "gentoo"

# Who is allowed to shut down the system?
# Allowed options are 'everyone', 'root', 'noone'
# default policy is everyone
shutdown_policy = noone

# How should latest user be calculated?
# global means get latest user that logged in using qingy from whichever tty
# tty    means get latest user that logged in using current tty
# none   means do not get (and set) latest user
# default policy is global
#last_user_policy = global

# How should latest user session be calculated?
# user means get last session of each user
# tty  means get last session of current tty
# none means do not get (and set) latest session
# default policy is user
last_session_policy = user

# What happens when we press the 'sleep' button?
#sleep = "/usr/local/sbin/hibernate"

# whether we should clear background image during dialogs (default is no)...
# this is the default setting, it gets overridden if the theme you are using
# sets the same setting differently...
clear_background = no

# whether to allow session locking; if you enable this, when you try to
# switch to a qingy-controlled tty whose owner is not your current
# user, you will be asked for the password of that user before being
# allowed to continue. If you are root, of course, you can switch
# to any tty you chose to. Default setting is 'no'.
lock_sessions = no

# whether to allow session timeout; if you enable this, after the amount
# of minutes specified in idle_timeout variable, idle_action will be
# performed. Allowed actions are:
# lock     will lock user session asking you for your password
# logout   will close your session
#idle_timeout = 30
#idle_action  = lock

# prevent qingy from logging in user or firing up its GUI if system
# is restarting / shutting down
#check_runlevel = yes
#exclude_runlevels = 0, 6

# these options are valid only if qingy is started from tty3
#tty = 3
#{
#   theme = "fireplace"
#   screensaver "pixel"

#   # Should we auto log in?
#   # Totally insecure, but very convenient ;-)
#   # Note that this section must be put inside a tty=n{} block
#   autologin
#   {
#      username = "myuser"
#      # You can also use 'session=lastsession' to automatically choose last user session
#      session  = "Text: emacs"
#      # if set to 'no', qingy will autologin only once every system restart
#      relogin  = no
#   }
#}

tty = 1
{
   autologin
   {
   username = "xbmc"
   session = "XBMCsession"
   relogin  = yes
   }
}


# keybindings
# {
#   prev_tty    = "win"      # switch to left tty
#   next_tty    = "menu"     # switch to right tty
#   poweroff    = "ALT-p"    # shutdown your system
#   reboot      = "ALT-r"    # restart your system
#   screensaver = "ALT-s"    # activate screen saver
#   sleep       = "ALT-z"    # put machine to sleep
#   kill        = "CTRL-c"   # kill qingy
#   text_mode   = "CTRL-ESC" # Revert to text mode
# }


Result:
ck-list-sessions

Code:
Session1:
   unix-user = '1000'
   realname = '(null)'
   seat = 'Seat2'
   session-type = ''
   active = FALSE
   x11-display = ':1'
   x11-display-device = '/dev/tty7'
   display-device = '/dev/tty1'
   remote-host-name = ''
   is-local = FALSE
   on-since = '2011-01-20T12:39:16.627858Z'
   login-session-id = ''


as you can see i don't get a session id and active = false.
anything special i should look at in addition?

qingy seems to support consolekit/pam officially since 12.2010 (referring to their news section).
Back to top
View user's profile Send private message
hal2050
n00b
n00b


Joined: 19 Jul 2008
Posts: 33

PostPosted: Sat Jan 22, 2011 4:13 pm    Post subject: Reply with quote

any qingy users around?

what should be the contents of "/etc/pam.d/qingy"?

cat /etc/pam.d/qingy
Code:
# File autogenerated by pamd_mimic in pam eclass


auth   include      system-local-login
account   include      system-local-login
password   include      system-local-login
session   include      system-local-login


or in addition to the above

Code:
session optional pam_loginuid.so
session optional pam_ck_connector.so debug


?

i read the latter in this report: http://bugs.gentoo.org/345135
Back to top
View user's profile Send private message
hal2050
n00b
n00b


Joined: 19 Jul 2008
Posts: 33

PostPosted: Thu Feb 03, 2011 3:48 pm    Post subject: Reply with quote

update:

i found out that i get an active session when i login manually with qingy. as soon as qingy takes over to autologin an user i end up with an unactive session, again.
this tastes like a bug. therefore i filed a new report upstream.
Back to top
View user's profile Send private message
ssuominen
Developer
Developer


Joined: 30 Sep 2005
Posts: 2129
Location: Finland

PostPosted: Thu Feb 03, 2011 4:34 pm    Post subject: Reply with quote

See here:

https://bbs.archlinux.org/viewtopic.php?id=112768

The post by "thestinger" about using mingetty for auto-login with ConsoleKit.

Enjoy :)
Back to top
View user's profile Send private message
hal2050
n00b
n00b


Joined: 19 Jul 2008
Posts: 33

PostPosted: Thu Feb 03, 2011 7:40 pm    Post subject: Reply with quote

thanks for the url, ssuominen. ;)
but it's funny because i stumbled upon this thread earlier the day and already tried that approach. the downside is mingetty drops the user to a shell. just like you would login manually on the login prompt. one could also put "/bin/login -f $USER" into "/etc/inittab" resulting in the same effect like mingetty produces.

i guess i have to give up for now and wait and hope until qingy or su/sudo will get an update to work together nicely with ck.
Back to top
View user's profile Send private message
kovidgoyal
n00b
n00b


Joined: 17 May 2013
Posts: 1

PostPosted: Fri May 17, 2013 1:19 pm    Post subject: Reply with quote

Here's my solution, just stick the attached script into /etc/local.d/X.start and make it executable. It starts X utomatically and sets up an activated consolekit session as well. You need to have python-dbus installed. Change the USER variable to the username you want auto-logged in.

Code:

#!/usr/bin/python2
# vim:fileencoding=utf-8
from __future__ import (unicode_literals, division, absolute_import,
                        print_function)

USER = b'kovid'

__license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'

import os
import time
import subprocess
from functools import partial

import dbus

bus = None


def setup_console_kit_session(uid):
    global bus
    u = partial(dbus.UInt32, variant_level=1)
    b = partial(dbus.Boolean, variant_level=1)
    s = partial(dbus.String, variant_level=1)

    # Wait at most two seconds for DBUS and ConsoleKit to be available
    for i in xrange(10):
        try:
            bus = dbus.SystemBus()
            break
        except:
            time.sleep(0.1)
    for i in xrange(10):
        try:
            manager = bus.get_object('org.freedesktop.ConsoleKit', "/org/freedesktop/ConsoleKit/Manager")
            break
        except:
            time.sleep(0.1)

    cookie = str(manager.OpenSessionWithParameters(
        dbus.Array([
            ('unix-user', u(uid)),
            ('is-local', b(True)),
            ('x11-display', s(':0')),
            ('x11-display-device', s('/dev/tty7')),
        ], signature='a(sv)'),
        dbus_interface='org.freedesktop.ConsoleKit.Manager'))
    os.environ['XDG_SESSION_COOKIE'] = cookie


def get_user_data():
    q = USER + b':'
    with open('/etc/passwd') as f:
        for line in f:
            if line.startswith(q):
                parts = line.rstrip().split(b':')
                if len(parts) > 6:
                    uid, gid, _, home, shell = parts[2:]
                    uid, gid = int(uid), int(gid)
                    break
    groups = set()
    with open('/etc/group') as f:
        for line in f:
            parts = line.rstrip().split(b':')
            if parts:
                names = parts[-1].split(b',')
                if USER in names:
                    try:
                        gid = int(parts[-2])
                    except:
                        continue
                    groups.add(gid)

    groups.discard(gid)

    path = b'/bin:/usr/bin'
    with open('/etc/login.defs') as f:
        for line in f:
            if line.startswith(b'ENV_PATH\t'):
                path = line.partition(b'=')[-1].rstrip()
                break

    return uid, gid, home, shell, groups, path


def main():
    global bus
    uid, gid, home, shell, groups, path = get_user_data()
    setup_console_kit_session(uid)
    try:
        os.setresgid(gid, gid, gid)
        os.setgroups(list(groups))
        os.setresuid(uid, uid, uid)
        env = {
            b'HOME': home,
            b'SHELL': shell,
            b'USER': USER,
            b'LOGNAME': USER,
            b'PATH': path,
        }
        if b'IFS' in os.environ:
            env[b'IFS'] = b' \t\n'
        for x in (b'XDG_SESSION_COOKIE', b'TERM', b'COLORTERM', b'DISPLAY', b'XAUTHORITY'):
            if x in os.environ:
                env[x] = os.environ[x]

        with open(os.path.join(home, '.xsession-errors'), 'w') as f:
            subprocess.Popen('source /etc/profile; exec startx -- vt7', shell=True, stdout=f, stderr=f, env=env, cwd=home).wait()
    finally:
        if bus is not None:
            bus.close()

if __name__ == '__main__':
    main()
[/code]
Back to top
View user's profile Send private message
52midnight
Tux's lil' helper
Tux's lil' helper


Joined: 20 Mar 2012
Posts: 131
Location: Brisbane AU

PostPosted: Sun Mar 30, 2014 10:27 pm    Post subject: Reply with quote

At the risk of being excommunicated for posting heresies on this forum, the following has been working flawlessly for me for many years. Edit /etc/inittab and change the first TERMINALS entry as shown:
Code:

# TERMINALS
#c1:12345:respawn:/sbin/agetty 38400 tty1 linux
c1:12345:respawn:/bin/login -f root 38400 tty1 linux
c2:2345:respawn:/sbin/agetty 38400 tty2 linux
c3:2345:respawn:/sbin/agetty 38400 tty3 linux
  :

X can be started by adding 'startx' at the end of ~/.bash_profile, but you may want to disable this for SSH logins:
Code:

echo TTY = $(tty)
if [ $(tty) = /dev/console ]
then
   startx
else
   echo No X via TTY
fi
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum