|
1 // Copyright (C) 2000 Bruce Guenter <bruceg@em.ca> |
|
2 // |
|
3 // This program is free software; you can redistribute it and/or modify |
|
4 // it under the terms of the GNU General Public License as published by |
|
5 // the Free Software Foundation; either version 2 of the License, or |
|
6 // (at your option) any later version. |
|
7 // |
|
8 // This program is distributed in the hope that it will be useful, |
|
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 // GNU General Public License for more details. |
|
12 // |
|
13 // You should have received a copy of the GNU General Public License |
|
14 // along with this program; if not, write to the Free Software |
|
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 #include <config.h> |
|
18 #include <errno.h> |
|
19 #include <unistd.h> |
|
20 #include "authvlib.h" |
|
21 #include "fdbuf/fdbuf.h" |
|
22 |
|
23 const mystring exec_presetuid = 0; |
|
24 const mystring exec_postsetuid = 0; |
|
25 |
|
26 void fail_login(const char*) |
|
27 { |
|
28 exit(1); |
|
29 } |
|
30 |
|
31 void fail_baddata(const char*) |
|
32 { |
|
33 exit(2); |
|
34 } |
|
35 |
|
36 void fail_temporary(const char*) |
|
37 { |
|
38 exit(111); |
|
39 } |
|
40 |
|
41 static void getdata(mystring& domain, mystring& user, mystring& pass) |
|
42 { |
|
43 char buf[513]; |
|
44 unsigned buflen = 0; |
|
45 while(buflen < 512) { |
|
46 int r; |
|
47 do |
|
48 r = read(0, buf+buflen, sizeof(buf) - buflen); |
|
49 while ((r == -1) && (errno == EINTR)); |
|
50 if (r == -1) fail_baddata("Read error"); |
|
51 if (r == 0) break; |
|
52 buflen += r; |
|
53 } |
|
54 if(buflen >= 512) |
|
55 fail_baddata("Read buffer too long"); |
|
56 buf[buflen] = 0; |
|
57 |
|
58 char* ptr = buf; |
|
59 char* end = buf + buflen; |
|
60 |
|
61 domain = ptr; |
|
62 ptr += domain.length()+1; |
|
63 if(ptr >= end) |
|
64 fail_baddata("Missing user name"); |
|
65 user = ptr; |
|
66 ptr += user.length()+1; |
|
67 if(ptr >= end) |
|
68 fail_baddata("Missing pass phrase"); |
|
69 pass = ptr; |
|
70 } |
|
71 |
|
72 int main() |
|
73 { |
|
74 mystring user; |
|
75 mystring pass; |
|
76 mystring domain; |
|
77 getdata(domain, user, pass); |
|
78 user_data* udata = authenticate(user, pass, domain, true); |
|
79 if(!udata) |
|
80 return 1; |
|
81 fout << |
|
82 "UID=" << udata->uid << "\n" |
|
83 "GID=" << udata->gid << "\n" |
|
84 "USER=" << udata->name << "\n" |
|
85 "HOME=" << udata->home << "\n" |
|
86 "MAILDIR=" << udata->maildir << "\n" |
|
87 "VUSER=" << udata->vname << "\n"; |
|
88 } |