Mercurial > dropbear
comparison svr-chansession.c @ 33:f789045062e6
Progressing client support
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 27 Jul 2004 16:30:46 +0000 |
parents | 469950e86d0f |
children | b4874d772210 |
comparison
equal
deleted
inserted
replaced
32:8fd0cdbb5b1b | 33:f789045062e6 |
---|---|
237 m_free(chansess->cmd); | 237 m_free(chansess->cmd); |
238 m_free(chansess->term); | 238 m_free(chansess->term); |
239 | 239 |
240 if (chansess->tty) { | 240 if (chansess->tty) { |
241 /* write the utmp/wtmp login record */ | 241 /* write the utmp/wtmp login record */ |
242 li = login_alloc_entry(chansess->pid, svr_ses.authstate.username, | 242 li = login_alloc_entry(chansess->pid, ses.authstate.username, |
243 ses.remotehost, chansess->tty); | 243 ses.remotehost, chansess->tty); |
244 login_logout(li); | 244 login_logout(li); |
245 login_free_entry(li); | 245 login_free_entry(li); |
246 | 246 |
247 pty_release(chansess->tty); | 247 pty_release(chansess->tty); |
423 chansess->tty = (char*)m_strdup(namebuf); | 423 chansess->tty = (char*)m_strdup(namebuf); |
424 if (!chansess->tty) { | 424 if (!chansess->tty) { |
425 dropbear_exit("out of memory"); /* TODO disconnect */ | 425 dropbear_exit("out of memory"); /* TODO disconnect */ |
426 } | 426 } |
427 | 427 |
428 pty_setowner(svr_ses.authstate.pw, chansess->tty); | 428 pty_setowner(ses.authstate.pw, chansess->tty); |
429 pty_change_window_size(chansess->master, chansess->termr, chansess->termc, | 429 pty_change_window_size(chansess->master, chansess->termr, chansess->termc, |
430 chansess->termw, chansess->termh); | 430 chansess->termw, chansess->termh); |
431 | 431 |
432 /* Term modes */ | 432 /* Term modes */ |
433 /* We'll ignore errors and continue if we can't set modes. | 433 /* We'll ignore errors and continue if we can't set modes. |
681 | 681 |
682 close(chansess->slave); | 682 close(chansess->slave); |
683 | 683 |
684 /* write the utmp/wtmp login record - must be after changing the | 684 /* write the utmp/wtmp login record - must be after changing the |
685 * terminal used for stdout with the dup2 above */ | 685 * terminal used for stdout with the dup2 above */ |
686 li= login_alloc_entry(getpid(), svr_ses.authstate.username, | 686 li= login_alloc_entry(getpid(), ses.authstate.username, |
687 ses.remotehost, chansess->tty); | 687 ses.remotehost, chansess->tty); |
688 login_login(li); | 688 login_login(li); |
689 login_free_entry(li); | 689 login_free_entry(li); |
690 | 690 |
691 m_free(chansess->tty); | 691 m_free(chansess->tty); |
693 #ifdef DO_MOTD | 693 #ifdef DO_MOTD |
694 if (svr_opts.domotd) { | 694 if (svr_opts.domotd) { |
695 /* don't show the motd if ~/.hushlogin exists */ | 695 /* don't show the motd if ~/.hushlogin exists */ |
696 | 696 |
697 /* 11 == strlen("/hushlogin\0") */ | 697 /* 11 == strlen("/hushlogin\0") */ |
698 len = strlen(svr_ses.authstate.pw->pw_dir) + 11; | 698 len = strlen(ses.authstate.pw->pw_dir) + 11; |
699 | 699 |
700 hushpath = m_malloc(len); | 700 hushpath = m_malloc(len); |
701 snprintf(hushpath, len, "%s/hushlogin", svr_ses.authstate.pw->pw_dir); | 701 snprintf(hushpath, len, "%s/hushlogin", ses.authstate.pw->pw_dir); |
702 | 702 |
703 if (stat(hushpath, &sb) < 0) { | 703 if (stat(hushpath, &sb) < 0) { |
704 /* more than a screenful is stupid IMHO */ | 704 /* more than a screenful is stupid IMHO */ |
705 motdbuf = buf_new(80 * 25); | 705 motdbuf = buf_new(80 * 25); |
706 if (buf_readfile(motdbuf, MOTD_FILENAME) == DROPBEAR_SUCCESS) { | 706 if (buf_readfile(motdbuf, MOTD_FILENAME) == DROPBEAR_SUCCESS) { |
806 #endif /* DEBUG_VALGRIND */ | 806 #endif /* DEBUG_VALGRIND */ |
807 | 807 |
808 /* We can only change uid/gid as root ... */ | 808 /* We can only change uid/gid as root ... */ |
809 if (getuid() == 0) { | 809 if (getuid() == 0) { |
810 | 810 |
811 if ((setgid(svr_ses.authstate.pw->pw_gid) < 0) || | 811 if ((setgid(ses.authstate.pw->pw_gid) < 0) || |
812 (initgroups(svr_ses.authstate.pw->pw_name, | 812 (initgroups(ses.authstate.pw->pw_name, |
813 svr_ses.authstate.pw->pw_gid) < 0) || | 813 ses.authstate.pw->pw_gid) < 0) || |
814 (setuid(svr_ses.authstate.pw->pw_uid) < 0)) { | 814 (setuid(ses.authstate.pw->pw_uid) < 0)) { |
815 dropbear_exit("error changing user"); | 815 dropbear_exit("error changing user"); |
816 } | 816 } |
817 } else { | 817 } else { |
818 /* ... but if the daemon is the same uid as the requested uid, we don't | 818 /* ... but if the daemon is the same uid as the requested uid, we don't |
819 * need to */ | 819 * need to */ |
820 | 820 |
821 /* XXX - there is a minor issue here, in that if there are multiple | 821 /* XXX - there is a minor issue here, in that if there are multiple |
822 * usernames with the same uid, but differing groups, then the | 822 * usernames with the same uid, but differing groups, then the |
823 * differing groups won't be set (as with initgroups()). The solution | 823 * differing groups won't be set (as with initgroups()). The solution |
824 * is for the sysadmin not to give out the UID twice */ | 824 * is for the sysadmin not to give out the UID twice */ |
825 if (getuid() != svr_ses.authstate.pw->pw_uid) { | 825 if (getuid() != ses.authstate.pw->pw_uid) { |
826 dropbear_exit("couldn't change user as non-root"); | 826 dropbear_exit("couldn't change user as non-root"); |
827 } | 827 } |
828 } | 828 } |
829 | 829 |
830 /* an empty shell should be interpreted as "/bin/sh" */ | 830 /* an empty shell should be interpreted as "/bin/sh" */ |
831 if (svr_ses.authstate.pw->pw_shell[0] == '\0') { | 831 if (ses.authstate.pw->pw_shell[0] == '\0') { |
832 usershell = "/bin/sh"; | 832 usershell = "/bin/sh"; |
833 } else { | 833 } else { |
834 usershell = svr_ses.authstate.pw->pw_shell; | 834 usershell = ses.authstate.pw->pw_shell; |
835 } | 835 } |
836 | 836 |
837 /* set env vars */ | 837 /* set env vars */ |
838 addnewvar("USER", svr_ses.authstate.pw->pw_name); | 838 addnewvar("USER", ses.authstate.pw->pw_name); |
839 addnewvar("LOGNAME", svr_ses.authstate.pw->pw_name); | 839 addnewvar("LOGNAME", ses.authstate.pw->pw_name); |
840 addnewvar("HOME", svr_ses.authstate.pw->pw_dir); | 840 addnewvar("HOME", ses.authstate.pw->pw_dir); |
841 addnewvar("SHELL", usershell); | 841 addnewvar("SHELL", usershell); |
842 if (chansess->term != NULL) { | 842 if (chansess->term != NULL) { |
843 addnewvar("TERM", chansess->term); | 843 addnewvar("TERM", chansess->term); |
844 } | 844 } |
845 | 845 |
846 /* change directory */ | 846 /* change directory */ |
847 if (chdir(svr_ses.authstate.pw->pw_dir) < 0) { | 847 if (chdir(ses.authstate.pw->pw_dir) < 0) { |
848 dropbear_exit("error changing directory"); | 848 dropbear_exit("error changing directory"); |
849 } | 849 } |
850 | 850 |
851 #ifndef DISABLE_X11FWD | 851 #ifndef DISABLE_X11FWD |
852 /* set up X11 forwarding if enabled */ | 852 /* set up X11 forwarding if enabled */ |