示例#1
0
static bool tdbsam_new_rid(struct pdb_methods *methods, uint32 *prid)
{
	uint32 rid;

	rid = BASE_RID;		/* Default if not set */

	if (!tdbsam_open(tdbsam_filename)) {
		DEBUG(0,("tdbsam_new_rid: failed to open %s!\n",
			tdbsam_filename));
		return false;
	}

	if (dbwrap_change_uint32_atomic(db_sam, NEXT_RID_STRING, &rid, 1) != 0) {
		DEBUG(3, ("tdbsam_new_rid: Failed to increase %s\n",
			NEXT_RID_STRING));
		return false;
	}

	*prid = rid;

	return true;
}
示例#2
0
/*
  Allocate a new id. 
*/
static NTSTATUS idmap_tdb2_allocate_id(struct unixid *xid)
{
	bool ret;
	const char *hwmkey;
	const char *hwmtype;
	uint32_t high_hwm;
	uint32_t hwm;
	int res;
	NTSTATUS status;

	status = idmap_tdb2_open_db();
	NT_STATUS_NOT_OK_RETURN(status);

	/* Get current high water mark */
	switch (xid->type) {

	case ID_TYPE_UID:
		hwmkey = HWM_USER;
		hwmtype = "UID";
		high_hwm = idmap_tdb2_state.high_uid;
		break;

	case ID_TYPE_GID:
		hwmkey = HWM_GROUP;
		hwmtype = "GID";
		high_hwm = idmap_tdb2_state.high_gid;
		break;

	default:
		DEBUG(2, ("Invalid ID type (0x%x)\n", xid->type));
		return NT_STATUS_INVALID_PARAMETER;
	}

	res = idmap_tdb2->transaction_start(idmap_tdb2);
	if (res != 0) {
		DEBUG(1,(__location__ " Failed to start transaction\n"));
		return NT_STATUS_UNSUCCESSFUL;
	}

	if ((hwm = dbwrap_fetch_int32(idmap_tdb2, hwmkey)) == -1) {
		idmap_tdb2->transaction_cancel(idmap_tdb2);
		return NT_STATUS_INTERNAL_DB_ERROR;
	}

	/* check it is in the range */
	if (hwm > high_hwm) {
		DEBUG(1, ("Fatal Error: %s range full!! (max: %lu)\n", 
			  hwmtype, (unsigned long)high_hwm));
		idmap_tdb2->transaction_cancel(idmap_tdb2);
		return NT_STATUS_UNSUCCESSFUL;
	}

	/* fetch a new id and increment it */
	ret = dbwrap_change_uint32_atomic(idmap_tdb2, hwmkey, &hwm, 1);
	if (ret == -1) {
		DEBUG(1, ("Fatal error while fetching a new %s value\n!", hwmtype));
		idmap_tdb2->transaction_cancel(idmap_tdb2);
		return NT_STATUS_UNSUCCESSFUL;
	}

	/* recheck it is in the range */
	if (hwm > high_hwm) {
		DEBUG(1, ("Fatal Error: %s range full!! (max: %lu)\n", 
			  hwmtype, (unsigned long)high_hwm));
		idmap_tdb2->transaction_cancel(idmap_tdb2);
		return NT_STATUS_UNSUCCESSFUL;
	}

	res = idmap_tdb2->transaction_commit(idmap_tdb2);
	if (res != 0) {
		DEBUG(1,(__location__ " Failed to commit transaction\n"));
		return NT_STATUS_UNSUCCESSFUL;
	}
	
	xid->id = hwm;
	DEBUG(10,("New %s = %d\n", hwmtype, hwm));

	return NT_STATUS_OK;
}