Difference between revisions of "AutoLogin"
Ashcharles (Talk | contribs) |
Aqisecoxefi (Talk | contribs) |
||
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> | |
− | #include | + | #include <unistd.h> |
− | #include | + | #include <stdio.h> |
int main() | int main() | ||
Line 17: | Line 25: | ||
// open autologin profile file | // open autologin profile file | ||
− | fptr = fopen( | + | fptr = fopen("/usr/autologin.profile\0","r\0"); |
// 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, | + | nrv = fscanf(fptr,"%s\0",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 | + | if (nrv > 0) |
− | nrv = execlp( | + | nrv = execlp("login\0","login\0","-f\0",user,0); |
else | else | ||
− | nrv = execlp( | + | nrv = execlp("login\0","login\0","\0",0,0); |
return 0; | return 0; | ||
} | } | ||
− | + | </pre> | |
== 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> | |
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> | |
== 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> | |
− | DESCRIPTION = | + | DESCRIPTION = "a simple tool to login to root with no prompt" |
− | PACKAGES = | + | PACKAGES ="${PN}" |
− | PR= | + | PR="r0" |
− | RDEPENDS= | + | RDEPENDS="tinylogin sed" |
− | SRC_URI = | + | SRC_URI = "file://autologin.c \ |
− | + | " | |
− | S = | + | S = "${WORKDIR}" |
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 | + | 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 | 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 | + | sed 's_ -n -l /usr/bin/autologin__' /etc/inittab > 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 = | + | PACKAGES = "${PN}" |
− | FILES_${PN} = | + | FILES_${PN} = "${bindir}/autologin" |
− | + | </pre> | |
== 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>
- include <unistd.h>
- 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