summaryrefslogtreecommitdiff
blob: 54a67b58499bd5c042844f88867310d23e898cd4 (plain)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
diff -urNad libnss-db-2.2.3pre1~/src/db-XXX.c libnss-db-2.2.3pre1/src/db-XXX.c
--- libnss-db-2.2.3pre1~/src/db-XXX.c	2010-03-30 10:41:48.026483855 -0700
+++ libnss-db-2.2.3pre1/src/db-XXX.c	2010-03-30 10:41:48.216484130 -0700
@@ -56,6 +56,7 @@
 
 /* Maintenance of the shared handle open on the database.  */
 
+static DB_ENV *dbenv;
 static DB *db;
 static int keep_db;
 static int entidx;
@@ -69,7 +70,7 @@
 
   pthread_mutex_lock (&lock);
 
-  status = internal_setent (DBFILE, &db);
+  status = internal_setent (DBFILE, &db, &dbenv);
 
   /* Remember STAYOPEN flag.  */
   if (db != NULL)
@@ -89,7 +90,7 @@
 {
   pthread_mutex_lock (&lock);
 
-  internal_endent (&db);
+  internal_endent (&db, &dbenv);
 
   /* Reset STAYOPEN flag.  */
   keep_db = 0;
@@ -112,7 +113,7 @@
   /* Open the database.  */
   if (db == NULL)
     {
-      status = internal_setent (DBFILE, &db);
+      status = internal_setent (DBFILE, &db, &dbenv);
       if (status != NSS_STATUS_SUCCESS)
 	{
 	  *errnop = errno;
@@ -194,7 +195,7 @@
     }
 
   if (! keep_db)
-    internal_endent (&db);
+    internal_endent (&db, &dbenv);
 
   return status;
 }
diff -urNad libnss-db-2.2.3pre1~/src/db-alias.c libnss-db-2.2.3pre1/src/db-alias.c
--- libnss-db-2.2.3pre1~/src/db-alias.c	2010-03-30 10:41:47.996483420 -0700
+++ libnss-db-2.2.3pre1/src/db-alias.c	2010-03-30 10:41:48.216484130 -0700
@@ -34,6 +34,7 @@
 
 /* Maintenance of the shared handle open on the database.  */
 
+static DB_ENV *dbenv;
 static DB *db;
 static int keep_db;
 static unsigned int entidx;	/* Index for `getaliasent_r'. */
@@ -47,7 +48,7 @@
 
   pthread_mutex_lock (&lock);
 
-  status = internal_setent (_PATH_VARDB "aliases.db", &db);
+  status = internal_setent (_PATH_VARDB "aliases.db", &db, &dbenv);
 
   /* Remember STAYOPEN flag.  */
   if (db != NULL)
@@ -68,7 +69,7 @@
 {
   pthread_mutex_lock (&lock);
 
-  internal_endent (&db);
+  internal_endent (&db, &dbenv);
 
   /* Reset STAYOPEN flag.  */
   keep_db = 0;
@@ -92,7 +93,7 @@
   /* Open the database.  */
   if (db == NULL)
     {
-      status = internal_setent (_PATH_VARDB "aliases.db", &db);
+      status = internal_setent (_PATH_VARDB "aliases.db", &db, &dbenv);
       if (status != NSS_STATUS_SUCCESS)
 	{
 	  *errnop = errno;
@@ -165,7 +166,7 @@
     status = NSS_STATUS_NOTFOUND;
 
   if (! keep_db)
-    internal_endent (&db);
+    internal_endent (&db, &dbenv);
 
   return status;
 }
diff -urNad libnss-db-2.2.3pre1~/src/db-compat.c libnss-db-2.2.3pre1/src/db-compat.c
--- libnss-db-2.2.3pre1~/src/db-compat.c	2010-03-30 10:41:47.956483550 -0700
+++ libnss-db-2.2.3pre1/src/db-compat.c	2010-03-30 10:41:48.216484130 -0700
@@ -27,15 +27,14 @@
 
 int
 db_open (const char *file, DBTYPE type, u_int32_t flags, int mode,
-	 void *dbenv, void *dbinfo, DB **dbp)
+	 DB_ENV *dbenv, void *dbinfo, DB **dbp)
 {
   DB *db;
   int err;
 
-  assert (dbenv == NULL);
   assert (dbinfo == NULL);
 
-  err = db_create (&db, NULL, 0);
+  err = db_create (&db, dbenv, 0);
   if (err)
     return err;
 
diff -urNad libnss-db-2.2.3pre1~/src/db-compat.h libnss-db-2.2.3pre1/src/db-compat.h
--- libnss-db-2.2.3pre1~/src/db-compat.h	2001-04-29 18:07:41.000000000 -0700
+++ libnss-db-2.2.3pre1/src/db-compat.h	2010-03-30 10:41:48.216484130 -0700
@@ -2,5 +2,5 @@
 
 #if DB_VERSION_MAJOR > 2
 extern int db_open (const char *__file, DBTYPE __type, u_int32_t __flags,
-		    int __mode, void *__dbenv, void *__dbinfo, DB **__dbp);
+		    int __mode, DB_ENV *dbenv, void *__dbinfo, DB **__dbp);
 #endif
diff -urNad libnss-db-2.2.3pre1~/src/db-netgrp.c libnss-db-2.2.3pre1/src/db-netgrp.c
--- libnss-db-2.2.3pre1~/src/db-netgrp.c	2010-03-30 10:41:47.996483420 -0700
+++ libnss-db-2.2.3pre1/src/db-netgrp.c	2010-03-30 10:41:48.216484130 -0700
@@ -35,6 +35,7 @@
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 
 /* Maintenance of the shared handle open on the database.  */
+static DB_ENV *dbenv;
 static DB *db;
 static char *entry;
 static char *cursor;
@@ -46,7 +47,7 @@
 
   pthread_mutex_lock (&lock);
 
-  status = internal_setent (DBFILE, &db);
+  status = internal_setent (DBFILE, &db, &dbenv);
 
   if (status == NSS_STATUS_SUCCESS)
     {
@@ -72,7 +73,7 @@
 {
   pthread_mutex_lock (&lock);
 
-  internal_endent (&db);
+  internal_endent (&db, &dbenv);
 
   pthread_mutex_unlock (&lock);
 
diff -urNad libnss-db-2.2.3pre1~/src/db-open.c libnss-db-2.2.3pre1/src/db-open.c
--- libnss-db-2.2.3pre1~/src/db-open.c	2010-03-30 10:41:47.996483420 -0700
+++ libnss-db-2.2.3pre1/src/db-open.c	2010-03-30 10:42:24.127733451 -0700
@@ -21,6 +21,9 @@
 #include <db.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libgen.h>
 
 #include "db-compat.h"
 
@@ -45,35 +48,46 @@
    handle in *DBP and return NSS_STATUS_SUCCESS.  On failure, return
    the appropriate lookup status.  */
 enum nss_status
-internal_setent (const char *file, DB **dbp)
+internal_setent (const char *file, DB **dbp, DB_ENV **dbenvp)
 {
-  DB *db;
+  char *filecopy = NULL, *home;
+  DB_ENV *dbenv = NULL;
+  DB *db = NULL;
   int err;
   int fd;
 
   if (*dbp)
     return NSS_STATUS_SUCCESS;
 
-  err = db_open (file, DB_BTREE, DB_RDONLY, 0, NULL, NULL, &db);
+  err = db_env_create(&dbenv, 0);
   if (err != 0)
-    {
-      if (err > 0)
-	errno = err;
-      return NSS_STATUS_UNAVAIL;
-    }
+    goto fail;
+  filecopy = strdup(file);
+  home = dirname(filecopy);
+  err = dbenv->open(dbenv, home, DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0);
+  if (err != 0)
+    goto fail_env;
+  err = db_open (file, DB_BTREE, DB_RDONLY, 0, dbenv, NULL, &db);
+  if (err != 0)
+   goto fail_env;
 
   /* We have to make sure the file is `closed on exec'.  */
   err = db->fd (db, &fd);
   if (err)
-    goto fail;
+    goto fail_db;
   if (set_cloexec_flag (fd) < 0)
-    goto fail;
+    goto fail_db;
 
+  *dbenvp = dbenv;
   *dbp = db;
   return NSS_STATUS_SUCCESS;
 
- fail:
+ fail_db:
   db->close (db, 0);
+ fail_env:
+  dbenv->close (dbenv, 0);
+ fail:
+  if (filecopy) free(filecopy);
   if (err > 0)
     errno = err;
   return NSS_STATUS_UNAVAIL;
@@ -81,8 +95,9 @@
 
 /* Close the database *DBP.  */
 void
-internal_endent (DB **dbp)
+internal_endent (DB **dbp, DB_ENV **dbenvp)
 {
+  DB_ENV *dbenv = *dbenvp;
   DB *db = *dbp;
 
   if (db != NULL)
@@ -90,4 +105,9 @@
       db->close (db, 0);
       *dbp = NULL;
     }
+  if (dbenv != NULL)
+    {
+      dbenv->close (dbenv, 0);
+      *dbenvp = NULL;
+    }
 }
diff -urNad libnss-db-2.2.3pre1~/src/nss_db.h libnss-db-2.2.3pre1/src/nss_db.h
--- libnss-db-2.2.3pre1~/src/nss_db.h	2001-04-29 18:07:41.000000000 -0700
+++ libnss-db-2.2.3pre1/src/nss_db.h	2010-03-30 10:41:48.216484130 -0700
@@ -26,9 +26,9 @@
 /* Open the database stored in FILE.  If succesful, store the database
    handle in *DBP and return NSS_STATUS_SUCCESS.  On failure, return
    the appropriate lookup status.  */
-extern enum nss_status internal_setent (const char *file, DB **dbp);
+extern enum nss_status internal_setent (const char *file, DB **dbp, DB_ENV **dbenvp);
 
 /* Close the database *DBP.  */
-extern void internal_endent (DB **dbp);
+extern void internal_endent (DB **dbp, DB_ENV **dbenvp);
 
 #endif	/* nss_db.h */