|
0
|
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>
|
|
2
|
19 |
#include <stdlib.h>
|
|
0
|
20 |
#include <unistd.h>
|
|
|
21 |
#include "authvlib.h"
|
|
|
22 |
#include "fdbuf/fdbuf.h"
|
|
|
23 |
|
|
|
24 |
const mystring exec_presetuid = 0;
|
|
|
25 |
const mystring exec_postsetuid = 0;
|
|
|
26 |
|
|
|
27 |
void fail_login(const char*)
|
|
|
28 |
{
|
|
|
29 |
exit(1);
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
void fail_baddata(const char*)
|
|
|
33 |
{
|
|
|
34 |
exit(2);
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
void fail_temporary(const char*)
|
|
|
38 |
{
|
|
|
39 |
exit(111);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
static void getdata(mystring& domain, mystring& user, mystring& pass)
|
|
|
43 |
{
|
|
|
44 |
char buf[513];
|
|
|
45 |
unsigned buflen = 0;
|
|
|
46 |
while(buflen < 512) {
|
|
|
47 |
int r;
|
|
|
48 |
do
|
|
|
49 |
r = read(0, buf+buflen, sizeof(buf) - buflen);
|
|
|
50 |
while ((r == -1) && (errno == EINTR));
|
|
|
51 |
if (r == -1) fail_baddata("Read error");
|
|
|
52 |
if (r == 0) break;
|
|
|
53 |
buflen += r;
|
|
|
54 |
}
|
|
|
55 |
if(buflen >= 512)
|
|
|
56 |
fail_baddata("Read buffer too long");
|
|
|
57 |
buf[buflen] = 0;
|
|
|
58 |
|
|
|
59 |
char* ptr = buf;
|
|
|
60 |
char* end = buf + buflen;
|
|
|
61 |
|
|
|
62 |
domain = ptr;
|
|
|
63 |
ptr += domain.length()+1;
|
|
|
64 |
if(ptr >= end)
|
|
|
65 |
fail_baddata("Missing user name");
|
|
|
66 |
user = ptr;
|
|
|
67 |
ptr += user.length()+1;
|
|
|
68 |
if(ptr >= end)
|
|
|
69 |
fail_baddata("Missing pass phrase");
|
|
|
70 |
pass = ptr;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
int main()
|
|
|
74 |
{
|
|
|
75 |
mystring user;
|
|
|
76 |
mystring pass;
|
|
|
77 |
mystring domain;
|
|
|
78 |
getdata(domain, user, pass);
|
|
|
79 |
user_data* udata = authenticate(user, pass, domain, true);
|
|
|
80 |
if(!udata)
|
|
|
81 |
return 1;
|
|
|
82 |
fout <<
|
|
|
83 |
"UID=" << udata->uid << "\n"
|
|
|
84 |
"GID=" << udata->gid << "\n"
|
|
|
85 |
"USER=" << udata->name << "\n"
|
|
|
86 |
"HOME=" << udata->home << "\n"
|
|
|
87 |
"MAILDIR=" << udata->maildir << "\n"
|
|
|
88 |
"VUSER=" << udata->vname << "\n";
|
|
|
89 |
}
|