/[inetutils]/inetutils/telnetd/pty.c
ViewVC logotype

Diff of /inetutils/telnetd/pty.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by gray, Thu Mar 14 14:24:11 2002 UTC revision 1.2 by gray, Fri Apr 5 00:03:12 2002 UTC
# Line 17  Line 17 
17     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18     Boston, MA 02111-1307, USA. */     Boston, MA 02111-1307, USA. */
19    
 #ifdef HAVE_CONFIG_H  
 #include <config.h>  
 #endif  
   
20  #include "telnetd.h"  #include "telnetd.h"
21    #include <sys/wait.h>
22    
23  #ifdef AUTHENTICATION  #ifdef AUTHENTICATION
24  # include <libtelnet/auth.h>  # include <libtelnet/auth.h>
# Line 39  do_auth () Line 36  do_auth ()
36    
37    if (autologin < auth_level)    if (autologin < auth_level)
38      {      {
39        fatal(net, "Authorization failed");        fatal (net, "Authorization failed");
40        exit(1);        exit (1);
41      }      }
42  #endif  #endif
43  }  }
# Line 82  startslave (char *host, int autologin, c Line 79  startslave (char *host, int autologin, c
79            close (net);            close (net);
80    
81          setup_utmp (line);          setup_utmp (line);
   
82          start_login (host, autologin, line);          start_login (host, autologin, line);
83        }        }
84    
# Line 90  startslave (char *host, int autologin, c Line 86  startslave (char *host, int autologin, c
86    return master;    return master;
87  }  }
88        
89    extern char **environ;
90  /*  /*
91   * scrub_env()   * scrub_env()
92   *   *
# Line 114  scrub_env () Line 111  scrub_env ()
111    *cpp2 = 0;    *cpp2 = 0;
112  }  }
113    
 struct args  
 {  
   int argc_size;  
   int argc;  
   char **argv;  
 };  
   
114  void  void
115  argv_add (struct args *ap, const char *value)  argv_add (struct obstack *sp, char *value)
116  {  {
117    if (ap->argc_size = 0)    char *p = value ? xstrdup (value) : NULL;
118      {    obstack_grow (sp, &p, sizeof(char*));
       ap->argc_size = 10;  
       ap->argc = 0;  
       ap->argv = xcalloc (10, sizeof (ap->argv[0]));  
     }  
   if (ap->argc >= ap->argc_size)  
     {  
       ap->argc_size += 10;  
       ap->argv = xrealloc (ap->argv,  
                            ap->argc_size * sizeof (ap->argv[0]));  
     }  
   ap->argv[ap->argc++] = value;  
119  }  }
120      
121  void  void
122  start_login (char *host, int autologin, char *name)  start_login (char *host, int autologin, char *name)
123  {  {
124    struct args a;    struct obstack stk;
125      char **argv;
126        
127    scrub_env ();    scrub_env ();
128    memset (&a, 0, sizeof a);    obstack_init (&stk);
129    
130    argv_add (&a, path_login);    argv_add (&stk, path_login);
131    argv_add (&a, "-h");    argv_add (&stk, "-h");
132    argv_add (&a, host);    argv_add (&stk, host);
133        
134  #ifdef  SOLARIS  #ifdef  SOLARIS
135    {    {
136      char *term = getenv ("TERM");      char *term = getenv ("TERM");
137      if (term == NULL || term[0] == 0)      if (term == NULL || term[0] == 0)
138        argv_add (&a, "-");        argv_add (&stk, "-");
139      else      else
140        {        {
141          char *tbuf = xmalloc (sizeof ("TERM=") + strlen (term));          char *tbuf = xmalloc (sizeof ("TERM=") + strlen (term));
142          strcat (strcpy (tbuf, "TERM="), term);          strcat (strcpy (tbuf, "TERM="), term);
143          argv_add (&a, tbuf);          argv_add (&stk, tbuf);
144        }        }
145    }    }
146  #endif  #endif
147    
148  #ifndef NO_LOGIN_P  #ifndef NO_LOGIN_P
149    argv_add (&a, "-p");    argv_add (&stk, "-p");
150  #endif  #endif
151    
 #ifdef LINEMODE  
152    /* Set the environment variable "LINEMODE" to indicate our linemode */    /* Set the environment variable "LINEMODE" to indicate our linemode */
153    if (lmodetype == REAL_LINEMODE)    if (lmodetype == REAL_LINEMODE)
154      setenv ("LINEMODE", "real", 1);      setenv ("LINEMODE", "real", 1);
155    else if (lmodetype == KLUDGE_LINEMODE || lmodetype == KLUDGE_OK)    else if (lmodetype == KLUDGE_LINEMODE || lmodetype == KLUDGE_OK)
156      setenv ("LINEMODE", "kludge", 1);      setenv ("LINEMODE", "kludge", 1);
 #endif  
157    
158  #ifdef AUTHENTICATION  #ifdef AUTHENTICATION
159    if (auth_level >= 0 && autologin == AUTH_VALID)    if (auth_level >= 0 && autologin == AUTH_VALID)
160      {      {
161        argv_add (&a, "-f");        argv_add (&stk, "-f");
162        argv_add (&a, name);        argv_add (&stk, name);
163      }      }
164  #endif  #endif
165        
166    if (getenv ("USER"))  /*  if (getenv ("USER"))
167      {      {
168        argv_add (&a, "--");        argv_add (&stk, "--");
169        argv_add (&a, getenv ("USER"));        argv_add (&stk, getenv ("USER"));
170        unsetenv ("USER");        unsetenv ("USER");
171      }        }*/
172    argv_add (&a, NULL);    argv_add (&stk, NULL);
173    execv (path_login, a.argv);  
174      argv = (char**) obstack_finish (&stk);
175      execv (path_login, argv);
176    syslog (LOG_ERR, "%s: %m\n", path_login);    syslog (LOG_ERR, "%s: %m\n", path_login);
177    fatalperror (net, path_login);    fatalperror (net, path_login);
178  }  }
# Line 202  cleanup (int sig) Line 182  cleanup (int sig)
182  {  {
183    char *p;    char *p;
184    
185      if (sig)
186        {
187          int status;
188          pid_t pid = waitpid((pid_t)-1, &status, WNOHANG);
189          syslog (LOG_INFO, "child process %ld exited: %d",
190                  (long) pid, WEXITSTATUS(status));
191        }
192      
193    p = line + sizeof (PATH_DEV) - 1;    p = line + sizeof (PATH_DEV) - 1;
194    utmp_logout (p);    utmp_logout (p);
195    chmod (line, 0644);    chmod (line, 0644);

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26