예제 #1
0
파일: db3.c 프로젝트: 2014-class/freerouter
static krb5_error_code
DB_lock(krb5_context context, HDB *db, int operation)
{
    DB *d = (DB*)db->hdb_db;
    int fd;
    if ((*d->fd)(d, &fd))
	return HDB_ERR_CANT_LOCK_DB;
    return hdb_lock(fd, operation);
}
예제 #2
0
파일: db.c 프로젝트: 2asoft/freebsd
static krb5_error_code
DB_lock(krb5_context context, HDB *db, int operation)
{
    DB *d = (DB*)db->hdb_db;
    int fd = (*d->fd)(d);
    if(fd < 0) {
	krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
			       "Can't lock database: %s", db->hdb_name);
	return HDB_ERR_CANT_LOCK_DB;
    }
    return hdb_lock(fd, operation);
}
예제 #3
0
static krb5_error_code
DB_lock(krb5_context context, HDB *db, int operation)
{
    DB *d = (DB*)db->hdb_db;
    int fd;
    krb5_error_code ret;

    if (db->lock_count > 1) {
	db->lock_count++;
	if (db->lock_count == HDB_WLOCK || db->lock_count == operation)
	    return 0;
    }

    if ((*d->fd)(d, &fd))
	return HDB_ERR_CANT_LOCK_DB;
    ret = hdb_lock(fd, operation);
    if (ret)
	return ret;
    db->lock_count++;
    return 0;
}
예제 #4
0
파일: ndbm.c 프로젝트: 0x24bin/winexe-1
static krb5_error_code
NDBM_lock(krb5_context context, HDB *db, int operation)
{
    struct ndbm_db *d = db->hdb_db;
    return hdb_lock(d->lock_fd, operation);
}
예제 #5
0
파일: ndbm.c 프로젝트: 0x24bin/winexe-1
static krb5_error_code
NDBM_rename(krb5_context context, HDB *db, const char *new_name)
{
    /* XXX this function will break */
    struct ndbm_db *d = db->hdb_db;

    int ret;
    char *old_dir, *old_pag, *new_dir, *new_pag;
    char *new_lock;
    int lock_fd;

    /* lock old and new databases */
    ret = db->hdb_lock(context, db, HDB_WLOCK);
    if(ret)
	return ret;
    asprintf(&new_lock, "%s.lock", new_name);
    if(new_lock == NULL) {
	db->hdb_unlock(context, db);
	krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
	return ENOMEM;
    }
    lock_fd = open(new_lock, O_RDWR | O_CREAT, 0600);
    if(lock_fd < 0) {
	ret = errno;
	db->hdb_unlock(context, db);
	krb5_set_error_message(context, ret, "open(%s): %s", new_lock,
			       strerror(ret));
	free(new_lock);
	return ret;
    }
    free(new_lock);
    ret = hdb_lock(lock_fd, HDB_WLOCK);
    if(ret) {
	db->hdb_unlock(context, db);
	close(lock_fd);
	return ret;
    }

    asprintf(&old_dir, "%s.dir", db->hdb_name);
    asprintf(&old_pag, "%s.pag", db->hdb_name);
    asprintf(&new_dir, "%s.dir", new_name);
    asprintf(&new_pag, "%s.pag", new_name);

    ret = rename(old_dir, new_dir) || rename(old_pag, new_pag);
    free(old_dir);
    free(old_pag);
    free(new_dir);
    free(new_pag);
    hdb_unlock(lock_fd);
    db->hdb_unlock(context, db);

    if(ret) {
	ret = errno;
	close(lock_fd);
	krb5_set_error_message(context, ret, "rename: %s", strerror(ret));
	return ret;
    }

    close(d->lock_fd);
    d->lock_fd = lock_fd;

    free(db->hdb_name);
    db->hdb_name = strdup(new_name);
    return 0;
}
예제 #6
0
static krb5_error_code
NDBM_rename(krb5_context context, HDB *db, const char *new_name)
{
    int ret;
    char *old_dir, *old_pag, *new_dir, *new_pag;
    int old_lock_fd, new_lock_fd;

    /* lock old and new databases */
    ret = open_lock_file(context, db->hdb_name, &old_lock_fd);
    if (ret)
	return ret;

    ret = hdb_lock(old_lock_fd, HDB_WLOCK);
    if(ret) {
	close(old_lock_fd);
	return ret;
    }

    ret = open_lock_file(context, new_name, &new_lock_fd);
    if (ret) {
	hdb_unlock(old_lock_fd);
	close(old_lock_fd);
	return ret;
    }

    ret = hdb_lock(new_lock_fd, HDB_WLOCK);
    if(ret) {
	hdb_unlock(old_lock_fd);
	close(old_lock_fd);
	close(new_lock_fd);
	return ret;
    }

    asprintf(&old_dir, "%s.dir", db->hdb_name);
    asprintf(&old_pag, "%s.pag", db->hdb_name);
    asprintf(&new_dir, "%s.dir", new_name);
    asprintf(&new_pag, "%s.pag", new_name);

    ret = rename(old_dir, new_dir) || rename(old_pag, new_pag);
    if (ret) {
	ret = errno;
	if (ret == 0)
	    ret = EPERM;
	krb5_set_error_message(context, ret, "rename: %s", strerror(ret));
    }

    free(old_dir);
    free(old_pag);
    free(new_dir);
    free(new_pag);

    hdb_unlock(new_lock_fd);
    hdb_unlock(old_lock_fd);
    close(new_lock_fd);
    close(old_lock_fd);

    if(ret)
	return ret;

    free(db->hdb_name);
    db->hdb_name = strdup(new_name);
    return 0;
}