|
1 /* |
|
2 ** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for |
|
3 ** distribution information. |
|
4 */ |
|
5 |
|
6 #include "auth.h" |
|
7 |
|
8 #include <stdio.h> |
|
9 #include <errno.h> |
|
10 #include <stdlib.h> |
|
11 #include <string.h> |
|
12 |
|
13 #if HAVE_UNISTD_H |
|
14 #include <unistd.h> |
|
15 #endif |
|
16 |
|
17 static const char rcsid[]="$Id: success.c,v 1.1 2000/04/13 17:55:05 bruce Exp $"; |
|
18 |
|
19 void authsuccess(const char *homedir, |
|
20 const char *username, |
|
21 const uid_t *uid, |
|
22 const gid_t *gid, |
|
23 const char *authaddr, |
|
24 const char *authfullname) |
|
25 { |
|
26 static char *authaddr_buf=0; |
|
27 static char *authfullname_buf=0; |
|
28 char *p; |
|
29 |
|
30 if (chdir(homedir)) |
|
31 { |
|
32 perror("chdir"); |
|
33 authexit(1); |
|
34 } |
|
35 |
|
36 if (username) |
|
37 { |
|
38 if (gid) |
|
39 authchangegroup(*gid); |
|
40 authchangeusername(username, gid); |
|
41 } |
|
42 else |
|
43 { |
|
44 if (!uid || !gid) |
|
45 { |
|
46 write(2, "AUTHFAILURE\n", 12); |
|
47 authexit(1); |
|
48 } |
|
49 authchangeuidgid(*uid, *gid); |
|
50 } |
|
51 |
|
52 if (!authaddr) authaddr=""; |
|
53 if (authaddr_buf) free(authaddr_buf); |
|
54 authaddr_buf=malloc(sizeof("AUTHADDR=")+strlen(authaddr)); |
|
55 if (!authaddr_buf) |
|
56 { |
|
57 perror("malloc"); |
|
58 authexit(1); |
|
59 } |
|
60 strcat(strcpy(authaddr_buf, "AUTHADDR="), authaddr); |
|
61 |
|
62 if (!authfullname) authfullname=""; |
|
63 if (authfullname_buf) free(authfullname_buf); |
|
64 authfullname_buf=malloc(sizeof("AUTHFULLNAME=")+strlen(authfullname)); |
|
65 if (!authfullname_buf) |
|
66 { |
|
67 perror("malloc"); |
|
68 authexit(1); |
|
69 } |
|
70 strcat(strcpy(authfullname_buf, "AUTHFULLNAME="), authfullname); |
|
71 |
|
72 /* Get rid of GECOS crud */ |
|
73 |
|
74 p=authfullname_buf+strlen(authfullname_buf); |
|
75 while (*--p == ',') |
|
76 *p=0; |
|
77 putenv(authaddr_buf); |
|
78 putenv(authfullname_buf); |
|
79 } |
|
80 |
|
81 void authdummy() |
|
82 { |
|
83 } |
|
84 |