mk-amd-map.c (38500) | mk-amd-map.c (38575) |
---|---|
1/* 2 * Copyright (c) 1997-1998 Erez Zadok 3 * Copyright (c) 1990 Jan-Simon Pendry 4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by --- 24 unchanged lines hidden (view full) --- 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * %W% (Berkeley) %G% 40 * | 1/* 2 * Copyright (c) 1997-1998 Erez Zadok 3 * Copyright (c) 1990 Jan-Simon Pendry 4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by --- 24 unchanged lines hidden (view full) --- 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * %W% (Berkeley) %G% 40 * |
41 * $Id: mk-amd-map.c,v 1.1.1.1 1998/08/23 22:07:21 obrien Exp $ | 41 * $Id: mk-amd-map.c,v 1.2 1998/08/23 22:52:09 obrien Exp $ |
42 */ 43 44/* 45 * Convert a file map into an ndbm map 46 */ 47 48#ifdef HAVE_CONFIG_H 49# include <config.h> 50#endif /* HAVE_CONFIG_H */ 51#include <am_defs.h> 52 53/* dummy variables */ | 42 */ 43 44/* 45 * Convert a file map into an ndbm map 46 */ 47 48#ifdef HAVE_CONFIG_H 49# include <config.h> 50#endif /* HAVE_CONFIG_H */ 51#include <am_defs.h> 52 53/* dummy variables */ |
54char *progname; | |
55char hostname[MAXHOSTNAMELEN]; 56int orig_umask, foreground, debug_flags; 57pid_t mypid; 58serv_state amd_state; 59 60 61#ifdef HAVE_MAP_NDBM 62 --- 151 unchanged lines hidden (view full) --- 214main(int argc, char *argv[]) 215{ 216 FILE *mapf; 217 int mapfd = -1; 218 char *map; 219 int rc = 0; 220 DBM *mapd = NULL; 221 static char maptmp[] = "dbmXXXXXX"; | 54char hostname[MAXHOSTNAMELEN]; 55int orig_umask, foreground, debug_flags; 56pid_t mypid; 57serv_state amd_state; 58 59 60#ifdef HAVE_MAP_NDBM 61 --- 151 unchanged lines hidden (view full) --- 213main(int argc, char *argv[]) 214{ 215 FILE *mapf; 216 int mapfd = -1; 217 char *map; 218 int rc = 0; 219 DBM *mapd = NULL; 220 static char maptmp[] = "dbmXXXXXX"; |
222 char maptpag[16], maptdir[16]; 223 char *mappag = (char *) NULL, *mapdir = (char *) NULL; | 221 char maptdb[16]; 222 char *mapdb = (char *) NULL; |
224 int len; 225 char *sl; 226 int printit = 0; 227 int usage = 0; 228 int ch; 229 extern int optind; 230 231 /* test options */ --- 22 unchanged lines hidden (view full) --- 254 perror(map); 255 exit(1); 256 } 257 map = sl + 1; 258 } 259 260 if (!printit) { 261 len = strlen(map); | 223 int len; 224 char *sl; 225 int printit = 0; 226 int usage = 0; 227 int ch; 228 extern int optind; 229 230 /* test options */ --- 22 unchanged lines hidden (view full) --- 253 perror(map); 254 exit(1); 255 } 256 map = sl + 1; 257 } 258 259 if (!printit) { 260 len = strlen(map); |
262 mappag = (char *) malloc(len + 5); 263 mapdir = (char *) malloc(len + 5); 264 if (!mappag || !mapdir) { | 261 mapdb = (char *) malloc(len + 4); 262 if (!mapdb) { |
265 perror("mk-amd-map: malloc"); 266 exit(1); 267 } 268#ifdef HAVE_MKSTEMP 269 mapfd = mkstemp(maptmp); 270#else /* not HAVE_MKSTEMP */ 271 map = mktemp(maptmp); 272 if (!maptmp) { 273 fprintf(stderr, "cannot create temporary file\n"); 274 exit(1); 275 } 276 mapfd = open(map, O_RDONLY); 277#endif /* not HAVE_MKSTEMP */ 278 279 /* open DBM files */ | 263 perror("mk-amd-map: malloc"); 264 exit(1); 265 } 266#ifdef HAVE_MKSTEMP 267 mapfd = mkstemp(maptmp); 268#else /* not HAVE_MKSTEMP */ 269 map = mktemp(maptmp); 270 if (!maptmp) { 271 fprintf(stderr, "cannot create temporary file\n"); 272 exit(1); 273 } 274 mapfd = open(map, O_RDONLY); 275#endif /* not HAVE_MKSTEMP */ 276 277 /* open DBM files */ |
280 sprintf(maptpag, "%s.pag", maptmp); 281 sprintf(maptdir, "%s.dir", maptmp); 282 if (remove_file(maptpag) < 0 || remove_file(maptdir) < 0) { 283 fprintf(stderr, "Can't remove existing temporary files; %s and", maptpag); 284 perror(maptdir); | 278 sprintf(maptdb, "%s.db", maptmp); 279 if (remove_file(maptdb) < 0) { 280 fprintf(stderr, "Can't remove existing temporary files;"); 281 perror(maptdb); |
285 exit(1); 286 } 287 } 288 /* open and check if map file was opened OK */ 289 mapf = fdopen(mapfd, "r"); 290 if (mapf && !printit) 291 mapd = dbm_open(maptmp, O_RDWR|O_CREAT, 0444); 292 else 293 mapd = 0; 294 295#ifndef DEBUG 296 /* ignore ^C if debuggung is on (but why?) */ 297 signal(SIGINT, SIG_IGN); 298#endif /* not DEBUG */ 299 300 if (mapd || printit) { 301 int error = read_file(mapf, map, mapd); 302 (void) close(mapfd); 303 (void) fclose(mapf); | 282 exit(1); 283 } 284 } 285 /* open and check if map file was opened OK */ 286 mapf = fdopen(mapfd, "r"); 287 if (mapf && !printit) 288 mapd = dbm_open(maptmp, O_RDWR|O_CREAT, 0444); 289 else 290 mapd = 0; 291 292#ifndef DEBUG 293 /* ignore ^C if debuggung is on (but why?) */ 294 signal(SIGINT, SIG_IGN); 295#endif /* not DEBUG */ 296 297 if (mapd || printit) { 298 int error = read_file(mapf, map, mapd); 299 (void) close(mapfd); 300 (void) fclose(mapf); |
304 dbm_close(mapd); | 301 dbm_close(mapd); |
305 if (printit) { 306 if (error) { 307 fprintf(stderr, "Error creating ndbm map for %s\n", map); 308 rc = 1; 309 } 310 } else { 311 312 if (error) { 313 fprintf(stderr, "Error reading source file %s\n", map); 314 rc = 1; 315 } else { | 302 if (printit) { 303 if (error) { 304 fprintf(stderr, "Error creating ndbm map for %s\n", map); 305 rc = 1; 306 } 307 } else { 308 309 if (error) { 310 fprintf(stderr, "Error reading source file %s\n", map); 311 rc = 1; 312 } else { |
316 sprintf(mappag, "%s.pag", map); 317 sprintf(mapdir, "%s.dir", map); 318 if (rename(maptpag, mappag) < 0) { 319 fprintf(stderr, "Couldn't rename %s to ", maptpag); 320 perror(mappag); | 313 sprintf(mapdb, "%s.db", map); 314 if (unlink(mapdb) == 0) 315 fprintf(stderr, "WARNING: existing map \"%s.db\" destroyed\n", map); 316 if (rename(maptdb, mapdb) < 0) { 317 fprintf(stderr, "Couldn't rename %s to ", maptdb); 318 perror(mapdb); |
321 /* Throw away the temporary map */ | 319 /* Throw away the temporary map */ |
322 unlink(maptpag); 323 unlink(maptdir); | 320 unlink(maptdb); |
324 rc = 1; | 321 rc = 1; |
325 326 } else if (rename(maptdir, mapdir) < 0) { 327 fprintf(stderr, "Couldn't rename %s to ", maptdir); 328 perror(mapdir); 329 /* Put the .pag file back */ 330 rename(mappag, maptpag); 331 /* Throw away remaining part of original map */ 332 unlink(mapdir); 333 fprintf(stderr, 334 "WARNING: existing map \"%s.{dir,pag}\" destroyed\n", 335 map); 336 rc = 1; | |
337 } 338 } 339 } 340 341 } else { | 322 } 323 } 324 } 325 326 } else { |
342 fprintf(stderr, "Can't open \"%s.{dir,pag}\" for ", map); | 327 fprintf(stderr, "Can't open \"%s.db\" for ", map); |
343 perror("writing"); 344 rc = 1; 345 } 346 exit(rc); 347} 348 349#else /* not HAVE_MAP_NDBM */ 350 351main() 352{ 353 fputs("mk-amd-map: This system does not support hashed database files\n", stderr); 354 exit(1); 355} 356 357#endif /* not HAVE_MAP_NDBM */ | 328 perror("writing"); 329 rc = 1; 330 } 331 exit(rc); 332} 333 334#else /* not HAVE_MAP_NDBM */ 335 336main() 337{ 338 fputs("mk-amd-map: This system does not support hashed database files\n", stderr); 339 exit(1); 340} 341 342#endif /* not HAVE_MAP_NDBM */ |