|
Packit Service |
09cdfc |
/*
|
|
Packit Service |
09cdfc |
* ID Mapping Plugin interface for cifs-utils
|
|
Packit Service |
09cdfc |
* Copyright (C) 2012 Jeff Layton (jlayton@samba.org)
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Service |
09cdfc |
* it under the terms of the GNU General Public License as published by
|
|
Packit Service |
09cdfc |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
09cdfc |
* (at your option) any later version.
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
09cdfc |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
09cdfc |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
09cdfc |
* GNU General Public License for more details.
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
09cdfc |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
#include <stdint.h>
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
#ifndef _CIFSIDMAP_H
|
|
Packit Service |
09cdfc |
#define _CIFSIDMAP_H
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
#define NUM_AUTHS (6) /* number of authority fields */
|
|
Packit Service |
09cdfc |
#define SID_MAX_SUB_AUTHORITIES (15) /* max number of sub authority fields */
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/*
|
|
Packit Service |
09cdfc |
* Binary representation of a SID as presented to/from the kernel. Note that
|
|
Packit Service |
09cdfc |
* the sub_auth field is always stored in little-endian here.
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
struct cifs_sid {
|
|
Packit Service |
09cdfc |
uint8_t revision; /* revision level */
|
|
Packit Service |
09cdfc |
uint8_t num_subauth;
|
|
Packit Service |
09cdfc |
uint8_t authority[NUM_AUTHS];
|
|
Packit Service |
09cdfc |
uint32_t sub_auth[SID_MAX_SUB_AUTHORITIES];
|
|
Packit Service |
09cdfc |
} __attribute__((packed));
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/*
|
|
Packit Service |
09cdfc |
* The type of the ID stored within cifs_uxid. UNKNOWN generally means that
|
|
Packit Service |
09cdfc |
* the mapping failed for some reason. BOTH means that the ID is usable as
|
|
Packit Service |
09cdfc |
* either a UID or a GID -- IOW, the UID and GID namespaces are unity-mapped.
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
#define CIFS_UXID_TYPE_UNKNOWN (0) /* mapping type is unknown */
|
|
Packit Service |
09cdfc |
#define CIFS_UXID_TYPE_UID (1) /* mapping is a UID */
|
|
Packit Service |
09cdfc |
#define CIFS_UXID_TYPE_GID (2) /* mapping is a GID */
|
|
Packit Service |
09cdfc |
#define CIFS_UXID_TYPE_BOTH (3) /* usable as UID or GID */
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/* This struct represents a uid or gid and its type */
|
|
Packit Service |
09cdfc |
struct cifs_uxid {
|
|
Packit Service |
09cdfc |
union {
|
|
Packit Service |
09cdfc |
uid_t uid;
|
|
Packit Service |
09cdfc |
gid_t gid;
|
|
Packit Service |
09cdfc |
} id;
|
|
Packit Service |
09cdfc |
unsigned char type;
|
|
Packit Service |
09cdfc |
} __attribute__((packed));
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/*
|
|
Packit Service |
09cdfc |
* Plugins should implement the following functions:
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/**
|
|
Packit Service |
09cdfc |
* cifs_idmap_init_plugin - Initialize the plugin interface
|
|
Packit Service |
09cdfc |
* @handle - return pointer for an opaque handle
|
|
Packit Service |
09cdfc |
* @errmsg - pointer to error message pointer
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* This function should do whatever is required to establish a context
|
|
Packit Service |
09cdfc |
* for later ID mapping operations. The "handle" is an opaque context
|
|
Packit Service |
09cdfc |
* cookie that will be passed in on subsequent ID mapping operations.
|
|
Packit Service |
09cdfc |
* The errmsg is used to pass back an error string both during the init
|
|
Packit Service |
09cdfc |
* and in subsequent idmapping functions. On any error, the plugin
|
|
Packit Service |
09cdfc |
* should point *errmsg at a string describing that error. Returns 0
|
|
Packit Service |
09cdfc |
* on success and non-zero on error.
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
extern int cifs_idmap_init_plugin(void **handle, const char **errmsg);
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/**
|
|
Packit Service |
09cdfc |
* cifs_idmap_exit_plugin - Destroy an idmapping context
|
|
Packit Service |
09cdfc |
* @handle - context handle that should be destroyed
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* When programs are finished with the idmapping plugin, they'll call
|
|
Packit Service |
09cdfc |
* this function to destroy any context that was created during the
|
|
Packit Service |
09cdfc |
* init_plugin. The handle passed back in was the one given by the init
|
|
Packit Service |
09cdfc |
* routine.
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
extern void cifs_idmap_exit_plugin(void *handle);
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/**
|
|
Packit Service |
09cdfc |
* cifs_idmap_sid_to_str - convert cifs_sid to a string
|
|
Packit Service |
09cdfc |
* @handle - context handle
|
|
Packit Service |
09cdfc |
* @sid - pointer to a cifs_sid
|
|
Packit Service |
09cdfc |
* @name - return pointer for the name
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* This function should convert the given cifs_sid to a string
|
|
Packit Service |
09cdfc |
* representation or mapped name in a heap-allocated buffer. The caller
|
|
Packit Service |
09cdfc |
* of this function is expected to free "name" on success. Returns 0 on
|
|
Packit Service |
09cdfc |
* success and non-zero on error. On error, the errmsg pointer passed
|
|
Packit Service |
09cdfc |
* in to the init_plugin function should point to an error string. The
|
|
Packit Service |
09cdfc |
* caller will not free the error string.
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
extern int cifs_idmap_sid_to_str(void *handle, const struct cifs_sid *sid,
|
|
Packit Service |
09cdfc |
char **name);
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/**
|
|
Packit Service |
09cdfc |
* cifs_idmap_str_to_sid - convert string to struct cifs_sid
|
|
Packit Service |
09cdfc |
* @handle - context handle
|
|
Packit Service |
09cdfc |
* @name - pointer to name string to be converted
|
|
Packit Service |
09cdfc |
* @sid - pointer to struct cifs_sid where result should go
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* This function converts a name string or string representation of
|
|
Packit Service |
09cdfc |
* a SID to a struct cifs_sid. The cifs_sid should already be
|
|
Packit Service |
09cdfc |
* allocated. Returns 0 on success and non-zero on error. On error, the
|
|
Packit Service |
09cdfc |
* plugin should reset the errmsg pointer passed to the init_plugin
|
|
Packit Service |
09cdfc |
* function to an error string. The caller will not free the error string.
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
extern int cifs_idmap_str_to_sid(void *handle, const char *name,
|
|
Packit Service |
09cdfc |
struct cifs_sid *sid);
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/**
|
|
Packit Service |
09cdfc |
* cifs_idmap_sids_to_ids - convert struct cifs_sids to struct cifs_uxids
|
|
Packit Service |
09cdfc |
* @handle - context handle
|
|
Packit Service |
09cdfc |
* @sid - pointer to array of struct cifs_sids to be converted
|
|
Packit Service |
09cdfc |
* @num - number of sids to be converted
|
|
Packit Service |
09cdfc |
* @cuxid - pointer to preallocated array of struct cifs_uxids for return
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* This function should map an array of struct cifs_sids to an array of
|
|
Packit Service |
09cdfc |
* struct cifs_uxids.
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* Returns 0 if at least one conversion was successful and non-zero on error.
|
|
Packit Service |
09cdfc |
* Any that were not successfully converted will have a cuxid->type of
|
|
Packit Service |
09cdfc |
* CIFS_UXID_TYPE_UNKNOWN.
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* On any error, the plugin should reset the errmsg pointer passed to the
|
|
Packit Service |
09cdfc |
* init_plugin function to an error string. The caller will not free the error
|
|
Packit Service |
09cdfc |
* string.
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
extern int cifs_idmap_sids_to_ids(void *handle, const struct cifs_sid *sid,
|
|
Packit Service |
09cdfc |
const size_t num, struct cifs_uxid *cuxid);
|
|
Packit Service |
09cdfc |
|
|
Packit Service |
09cdfc |
/**
|
|
Packit Service |
09cdfc |
* cifs_idmap_ids_to_sids - convert uid to struct cifs_sid
|
|
Packit Service |
09cdfc |
* @handle - context handle
|
|
Packit Service |
09cdfc |
* @cuxid - pointer to array of struct cifs_uxid to be converted to SIDs
|
|
Packit Service |
09cdfc |
* @num - number of cifs_uxids to be converted to SIDs
|
|
Packit Service |
09cdfc |
* @sid - pointer to preallocated array of struct cifs_sid where results
|
|
Packit Service |
09cdfc |
* should be stored
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* This function should map an array of cifs_uxids an array of struct cifs_sids.
|
|
Packit Service |
09cdfc |
* Returns 0 if at least one conversion was successful and non-zero on error.
|
|
Packit Service |
09cdfc |
* Any sids that were not successfully converted should have their revision
|
|
Packit Service |
09cdfc |
* number set to 0.
|
|
Packit Service |
09cdfc |
*
|
|
Packit Service |
09cdfc |
* On any error, the plugin should reset the errmsg pointer passed to the
|
|
Packit Service |
09cdfc |
* init_plugin function to an error string. The caller will not free the error
|
|
Packit Service |
09cdfc |
* string.
|
|
Packit Service |
09cdfc |
*/
|
|
Packit Service |
09cdfc |
extern int cifs_idmap_ids_to_sids(void *handle, const struct cifs_uxid *cuxid,
|
|
Packit Service |
09cdfc |
const size_t num, struct cifs_sid *sid);
|
|
Packit Service |
09cdfc |
#endif /* _CIFSIDMAP_H */
|