98 lines
2.9 KiB
C
98 lines
2.9 KiB
C
/*
|
|
* security.c - Code for handling security/ACLs in NTFS. Part of the
|
|
* Linux-NTFS project.
|
|
*
|
|
* Copyright (c) 2004 Anton Altaparmakov
|
|
*
|
|
* This program/include file is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License as published
|
|
* by the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program/include file is distributed in the hope that it will be
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program (in the main directory of the Linux-NTFS
|
|
* distribution in the file COPYING); if not, write to the Free Software
|
|
* Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
|
|
#include "types.h"
|
|
#include "layout.h"
|
|
#include "security.h"
|
|
|
|
/*
|
|
* The zero GUID.
|
|
*/
|
|
static const GUID __zero_guid = { const_cpu_to_le32(0), const_cpu_to_le16(0),
|
|
const_cpu_to_le16(0), { 0, 0, 0, 0, 0, 0, 0, 0 } };
|
|
const GUID *const zero_guid = &__zero_guid;
|
|
|
|
/**
|
|
* ntfs_guid_is_zero - check if a GUID is zero
|
|
* @guid: guid to check
|
|
*
|
|
* Return TRUE if @guid is a valid pointer to a GUID and it is the zero GUID
|
|
* and FALSE otherwise.
|
|
*/
|
|
BOOL ntfs_guid_is_zero(const GUID *guid)
|
|
{
|
|
return (memcmp(guid, zero_guid, sizeof(*zero_guid)));
|
|
}
|
|
|
|
/**
|
|
* ntfs_guid_to_mbs - convert a GUID to a multi byte string
|
|
* @guid: guid to convert
|
|
* @guid_str: string in which to return the GUID (optional)
|
|
*
|
|
* Convert the GUID pointed to by @guid to a multi byte string of the form
|
|
* "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX". Therefore, @guid_str (if not NULL)
|
|
* needs to be able to store at least 37 bytes.
|
|
*
|
|
* If @guid_str is not NULL it will contain the converted GUID on return. If
|
|
* it is NULL a string will be allocated and this will be returned. The caller
|
|
* is responsible for free()ing the string in that case.
|
|
*
|
|
* On success return the converted string and on failure return NULL with errno
|
|
* set to the error code.
|
|
*/
|
|
char *ntfs_guid_to_mbs(const GUID *guid, char *guid_str)
|
|
{
|
|
char *_guid_str;
|
|
int res;
|
|
|
|
if (!guid) {
|
|
errno = EINVAL;
|
|
return NULL;
|
|
}
|
|
_guid_str = guid_str;
|
|
if (!_guid_str) {
|
|
_guid_str = malloc(37);
|
|
if (!_guid_str)
|
|
return _guid_str;
|
|
}
|
|
res = snprintf(_guid_str, 37,
|
|
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
|
le32_to_cpu(guid->data1),
|
|
le16_to_cpu(guid->data2), le16_to_cpu(guid->data3),
|
|
guid->data4[0], guid->data4[1],
|
|
guid->data4[2], guid->data4[3], guid->data4[4],
|
|
guid->data4[5], guid->data4[6], guid->data4[7]);
|
|
if (res == 36)
|
|
return _guid_str;
|
|
if (!guid_str)
|
|
free(_guid_str);
|
|
errno = EINVAL;
|
|
return NULL;
|
|
}
|