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-spwd.c,v 1.12 2004/11/13 16:25:26 cinergi Exp $ ";
20
21 #include "lookup.h"
22 #ifdef HAVE_SHADOW_H
23 #include <shadow.h>
24
25 extern conf_t conf;
26
27 MYSQL_RES *mresult_spent = NULL;
28
29 /*
30 * getspnam
31 */
32 NSS_STATUS
33 #ifdef HAVE_NSS_H
_nss_mysql_getspnam_r(const char * name,struct spwd * result,char * buffer,size_t buflen,int * errnop)34 _nss_mysql_getspnam_r (const char *name, struct spwd *result, char *buffer,
35 size_t buflen, int *errnop)
36 #elif defined(HAVE_NSS_COMMON_H)
37 _nss_mysql_getspnam_r (nss_backend_t *be, void *args)
38 #endif
39 {
40 DN ("_nss_mysql_getspnam_r")
41 int retVal;
42 MYSQL_RES *mresult = NULL;
43
44 DENTER
45 LOCK;
46 #ifdef HAVE_NSS_H
47 retVal = _nss_mysql_lookup (BYNAME, name, 0, conf.sql.query.getspnam,
48 ntrue, result, buffer, buflen, errnop,
49 _nss_mysql_load_shadow, &mresult, FUNCNAME);
50 #else
51 retVal = _nss_mysql_lookup (BYNAME, NSS_ARGS(args)->key.name, 0,
52 conf.sql.query.getspnam, ntrue,
53 NSS_ARGS(args)->buf.result,
54 NSS_ARGS(args)->buf.buffer,
55 NSS_ARGS(args)->buf.buflen,
56 &NSS_ARGS(args)->erange,
57 _nss_mysql_load_shadow, &mresult, FUNCNAME);
58 if (retVal == NSS_SUCCESS)
59 NSS_ARGS(args)->returnval = NSS_ARGS(args)->buf.result;
60 #endif
61 UNLOCK;
62 DSRETURN (retVal)
63 }
64
65 /*
66 * endspent
67 */
68 ENDENT(spent)
69
70 /*
71 * setspent
72 */
SETENT(spent)73 SETENT(spent)
74
75 /*
76 * getspent
77 */
78 NSS_STATUS
79 #ifdef HAVE_NSS_H
80 _nss_mysql_getspent_r (struct spwd *result, char *buffer, size_t buflen,
81 int *errnop)
82 #elif defined(HAVE_NSS_COMMON_H)
83 _nss_mysql_getspent_r (nss_backend_t *be, void *args)
84 #endif
85 {
86 DN ("_nss_mysql_getspent_r")
87 int retVal;
88
89 DENTER
90 LOCK;
91 #ifdef HAVE_NSS_H
92 retVal = _nss_mysql_lookup (BYNONE, NULL, 0, conf.sql.query.getspent,
93 ntrue, result, buffer, buflen, errnop,
94 _nss_mysql_load_shadow, &mresult_spent, FUNCNAME);
95 #else
96 retVal = _nss_mysql_lookup (BYNONE, NULL, 0, conf.sql.query.getspent,
97 ntrue, NSS_ARGS(args)->buf.result,
98 NSS_ARGS(args)->buf.buffer,
99 NSS_ARGS(args)->buf.buflen,
100 &NSS_ARGS(args)->erange,
101 _nss_mysql_load_shadow, &mresult_spent, FUNCNAME);
102 if (retVal == NSS_SUCCESS)
103 NSS_ARGS(args)->returnval = NSS_ARGS(args)->buf.result;
104 #endif
105 UNLOCK;
106 DSRETURN (retVal)
107 }
108
109 #ifdef HAVE_NSS_COMMON_H
110
111 static nss_backend_op_t shadow_ops[] = {
112 _nss_mysql_default_destr, /* NSS_DBOP_DESTRUCTOR */
113 _nss_mysql_endspent, /* NSS_DBOP_ENDENT */
114 _nss_mysql_setspent, /* NSS_DBOP_SETENT */
115 _nss_mysql_getspent_r, /* NSS_DBOP_GETENT */
116 _nss_mysql_getspnam_r /* NSS_DBOP_SHADOW_BYNAME */
117 };
118
119 CONSTR(shadow)
120
121 #endif
122 #endif /* HAVE_SHADOW_H */
123