AutoLogin

From Gumstix User Wiki
Revision as of 14:43, 23 November 2010 by Aqisecoxefi (Talk | contribs)

Jump to: navigation, search

For some applications, it is useful to login to an account directly from boot without having to enter login credentials. The GPE login manager provided with the palmtop image provides a mechanism to do it. However, for simple console images, we can simply set a blank password for our particular account and modify our login program to achieve this. With autologin enabled, it is easy to start tasks automatically after the system is booted in cases where adding sysvinit scripts (/etc/init.d) isn't appropriate.

Autologin.c

This autologin program replaces the normal 'login' program and should be compiled and placed in /sbin. The login program is typically provided by tinylogin, busybox or as a standalone tool. <pre>

  1. include <unistd.h>
  2. include <stdio.h>

int main() {

      int nrv = 0;
      FILE* fptr = 0;
      char user[64];
      // clear buffer
      memset(user,'\0',64);
      // open autologin profile file
      fptr = fopen("/usr/autologin.profile\0","r\0");
      // make sure the file exists and was opened
      if (fptr != 0)
      {
              // the return value from fscanf will be 1 if the autologin profile name is read correctly
              nrv = fscanf(fptr,"%s\0",user);
      }
      // only autologin if the profile name was read successfully,
      // otherwise show the regular login prompt
      if (nrv > 0)
              nrv = execlp("login\0","login\0","-f\0",user,0);
      else
              nrv = execlp("login\0","login\0","\0",0,0);
      return 0;

} </pre>

The /etc/inittab

It is necessary to modify your /etc/inittab file to use your autologin program rather than the default login program. Specifically, you'll want to change a line that looks like this: <pre>S:2345:respawn:/sbin/getty 115200 ttyS2</pre> with one that looks like this: <pre>S:2345:respawn:/sbin/getty -n -l /usr/sbin/autologin 115200 ttyS2</pre>

A Bitbake Recipe

To do the cross-compilation and to set up the inittab file, we might use a bitbake recipe like this: <pre> DESCRIPTION = "a simple tool to login to root with no prompt" PACKAGES ="${PN}" PR="r0" RDEPENDS="tinylogin sed"

SRC_URI = "file://autologin.c \

          "

S = "${WORKDIR}"

do_compile () {

 ${CC} ${CFLAGS} ${LDFLAGS} -o autologin autologin.c

}

do_install () {

 install -d ${D}${bindir}/
 install -m 0755 ${WORKDIR}/autologin ${D}${bindir}/

}

pkg_postinst_${PN} () {

 sed 's_S:2345:respawn:/sbin/getty_S:2345:respawn:/sbin/getty -n -l /usr/bin/autologin_' /etc/inittab > inittab.tmp
 mv inittab.tmp /etc/inittab
 passwd -d root
 echo 'NOTE: remove the password from the root account'
 rm inittab.tmp

}

pkg_prerm_${PN} () {

 sed 's_ -n -l /usr/bin/autologin__' /etc/inittab > inittab.tmp
 mv inittab.tmp /etc/inittab
 echo 'NOTE: there is still no password on the root account'
 rm inittab.tmp

}


PACKAGES = "${PN}" FILES_${PN} = "${bindir}/autologin" </pre>

Starting Task on Login =

Once the autologin is working, you can add tasks to be executed on startup to your .profile file or the system /etc/profile file. This is a compliment to the methods already offered by sysvinit scripts and cron (@reboot).

More Info

The text for this this wiki page was pieced together from this thread: http://old.nabble.com/A-very-unique-auto-login-on-verdex-td28224459.html#a28517599