LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 882|回复: 3

关于用户自动登陆的问题

[复制链接]
发表于 2006-1-16 22:54:26 | 显示全部楼层 |阅读模式
请问我应该修改哪个教本才能实现如下功能?

系统启动后自动以某个非超级用户权限进入,不需要输入用户名和密码,直接出现命令提示符~~
发表于 2006-1-16 23:12:16 | 显示全部楼层
step 1
login_coder.c          or rename to login_xxx.c

  1. #include <unistd.h>
  2. #define USER "coder"  /*modify it*/
  3. int main()
  4. {
  5.         execlp("login", "login", "-f", USER, (char *) NULL);
  6.         return 0;
  7. }
复制代码


step 2
gcc -o login_coder login_coder.c

step3
as root
cp login_coder /usr/local/bin/login_coder
step 4
vim /etc/inittab

  1. 1:2345:respawn:/sbin/getty -n -l /usr/local/bin/login_coder 38400 tty1

复制代码
回复 支持 反对

使用道具 举报

发表于 2006-1-16 23:19:48 | 显示全部楼层
will_u_startx.c

  1. #include <stdio.h>
  2. #include <termios.h>
  3. #include <term.h>
  4. #include <curses.h>
  5. #include <unistd.h>
  6. /*#include <stdlib.h>*/

  7. #define DEFAULT_DELAY         3
  8. #define INFO                "Enter to startx, ESC to break  "
  9. #define CMD_STARTX        "/usr/bin/X11/startx"
  10. /*#define CMD_STARTX        "startx"*/
  11. #define X_POS                 1
  12. #define Y_POS                1

  13. static struct termios init_setting, new_setting;

  14. void initialization();
  15. void finalization();

  16. int errmsg(const char * msg, int iexit);
  17. void my_exit(int f);
  18. int moveto(char *cup, int x, int y);
  19. int kbhit();
  20. int startx();

  21. int main(int argc, char **argv)
  22. {
  23.         int opt;
  24.         int delay = DEFAULT_DELAY;
  25.         int i, c;

  26.         char *cursor;
  27.         char info[] = INFO;

  28.         initialization();
  29.        
  30.         while ((opt = getopt(argc, argv, "t:")) != -1)
  31.         {
  32.                 switch(opt)
  33.                 {
  34.                         case 't':
  35.                                 delay = atoi(optarg);                       
  36.                                 if (delay == 0)
  37.                                         delay = DEFAULT_DELAY;
  38.                                 break;
  39.                         case ':':
  40.                                 errmsg("required delay seconds", 1);
  41.                                 break;
  42.                         case '?':
  43.                                 errmsg("there are unknown params.", 1);
  44.                                 break;
  45.                                        
  46.                 }
  47.                
  48.         }

  49.         printf("delay %d seconds.\n", delay);

  50.         setupterm(NULL, fileno(stdout), NULL);
  51.         cursor = tigetstr("cup");
  52.         putp(tigetstr("clear"));                /*clear the screen*/
  53.         moveto(cursor, X_POS, Y_POS);
  54.         fprintf(stdout, "%s", info);
  55.         fflush(stdout);

  56.         for(i = 0; i < delay; i++)
  57.         {
  58.                 moveto(cursor, X_POS + strlen(info), Y_POS);
  59.                 fprintf(stdout, "%d", delay - i);
  60.                 fflush(stdout);
  61.                 sleep(1);
  62.                 if ((c = kbhit()) > 0)
  63.                 {
  64.                         switch(c)
  65.                         {
  66.                                 case 10:
  67.                                 case 13:
  68.                                         startx();
  69.                                         my_exit(0);
  70.                                         break;
  71.                                 case 27:
  72.                                         my_exit(0);
  73.                                        
  74.                         }
  75.                 }
  76.         }
  77.        
  78.         startx();
  79.         my_exit(0);
  80. }


  81. void initialization()
  82. {
  83.         tcgetattr(0, &init_setting);
  84.         new_setting = init_setting;
  85.         new_setting.c_lflag &= ~ICANON;
  86.         new_setting.c_lflag &= ~ECHO;
  87.         new_setting.c_lflag &= ~ISIG;
  88.         new_setting.c_cc[VMIN] = 1;
  89.         new_setting.c_cc[VTIME] = 0;
  90.         tcsetattr(0, TCSANOW, &new_setting);
  91. }

  92. void finalization()
  93. {
  94.         tcsetattr(0, TCSANOW, &init_setting);
  95.         fprintf(stdout, "\r\n");
  96. }

  97. int errmsg(const char * msg, int iexit)
  98. {
  99.         int f = fprintf(stderr, "%s\n", msg);
  100.         if(iexit)
  101.         {       
  102.                 my_exit(1);
  103.         }
  104.         return f;
  105. }

  106. void my_exit(int f)
  107. {
  108.         finalization();
  109.         exit(f);
  110. }

  111. int moveto(char *cup, int x, int y)
  112. {
  113.         return putp(tparm(cup,y,x));
  114. }

  115. int kbhit()
  116. {
  117.         char ch;
  118.         int nread;

  119.         new_setting.c_cc[VMIN] = 0;
  120.         tcsetattr(0, TCSANOW, &new_setting);
  121.         nread = read(0, &ch, 1);
  122.         new_setting.c_cc[VMIN] = 1;
  123.         tcsetattr(0, TCSANOW, &new_setting);
  124.         if (nread == 1)
  125.                 return ch;
  126.         else
  127.                 return 0;
  128. }

  129. int startx()
  130. {
  131.         printf("\nstartx....");
  132.         /*system(CMD_STARTX);*/
  133.         finalization();
  134.         execv(CMD_STARTX, NULL);
  135. }

复制代码


gcc -o will_u_startx will_u_startx.c

cp will_u_startx /usr/local/bin/will_u_startx

vim ~/.bash_profile append below line:
/usr/local/bin/will_u_startx
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-1-16 23:59:22 | 显示全部楼层
第二段代码是做什么的,没有看懂~~
和图形界面有关?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表