File: userdb2.c

package info (click to toggle)
courier-authlib 0.58-4%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 16,212 kB
  • ctags: 1,896
  • sloc: ansic: 21,550; sh: 14,071; makefile: 866; perl: 842; cpp: 284
file content (52 lines) | stat: -rw-r--r-- 918 bytes parent folder | download | duplicates (3)
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
/*
** Copyright 1998 - 1999 Double Precision, Inc.
** See COPYING for distribution information.
*/

#if	HAVE_CONFIG_H
#include	"config.h"
#endif
#include	"dbobj.h"
#include	"userdb.h"
#include	<string.h>
#include	<stdlib.h>
#include	<stdio.h>
#include	<errno.h>

static const char rcsid[]="$Id: userdb2.c,v 1.4 2004/04/18 15:54:39 mrsam Exp $";

extern int userdb_debug_level;

char	*userdbshadow(const char *sh, const char *u)
{
struct dbobj d;
char	*p,*q;
size_t	l;

	dbobj_init(&d);

	if (dbobj_open(&d, sh, "R"))
	{
		userdb_debug_level && fprintf(stderr,
			"DEBUG: userdbshadow: unable to open %s\n", sh);
		return (0);
	}

	q=dbobj_fetch(&d, u, strlen(u), &l, "");
	dbobj_close(&d);
	if (!q)
	{
		userdb_debug_level && fprintf(stderr,
			"DEBUG: userdbshadow: entry not found\n");
		errno=ENOENT;
		return(0);
	}

	p=malloc(l+1);
	if (!p)	return (0);

	if (l)	memcpy(p, q, l);
	free(q);
	p[l]=0;
	return (p);
}