Open Files 5.3.0
Multi-Platform Event-Driven Application Framework
smbinit.c

This is a common initialization module for the smbcp class of commands. It will perform a manual initialization, configuration, and startup of the stack if needed.

/* Copyright (c) 2021 Connected Way, LLC. All rights reserved.
* Use of this source code is unrestricted
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <unistd.h>
#include <time.h>
#include <ofc/config.h>
#include <ofc/framework.h>
#include <ofc/handle.h>
#include <ofc/types.h>
#include <ofc/file.h>
#include <ofc/waitset.h>
#include <ofc/queue.h>
#if !defined(INIT_ON_LOAD)
/*
* Forward Declaration of explicit configuration routine
*/
void smbcp_configure(void);
#endif
void smbcp_init(void)
{
#if defined(INIT_ON_LOAD)
/*
* Force an SMB library load, which will force initialization
*/
volatile OFC_VOID *init = of_smb_init;
#else
/*
* Explicit Open Files Initialization
*/
/*
* Configure the stack either through persistent configuration or
* explicitly through APIs
*/
smbcp_configure();
/*
* Startup SMB. The argument is a handle to a scheduler (i.e. a
* run loop thread. If Null, one will be created for it
*/
#endif
}
#if !defined(INIT_ON_LOAD)
void disable_smb_dialects(void)
{
}
void generate_uuid(char *uuid)
{
const char *chars = "0123456789abcdef";
int i;
srand((unsigned int)time(NULL));
for (i = 0; i < 36; i++)
{
if (i == 8 || i == 13 || i == 18 || i == 23)
{
uuid[i] = '-';
}
else if (i == 14)
{
uuid[i] = '4';
}
else if (i == 19)
{
uuid[i] = chars[(rand() % 4) + 8];
}
else
{
uuid[i] = chars[rand() % 16];
}
}
uuid[36] = '\0';
}
void smbcp_configure(void)
{
#if defined(OFC_PERSIST)
/*
* Our build supports loading configuration from a file.
* We can either specify the file to load, or we can
* specify NULL which will implicity specify a default
* location for the platform. NOTE: not all platforms
* have a default os to be safe, you probably should
* explicitly specify the location.
*/
#else
/*
* We will explicity configure the stack.
*
* Set up the network. Openfiles supports network
* autoconfiguration which is useful if the objective
* is to bring up all interfaces available on the platform
* and to have it adapt to interfaces dynamically coming
* on and offline. Manual network configuration is useful
* if you wish to use a WINS server (which cannot be
* autoconfigured). NOTE: If autoconfiguration is off
* there is no reason to have Network Monitoring On.
* Network Monitoring will monitor for interface interruption.
*/
#if defined(SMBCP_NETWORK_AUTOCONFIG)
#else
/*
* Turn off interface discovery
*/
/*
* Add an interface. This is done by filling in an
* framework interface structure add calling
* ofc_framework_add_interface
*/
/*
* Configure WINS (PMODE) mode.
* Other mode are Broadcast (BMODE), Mixed (MMODE), and
* Hybrid (HMODE). Mixed is broadcast first, if that
* fails, then WINS. Hybrid is WINS first, then broadcast.
*/
/*
* Configure the IP address. The IP address is an
* OFC_IPADDR which can initialized by a call to
* ofc_pton. NOTE: Be sure to retrieve and specify
* the actual IP you wish to use.
*/
ofc_pton("0.0.0.0", &iface.ip);
ofc_pton("255.255.255.255", &iface.bcast);
ofc_pton("0.0.0.0", &iface.mask);
/*
* Local Master Browser is not supported in SMBv2. Deprecated
* but specify as NULL.
*/
iface.lmb = OFC_NULL;
/*
* Build a WINS list
* A wins list consists of a count of wins servers followed
* by a pointer to an array of WINS ip addresses
* The wins list can be statically or dynamically allocated.
* If you are dynamically allocating it, make sure you
* free it after the ofc_framework_add_interface call.
*/
OFC_IPADDR winsaddr[2];
/* Change these to appropriate values for your configuration */
ofc_pton("192.168.1.61", &winsaddr[0]);
ofc_pton("192.168.1.62", &winsaddr[1]);
iface.wins.num_wins = 2;
iface.wins.winsaddr = winsaddr;
/*
* Now add the interface
*/
#endif
/*
* Set up logging. We want to log INFO messages and
* higher. Don't log to the console. On Linux,
* This will log to syslog
*/
/*
* Set the host name
* This is not required for a client. It is never used.
* The fields are the hostname, the workgroup/domain name,
* and a description
*/
ofc_framework_set_host_name(TSTR("example"), TSTR("example.com"),
TSTR("Example Host"));
/*
* It is also possible to configure drives which is similar to
* aliases. In other words, you can set a tag for a particular
* destination. This would be done by calls to ofc_framework_add_map
* Typically this is only done by the Android app so won't
* be documented here.
*/
/*
* Enable Netbios
*/
/*
* Before calling this routine, we had made a call to of_smb_init.
* That will have enabled all smb dialects. If you wish to enable
* a single smb dialect, we can disable all, then enable just
* the one we wish.
*/
disable_smb_dialects();
/*
* Now enable just 3.1.1.
*/
/*
* Set the UUID. This needs to be unique per client.
*/
static OFC_CHAR uuid[37];
generate_uuid(uuid);
/*
* Set the default realm
* You will want to adjust this for your config. You can skip this step
* if you are setting the default realm in krb5.conf or you are not
* using Kerberos authentication
*/
ofc_framework_set_realm("DOUBLEDOUBLEU.COM");
/*
* bootstrap_dcs can be explicity specified, but if
* not set, DFS will query DNS. So no need to configure
*/
/*
* There is configuration for supported ciphers, but by
* default we specify both AES-128-GCM and AES-128-CCM.
* There should never be a reason to change this
*/
/*
* There is also a configuration for max smb version but
* by default we specify SMB 3.11. There should never be
* a reason to change this.
*/
#endif
}
#endif
void smbcp_deactivate(void)
{
#if !defined(INIT_ON_LOAD)
/*
* Shutdown and deactivate SMB
*/
/*
* Shutdown and deactivate the core framework
*/
#endif
}
#define OFC_HANDLE_NULL
Definition: handle.h:64
OFC_CORE_LIB OFC_VOID ofc_framework_set_logging(OFC_UINT log_level, OFC_BOOL log_console)
OFC_CORE_LIB OFC_VOID ofc_framework_set_host_name(OFC_LPCTSTR name, OFC_LPCTSTR workgroup, OFC_LPCTSTR desc)
OFC_CORE_LIB OFC_VOID ofc_framework_load(OFC_LPCTSTR filename)
OFC_CORE_LIB OFC_VOID ofc_framework_set_netbios(OFC_BOOL enabled)
OFC_CORE_LIB OFC_VOID ofc_framework_destroy(OFC_VOID)
OFC_VOID ofc_framework_add_interface(OFC_FRAMEWORK_INTERFACE *iface)
OFC_CORE_LIB OFC_VOID ofc_framework_startup(OFC_VOID)
OFC_CORE_LIB OFC_VOID ofc_framework_shutdown(OFC_VOID)
@ OFC_CONFIG_HMODE
Definition: framework.h:143
OFC_CORE_LIB OFC_VOID ofc_framework_init(OFC_VOID)
OFC_VOID ofc_framework_set_realm(const OFC_CHAR *realm)
OFC_VOID ofc_framework_set_interface_discovery(OFC_BOOL on)
OFC_VOID ofc_framework_set_uuid(const OFC_CHAR *cuuid)
OF_SMB_LIB OFC_VOID of_smb_shutdown(OFC_VOID)
OF_SMB_LIB OFC_VOID of_smb_init(OFC_VOID)
OF_SMB_LIB OFC_VOID of_smb_enable_dialect(OFC_UINT dialect)
OF_SMB_LIB OFC_VOID of_smb_destroy(OFC_VOID)
OF_SMB_LIB OFC_VOID of_smb_disable_dialect(OFC_UINT dialect)
OF_SMB_LIB OFC_VOID of_smb_startup(OFC_HANDLE hScheduler)
Definition: framework.h:150
OFC_FRAMEWORK_WINSLIST wins
Definition: framework.h:156
OFC_IPADDR ip
Definition: framework.h:152
OFC_CONFIG_MODE netBiosMode
Definition: framework.h:151
OFC_IPADDR mask
Definition: framework.h:154
OFC_LPCSTR lmb
Definition: framework.h:155
OFC_IPADDR bcast
Definition: framework.h:153
OFC_IPADDR * winsaddr
Array of Wins IP addresses.
Definition: framework.h:129
OFC_INT num_wins
Number of Wins IP addresses.
Definition: framework.h:128
@ OFC_FALSE
Definition: types.h:632
@ OFC_TRUE
Definition: types.h:636
void OFC_VOID
Definition: types.h:159
@ OFC_LOG_INFO
Definition: types.h:649
#define OFC_NULL
Definition: types.h:656
char OFC_CHAR
Definition: types.h:143
#define TSTR(x)
Definition: types.h:534