… | |
… | |
6 | *----------------------------------------------------------------------* |
6 | *----------------------------------------------------------------------* |
7 | * |
7 | * |
8 | * All portions of code are copyright by their respective author/s. |
8 | * All portions of code are copyright by their respective author/s. |
9 | * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com> |
9 | * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com> |
10 | * Copyright (c) 2004-2006 Marc Lehmann <pcg@goof.com> |
10 | * Copyright (c) 2004-2006 Marc Lehmann <pcg@goof.com> |
11 | * Copyright (c) 2006 Emanuele Giaquinta <e.giaquinta@glauco.it> |
11 | * Copyright (c) 2006 Emanuele Giaquinta <e.giaquinta@glauco.it> |
12 | * |
12 | * |
13 | * This program is free software; you can redistribute it and/or modify |
13 | * This program is free software; you can redistribute it and/or modify |
14 | * it under the terms of the GNU General Public License as published by |
14 | * it under the terms of the GNU General Public License as published by |
15 | * the Free Software Foundation; either version 2 of the License, or |
15 | * the Free Software Foundation; either version 2 of the License, or |
16 | * (at your option) any later version. |
16 | * (at your option) any later version. |
… | |
… | |
371 | } |
371 | } |
372 | |
372 | |
373 | return true; |
373 | return true; |
374 | } |
374 | } |
375 | |
375 | |
|
|
376 | ///////////////////////////////////////////////////////////////////////////// |
|
|
377 | // helper/proxy support |
|
|
378 | |
376 | #if PTYTTY_HELPER |
379 | #if PTYTTY_HELPER |
377 | |
380 | |
378 | static int sock_fd = -1; |
381 | static int sock_fd = -1; |
379 | static int helper_pid, owner_pid; |
382 | static int helper_pid, owner_pid; |
380 | |
383 | |
… | |
… | |
482 | } |
485 | } |
483 | } |
486 | } |
484 | else if (cmd.type == command::login) |
487 | else if (cmd.type == command::login) |
485 | { |
488 | { |
486 | #if UTMP_SUPPORT |
489 | #if UTMP_SUPPORT |
487 | if (find (ptys.begin (), ptys.end (), cmd.id)) |
490 | if (find (ptys.begin (), ptys.end (), cmd.id) != ptys.end ()) |
488 | { |
491 | { |
489 | cmd.hostname[sizeof (cmd.hostname) - 1] = 0; |
492 | cmd.hostname[sizeof (cmd.hostname) - 1] = 0; |
490 | cmd.id->login (cmd.cmd_pid, cmd.login_shell, cmd.hostname); |
493 | cmd.id->login (cmd.cmd_pid, cmd.login_shell, cmd.hostname); |
491 | } |
494 | } |
492 | #endif |
495 | #endif |
… | |
… | |
609 | if (uid != geteuid () |
612 | if (uid != geteuid () |
610 | || gid != getegid ()) |
613 | || gid != getegid ()) |
611 | ptytty_fatal ("unable to drop privileges, aborting.\n"); |
614 | ptytty_fatal ("unable to drop privileges, aborting.\n"); |
612 | } |
615 | } |
613 | |
616 | |
|
|
617 | ///////////////////////////////////////////////////////////////////////////// |
|
|
618 | // C API |
|
|
619 | |
|
|
620 | #ifndef NO_C_API |
|
|
621 | |
|
|
622 | #define DEFINE_METHOD(retval, name, args1, args2) \ |
|
|
623 | extern "C" retval ptytty_ ## name args1 \ |
|
|
624 | { return ((struct ptytty *)ptytty)->name args2; } |
|
|
625 | |
|
|
626 | DEFINE_METHOD(int,pty,(void *ptytty),) |
|
|
627 | DEFINE_METHOD(int,tty,(void *ptytty),) |
|
|
628 | DEFINE_METHOD(int,get,(void *ptytty),()) |
|
|
629 | DEFINE_METHOD(void,login,(void *ptytty, int cmd_pid, bool login_shell, const char *hostname),(cmd_pid,login_shell,hostname)) |
|
|
630 | |
|
|
631 | DEFINE_METHOD(void,close_tty,(void *ptytty),()) |
|
|
632 | DEFINE_METHOD(int,make_controlling_tty,(void *ptytty),()) |
|
|
633 | DEFINE_METHOD(void,set_utf8_mode,(void *ptytty, int on),(on)) |
|
|
634 | |
|
|
635 | #define DEFINE_STATIC(retval, name, args) \ |
|
|
636 | extern "C" retval ptytty_ ## name args \ |
|
|
637 | { return ptytty::name args; } |
|
|
638 | |
|
|
639 | DEFINE_STATIC(void,init,()) |
|
|
640 | DEFINE_STATIC(void *,create,()) |
|
|
641 | |
|
|
642 | void ptytty_delete (void *ptytty) |
|
|
643 | { |
|
|
644 | delete (struct ptytty *)ptytty; |
|
|
645 | } |
|
|
646 | |
|
|
647 | DEFINE_STATIC(void,drop_privileges,()) |
|
|
648 | DEFINE_STATIC(void,use_helper,()) |
|
|
649 | |
|
|
650 | #endif |