blob: 8585f5d6b6fb4ba541eda0a9d0f4d7a24326ea78 [file] [log] [blame]
Damien Miller92ddb7d2001-02-14 01:25:23 +11001#include "includes.h"
2
3#ifdef HAVE_OSF_SIA
4#include "ssh.h"
5#include "auth-sia.h"
6#include "log.h"
7#include "servconf.h"
8#include "canohost.h"
9
10#include <sia.h>
11#include <siad.h>
12#include <pwd.h>
13#include <signal.h>
14#include <setjmp.h>
15#include <sys/resource.h>
16#include <unistd.h>
17#include <string.h>
18
19extern ServerOptions options;
20extern int saved_argc;
21extern char **saved_argv;
22
23extern int errno;
24
25int
26auth_sia_password(char *user, char *pass)
27{
28 int ret;
29 SIAENTITY *ent = NULL;
30 const char *host;
31
Damien Millerf3451a22002-02-05 12:40:46 +110032 host = get_canonical_hostname(options.verify_reverse_mapping);
Damien Miller92ddb7d2001-02-14 01:25:23 +110033
34 if (!user || !pass)
35 return(0);
36
37 if (sia_ses_init(&ent, saved_argc, saved_argv, host, user, NULL, 0,
38 NULL) != SIASUCCESS)
39 return(0);
40
41 if ((ret = sia_ses_authent(NULL, pass, ent)) != SIASUCCESS) {
42 error("couldn't authenticate %s from %s", user, host);
43 if (ret & SIASTOP)
44 sia_ses_release(&ent);
45 return(0);
46 }
47
48 sia_ses_release(&ent);
49
50 return(1);
51}
52
53void
54session_setup_sia(char *user, char *tty)
55{
56 int ret;
57 struct passwd *pw;
58 SIAENTITY *ent = NULL;
59 const char *host;
60
Damien Millerf3451a22002-02-05 12:40:46 +110061 host = get_canonical_hostname (options.verify_reverse_mapping);
Damien Miller92ddb7d2001-02-14 01:25:23 +110062
63 if (sia_ses_init(&ent, saved_argc, saved_argv, host, user, tty, 0,
Damien Miller364a9bd2001-04-16 18:37:05 +100064 NULL) != SIASUCCESS) {
65 error("sia_ses_init failed");
66 exit(1);
67 }
Damien Miller92ddb7d2001-02-14 01:25:23 +110068
69 if ((pw = getpwnam(user)) == NULL) {
70 sia_ses_release(&ent);
Damien Miller364a9bd2001-04-16 18:37:05 +100071 error("getpwnam(%s) failed: %s", user, strerror(errno));
72 exit(1);
Damien Miller92ddb7d2001-02-14 01:25:23 +110073 }
74 if (sia_make_entity_pwd(pw, ent) != SIASUCCESS) {
75 sia_ses_release(&ent);
Damien Miller364a9bd2001-04-16 18:37:05 +100076 error("sia_make_entity_pwd failed");
77 exit(1);
Damien Miller92ddb7d2001-02-14 01:25:23 +110078 }
79
80 ent->authtype = SIA_A_NONE;
Damien Miller364a9bd2001-04-16 18:37:05 +100081 if (sia_ses_estab(sia_collect_trm, ent) != SIASUCCESS) {
82 error("couldn't establish session for %s from %s", user,
Damien Miller92ddb7d2001-02-14 01:25:23 +110083 host);
Damien Miller364a9bd2001-04-16 18:37:05 +100084 exit(1);
85 }
Damien Miller92ddb7d2001-02-14 01:25:23 +110086
87 if (setpriority(PRIO_PROCESS, 0, 0) == -1) {
88 sia_ses_release(&ent);
Damien Miller364a9bd2001-04-16 18:37:05 +100089 error("setpriority failed: %s", strerror (errno));
90 exit(1);
Damien Miller92ddb7d2001-02-14 01:25:23 +110091 }
92
Damien Miller364a9bd2001-04-16 18:37:05 +100093 if (sia_ses_launch(sia_collect_trm, ent) != SIASUCCESS) {
94 error("couldn't launch session for %s from %s", user, host);
95 exit(1);
96 }
Damien Miller92ddb7d2001-02-14 01:25:23 +110097
98 sia_ses_release(&ent);
99
Damien Miller364a9bd2001-04-16 18:37:05 +1000100 if (setreuid(geteuid(), geteuid()) < 0) {
101 error("setreuid failed: %s", strerror (errno));
102 exit(1);
103 }
Damien Miller92ddb7d2001-02-14 01:25:23 +1100104}
105
106#endif /* HAVE_OSF_SIA */
107