File: authoption.c

package info (click to toggle)
courier 0.47-4sarge5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 32,680 kB
  • ctags: 12,265
  • sloc: ansic: 164,045; cpp: 23,863; sh: 19,569; perl: 7,225; makefile: 4,192; yacc: 316; sed: 16
file content (66 lines) | stat: -rw-r--r-- 1,188 bytes parent folder | download
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
/*
** Copyright 2002 Double Precision, Inc.  See COPYING for
** distribution information.
*/

#if	HAVE_CONFIG_H
#include	"config.h"
#endif
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<errno.h>
#include	<pwd.h>
#if	HAVE_UNISTD_H
#include	<unistd.h>
#endif

#include	"auth.h"

static const char rcsid[]="$Id: authoption.c,v 1.1 2004/01/19 19:37:37 mrsam Exp $";


char *authgetoptionenv(const char *keyword)
{
	return authgetoption(getenv("OPTIONS"), keyword);
}

char *authgetoption(const char *options, const char *keyword)
{
	size_t keyword_l=strlen(keyword);
	char *p;

	while (options)
	{
		if (strncmp(options, keyword, keyword_l) == 0)
		{
			if (options[keyword_l] == 0 ||
			    options[keyword_l] == ',')
				return strdup("");

			if (options[keyword_l] == '=')
			{
				options += keyword_l;
				++options;

				for (keyword_l=0;
				     options[keyword_l] &&
					     options[keyword_l] != ',';
				     ++keyword_l)
					;

				if (!(p=malloc(keyword_l+1)))
					return NULL;
				memcpy(p, options, keyword_l);
				p[keyword_l]=0;
				return p;
			}
		}

		options=strchr(options, ',');
		if (options)
			++options;
	}
	errno=ENOENT;
	return NULL;
}