2 * builddbm.c Build a DBM file from an ASCII users file.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Copyright 2000 The FreeRADIUS server project
21 * Copyright 2000 Miquel van Smoorenburg <miquels@cistron.nl>
25 "@(#)builddbm.c 2.2 Copyright 1999 Cistron Internet Services";
29 #include <sys/types.h>
55 * Print a list of VALUE_PAIRS into a string,
56 * separated by comma's and closed off with a newline.
58 void makelist(char *out, int outlen, VALUE_PAIR *vp)
66 while (vp && outlen > 3) {
67 vp_prints(ptr, outlen, vp);
78 int main(int argc, char **argv)
81 char name[MAX_STRING_LEN];
98 if (dict_init(RADDBDIR, RADIUS_DICTIONARY) < 0) {
99 librad_perror("builddbm");
104 * Read the "users" file.
106 if ((users = pairlist_read(RADIUS_USERS, 1)) == NULL)
110 * Initialize a new, empty database.
114 if ((fd = open("users.pag", O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) {
115 fprintf(stderr, "%s: Couldn't open users.pag for writing\n",
120 if ((fd = open("users.dir", O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) {
121 fprintf(stderr, "%s: Couldn't open users.dir for writing\n",
126 if (dbminit("users") != 0) {
127 fprintf(stderr, "%s: ", progname);
128 perror("dbminit(users)");
133 if ((dbm = dbm_open("users", O_RDWR|O_CREAT|O_TRUNC, 0600)) == NULL) {
134 fprintf(stderr, "%s: ", progname);
135 perror("dbm_open(users)");
142 makelist(content, sizeof(content), users->check);
143 len = strlen(content);
144 makelist(content + len, sizeof(content) - len, users->reply);
146 strNcpy(name, users->name, sizeof(name));
147 if (strcmp(name, "DEFAULT") == 0) {
149 sprintf(name, "DEFAULT%d", defno);
153 named.dsize = strlen(name);
154 contentd.dptr = content;
155 contentd.dsize = strlen(content);
157 if (store(named, contentd) != 0)
160 if (dbm_store(dbm, named, contentd, DBM_INSERT) != 0)
163 fprintf(stderr, "%s: Couldn't store datum for %s\n",