2007-12-12 18:14:54 +01:00
/*
* Unix SMB / CIFS implementation .
* NetApi Support
2008-01-07 12:44:25 +01:00
* Copyright ( C ) Guenther Deschner 2007 - 2008
2007-12-12 18:14:54 +01:00
*
* This program 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 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 "includes.h"
2017-09-05 13:37:41 +02:00
# include "../libcli/auth/netlogon_creds_cli.h"
2007-12-12 18:14:54 +01:00
# include "lib/netapi/netapi.h"
2008-04-10 22:04:04 +02:00
# include "lib/netapi/netapi_private.h"
2010-08-05 02:25:37 +02:00
# include "secrets.h"
2010-08-18 18:45:36 +02:00
# include "krb5_env.h"
2021-03-18 10:43:26 +01:00
# include "source3/param/loadparm.h"
# include "lib/param/param.h"
2021-03-18 10:57:10 +01:00
# include "auth/gensec/gensec.h"
2007-12-12 18:14:54 +01:00
2007-12-18 02:47:01 +01:00
struct libnetapi_ctx * stat_ctx = NULL ;
2007-12-12 18:14:54 +01:00
static bool libnetapi_initialized = false ;
2008-01-07 20:01:28 +01:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-07-01 20:14:36 +02:00
static NET_API_STATUS libnetapi_init_private_context ( struct libnetapi_ctx * ctx )
{
struct libnetapi_private_ctx * priv ;
if ( ! ctx ) {
2015-12-03 15:24:23 +01:00
return W_ERROR_V ( WERR_INVALID_PARAMETER ) ;
2008-07-01 20:14:36 +02:00
}
2011-06-07 11:44:43 +10:00
priv = talloc_zero ( ctx , struct libnetapi_private_ctx ) ;
2008-07-01 20:14:36 +02:00
if ( ! priv ) {
2015-12-03 15:24:14 +01:00
return W_ERROR_V ( WERR_NOT_ENOUGH_MEMORY ) ;
2008-07-01 20:14:36 +02:00
}
ctx - > private_data = priv ;
return NET_API_STATUS_SUCCESS ;
}
/****************************************************************
2010-11-21 20:40:50 +11:00
Create a libnetapi context , for use in non - Samba applications . This
loads the smb . conf file and sets the debug level to 0 , so that
applications are not flooded with debug logs at level 10 , when they
were not expecting it .
2008-07-01 20:14:36 +02:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-18 02:29:50 +01:00
NET_API_STATUS libnetapi_init ( struct libnetapi_ctx * * context )
2007-12-12 18:14:54 +01:00
{
2011-05-10 22:08:36 +02:00
NET_API_STATUS ret ;
TALLOC_CTX * frame ;
2023-09-07 14:34:36 +02:00
struct loadparm_context * lp_ctx = NULL ;
2007-12-18 02:47:01 +01:00
if ( stat_ctx & & libnetapi_initialized ) {
* context = stat_ctx ;
2008-01-07 18:36:06 +01:00
return NET_API_STATUS_SUCCESS ;
2007-12-12 18:14:54 +01:00
}
2008-04-17 14:09:29 +02:00
#if 0
2008-01-07 22:48:19 +01:00
talloc_enable_leak_report ( ) ;
# endif
2007-12-12 18:14:54 +01:00
frame = talloc_stackframe ( ) ;
2023-08-20 23:06:56 +03:00
lp_ctx = loadparm_init_s3 ( frame , loadparm_s3_helpers ( ) ) ;
if ( lp_ctx = = NULL ) {
TALLOC_FREE ( frame ) ;
return W_ERROR_V ( WERR_NOT_ENOUGH_MEMORY ) ;
}
2010-11-21 20:40:50 +11:00
/* When libnetapi is invoked from an application, it does not
* want to be swamped with level 10 debug messages , even if
* this has been set for the server in smb . conf */
2023-08-20 23:06:56 +03:00
lpcfg_set_cmdline ( lp_ctx , " log level " , " 0 " ) ;
2010-10-29 14:19:32 +11:00
setup_logging ( " libnetapi " , DEBUG_STDERR ) ;
2007-12-18 02:43:22 +01:00
2011-07-27 00:25:59 +02:00
if ( ! lp_load_global ( get_dyn_CONFIGFILE ( ) ) ) {
2007-12-12 18:14:54 +01:00
TALLOC_FREE ( frame ) ;
2009-06-29 08:12:03 +02:00
fprintf ( stderr , " error loading %s \n " , get_dyn_CONFIGFILE ( ) ) ;
2015-12-03 15:24:20 +01:00
return W_ERROR_V ( WERR_GEN_FAILURE ) ;
2007-12-12 18:14:54 +01:00
}
load_interfaces ( ) ;
reopen_logs ( ) ;
BlockSignals ( True , SIGPIPE ) ;
2023-09-07 14:53:22 +02:00
ret = libnetapi_net_init ( context , lp_ctx , NULL ) ;
2023-08-20 23:06:56 +03:00
if ( ret = = NET_API_STATUS_SUCCESS ) {
talloc_steal ( * context , lp_ctx ) ;
}
2011-05-10 22:08:36 +02:00
TALLOC_FREE ( frame ) ;
return ret ;
2010-11-21 20:40:50 +11:00
}
/****************************************************************
Create a libnetapi context , for use inside the ' net ' binary .
As we know net has already loaded the smb . conf file , and set the debug
level etc , this avoids doing so again ( which causes trouble with - d on
the command line ) .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2023-09-07 14:34:36 +02:00
NET_API_STATUS libnetapi_net_init ( struct libnetapi_ctx * * context ,
2023-09-07 14:53:22 +02:00
struct loadparm_context * lp_ctx ,
struct cli_credentials * creds )
2010-11-21 20:40:50 +11:00
{
NET_API_STATUS status ;
struct libnetapi_ctx * ctx = NULL ;
2023-08-20 23:50:38 +03:00
TALLOC_CTX * frame = NULL ;
2010-11-21 20:40:50 +11:00
2023-08-20 23:50:38 +03:00
if ( stat_ctx ! = NULL & & libnetapi_initialized ) {
* context = stat_ctx ;
return NET_API_STATUS_SUCCESS ;
}
frame = talloc_stackframe ( ) ;
2010-11-21 20:40:50 +11:00
ctx = talloc_zero ( frame , struct libnetapi_ctx ) ;
if ( ! ctx ) {
TALLOC_FREE ( frame ) ;
2015-12-03 15:24:14 +01:00
return W_ERROR_V ( WERR_NOT_ENOUGH_MEMORY ) ;
2010-11-21 20:40:50 +11:00
}
2023-08-20 23:06:56 +03:00
ctx - > lp_ctx = lp_ctx ;
2023-09-07 14:53:22 +02:00
ctx - > creds = creds ;
2021-03-18 10:43:26 +01:00
if ( ctx - > creds = = NULL ) {
2023-09-07 14:53:22 +02:00
ctx - > creds = cli_credentials_init ( ctx ) ;
if ( ctx - > creds = = NULL ) {
TALLOC_FREE ( frame ) ;
return W_ERROR_V ( WERR_NOT_ENOUGH_MEMORY ) ;
}
/* Ignore return code, as we might not have a smb.conf */
( void ) cli_credentials_guess ( ctx - > creds , lp_ctx ) ;
2021-03-18 10:43:26 +01:00
}
2010-11-21 20:40:50 +11:00
BlockSignals ( True , SIGPIPE ) ;
2008-07-01 20:14:36 +02:00
status = libnetapi_init_private_context ( ctx ) ;
if ( status ! = 0 ) {
TALLOC_FREE ( frame ) ;
return status ;
}
2007-12-12 18:14:54 +01:00
libnetapi_initialized = true ;
2011-05-10 22:08:36 +02:00
talloc_steal ( NULL , ctx ) ;
2007-12-18 02:47:01 +01:00
* context = stat_ctx = ctx ;
2023-08-20 23:06:56 +03:00
2011-05-10 22:08:36 +02:00
TALLOC_FREE ( frame ) ;
2008-01-07 18:36:06 +01:00
return NET_API_STATUS_SUCCESS ;
2007-12-12 18:14:54 +01:00
}
2008-01-07 20:01:28 +01:00
/****************************************************************
2010-11-24 17:59:41 +11:00
Return the static libnetapi context
2008-01-07 20:01:28 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-18 02:47:01 +01:00
NET_API_STATUS libnetapi_getctx ( struct libnetapi_ctx * * ctx )
{
if ( stat_ctx ) {
* ctx = stat_ctx ;
2008-01-07 18:36:06 +01:00
return NET_API_STATUS_SUCCESS ;
2007-12-18 02:47:01 +01:00
}
return libnetapi_init ( ctx ) ;
}
2008-01-07 20:01:28 +01:00
/****************************************************************
2010-11-24 17:59:41 +11:00
Free the static libnetapi context
2008-01-07 20:01:28 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-18 02:29:50 +01:00
NET_API_STATUS libnetapi_free ( struct libnetapi_ctx * ctx )
2007-12-12 18:14:54 +01:00
{
2012-07-18 15:07:28 +09:30
TALLOC_CTX * frame ;
2008-04-13 17:33:27 +02:00
if ( ! ctx ) {
return NET_API_STATUS_SUCCESS ;
}
2012-07-18 15:07:28 +09:30
frame = talloc_stackframe ( ) ;
2008-07-17 19:06:02 +02:00
libnetapi_samr_free ( ctx ) ;
2008-04-10 22:04:04 +02:00
libnetapi_shutdown_cm ( ctx ) ;
2008-01-08 11:49:35 +01:00
2007-12-18 02:47:01 +01:00
gfree_loadparm ( ) ;
gfree_charcnv ( ) ;
gfree_interfaces ( ) ;
2008-01-07 12:44:25 +01:00
secrets_shutdown ( ) ;
2017-07-24 16:12:45 -07:00
netlogon_creds_cli_close_global_db ( ) ;
2011-05-10 22:08:36 +02:00
if ( ctx = = stat_ctx ) {
stat_ctx = NULL ;
}
2007-12-12 18:14:54 +01:00
TALLOC_FREE ( ctx ) ;
2007-12-18 02:47:01 +01:00
gfree_debugsyms ( ) ;
2012-07-18 15:07:28 +09:30
talloc_free ( frame ) ;
2007-12-18 02:47:01 +01:00
2008-01-07 18:36:06 +01:00
return NET_API_STATUS_SUCCESS ;
2007-12-12 18:14:54 +01:00
}
2007-12-18 02:34:07 +01:00
2008-01-07 20:01:28 +01:00
/****************************************************************
2010-11-24 17:59:41 +11:00
Override the current log level for libnetapi
2008-01-07 20:01:28 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-18 02:43:22 +01:00
NET_API_STATUS libnetapi_set_debuglevel ( struct libnetapi_ctx * ctx ,
const char * debuglevel )
{
2011-05-10 22:08:36 +02:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2008-01-07 20:06:41 +01:00
ctx - > debuglevel = talloc_strdup ( ctx , debuglevel ) ;
2023-08-20 23:06:56 +03:00
if ( ! lpcfg_set_cmdline ( ctx - > lp_ctx , " log level " , debuglevel ) ) {
2011-05-10 22:08:36 +02:00
TALLOC_FREE ( frame ) ;
2015-12-03 15:24:20 +01:00
return W_ERROR_V ( WERR_GEN_FAILURE ) ;
2007-12-18 02:43:22 +01:00
}
2011-05-10 22:08:36 +02:00
TALLOC_FREE ( frame ) ;
2008-01-07 18:36:06 +01:00
return NET_API_STATUS_SUCCESS ;
2007-12-18 02:43:22 +01:00
}
2008-01-07 20:01:28 +01:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-02-15 17:33:46 +01:00
NET_API_STATUS libnetapi_set_logfile ( struct libnetapi_ctx * ctx ,
const char * logfile )
{
TALLOC_CTX * frame = talloc_stackframe ( ) ;
ctx - > logfile = talloc_strdup ( ctx , logfile ) ;
2023-08-20 23:06:56 +03:00
if ( ! lpcfg_set_cmdline ( ctx - > lp_ctx , " log file " , logfile ) ) {
2021-02-15 17:33:46 +01:00
TALLOC_FREE ( frame ) ;
return W_ERROR_V ( WERR_GEN_FAILURE ) ;
}
debug_set_logfile ( logfile ) ;
setup_logging ( " libnetapi " , DEBUG_FILE ) ;
TALLOC_FREE ( frame ) ;
return NET_API_STATUS_SUCCESS ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-18 02:43:22 +01:00
NET_API_STATUS libnetapi_get_debuglevel ( struct libnetapi_ctx * ctx ,
2008-01-07 20:06:41 +01:00
char * * debuglevel )
2007-12-18 02:43:22 +01:00
{
* debuglevel = ctx - > debuglevel ;
2008-01-07 18:36:06 +01:00
return NET_API_STATUS_SUCCESS ;
2007-12-18 02:43:22 +01:00
}
2008-01-07 20:01:28 +01:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-03-18 09:59:08 +01:00
/**
* @ brief Get the username of the libnet context
*
* @ param [ in ] ctx The netapi context
*
* @ param [ in ] username A pointer to hold the username .
*
* @ return 0 on success , an werror code otherwise .
*/
NET_API_STATUS libnetapi_get_username ( struct libnetapi_ctx * ctx ,
const char * * username )
{
if ( ctx = = NULL ) {
return W_ERROR_V ( WERR_INVALID_PARAMETER ) ;
}
if ( username ! = NULL ) {
2021-03-18 11:12:09 +01:00
* username = cli_credentials_get_username ( ctx - > creds ) ;
2021-03-18 09:59:08 +01:00
}
return NET_API_STATUS_SUCCESS ;
}
/**
* @ brief Get the password of the libnet context
*
* @ param [ in ] ctx The netapi context
*
* @ param [ in ] password A pointer to hold the password .
*
* @ return 0 on success , an werror code otherwise .
*/
NET_API_STATUS libnetapi_get_password ( struct libnetapi_ctx * ctx ,
const char * * password )
{
if ( ctx = = NULL ) {
return W_ERROR_V ( WERR_INVALID_PARAMETER ) ;
}
if ( password ! = NULL ) {
2021-03-18 11:12:09 +01:00
* password = cli_credentials_get_password ( ctx - > creds ) ;
2021-03-18 09:59:08 +01:00
}
return NET_API_STATUS_SUCCESS ;
}
2007-12-18 02:34:07 +01:00
NET_API_STATUS libnetapi_set_username ( struct libnetapi_ctx * ctx ,
const char * username )
{
2021-03-18 10:57:10 +01:00
if ( ctx = = NULL | | username = = NULL ) {
return W_ERROR_V ( WERR_INVALID_PARAMETER ) ;
}
cli_credentials_parse_string ( ctx - > creds , username , CRED_SPECIFIED ) ;
2008-01-07 18:36:06 +01:00
return NET_API_STATUS_SUCCESS ;
2007-12-18 02:34:07 +01:00
}
NET_API_STATUS libnetapi_set_password ( struct libnetapi_ctx * ctx ,
const char * password )
{
2021-03-18 10:57:10 +01:00
bool ok ;
if ( ctx = = NULL | | password = = NULL ) {
return W_ERROR_V ( WERR_INVALID_PARAMETER ) ;
}
ok = cli_credentials_set_password ( ctx - > creds , password , CRED_SPECIFIED ) ;
if ( ! ok ) {
return W_ERROR_V ( WERR_INTERNAL_ERROR ) ;
}
2008-01-07 18:36:06 +01:00
return NET_API_STATUS_SUCCESS ;
2007-12-18 02:34:07 +01:00
}
NET_API_STATUS libnetapi_set_workgroup ( struct libnetapi_ctx * ctx ,
const char * workgroup )
{
2021-03-18 10:57:10 +01:00
bool ok ;
ok = cli_credentials_set_domain ( ctx - > creds , workgroup , CRED_SPECIFIED ) ;
if ( ! ok ) {
return W_ERROR_V ( WERR_INTERNAL_ERROR ) ;
}
2008-01-07 18:36:06 +01:00
return NET_API_STATUS_SUCCESS ;
2007-12-18 02:34:07 +01:00
}
2007-12-19 12:09:08 +01:00
2021-03-18 13:34:15 +01:00
/**
* @ brief Set the cli_credentials to be used in the netapi context
*
* @ param [ in ] ctx The netapi context
*
* @ param [ in ] creds The cli_credentials which should be used by netapi .
*
* @ return 0 on success , an werror code otherwise .
*/
NET_API_STATUS libnetapi_set_creds ( struct libnetapi_ctx * ctx ,
struct cli_credentials * creds )
{
if ( ctx = = NULL | | creds = = NULL ) {
return W_ERROR_V ( WERR_INVALID_PARAMETER ) ;
}
ctx - > creds = creds ;
return NET_API_STATUS_SUCCESS ;
}
2008-01-07 20:01:28 +01:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-13 19:22:24 +02:00
NET_API_STATUS libnetapi_set_use_kerberos ( struct libnetapi_ctx * ctx )
{
2021-03-18 10:57:10 +01:00
cli_credentials_set_kerberos_state ( ctx - > creds ,
2020-08-19 15:46:11 +02:00
CRED_USE_KERBEROS_REQUIRED ,
CRED_SPECIFIED ) ;
2021-03-18 10:57:10 +01:00
2008-04-13 19:22:24 +02:00
return NET_API_STATUS_SUCCESS ;
}
2011-09-21 17:28:02 +02:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2021-04-08 22:14:41 +02:00
NET_API_STATUS libnetapi_get_use_kerberos ( struct libnetapi_ctx * ctx ,
int * use_kerberos )
{
enum credentials_use_kerberos creds_use_kerberos ;
* use_kerberos = 0 ;
creds_use_kerberos = cli_credentials_get_kerberos_state ( ctx - > creds ) ;
if ( creds_use_kerberos > CRED_USE_KERBEROS_DESIRED ) {
* use_kerberos = 1 ;
}
return NET_API_STATUS_SUCCESS ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-01-24 18:50:31 +01:00
NET_API_STATUS libnetapi_set_use_ccache ( struct libnetapi_ctx * ctx )
{
2021-03-18 10:57:10 +01:00
uint32_t gensec_features ;
gensec_features = cli_credentials_get_gensec_features ( ctx - > creds ) ;
gensec_features | = GENSEC_FEATURE_NTLM_CCACHE ;
2020-08-20 10:50:30 +02:00
cli_credentials_set_gensec_features ( ctx - > creds ,
gensec_features ,
CRED_SPECIFIED ) ;
2021-03-18 10:57:10 +01:00
2010-01-24 18:50:31 +01:00
return NET_API_STATUS_SUCCESS ;
}
2008-04-13 19:22:24 +02:00
/****************************************************************
2011-05-10 22:08:36 +02:00
Return a libnetapi error as a string , caller must free with NetApiBufferFree
2008-04-13 19:22:24 +02:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-05-10 22:08:36 +02:00
char * libnetapi_errstr ( NET_API_STATUS status )
2007-12-19 12:09:08 +01:00
{
2011-05-10 22:08:36 +02:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
char * ret ;
2007-12-21 15:30:29 +01:00
if ( status & 0xc0000000 ) {
2023-08-20 23:06:56 +03:00
ret = talloc_strdup ( NULL ,
2011-05-10 22:08:36 +02:00
get_friendly_nt_error_msg ( NT_STATUS ( status ) ) ) ;
2011-05-20 13:25:31 +02:00
} else {
ret = talloc_strdup ( NULL ,
get_friendly_werror_msg ( W_ERROR ( status ) ) ) ;
2007-12-19 12:09:08 +01:00
}
2011-05-10 22:08:36 +02:00
TALLOC_FREE ( frame ) ;
return ret ;
2007-12-19 12:09:08 +01:00
}
2008-01-07 20:06:41 +01:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
NET_API_STATUS libnetapi_set_error_string ( struct libnetapi_ctx * ctx ,
2008-01-18 01:56:01 +01:00
const char * format , . . . )
2008-01-07 20:06:41 +01:00
{
2008-01-18 01:56:01 +01:00
va_list args ;
2008-01-07 20:06:41 +01:00
TALLOC_FREE ( ctx - > error_string ) ;
2008-01-18 01:56:01 +01:00
va_start ( args , format ) ;
ctx - > error_string = talloc_vasprintf ( ctx , format , args ) ;
va_end ( args ) ;
2008-01-07 20:06:41 +01:00
if ( ! ctx - > error_string ) {
2015-12-03 15:24:14 +01:00
return W_ERROR_V ( WERR_NOT_ENOUGH_MEMORY ) ;
2008-01-07 20:06:41 +01:00
}
return NET_API_STATUS_SUCCESS ;
}
/****************************************************************
2011-05-10 22:08:36 +02:00
Return a libnetapi_errstr ( ) , caller must free with NetApiBufferFree
2008-01-07 20:06:41 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-05-10 22:08:36 +02:00
char * libnetapi_get_error_string ( struct libnetapi_ctx * ctx ,
2008-04-16 00:14:52 +02:00
NET_API_STATUS status_in )
2008-01-07 20:06:41 +01:00
{
2008-04-16 00:14:52 +02:00
NET_API_STATUS status ;
2008-01-11 14:47:23 +01:00
struct libnetapi_ctx * tmp_ctx = ctx ;
if ( ! tmp_ctx ) {
status = libnetapi_getctx ( & tmp_ctx ) ;
if ( status ! = 0 ) {
return NULL ;
}
}
if ( tmp_ctx - > error_string ) {
2011-05-10 22:08:36 +02:00
return talloc_strdup ( NULL , tmp_ctx - > error_string ) ;
2008-01-11 14:47:23 +01:00
}
2008-04-16 00:14:52 +02:00
return libnetapi_errstr ( status_in ) ;
2008-01-07 20:06:41 +01:00
}
2008-01-08 11:53:38 +01:00
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-08-01 16:44:05 +02:00
NET_API_STATUS NetApiBufferAllocate ( uint32_t byte_count ,
void * * buffer )
{
void * buf = NULL ;
if ( ! buffer ) {
return W_ERROR_V ( WERR_INSUFFICIENT_BUFFER ) ;
}
if ( byte_count = = 0 ) {
goto done ;
}
buf = talloc_size ( NULL , byte_count ) ;
if ( ! buf ) {
2015-12-03 15:24:14 +01:00
return W_ERROR_V ( WERR_NOT_ENOUGH_MEMORY ) ;
2008-08-01 16:44:05 +02:00
}
done :
* buffer = buf ;
return NET_API_STATUS_SUCCESS ;
}
/****************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-01-08 11:53:38 +01:00
NET_API_STATUS NetApiBufferFree ( void * buffer )
{
if ( ! buffer ) {
return W_ERROR_V ( WERR_INSUFFICIENT_BUFFER ) ;
}
talloc_free ( buffer ) ;
return NET_API_STATUS_SUCCESS ;
}