8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / mkpwdict / mkpwdict.c
blob18ce36b135cb8fb6923d544bb8c281a3048897ce
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <string.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <errno.h>
33 #include <deflt.h>
34 #include <locale.h>
35 #include <libintl.h>
36 #include "packer.h"
38 char options[] = "s:d:";
40 char *pname;
42 void
43 fatal(char *msg)
45 (void) fprintf(stderr, "%s: Fatal error: %s. Database not remade.\n",
46 pname, msg);
47 exit(-1);
50 void
51 usage(void)
53 (void) fprintf(stderr,
54 "usage: %s [-s dict1,...,dictn ] [-d dest-path ]\n", pname);
55 exit(-1);
58 int
59 main(int argc, char *argv[])
61 char *default_dbdst = NULL;
62 char *default_dbsrc = NULL;
63 char *p;
65 char *dbdst = NULL;
66 char *dbsrc = NULL;
67 size_t dbsrc_len = 0;
68 int c;
69 int result;
71 (void) setlocale(LC_ALL, "");
73 if ((pname = strrchr(argv[0], '/')) == NULL)
74 pname = argv[0];
75 else
76 pname++;
78 if (defopen(PWADMIN) == 0) {
79 if ((p = defread("DICTIONLIST=")) != NULL)
80 default_dbsrc = strdup(p);
81 if ((p = defread("DICTIONDBDIR=")) != NULL)
82 default_dbdst = strdup(p);
83 (void) defopen(NULL);
86 if (default_dbdst == NULL)
87 default_dbdst = CRACK_DIR;
89 while ((c = getopt(argc, argv, options)) != EOF) {
90 switch (c) {
91 case 's':
92 if (dbsrc != NULL) {
93 dbsrc_len += strlen(optarg) + 2; /* ',' + \0 */
94 if ((dbsrc = realloc(dbsrc, dbsrc_len)) == NULL)
95 fatal(strerror(errno));
96 (void) strlcat(dbsrc, ",", dbsrc_len);
97 (void) strlcat(dbsrc, optarg, dbsrc_len);
98 } else {
99 if ((dbsrc = strdup(optarg)) == NULL)
100 fatal(strerror(errno));
101 dbsrc_len = strlen(optarg) + 1;
103 break;
104 case 'd':
105 dbdst = optarg;
106 break;
107 default:
108 usage();
109 break;
112 if (optind != argc)
113 usage();
115 if (dbdst == NULL) {
116 (void) fprintf(stderr,
117 gettext("%s: using default database location: %s.\n"),
118 pname, default_dbdst);
119 dbdst = default_dbdst;
122 if (dbsrc == NULL)
123 if ((dbsrc = default_dbsrc) == NULL)
124 fatal(gettext("No source databases defined"));
125 else
126 (void) fprintf(stderr,
127 gettext("%s: using default dictionary list: %s.\n"),
128 pname, default_dbsrc);
130 if ((result = lock_db(dbdst)) == 0) {
131 PWRemove(dbdst);
132 result = build_dict_database(dbsrc, dbdst);
133 unlock_db();
135 if (result != 0)
136 fatal(strerror(errno));
137 return (0);