Deleted Added
full compact
makemap.c (71348) makemap.c (90795)
1/*
1/*
2 * Copyright (c) 1998-2000 Sendmail, Inc. and its suppliers.
2 * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 * Copyright (c) 1992 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
11 *
12 */
13
3 * All rights reserved.
4 * Copyright (c) 1992 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
11 *
12 */
13
14#ifndef lint
15static char copyright[] =
16"@(#) Copyright (c) 1998-2000 Sendmail, Inc. and its suppliers.\n\
14#include <sm/gen.h>
15
16SM_IDSTR(copyright,
17"@(#) Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.\n\
17 All rights reserved.\n\
18 Copyright (c) 1992 Eric P. Allman. All rights reserved.\n\
19 Copyright (c) 1992, 1993\n\
18 All rights reserved.\n\
19 Copyright (c) 1992 Eric P. Allman. All rights reserved.\n\
20 Copyright (c) 1992, 1993\n\
20 The Regents of the University of California. All rights reserved.\n";
21#endif /* ! lint */
21 The Regents of the University of California. All rights reserved.\n")
22
22
23#ifndef lint
24static char id[] = "@(#)$Id: makemap.c,v 8.135.4.13 2000/10/05 23:00:50 gshapiro Exp $";
25#endif /* ! lint */
23SM_IDSTR(id, "@(#)$Id: makemap.c,v 8.175 2001/12/28 22:44:01 ca Exp $")
26
24
27/* $FreeBSD: head/contrib/sendmail/makemap/makemap.c 71348 2001-01-21 22:21:43Z gshapiro $ */
25/* $FreeBSD: head/contrib/sendmail/makemap/makemap.c 90795 2002-02-17 21:58:34Z gshapiro $ */
28
29#include <sys/types.h>
30#ifndef ISC_UNIX
31# include <sys/file.h>
32#endif /* ! ISC_UNIX */
33#include <ctype.h>
34#include <stdlib.h>
35#include <unistd.h>

--- 7 unchanged lines hidden (view full) ---

43
44uid_t RealUid;
45gid_t RealGid;
46char *RealUserName;
47uid_t RunAsUid;
48uid_t RunAsGid;
49char *RunAsUserName;
50int Verbose = 2;
26
27#include <sys/types.h>
28#ifndef ISC_UNIX
29# include <sys/file.h>
30#endif /* ! ISC_UNIX */
31#include <ctype.h>
32#include <stdlib.h>
33#include <unistd.h>

--- 7 unchanged lines hidden (view full) ---

41
42uid_t RealUid;
43gid_t RealGid;
44char *RealUserName;
45uid_t RunAsUid;
46uid_t RunAsGid;
47char *RunAsUserName;
48int Verbose = 2;
51bool DontInitGroups = FALSE;
49bool DontInitGroups = false;
52uid_t TrustedUid = 0;
53BITMAP256 DontBlameSendmail;
54
55#define BUFSIZE 1024
50uid_t TrustedUid = 0;
51BITMAP256 DontBlameSendmail;
52
53#define BUFSIZE 1024
56#if _FFR_DELIM
57# define ISSEP(c) ((sep == '\0' && isascii(c) && isspace(c)) || (c) == sep)
58#else /* _FFR_DELIM */
59# define ISSEP(c) (isascii(c) && isspace(c))
60#endif /* _FFR_DELIM */
54#define ISSEP(c) (sep == '\0' ? isascii(c) && isspace(c) : (c) == sep)
61
55
62
63static void
64usage(progname)
65 char *progname;
66{
56static void
57usage(progname)
58 char *progname;
59{
67 fprintf(stderr,
68 "Usage: %s [-C cffile] [-N] [-c cachesize] [-d] [-e] [-f] [-l] [-o] [-r] [-s] %s[-u] [-v] type mapname\n",
69 progname,
70#if _FFR_DELIM
71 "[-t delimiter] "
72#else /* _FFR_DELIM */
73 ""
74#endif /* _FFR_DELIM */
75 );
60 /* XXX break the usage output into multiple lines? it's too long */
61 sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
62 "Usage: %s [-C cffile] [-N] [-c cachesize] [-d] [-e] [-f] [-l] [-o] [-r] [-s] [-t delimiter] [-u] [-v] type mapname\n",
63 progname);
64#if _FFR_COMMENT_CHAR
65 /* add -D comment-char */
66#endif /* _FFR_COMMENT_CHAR */
76 exit(EX_USAGE);
77}
78
79int
80main(argc, argv)
81 int argc;
82 char **argv;
83{
84 char *progname;
85 char *cfile;
67 exit(EX_USAGE);
68}
69
70int
71main(argc, argv)
72 int argc;
73 char **argv;
74{
75 char *progname;
76 char *cfile;
86 bool inclnull = FALSE;
87 bool notrunc = FALSE;
88 bool allowreplace = FALSE;
89 bool allowempty = FALSE;
90 bool verbose = FALSE;
91 bool foldcase = TRUE;
92 bool unmake = FALSE;
93#if _FFR_DELIM
77 bool inclnull = false;
78 bool notrunc = false;
79 bool allowreplace = false;
80 bool allowempty = false;
81 bool verbose = false;
82 bool foldcase = true;
83 bool unmake = false;
94 char sep = '\0';
84 char sep = '\0';
95#endif /* _FFR_DELIM */
85 char comment = '#';
96 int exitstat;
97 int opt;
98 char *typename = NULL;
99 char *mapname = NULL;
86 int exitstat;
87 int opt;
88 char *typename = NULL;
89 char *mapname = NULL;
100 int lineno;
90 unsigned int lineno;
101 int st;
102 int mode;
103 int smode;
104 int putflags = 0;
105 long sff = SFF_ROOTOK|SFF_REGONLY;
106 struct passwd *pw;
107 SMDB_DATABASE *database;
108 SMDB_CURSOR *cursor;
109 SMDB_DBENT db_key, db_val;
110 SMDB_DBPARAMS params;
111 SMDB_USER_INFO user_info;
112 char ibuf[BUFSIZE];
113#if HASFCHOWN
91 int st;
92 int mode;
93 int smode;
94 int putflags = 0;
95 long sff = SFF_ROOTOK|SFF_REGONLY;
96 struct passwd *pw;
97 SMDB_DATABASE *database;
98 SMDB_CURSOR *cursor;
99 SMDB_DBENT db_key, db_val;
100 SMDB_DBPARAMS params;
101 SMDB_USER_INFO user_info;
102 char ibuf[BUFSIZE];
103#if HASFCHOWN
114 FILE *cfp;
104 SM_FILE_T *cfp;
115 char buf[MAXLINE];
116#endif /* HASFCHOWN */
117 static char rnamebuf[MAXNAME]; /* holds RealUserName */
118 extern char *optarg;
119 extern int optind;
120
121 memset(&params, '\0', sizeof params);
122 params.smdbp_cache_size = 1024 * 1024;
123
124 progname = strrchr(argv[0], '/');
125 if (progname != NULL)
126 progname++;
127 else
128 progname = argv[0];
105 char buf[MAXLINE];
106#endif /* HASFCHOWN */
107 static char rnamebuf[MAXNAME]; /* holds RealUserName */
108 extern char *optarg;
109 extern int optind;
110
111 memset(&params, '\0', sizeof params);
112 params.smdbp_cache_size = 1024 * 1024;
113
114 progname = strrchr(argv[0], '/');
115 if (progname != NULL)
116 progname++;
117 else
118 progname = argv[0];
129 cfile = _PATH_SENDMAILCF;
119 cfile = getcfname(0, 0, SM_GET_SENDMAIL_CF, NULL);
130
131 clrbitmap(DontBlameSendmail);
132 RunAsUid = RealUid = getuid();
133 RunAsGid = RealGid = getgid();
134 pw = getpwuid(RealUid);
135 if (pw != NULL)
120
121 clrbitmap(DontBlameSendmail);
122 RunAsUid = RealUid = getuid();
123 RunAsGid = RealGid = getgid();
124 pw = getpwuid(RealUid);
125 if (pw != NULL)
136 (void) strlcpy(rnamebuf, pw->pw_name, sizeof rnamebuf);
126 (void) sm_strlcpy(rnamebuf, pw->pw_name, sizeof rnamebuf);
137 else
127 else
138 (void) snprintf(rnamebuf, sizeof rnamebuf, "Unknown UID %d",
139 (int) RealUid);
128 (void) sm_snprintf(rnamebuf, sizeof rnamebuf,
129 "Unknown UID %d", (int) RealUid);
140 RunAsUserName = RealUserName = rnamebuf;
141 user_info.smdbu_id = RunAsUid;
142 user_info.smdbu_group_id = RunAsGid;
130 RunAsUserName = RealUserName = rnamebuf;
131 user_info.smdbu_id = RunAsUid;
132 user_info.smdbu_group_id = RunAsGid;
143 (void) strlcpy(user_info.smdbu_name, RunAsUserName,
133 (void) sm_strlcpy(user_info.smdbu_name, RunAsUserName,
144 SMDB_MAX_USER_NAME_LEN);
145
134 SMDB_MAX_USER_NAME_LEN);
135
146
147#define OPTIONS "C:Nc:t:deflorsuv"
136#define OPTIONS "C:D:Nc:deflorst:uv"
148 while ((opt = getopt(argc, argv, OPTIONS)) != -1)
149 {
150 switch (opt)
151 {
152 case 'C':
153 cfile = optarg;
154 break;
155
156 case 'N':
137 while ((opt = getopt(argc, argv, OPTIONS)) != -1)
138 {
139 switch (opt)
140 {
141 case 'C':
142 cfile = optarg;
143 break;
144
145 case 'N':
157 inclnull = TRUE;
146 inclnull = true;
158 break;
159
160 case 'c':
161 params.smdbp_cache_size = atol(optarg);
162 break;
163
164 case 'd':
147 break;
148
149 case 'c':
150 params.smdbp_cache_size = atol(optarg);
151 break;
152
153 case 'd':
165 params.smdbp_allow_dup = TRUE;
154 params.smdbp_allow_dup = true;
166 break;
167
168 case 'e':
155 break;
156
157 case 'e':
169 allowempty = TRUE;
158 allowempty = true;
170 break;
171
172 case 'f':
159 break;
160
161 case 'f':
173 foldcase = FALSE;
162 foldcase = false;
174 break;
175
163 break;
164
165#if _FFR_COMMENT_CHAR
166 case 'D':
167 comment = *optarg;
168 break;
169#endif /* _FFR_COMMENT_CHAR */
170
176 case 'l':
177 smdb_print_available_types();
178 exit(EX_OK);
179 break;
180
181 case 'o':
171 case 'l':
172 smdb_print_available_types();
173 exit(EX_OK);
174 break;
175
176 case 'o':
182 notrunc = TRUE;
177 notrunc = true;
183 break;
184
185 case 'r':
178 break;
179
180 case 'r':
186 allowreplace = TRUE;
181 allowreplace = true;
187 break;
188
189 case 's':
190 setbitn(DBS_MAPINUNSAFEDIRPATH, DontBlameSendmail);
191 setbitn(DBS_WRITEMAPTOHARDLINK, DontBlameSendmail);
192 setbitn(DBS_WRITEMAPTOSYMLINK, DontBlameSendmail);
193 setbitn(DBS_LINKEDMAPINWRITABLEDIR, DontBlameSendmail);
194 break;
195
182 break;
183
184 case 's':
185 setbitn(DBS_MAPINUNSAFEDIRPATH, DontBlameSendmail);
186 setbitn(DBS_WRITEMAPTOHARDLINK, DontBlameSendmail);
187 setbitn(DBS_WRITEMAPTOSYMLINK, DontBlameSendmail);
188 setbitn(DBS_LINKEDMAPINWRITABLEDIR, DontBlameSendmail);
189 break;
190
196#if _FFR_DELIM
197 case 't':
198 if (optarg == NULL || *optarg == '\0')
199 {
191 case 't':
192 if (optarg == NULL || *optarg == '\0')
193 {
200 fprintf(stderr, "Invalid separator\n");
194 sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
195 "Invalid separator\n");
201 break;
202 }
203 sep = *optarg;
204 break;
196 break;
197 }
198 sep = *optarg;
199 break;
205#endif /* _FFR_DELIM */
206
207 case 'u':
200
201 case 'u':
208 unmake = TRUE;
202 unmake = true;
209 break;
210
211 case 'v':
203 break;
204
205 case 'v':
212 verbose = TRUE;
206 verbose = true;
213 break;
214
215 default:
216 usage(progname);
217 /* NOTREACHED */
218 }
219 }
220

--- 14 unchanged lines hidden (view full) ---

235 else
236 {
237 typename = argv[0];
238 mapname = argv[1];
239 }
240
241#if HASFCHOWN
242 /* Find TrustedUser value in sendmail.cf */
207 break;
208
209 default:
210 usage(progname);
211 /* NOTREACHED */
212 }
213 }
214

--- 14 unchanged lines hidden (view full) ---

229 else
230 {
231 typename = argv[0];
232 mapname = argv[1];
233 }
234
235#if HASFCHOWN
236 /* Find TrustedUser value in sendmail.cf */
243 if ((cfp = fopen(cfile, "r")) == NULL)
237 if ((cfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, cfile, SM_IO_RDONLY,
238 NULL)) == NULL)
244 {
239 {
245 fprintf(stderr, "makemap: %s: %s", cfile, errstring(errno));
240 sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "makemap: %s: %s",
241 cfile, sm_errstring(errno));
246 exit(EX_NOINPUT);
247 }
242 exit(EX_NOINPUT);
243 }
248 while (fgets(buf, sizeof(buf), cfp) != NULL)
244 while (sm_io_fgets(cfp, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL)
249 {
250 register char *b;
251
252 if ((b = strchr(buf, '\n')) != NULL)
253 *b = '\0';
254
255 b = buf;
256 switch (*b++)

--- 9 unchanged lines hidden (view full) ---

266 continue;
267 if (isascii(*b) && isdigit(*b))
268 TrustedUid = atoi(b);
269 else
270 {
271 TrustedUid = 0;
272 pw = getpwnam(b);
273 if (pw == NULL)
245 {
246 register char *b;
247
248 if ((b = strchr(buf, '\n')) != NULL)
249 *b = '\0';
250
251 b = buf;
252 switch (*b++)

--- 9 unchanged lines hidden (view full) ---

262 continue;
263 if (isascii(*b) && isdigit(*b))
264 TrustedUid = atoi(b);
265 else
266 {
267 TrustedUid = 0;
268 pw = getpwnam(b);
269 if (pw == NULL)
274 fprintf(stderr,
275 "TrustedUser: unknown user %s\n", b);
270 (void) sm_io_fprintf(smioerr,
271 SM_TIME_DEFAULT,
272 "TrustedUser: unknown user %s\n", b);
276 else
277 TrustedUid = pw->pw_uid;
278 }
279
280# ifdef UID_MAX
281 if (TrustedUid > UID_MAX)
282 {
273 else
274 TrustedUid = pw->pw_uid;
275 }
276
277# ifdef UID_MAX
278 if (TrustedUid > UID_MAX)
279 {
283 fprintf(stderr,
284 "TrustedUser: uid value (%ld) > UID_MAX (%ld)",
280 (void) sm_io_fprintf(smioerr,
281 SM_TIME_DEFAULT,
282 "TrustedUser: uid value (%ld) > UID_MAX (%ld)",
285 (long) TrustedUid,
286 (long) UID_MAX);
287 TrustedUid = 0;
288 }
289# endif /* UID_MAX */
290 break;
291 }
292
293
294 default:
295 continue;
296 }
297 }
283 (long) TrustedUid,
284 (long) UID_MAX);
285 TrustedUid = 0;
286 }
287# endif /* UID_MAX */
288 break;
289 }
290
291
292 default:
293 continue;
294 }
295 }
298 (void) fclose(cfp);
296 (void) sm_io_close(cfp, SM_TIME_DEFAULT);
299#endif /* HASFCHOWN */
300
301 if (!params.smdbp_allow_dup && !allowreplace)
302 putflags = SMDBF_NO_OVERWRITE;
303
304 if (unmake)
305 {
306 mode = O_RDONLY;

--- 15 unchanged lines hidden (view full) ---

322 errno = smdb_open_database(&database, mapname, mode, smode, sff,
323 typename, &user_info, &params);
324 if (errno != SMDBE_OK)
325 {
326 char *hint;
327
328 if (errno == SMDBE_UNSUPPORTED_DB_TYPE &&
329 (hint = smdb_db_definition(typename)) != NULL)
297#endif /* HASFCHOWN */
298
299 if (!params.smdbp_allow_dup && !allowreplace)
300 putflags = SMDBF_NO_OVERWRITE;
301
302 if (unmake)
303 {
304 mode = O_RDONLY;

--- 15 unchanged lines hidden (view full) ---

320 errno = smdb_open_database(&database, mapname, mode, smode, sff,
321 typename, &user_info, &params);
322 if (errno != SMDBE_OK)
323 {
324 char *hint;
325
326 if (errno == SMDBE_UNSUPPORTED_DB_TYPE &&
327 (hint = smdb_db_definition(typename)) != NULL)
330 fprintf(stderr,
331 "%s: Need to recompile with -D%s for %s support\n",
332 progname, hint, typename);
328 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
329 "%s: Need to recompile with -D%s for %s support\n",
330 progname, hint, typename);
333 else
331 else
334 fprintf(stderr,
335 "%s: error opening type %s map %s: %s\n",
336 progname, typename, mapname, errstring(errno));
332 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
333 "%s: error opening type %s map %s: %s\n",
334 progname, typename, mapname,
335 sm_errstring(errno));
337 exit(EX_CANTCREAT);
338 }
339
340 (void) database->smdb_sync(database, 0);
341
342 if (!unmake && geteuid() == 0 && TrustedUid != 0)
343 {
344 errno = database->smdb_set_owner(database, TrustedUid, -1);
345 if (errno != SMDBE_OK)
346 {
336 exit(EX_CANTCREAT);
337 }
338
339 (void) database->smdb_sync(database, 0);
340
341 if (!unmake && geteuid() == 0 && TrustedUid != 0)
342 {
343 errno = database->smdb_set_owner(database, TrustedUid, -1);
344 if (errno != SMDBE_OK)
345 {
347 fprintf(stderr,
348 "WARNING: ownership change on %s failed %s",
349 mapname, errstring(errno));
346 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
347 "WARNING: ownership change on %s failed %s",
348 mapname, sm_errstring(errno));
350 }
351 }
352
353 /*
354 ** Copy the data
355 */
356
357 exitstat = EX_OK;
358 if (unmake)
359 {
360 errno = database->smdb_cursor(database, &cursor, 0);
361 if (errno != SMDBE_OK)
362 {
363
349 }
350 }
351
352 /*
353 ** Copy the data
354 */
355
356 exitstat = EX_OK;
357 if (unmake)
358 {
359 errno = database->smdb_cursor(database, &cursor, 0);
360 if (errno != SMDBE_OK)
361 {
362
364 fprintf(stderr,
365 "%s: cannot make cursor for type %s map %s\n",
366 progname, typename, mapname);
363 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
364 "%s: cannot make cursor for type %s map %s\n",
365 progname, typename, mapname);
367 exit(EX_SOFTWARE);
368 }
369
370 memset(&db_key, '\0', sizeof db_key);
371 memset(&db_val, '\0', sizeof db_val);
372
373 for (lineno = 0; ; lineno++)
374 {
375 errno = cursor->smdbc_get(cursor, &db_key, &db_val,
376 SMDB_CURSOR_GET_NEXT);
377 if (errno != SMDBE_OK)
378 break;
379
366 exit(EX_SOFTWARE);
367 }
368
369 memset(&db_key, '\0', sizeof db_key);
370 memset(&db_val, '\0', sizeof db_val);
371
372 for (lineno = 0; ; lineno++)
373 {
374 errno = cursor->smdbc_get(cursor, &db_key, &db_val,
375 SMDB_CURSOR_GET_NEXT);
376 if (errno != SMDBE_OK)
377 break;
378
380 printf("%.*s\t%.*s\n",
381 (int) db_key.size,
382 (char *) db_key.data,
383 (int) db_val.size,
384 (char *)db_val.data);
379 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
380 "%.*s\t%.*s\n",
381 (int) db_key.size,
382 (char *) db_key.data,
383 (int) db_val.size,
384 (char *)db_val.data);
385
386 }
387 (void) cursor->smdbc_close(cursor);
388 }
389 else
390 {
391 lineno = 0;
385
386 }
387 (void) cursor->smdbc_close(cursor);
388 }
389 else
390 {
391 lineno = 0;
392 while (fgets(ibuf, sizeof ibuf, stdin) != NULL)
392 while (sm_io_fgets(smioin, SM_TIME_DEFAULT, ibuf, sizeof ibuf)
393 != NULL)
393 {
394 register char *p;
395
396 lineno++;
397
398 /*
399 ** Parse the line.
400 */
401
402 p = strchr(ibuf, '\n');
403 if (p != NULL)
404 *p = '\0';
394 {
395 register char *p;
396
397 lineno++;
398
399 /*
400 ** Parse the line.
401 */
402
403 p = strchr(ibuf, '\n');
404 if (p != NULL)
405 *p = '\0';
405 else if (!feof(stdin))
406 else if (!sm_io_eof(smioin))
406 {
407 {
407 fprintf(stderr,
408 "%s: %s: line %d: line too long (%ld bytes max)\n",
409 progname, mapname, lineno, (long) sizeof ibuf);
408 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
409 "%s: %s: line %u: line too long (%ld bytes max)\n",
410 progname, mapname, lineno,
411 (long) sizeof ibuf);
410 exitstat = EX_DATAERR;
411 continue;
412 }
413
412 exitstat = EX_DATAERR;
413 continue;
414 }
415
414 if (ibuf[0] == '\0' || ibuf[0] == '#')
416 if (ibuf[0] == '\0' || ibuf[0] == comment)
415 continue;
417 continue;
416 if (
417#if _FFR_DELIM
418 sep == '\0' &&
419#endif /* _FFR_DELIM */
420 isascii(ibuf[0]) && isspace(ibuf[0]))
418 if (sep == '\0' && isascii(ibuf[0]) && isspace(ibuf[0]))
421 {
419 {
422 fprintf(stderr,
423 "%s: %s: line %d: syntax error (leading space)\n",
424 progname, mapname, lineno);
420 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
421 "%s: %s: line %u: syntax error (leading space)\n",
422 progname, mapname, lineno);
425 exitstat = EX_DATAERR;
426 continue;
427 }
428
429 memset(&db_key, '\0', sizeof db_key);
430 memset(&db_val, '\0', sizeof db_val);
431 db_key.data = ibuf;
432
433 for (p = ibuf; *p != '\0' && !(ISSEP(*p)); p++)
434 {
435 if (foldcase && isascii(*p) && isupper(*p))
436 *p = tolower(*p);
437 }
438 db_key.size = p - ibuf;
439 if (inclnull)
440 db_key.size++;
441
442 if (*p != '\0')
443 *p++ = '\0';
423 exitstat = EX_DATAERR;
424 continue;
425 }
426
427 memset(&db_key, '\0', sizeof db_key);
428 memset(&db_val, '\0', sizeof db_val);
429 db_key.data = ibuf;
430
431 for (p = ibuf; *p != '\0' && !(ISSEP(*p)); p++)
432 {
433 if (foldcase && isascii(*p) && isupper(*p))
434 *p = tolower(*p);
435 }
436 db_key.size = p - ibuf;
437 if (inclnull)
438 db_key.size++;
439
440 if (*p != '\0')
441 *p++ = '\0';
444 while (ISSEP(*p))
442 while (*p != '\0' && ISSEP(*p))
445 p++;
446 if (!allowempty && *p == '\0')
447 {
443 p++;
444 if (!allowempty && *p == '\0')
445 {
448 fprintf(stderr,
449 "%s: %s: line %d: no RHS for LHS %s\n",
450 progname, mapname, lineno,
451 (char *) db_key.data);
446 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
447 "%s: %s: line %u: no RHS for LHS %s\n",
448 progname, mapname, lineno,
449 (char *) db_key.data);
452 exitstat = EX_DATAERR;
453 continue;
454 }
455
456 db_val.data = p;
457 db_val.size = strlen(p);
458 if (inclnull)
459 db_val.size++;
460
461 /*
462 ** Do the database insert.
463 */
464
465 if (verbose)
466 {
450 exitstat = EX_DATAERR;
451 continue;
452 }
453
454 db_val.data = p;
455 db_val.size = strlen(p);
456 if (inclnull)
457 db_val.size++;
458
459 /*
460 ** Do the database insert.
461 */
462
463 if (verbose)
464 {
467 printf("key=`%s', val=`%s'\n",
468 (char *) db_key.data,
469 (char *) db_val.data);
465 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
466 "key=`%s', val=`%s'\n",
467 (char *) db_key.data,
468 (char *) db_val.data);
470 }
471
472 errno = database->smdb_put(database, &db_key, &db_val,
473 putflags);
474 switch (errno)
475 {
476 case SMDBE_KEY_EXIST:
477 st = 1;

--- 5 unchanged lines hidden (view full) ---

483
484 default:
485 st = -1;
486 break;
487 }
488
489 if (st < 0)
490 {
469 }
470
471 errno = database->smdb_put(database, &db_key, &db_val,
472 putflags);
473 switch (errno)
474 {
475 case SMDBE_KEY_EXIST:
476 st = 1;

--- 5 unchanged lines hidden (view full) ---

482
483 default:
484 st = -1;
485 break;
486 }
487
488 if (st < 0)
489 {
491 fprintf(stderr,
492 "%s: %s: line %d: key %s: put error: %s\n",
493 progname, mapname, lineno,
494 (char *) db_key.data,
495 errstring(errno));
490 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
491 "%s: %s: line %u: key %s: put error: %s\n",
492 progname, mapname, lineno,
493 (char *) db_key.data,
494 sm_errstring(errno));
496 exitstat = EX_IOERR;
497 }
498 else if (st > 0)
499 {
495 exitstat = EX_IOERR;
496 }
497 else if (st > 0)
498 {
500 fprintf(stderr,
501 "%s: %s: line %d: key %s: duplicate key\n",
502 progname, mapname,
503 lineno, (char *) db_key.data);
499 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
500 "%s: %s: line %u: key %s: duplicate key\n",
501 progname, mapname,
502 lineno,
503 (char *) db_key.data);
504 exitstat = EX_DATAERR;
505 }
506 }
507 }
508
509 /*
510 ** Now close the database.
511 */
512
513 errno = database->smdb_close(database);
514 if (errno != SMDBE_OK)
515 {
504 exitstat = EX_DATAERR;
505 }
506 }
507 }
508
509 /*
510 ** Now close the database.
511 */
512
513 errno = database->smdb_close(database);
514 if (errno != SMDBE_OK)
515 {
516 fprintf(stderr, "%s: close(%s): %s\n",
517 progname, mapname, errstring(errno));
516 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
517 "%s: close(%s): %s\n",
518 progname, mapname, sm_errstring(errno));
518 exitstat = EX_IOERR;
519 }
520 smdb_free_database(database);
521
522 exit(exitstat);
519 exitstat = EX_IOERR;
520 }
521 smdb_free_database(database);
522
523 exit(exitstat);
524
523 /* NOTREACHED */
524 return exitstat;
525}
525 /* NOTREACHED */
526 return exitstat;
527}
526
527/*VARARGS1*/
528void
529#ifdef __STDC__
530message(const char *msg, ...)
531#else /* __STDC__ */
532message(msg, va_alist)
533 const char *msg;
534 va_dcl
535#endif /* __STDC__ */
536{
537 const char *m;
538 VA_LOCAL_DECL
539
540 m = msg;
541 if (isascii(m[0]) && isdigit(m[0]) &&
542 isascii(m[1]) && isdigit(m[1]) &&
543 isascii(m[2]) && isdigit(m[2]) && m[3] == ' ')
544 m += 4;
545 VA_START(msg);
546 (void) vfprintf(stderr, m, ap);
547 VA_END;
548 (void) fprintf(stderr, "\n");
549}
550
551/*VARARGS1*/
552void
553#ifdef __STDC__
554syserr(const char *msg, ...)
555#else /* __STDC__ */
556syserr(msg, va_alist)
557 const char *msg;
558 va_dcl
559#endif /* __STDC__ */
560{
561 const char *m;
562 VA_LOCAL_DECL
563
564 m = msg;
565 if (isascii(m[0]) && isdigit(m[0]) &&
566 isascii(m[1]) && isdigit(m[1]) &&
567 isascii(m[2]) && isdigit(m[2]) && m[3] == ' ')
568 m += 4;
569 VA_START(msg);
570 (void) vfprintf(stderr, m, ap);
571 VA_END;
572 (void) fprintf(stderr, "\n");
573}