dict.c revision c7402f0767d7a0360fabd0bd449c6baf9b282074
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <syslog.h>
#include <fcntl.h>
#include <time.h>
#include <errno.h>
#include <signal.h>
#include "packer.h"
static int lockfd = -1;
#define LOCK_WAIT 1000000
#define LOCK_RETRIES 60
/*
* lock_db()
*
* Create a lockfile to prevent simultaneous access to the database
* creation routines. We set a timeout to LOCK_WAIT seconds. If we
* haven't obtained a lock after LOCK_RETIRES attempts, we bail out.
*
* returns 0 on succes, -1 on (lock) failure.
* side effect: the directory "path" will be created if it didn't exist.
*/
int
{
int retval;
int retries = 0;
/* create directory "path" if it doesn't exist */
return (-1);
}
if (lockfd == -1) {
return (-1);
}
}
do {
if (retval == -1)
if (retval == -1) {
int errno_saved = errno;
"waiting for dictionary lock.");
errno = errno_saved;
}
return (retval);
}
/*
* unlock_db()
*
* Release the database lock
*/
void
unlock_db(void)
{
if (lockfd != -1) {
lockfd = -1;
}
}
/*
* database_present()
*
* returns 0 if the database files are found, and the database size is
* greater than 0 and the database version matches the current version.
*/
int
database_present(char *path)
{
return (NO_DICTDATABASE);
/* verify database version number by trying to open it */
/* the files are there, but an outdated version */
return (NO_DICTDATABASE);
}
return (0);
}
/*
* build_dict_database(list, char *path)
*
* Create the Crack Dictionary Database based on the list of sources
* dictionaries specified in "list". Store the database in "path".
*/
int
{
}
/*
* Rebuild the database in "path" if the database is older than one of the
* files listed in "list", or older than the config-file PWADMIN.
*/
int
{
char *buf;
char *listcopy;
return (DICTFILE_ERR);
return (DICTFILE_ERR);
/* Compare mtime of each listed dictionary against DB mtime */
"pam_authtok_check:update_dict_database: "
"dictionary \"%s\" not present.", buf);
} else {
"pam_authtok_check:update_dict_database: "
"stat(%s) failed: %s", buf,
}
return (DICTFILE_ERR);
}
}
/*
* Because this is the only way we can check if files have been
* Drawback: the database will also be generated when other
* tunables are changed.
*/
if (update_needed) {
/*
* Since we actually rebuild the database, we need to remove
* the old database first.
*/
}
return (0);
}
/*
* Build or update database, while holding the global lock.
*/
int
{
int r = -1;
else
unlock_db();
}
return (r);
}