manifest_hash.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <libintl.h>
#include <libscf.h>
#include <libuutil.h>
#include <limits.h>
#include <md5.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <manifest_hash.h>
/*
* Translate a file name to property name. Return an allocated string or NULL
* if realpath() fails.
*/
char *
mhash_filename_to_propname(const char *in)
{
return (NULL);
}
/*
* We copy-shift over the basedir and the leading slash, since it's
* not relevant to when we boot with this repository.
*/
if (*cp == '/')
cp++;
/* Use the first half and the second half. */
piece_len + 1);
}
/*
* Translate non-property characters to '_', first making sure that
* we don't begin with '_'.
*/
*out = 'A';
*cp = '_';
}
return (out);
}
int
{
int result = 0;
/*
* In this implementation the hash for name is the opaque value of
* svc:/MHASH_SVC/:properties/name/MHASH_PROP
*/
result = -1;
goto out;
}
result = -1;
goto out;
}
result = -1;
goto out;
}
result = -1;
goto out;
}
result = -1;
goto out;
}
result = -1;
goto out;
}
if (szret < 0) {
result = -1;
goto out;
}
if (szret != MHASH_SIZE) {
result = -1;
goto out;
}
out:
(void) scf_value_destroy(val);
return (result);
}
int
char **errstr)
{
scf_transaction_entry_t *e = NULL;
int i;
result = -1;
goto out;
}
result = -1;
goto out;
}
for (i = 0; i < 5; ++i) {
break;
if (scf_error() != SCF_ERROR_NOT_FOUND) {
"service");
result = -1;
goto out;
}
break;
if (err == SCF_ERROR_EXISTS)
/* Try again. */
continue;
else if (err == SCF_ERROR_PERMISSION_DENIED) {
"permission denied.\n");
result = -1;
goto out;
}
"service");
result = -1;
goto out;
}
if (i == 5) {
"service addition contention.\n");
result = -1;
goto out;
}
for (i = 0; i < 5; ++i) {
break;
if (scf_error() != SCF_ERROR_NOT_FOUND) {
"hash record)");
result = -1;
goto out;
}
break;
if (err == SCF_ERROR_EXISTS)
/* Try again. */
continue;
else if (err == SCF_ERROR_PERMISSION_DENIED) {
"permission denied.\n");
result = -1;
goto out;
}
result = -1;
goto out;
}
if (i == 5) {
"property group addition contention.\n");
result = -1;
goto out;
}
"permission denied.\n");
result = -1;
goto out;
}
result = -1;
goto out;
}
do {
"entry");
result = -1;
goto out;
}
if (scf_error() != SCF_ERROR_PERMISSION_DENIED) {
"hash transaction.\n");
result = -1;
goto out;
}
"permission denied.\n");
result = -1;
(void) scf_entry_destroy(e);
goto out;
}
SCF_TYPE_OPAQUE) != SCF_SUCCESS &&
SCF_TYPE_OPAQUE) != SCF_SUCCESS) {
"entry");
result = -1;
goto out;
}
if (ret == 0)
} while (ret == 0);
if (ret < 0) {
if (scf_error() != SCF_ERROR_PERMISSION_DENIED) {
"permission denied.\n");
result = -1;
goto out;
}
result = -1;
}
(void) scf_entry_destroy(e);
out:
(void) scf_value_destroy(val);
return (result);
}
/*
* int mhash_test_file(scf_handle_t *, const char *, uint_t, char **, uchar_t *)
* Test the given filename against the hashed metadata in the repository.
* The behaviours for import and apply are slightly different. For imports,
* if the hash value is absent or different, then the import operation
* continues. For profile application, the operation continues only if the
* hash value for the file is absent.
*
* Return non-zero if we should skip the file because it is unchanged or
* nonexistent.
*/
int
{
char *cp;
char *data;
char *pname;
int ret;
/*
* In the case where we are doing automated imports, we reduce the UID,
* the GID, the size, and the mtime into a string (to eliminate
* endianness) which we then make opaque as a single MD5 digest.
*
* The previous hash was composed of the inode number, the UID, the file
* size, and the mtime. This formulation was found to be insufficiently
* portable for use in highly replicated deployments. The current
* algorithm will allow matches of this "v1" hash, but always returns
* the effective "v2" hash, such that updates result in the more
* portable hash being used.
*
* If neither calculated digest matches the stored value, we consider
* the test to have failed, implying that some aspect of the manifest
* has changed.
*/
if (!do_hash) {
return (0);
}
do
if (ret < 0) {
return (-1);
}
return (-1);
}
return (-1);
if (is_profile) {
return (1);
}
/*
* Manifest import.
*/
return (1);
/*
* No match on V2 hash; compare V1 hash.
*/
return (-1);
return (1);
}
return (0);
}