File: authtest.c

package info (click to toggle)
courier-authlib 0.72.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,824 kB
  • sloc: ansic: 15,828; sh: 5,047; cpp: 4,205; makefile: 853; perl: 761
file content (124 lines) | stat: -rw-r--r-- 2,436 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
** Copyright 1998 - 2004 Double Precision, Inc.  See COPYING for
** distribution information.
*/

#include	"auth.h"
#include	"courierauthstaticlist.h"
#include	"courierauthsasl.h"
#include	"courierauthdebug.h"
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<errno.h>
#if	HAVE_UNISTD_H
#include	<unistd.h>
#endif

#include	"debug.c"
/* libtool bork-age */


static void usage()
{
	fprintf(stderr, "Usage: authtest [-s service] userid [ password [ newpassword ] ]\n");
	exit(1);
}

static int callback_pre(struct authinfo *a, void *dummy)
{
#define PTR(x) ((x) ? (x):"(none)")

	printf("Authentication succeeded.\n\n");
	printf("     Authenticated: %s ", PTR(a->address));
	if (a->sysusername)
		printf(" (system username: %s)\n", a->sysusername);
	else if (a->sysuserid)
		printf(" (uid %lu, gid %lu)\n", (unsigned long)*a->sysuserid,
		       (unsigned long)a->sysgroupid);
	else printf(" (*** UID/GID initialization error***)\n");

	printf("    Home Directory: %s\n", PTR(a->homedir));
	printf("           Maildir: %s\n", PTR(a->maildir));
	printf("             Quota: %s\n", PTR(a->quota));
	printf("Encrypted Password: %s\n", PTR(a->passwd));
	printf("Cleartext Password: %s\n", PTR(a->clearpasswd));
	printf("           Options: %s\n", PTR(a->options));
#undef PTR

	return (0);
}

int main(int argc, char **argv)
{
int	argn;
const char *service="login";

	for (argn=1; argn<argc; argn++)
	{
	const char *argp;

		if (argv[argn][0] != '-')	break;
		if (argv[argn][1] == 0)
		{
			++argn;
			break;
		}

		argp=argv[argn]+2;

		switch (argv[argn][1])	{
		case 's':
			if (!*argp && argn+1 < argc)
				argp=argv[++argn];
			service=argp;
			break;
		default:
			usage();
		}
	}
	if (argc - argn <= 0)
		usage();

	courier_authdebug_login_level = 2;

	if (argc - argn >= 3)
	{
		if (auth_passwd(service, argv[argn],
				argv[argn+1],
				argv[argn+2]))
		{
			perror("Authentication FAILED");
			exit(1);
		}
		else
		{
			fprintf(stderr, "Password change succeeded.\n");
			exit(0);
		}
	}
	setenv("TCPREMOTEIP", "::1", 0);

	if (argc - argn >= 2)
	{
		if (auth_login_meta(NULL, service, argv[argn],
				    argv[argn+1],
				    callback_pre,
				    NULL))
		{
			perror("Authentication FAILED");
			exit(1);
		}
	}
	else if (argc - argn >= 1)
	{
		if (auth_getuserinfo_meta(NULL, service, argv[argn],
					  callback_pre,
					  NULL))
		{
			perror("Authentication FAILED");
			exit(1);
		}
	}
	exit(0);
}