ad_gpo_child.c revision 9f0bffebd070115ab47a92eadc6890a721c7b78d
/*
SSSD
AD GPO Backend Module -- perform SMB and CSE processing in a child process
Authors:
Yassir Elley <yelley@redhat.com>
Copyright (C) 2013 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program 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. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unistd.h>
#include <popt.h>
#include <libsmbclient.h>
#include <ini_configobj.h>
#include <security/pam_modules.h>
#include "util/child_common.h"
#include "providers/dp_backend.h"
#include "sss_cli.h"
#define SMB_BUFFER_SIZE 65536
#define GPT_INI "/GPT.INI"
#define INI_GENERAL_SECTION "General"
#define GPT_INI_VERSION "Version"
struct input_buffer {
int cached_gpt_version;
const char *smb_server;
const char *smb_share;
const char *smb_path;
const char *smb_cse_suffix;
};
static errno_t
struct input_buffer *ibuf)
{
size_t p = 0;
/* cached_gpt_version */
/* smb_server */
if (len == 0) {
return EINVAL;
} else {
p += len;
}
/* smb_share */
if (len == 0) {
return EINVAL;
} else {
p += len;
}
/* smb_path */
if (len == 0) {
return EINVAL;
} else {
p += len;
}
/* smb_cse_suffix */
if (len == 0) {
return EINVAL;
} else {
p += len;
}
return EOK;
}
static errno_t
pack_buffer(struct response *r,
int sysvol_gpt_version,
int result)
{
size_t p = 0;
/* A buffer with the following structure must be created:
* uint32_t sysvol_gpt_version (required)
* uint32_t status of the request (required)
*/
return ENOMEM;
}
/* sysvol_gpt_version */
/* result */
return EOK;
}
static errno_t
int sysvol_gpt_version,
int result,
{
int ret;
if (r == NULL) {
return ENOMEM;
}
r->size = 0;
return ret;
}
*rsp = r;
return EOK;
}
static void
sssd_krb_get_auth_data_fn(const char * pServer,
const char * pShare,
char * pWorkgroup,
int maxLenWorkgroup,
char * pUsername,
int maxLenUsername,
char * pPassword,
int maxLenPassword)
{
/* since we are using kerberos for authentication, we simply return */
return;
}
/*
* This function prepares the gpo_cache by:
* - parsing the input_smb_path into its component directories
* - creating each component directory (if it doesn't already exist)
*/
const char *cache_dir,
const char *input_smb_path_with_suffix)
{
char *current_dir;
char *ptr;
const char delim = '/';
int num_dirs = 0;
int i;
char *smb_path_with_suffix = NULL;
if (smb_path_with_suffix == NULL) {
return ENOMEM;
}
if (current_dir == NULL) {
return ENOMEM;
}
ptr++;
num_dirs++;
}
for (i = 0; i < num_dirs; i++) {
return EINVAL;
}
*last = '\0';
last++;
if (current_dir == NULL) {
return ENOMEM;
}
return ret;
}
}
return EOK;
}
/*
* This function stores the input buf to a local file, whose file path
* is constructed by concatenating:
* GPO_CACHE_PATH,
* input smb_path,
* input smb_cse_suffix
* Note that the backend will later read the file from the same file path.
*/
const char *smb_cse_suffix,
int buflen)
{
int ret;
int fd = -1;
char *smb_path_with_suffix = NULL;
goto done;
}
if (smb_path_with_suffix == NULL) {
goto done;
}
/* create component directories of smb_path, if needed */
"prepare_gpo_cache failed [%d][%s]\n",
goto done;
}
goto done;
}
goto done;
}
if (fd == -1) {
goto done;
}
errno = 0;
if (written == -1) {
goto done;
}
"Write error, wrote [%zd] bytes, expected [%d]\n",
goto done;
}
if (ret == -1) {
goto done;
}
if (ret == -1) {
goto done;
}
if (ret == -1) {
goto done;
}
done:
}
return ret;
}
static errno_t
int *_gpt_version)
{
int ret;
int gpt_version;
if (ret != 0) {
goto done;
}
goto done;
}
if (ret != 0) {
"ini_get_int32_config_value failed [%d][%s]\n",
goto done;
}
done:
return ret;
}
/*
* This function parses the GPT_INI file stored in the gpo_cache, and uses the
* results to populate the output parameters ...
*/
static errno_t
ad_gpo_parse_ini_file(const char *smb_path,
int *_gpt_version)
{
const char *ini_filename;
int ret;
int gpt_version = -1;
goto done;
}
if (ini_filename == NULL) {
goto done;
}
if (ret != 0) {
goto done;
}
if (ret != 0) {
goto done;
}
if (ret != 0) {
goto done;
}
if (ret != 0) {
"parse_ini_file_with_libini failed [%d][%s]\n",
goto done;
}
done:
}
return ret;
}
/*
* This function uses the input smb uri components to download a sysvol file
* (e.g. INI file, policy file, etc) and store it to the GPO_CACHE directory.
*/
static errno_t
const char *smb_server,
const char *smb_share,
const char *smb_path,
const char *smb_cse_suffix)
{
int ret;
int buflen = 0;
return ENOMEM;
}
goto done;
}
errno = 0;
goto done;
}
goto done;
}
errno = 0;
if (buflen < 0) {
goto done;
}
"gpo_cache_store_file failed [%d][%s]\n",
goto done;
}
done:
return ret;
}
/*
* Using its smb_uri components and cached_gpt_version inputs, this function
* does several things:
* - it downloads the GPT_INI file to GPO_CACHE
* - it parses the sysvol_gpt_version field from the GPT_INI file
* - if the sysvol_gpt_version is greater than the cached_gpt_version
* - it downloads the policy file to GPO_CACHE
* - else
* - it doesn't retrieve the policy file
* - in this case, the backend will use the existing policy file in GPO_CACHE
* - it returns the sysvol_gpt_version in the _sysvol_gpt_version output param
*
* Note that if the cached_gpt_version sent by the backend is -1 (to indicate
* that no gpt_version has been set in the cache for the corresponding gpo_guid),
* then the parsed sysvol_gpt_version (which must be at least 0) will be greater
* than the cached_gpt_version, thereby triggering a fresh download.
*
* Note that the backend will later do the following:
* - backend will save the sysvol_gpt_version to sysdb cache
* - backend will read the policy file from the GPO_CACHE
*/
static errno_t
const char *smb_server,
const char *smb_share,
const char *smb_path,
const char *smb_cse_suffix,
int *_sysvol_gpt_version)
{
int ret;
int sysvol_gpt_version;
smbc_ctx = smbc_new_context();
goto done;
}
/* Initialize the context using the previously specified options */
goto done;
}
/* download ini file */
GPT_INI);
"copy_smb_file_to_gpo_cache failed [%d][%s]\n",
goto done;
}
goto done;
}
if (sysvol_gpt_version > cached_gpt_version) {
/* download policy file */
"copy_smb_file_to_gpo_cache failed [%d][%s]\n",
goto done;
}
}
done:
return ret;
}
int
{
int opt;
int debug_fd = -1;
int sysvol_gpt_version;
int result;
struct poptOption long_options[] = {
_("Debug level"), NULL},
_("Add debug timestamps"), NULL},
_("Show timestamps with microseconds"), NULL},
_("An open file descriptor for the debug logs"), NULL},
&debug_to_stderr, 0,
_("Send the debug output to stderr directly."), NULL },
};
/* Set debug level to invalid value so we can decide if -d 0 was used. */
switch(opt) {
default:
_exit(-1);
}
}
if (debug_prg_name == NULL) {
goto fail;
}
if (debug_fd != -1) {
}
}
goto fail;
}
goto fail;
}
goto fail;
}
errno = 0;
if (len == -1) {
goto fail;
}
goto fail;
}
"perform_smb_operations failed.[%d][%s].\n",
goto fail;
}
goto fail;
}
errno = 0;
if (written == -1) {
goto fail;
}
goto fail;
}
return EXIT_SUCCESS;
fail:
return EXIT_FAILURE;
}