Difference between revisions of "AutoLogin"

From Gumstix User Wiki
Jump to: navigation, search
Line 1: Line 1:
 +
----
 +
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 +
----
 +
=[http://upezobyxez.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]=
 +
----
 +
=[http://upezobyxez.co.cc CLICK HERE]=
 +
----
 +
</div>
 
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.
 
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 ==
 
== 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.
 
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>
+
&lt;pre&gt;
#include <unistd.h>
+
#include &lt;unistd.h&gt;
#include <stdio.h>
+
#include &lt;stdio.h&gt;
  
 
int main()
 
int main()
Line 17: Line 25:
  
 
       // open autologin profile file
 
       // open autologin profile file
       fptr = fopen("/usr/autologin.profile\0","r\0");
+
       fptr = fopen(&quot;/usr/autologin.profile\0&quot;,&quot;r\0&quot;);
  
 
       // make sure the file exists and was opened
 
       // make sure the file exists and was opened
Line 23: Line 31:
 
       {
 
       {
 
               // the return value from fscanf will be 1 if the autologin profile name is read correctly
 
               // the return value from fscanf will be 1 if the autologin profile name is read correctly
               nrv = fscanf(fptr,"%s\0",user);
+
               nrv = fscanf(fptr,&quot;%s\0&quot;,user);
 
       }
 
       }
  
 
       // only autologin if the profile name was read successfully,
 
       // only autologin if the profile name was read successfully,
 
       // otherwise show the regular login prompt
 
       // otherwise show the regular login prompt
       if (nrv > 0)
+
       if (nrv &gt; 0)
               nrv = execlp("login\0","login\0","-f\0",user,0);
+
               nrv = execlp(&quot;login\0&quot;,&quot;login\0&quot;,&quot;-f\0&quot;,user,0);
 
       else
 
       else
               nrv = execlp("login\0","login\0","\0",0,0);
+
               nrv = execlp(&quot;login\0&quot;,&quot;login\0&quot;,&quot;\0&quot;,0,0);
  
 
       return 0;
 
       return 0;
 
}
 
}
</pre>
+
&lt;/pre&gt;
  
 
== The /etc/inittab ==
 
== The /etc/inittab ==
 
It is necessary to modify your /etc/inittab file to use your autologin program rather than the default login program.
 
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:
 
Specifically, you'll want to change a line that looks like this:
<pre>S:2345:respawn:/sbin/getty 115200 ttyS2</pre>
+
&lt;pre&gt;S:2345:respawn:/sbin/getty 115200 ttyS2&lt;/pre&gt;
 
with one that looks like this:
 
with one that looks like this:
<pre>S:2345:respawn:/sbin/getty -n -l /usr/sbin/autologin 115200 ttyS2</pre>
+
&lt;pre&gt;S:2345:respawn:/sbin/getty -n -l /usr/sbin/autologin 115200 ttyS2&lt;/pre&gt;
  
 
== A Bitbake Recipe ==
 
== A Bitbake Recipe ==
 
To do the cross-compilation and to set up the inittab file, we might use a bitbake recipe like this:
 
To do the cross-compilation and to set up the inittab file, we might use a bitbake recipe like this:
<pre>
+
&lt;pre&gt;
DESCRIPTION = "a simple tool to login to root with no prompt"
+
DESCRIPTION = &quot;a simple tool to login to root with no prompt&quot;
PACKAGES ="${PN}"
+
PACKAGES =&quot;${PN}&quot;
PR="r0"
+
PR=&quot;r0&quot;
RDEPENDS="tinylogin sed"
+
RDEPENDS=&quot;tinylogin sed&quot;
  
SRC_URI = "file://autologin.c \
+
SRC_URI = &quot;file://autologin.c \
           "
+
           &quot;
  
S = "${WORKDIR}"
+
S = &quot;${WORKDIR}&quot;
  
 
do_compile () {
 
do_compile () {
Line 67: Line 75:
  
 
pkg_postinst_${PN} () {
 
pkg_postinst_${PN} () {
   sed 's_S:2345:respawn:/sbin/getty_S:2345:respawn:/sbin/getty -n -l /usr/bin/autologin_' /etc/inittab > inittab.tmp
+
   sed 's_S:2345:respawn:/sbin/getty_S:2345:respawn:/sbin/getty -n -l /usr/bin/autologin_' /etc/inittab &gt; inittab.tmp
 
   mv inittab.tmp /etc/inittab
 
   mv inittab.tmp /etc/inittab
 
   passwd -d root
 
   passwd -d root
Line 75: Line 83:
  
 
pkg_prerm_${PN} () {
 
pkg_prerm_${PN} () {
   sed 's_ -n -l /usr/bin/autologin__' /etc/inittab > inittab.tmp
+
   sed 's_ -n -l /usr/bin/autologin__' /etc/inittab &gt; inittab.tmp
 
   mv inittab.tmp /etc/inittab
 
   mv inittab.tmp /etc/inittab
 
   echo 'NOTE: there is still no password on the root account'
 
   echo 'NOTE: there is still no password on the root account'
Line 82: Line 90:
  
  
PACKAGES = "${PN}"
+
PACKAGES = &quot;${PN}&quot;
FILES_${PN} = "${bindir}/autologin"
+
FILES_${PN} = &quot;${bindir}/autologin&quot;
</pre>
+
&lt;/pre&gt;
  
 
== Starting Task on Login ===
 
== Starting Task on Login ===

Revision as of 14:43, 23 November 2010


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