Update Standards-Version
[manu/libnss-mysql-bg.git] / src / mysql-pwd.c
1 /* Copyright (C) 2002 Ben Goodwin
2    This file is part of the nss-mysql library.
3   
4    The nss-mysql library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public License as published
6    by the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8   
9    The nss-mysql library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13    You should have received a copy of the GNU General Public License
14    along with the nss-mysql library; if not, write to the Free Software
15    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17
18 static const char rcsid[] =
19     "$Id: mysql-pwd.c,v 1.11 2004/11/13 16:25:26 cinergi Exp $ ";
20
21 #include "lookup.h"
22 #include <pwd.h>
23
24 extern conf_t conf;
25
26 MYSQL_RES *mresult_pwent = NULL;
27
28 /*
29  * getpwnam
30  */
31 NSS_STATUS
32 #ifdef HAVE_NSS_H
33 _nss_mysql_getpwnam_r (const char *name, struct passwd *result, char *buffer,
34                        size_t buflen, int *errnop)
35 #elif defined(HAVE_NSS_COMMON_H)
36 _nss_mysql_getpwnam_r (nss_backend_t *be, void *args)
37 #endif
38 {
39   DN ("_nss_mysql_getpwnam_r")
40   int retVal;
41   MYSQL_RES *mresult = NULL;
42
43   DENTER
44   LOCK;
45 #ifdef HAVE_NSS_H
46   retVal = _nss_mysql_lookup (BYNAME, name, 0, conf.sql.query.getpwnam,
47                               nfalse, result, buffer, buflen, errnop,
48                               _nss_mysql_load_passwd, &mresult, FUNCNAME);
49 #else
50   retVal = _nss_mysql_lookup (BYNAME, NSS_ARGS(args)->key.name, 0,
51                               conf.sql.query.getpwnam, nfalse,
52                               NSS_ARGS(args)->buf.result,
53                               NSS_ARGS(args)->buf.buffer,
54                               NSS_ARGS(args)->buf.buflen,
55                               &NSS_ARGS(args)->erange,
56                               _nss_mysql_load_passwd, &mresult, FUNCNAME);
57   if (retVal == NSS_SUCCESS)
58     NSS_ARGS(args)->returnval = NSS_ARGS(args)->buf.result;
59 #endif
60   UNLOCK;
61   DSRETURN (retVal)
62 }
63
64 /*
65  * getpwuid
66  */
67 NSS_STATUS
68 #ifdef HAVE_NSS_H
69 _nss_mysql_getpwuid_r (uid_t uid, struct passwd *result, char *buffer,
70                        size_t buflen, int *errnop)
71 #elif defined(HAVE_NSS_COMMON_H)
72 _nss_mysql_getpwuid_r (nss_backend_t *be, void *args)
73 #endif
74 {
75   DN ("_nss_mysql_getpwuid_r")
76   int retVal;
77   MYSQL_RES *mresult = NULL;
78
79   DENTER
80   LOCK;
81 #ifdef HAVE_NSS_H
82   retVal = _nss_mysql_lookup (BYNUM, NULL, uid, conf.sql.query.getpwuid,
83                               nfalse, result, buffer, buflen, errnop,
84                               _nss_mysql_load_passwd, &mresult, FUNCNAME);
85 #else
86   retVal = _nss_mysql_lookup (BYNUM, NULL, NSS_ARGS(args)->key.uid,
87                               conf.sql.query.getpwuid, nfalse,
88                               NSS_ARGS(args)->buf.result,
89                               NSS_ARGS(args)->buf.buffer,
90                               NSS_ARGS(args)->buf.buflen,
91                               &NSS_ARGS(args)->erange,
92                               _nss_mysql_load_passwd, &mresult, FUNCNAME);
93   if (retVal == NSS_SUCCESS)
94     NSS_ARGS(args)->returnval = NSS_ARGS(args)->buf.result;
95 #endif
96   UNLOCK;
97   DSRETURN (retVal)
98 }
99
100 /*
101  * endpwent
102  */
103 ENDENT(pwent)
104
105 /*
106  * setpwent
107  */
108 SETENT(pwent)
109
110 /*
111  * getpwent
112  */
113 NSS_STATUS
114 #ifdef HAVE_NSS_H
115 _nss_mysql_getpwent_r (struct passwd *result, char *buffer, size_t buflen,
116                        int *errnop)
117 #elif defined(HAVE_NSS_COMMON_H)
118 _nss_mysql_getpwent_r (nss_backend_t *be, void *args)
119 #endif
120 {
121   DN ("_nss_mysql_getpwent_r")
122   int retVal;
123
124   DENTER
125   LOCK;
126 #ifdef HAVE_NSS_H
127   retVal = _nss_mysql_lookup (BYNONE, NULL, 0, conf.sql.query.getpwent,
128                               nfalse, result, buffer, buflen, errnop,
129                               _nss_mysql_load_passwd, &mresult_pwent, FUNCNAME);
130 #else
131   retVal = _nss_mysql_lookup (BYNONE, NULL, 0, conf.sql.query.getpwent,
132                               nfalse, NSS_ARGS(args)->buf.result,
133                               NSS_ARGS(args)->buf.buffer,
134                               NSS_ARGS(args)->buf.buflen,
135                               &NSS_ARGS(args)->erange,
136                               _nss_mysql_load_passwd, &mresult_pwent, FUNCNAME);
137   if (retVal == NSS_SUCCESS)
138     NSS_ARGS(args)->returnval = NSS_ARGS(args)->buf.result;
139 #endif
140   UNLOCK;
141   DSRETURN (retVal)
142 }
143
144 #ifdef HAVE_NSS_COMMON_H
145
146 static nss_backend_op_t passwd_ops[] = {
147     _nss_mysql_default_destr,       /* NSS_DBOP_DESTRUCTOR */
148     _nss_mysql_endpwent,            /* NSS_DBOP_ENDENT */
149     _nss_mysql_setpwent,            /* NSS_DBOP_SETENT */
150     _nss_mysql_getpwent_r,          /* NSS_DBOP_GETENT */
151     _nss_mysql_getpwnam_r,          /* NSS_DBOP_PASSWD_BYNAME */
152     _nss_mysql_getpwuid_r           /* NSS_DBOP_PASSWD_BYUID */
153 };
154
155 CONSTR(passwd)
156
157 #endif