switch (si->family) {
case AF_INET:
break;
+#ifdef HAVE_IPV6
case AF_INET6:
break;
+#endif
default:
return NULL;
}
become_daemon.o \
rbtree.o \
talloc_stack.o \
+ smb_threads.o \
params.o)
PUBLIC_HEADERS += $(addprefix $(libutilsrcdir)/, util.h \
#include "includes.h"
-#define NUM_GLOBAL_LOCKS 1
-
/*********************************************************
Functions to vector the locking primitives used internally
by libsmbclient.
global_tfp = tf;
+#if defined(PARANOID_MALLOC_CHECKER)
+#ifdef malloc
+#undef malloc
+#endif
+#endif
+
/* Here we initialize any static locks we're using. */
- global_lock_array = (void **)SMB_MALLOC_ARRAY(void *, NUM_GLOBAL_LOCKS);
+ global_lock_array = (void **)malloc(sizeof(void *) *NUM_GLOBAL_LOCKS);
+
+#if defined(PARANOID_MALLOC_CHECKER)
+#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY
+#endif
+
if (global_lock_array == NULL) {
return ENOMEM;
}
SAFE_FREE(global_lock_array);
return ENOMEM;
}
- global_tfp->create_mutex(name,
+ if (global_tfp->create_mutex(name,
&global_lock_array[i],
- __location__);
+ __location__)) {
+ smb_panic("smb_thread_set_functions: create mutexes failed");
+ }
SAFE_FREE(name);
}
SMB_THREADS_DEF_PTHREAD_IMPLEMENTATION(tf);
+void *pkey = NULL;
+
/* Test function. */
int test_threads(void)
{
int ret;
void *plock = NULL;
-
smb_thread_set_functions(&tf);
+ if ((ret = SMB_THREAD_CREATE_TLS_ONCE("test_tls", pkey)) != 0) {
+ printf("Create tls once error: %d\n", ret);
+ }
if ((ret = SMB_THREAD_CREATE_MUTEX("test", plock)) != 0) {
printf("Create lock error: %d\n", ret);
}
printf("unlock error: %d\n", ret);
}
SMB_THREAD_DESTROY_MUTEX(plock);
+ SMB_THREAD_DESTROY_TLS_ONCE(pkey);
return 0;
}
const char *location);
/* Thread local storage. */
- int (*create_tls)(const char *keyname,
+ int (*create_tls_once)(const char *keyname,
void **ppkey,
const char *location);
- void (*destroy_tls)(void *pkey,
+ void (*destroy_tls_once)(void **pkey,
const char *location);
int (*set_tls)(void *pkey, const void *pval, const char *location);
void *(*get_tls)(void *pkey, const char *location);
\
static int smb_create_mutex_pthread(const char *lockname, void **pplock, const char *location) \
{ \
- pthread_mutex_t *pmut = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); \
- if (!pmut) { \
- return ENOMEM; \
- } \
- pthread_mutex_init(pmut, NULL); \
- *pplock = (void *)pmut; \
- return 0; \
+ pthread_mutex_t *pmut = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); \
+ if (!pmut) { \
+ return ENOMEM; \
+ } \
+ pthread_mutex_init(pmut, NULL); \
+ *pplock = (void *)pmut; \
+ return 0; \
} \
\
static void smb_destroy_mutex_pthread(void *plock, const char *location) \
{ \
- pthread_mutex_destroy((pthread_mutex_t *)plock); \
+ pthread_mutex_destroy((pthread_mutex_t *)plock); \
free(plock); \
} \
\
static int smb_lock_pthread(void *plock, enum smb_thread_lock_type lock_type, const char *location) \
{ \
- if (lock_type == SMB_THREAD_UNLOCK) { \
- return pthread_mutex_unlock((pthread_mutex_t *)plock); \
- } else { \
- return pthread_mutex_lock((pthread_mutex_t *)plock); \
- } \
+ if (lock_type == SMB_THREAD_UNLOCK) { \
+ return pthread_mutex_unlock((pthread_mutex_t *)plock); \
+ } else { \
+ return pthread_mutex_lock((pthread_mutex_t *)plock); \
+ } \
} \
\
-static int smb_create_tls_pthread(const char *keyname, void **ppkey, const char *location) \
+static pthread_mutex_t create_tls_mutex = PTHREAD_MUTEX_INITIALIZER; \
+ \
+static int smb_create_tls_once_pthread(const char *keyname, void **ppkey, const char *location) \
{ \
- int ret; \
- pthread_key_t *pkey = (pthread_key_t *)malloc(sizeof(pthread_key_t)); \
- if (!pkey) { \
- return ENOMEM; \
- } \
- ret = pthread_key_create(pkey, NULL); \
- if (ret) { \
- return ret; \
- } \
- *ppkey = (void *)pkey; \
- return 0; \
+ int ret; \
+ pthread_key_t *pkey; \
+ ret = pthread_mutex_lock(&create_tls_mutex); \
+ if (ret) { \
+ return ret; \
+ } \
+ if (*ppkey) { \
+ pthread_mutex_unlock(&create_tls_mutex); \
+ return 0; \
+ } \
+ pkey = (pthread_key_t *)malloc(sizeof(pthread_key_t)); \
+ if (!pkey) { \
+ pthread_mutex_unlock(&create_tls_mutex); \
+ return ENOMEM; \
+ } \
+ ret = pthread_key_create(pkey, NULL); \
+ if (ret) { \
+ free(pkey); \
+ pthread_mutex_unlock(&create_tls_mutex); \
+ return ret; \
+ } \
+ *ppkey = (void *)pkey; \
+ pthread_mutex_unlock(&create_tls_mutex); \
+ return 0; \
} \
\
-static void smb_destroy_tls_pthread(void *pkey, const char *location) \
+static void smb_destroy_tls_once_pthread(void **ppkey, const char *location) \
{ \
- pthread_key_delete(*(pthread_key_t *)pkey); \
- free(pkey); \
+ pthread_mutex_lock(&create_tls_mutex); \
+ if (*ppkey) { \
+ pthread_key_delete(*(pthread_key_t *)ppkey); \
+ free(*ppkey); \
+ *ppkey = NULL; \
+ } \
+ pthread_mutex_unlock(&create_tls_mutex); \
} \
\
static int smb_set_tls_pthread(void *pkey, const void *pval, const char *location) \
smb_create_mutex_pthread, \
smb_destroy_mutex_pthread, \
smb_lock_pthread, \
- smb_create_tls_pthread, \
- smb_destroy_tls_pthread, \
+ smb_create_tls_once_pthread, \
+ smb_destroy_tls_once_pthread, \
smb_set_tls_pthread, \
smb_get_tls_pthread }
#define SMB_THREAD_LOCK(plock, type) \
(global_tfp ? global_tfp->lock_mutex((plock), (type), __location__) : 0)
-#define SMB_THREAD_CREATE_TLS(keyname, key) \
- (global_tfp ? global_tfp->create_tls((keyname), &(key), __location__) : 0)
+#define SMB_THREAD_CREATE_TLS_ONCE(keyname, key) \
+ (global_tfp ? global_tfp->create_tls_once((keyname), &(key), __location__) : 0)
-#define SMB_THREAD_DESTROY_TLS(key) \
+#define SMB_THREAD_DESTROY_TLS_ONCE(key) \
do { \
if (global_tfp) { \
- global_tfp->destroy_tls(key); \
+ global_tfp->destroy_tls_once(&(key), __location__); \
}; \
} while (0)
#define SMB_THREAD_SET_TLS(key, val) \
- (global_tfp ? global_tfp->set_tls((key),(val),__location__) : 0)
+ (global_tfp ? global_tfp->set_tls((key),(val),__location__) : \
+ ((key) = (val), 0))
#define SMB_THREAD_GET_TLS(key) \
- (global_tfp ? global_tfp->get_tls((key), __location__) : NULL)
+ (global_tfp ? global_tfp->get_tls((key), __location__) : (key))
+
+/*
+ * Global thread lock list.
+ */
+
+#define NUM_GLOBAL_LOCKS 1
+
+#define GLOBAL_LOCK(locknum) (global_lock_array ? global_lock_array[(locknum)] : NULL)
#endif
Unix SMB/CIFS implementation.
Implement a stack of talloc contexts
Copyright (C) Volker Lendecke 2007
+ Copyright (C) Jeremy Allison 2009 - made thread safe.
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
#include "includes.h"
-static int talloc_stacksize;
-static int talloc_stack_arraysize;
-static TALLOC_CTX **talloc_stack;
+struct talloc_stackframe {
+ int talloc_stacksize;
+ int talloc_stack_arraysize;
+ TALLOC_CTX **talloc_stack;
+};
+
+/*
+ * In the single threaded case this is a pointer
+ * to the global talloc_stackframe. In the MT-case
+ * this is the pointer to the thread-specific key
+ * used to look up the per-thread talloc_stackframe
+ * pointer.
+ */
+
+static void *global_ts;
+
+static struct talloc_stackframe *talloc_stackframe_init(void)
+{
+#if defined(PARANOID_MALLOC_CHECKER)
+#ifdef malloc
+#undef malloc
+#endif
+#endif
+ struct talloc_stackframe *ts =
+ (struct talloc_stackframe *)malloc(sizeof(struct talloc_stackframe));
+#if defined(PARANOID_MALLOC_CHECKER)
+#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY
+#endif
+
+ if (!ts) {
+ smb_panic("talloc_stackframe_init malloc failed");
+ }
+
+ ZERO_STRUCTP(ts);
+
+ if (SMB_THREAD_CREATE_TLS_ONCE("talloc_stackframe", global_ts)) {
+ smb_panic("talloc_stackframe_init create_tls failed");
+ }
+
+ if (SMB_THREAD_SET_TLS(global_ts, ts)) {
+ smb_panic("talloc_stackframe_init set_tls failed");
+ }
+ return ts;
+}
static int talloc_pop(TALLOC_CTX *frame)
{
+ struct talloc_stackframe *ts =
+ (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts);
int i;
- for (i=talloc_stacksize-1; i>0; i--) {
- if (frame == talloc_stack[i]) {
+ for (i=ts->talloc_stacksize-1; i>0; i--) {
+ if (frame == ts->talloc_stack[i]) {
break;
}
- talloc_free(talloc_stack[i]);
+ talloc_free(ts->talloc_stack[i]);
}
- talloc_stacksize = i;
+ ts->talloc_stacksize = i;
return 0;
}
static TALLOC_CTX *talloc_stackframe_internal(size_t poolsize)
{
TALLOC_CTX **tmp, *top, *parent;
+ struct talloc_stackframe *ts =
+ (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts);
- if (talloc_stack_arraysize < talloc_stacksize + 1) {
- tmp = talloc_realloc(NULL, talloc_stack, TALLOC_CTX *,
- talloc_stacksize + 1);
+ if (ts == NULL) {
+ ts = talloc_stackframe_init();
+ }
+
+ if (ts->talloc_stack_arraysize < ts->talloc_stacksize + 1) {
+ tmp = talloc_realloc(NULL, ts->talloc_stack, TALLOC_CTX *,
+ ts->talloc_stacksize + 1);
if (tmp == NULL) {
goto fail;
}
- talloc_stack = tmp;
- talloc_stack_arraysize = talloc_stacksize + 1;
+ ts->talloc_stack = tmp;
+ ts->talloc_stack_arraysize = ts->talloc_stacksize + 1;
}
- if (talloc_stacksize == 0) {
- parent = talloc_stack;
- }
- else {
- parent = talloc_stack[talloc_stacksize-1];
+ if (ts->talloc_stacksize == 0) {
+ parent = ts->talloc_stack;
+ } else {
+ parent = ts->talloc_stack[ts->talloc_stacksize-1];
}
if (poolsize) {
talloc_set_destructor(top, talloc_pop);
- talloc_stack[talloc_stacksize++] = top;
+ ts->talloc_stack[ts->talloc_stacksize++] = top;
return top;
fail:
TALLOC_CTX *talloc_tos(void)
{
- if (talloc_stacksize == 0) {
+ struct talloc_stackframe *ts =
+ (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts);
+
+ if (ts == NULL) {
talloc_stackframe();
+ ts = (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts);
DEBUG(0, ("no talloc stackframe around, leaking memory\n"));
}
- return talloc_stack[talloc_stacksize-1];
+ return ts->talloc_stack[ts->talloc_stacksize-1];
}
/**
* @brief Free library allocated memory
*
- * @param *p Pointer to free
+ * @param * Pointer to free
*
* @return void
**/
/**
* @brief Convert a character string to a binary SID
*
- * @param *str Character string in the form of S-...
+ * @param *sid_string Character string in the form of S-...
* @param sid Resulting binary SID
*
* @return #wbcErr
/**
* @brief Convert a character string to a binary GUID
*
- * @param *str Character string
+ * @param *guid_string Character string
* @param guid Resulting binary GUID
*
* @return #wbcErr
/**
* @brief Convert a domain and name to SID
*
- * @param domain Domain name (possibly "")
+ * @param dom_name Domain name (possibly "")
* @param name User or group name
* @param *sid Pointer to the resolved domain SID
* @param *name_type Pointer to the SID type
* @brief Convert a SID to a domain and name
*
* @param *sid Pointer to the domain SID to be resolved
- * @param pdomain Resolved Domain name (possibly "")
- * @param pname Resolved User or group name
- * @param *pname_type Pointer to the resolved SID type
+ * @param domain Resolved Domain name (possibly "")
+ * @param name Resolved User or group name
+ * @param *name_type Pointer to the resolved SID type
*
* @return #wbcErr
**/
* @brief Lookup the current status of a trusted domain
*
* @param domain Domain to query
- * @param *dinfo Pointer to returned domain_info struct
+ * @param *info Pointer to returned domain_info struct
*
* @return #wbcErr
**/
int pack_devicemode(NT_DEVICEMODE *nt_devmode, uint8 *buf, int buflen);
uint32 del_a_printer(const char *sharename);
NT_DEVICEMODE *construct_nt_devicemode(const fstring default_devicename);
-NT_DEVICEMODE *dup_nt_devicemode(NT_DEVICEMODE *nt_devicemode);
void free_nt_devicemode(NT_DEVICEMODE **devmode_ptr);
int unpack_devicemode(NT_DEVICEMODE **nt_devmode, const uint8 *buf, int buflen);
int add_new_printer_key( NT_PRINTER_DATA *data, const char *name );
gboolean hostname_changed;
uint32_t stored_num_ous;
char *target_hostname;
+ uid_t uid;
} join_state;
static void debug(const char *format, ...)
/* Entry */
entry = gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(entry), 256);
+
+ if (state->uid != 0) {
+ gtk_widget_set_sensitive(GTK_WIDGET(entry), FALSE);
+ }
g_signal_connect(G_OBJECT(entry), "changed",
G_CALLBACK(callback_enter_computer_description_and_unlock),
state);
G_CALLBACK(callback_do_change),
(gpointer)state);
gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
+ if (state->uid != 0) {
+ gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
+ }
gtk_widget_show(button);
/* Label (hidden) */
gtk_label_set_line_wrap(GTK_LABEL(state->label_reboot), TRUE);
gtk_misc_set_alignment(GTK_MISC(state->label_reboot), 0, 0);
gtk_box_pack_start(GTK_BOX(vbox), state->label_reboot, TRUE, TRUE, 0);
+ if (state->uid != 0) {
+ gtk_label_set_text(GTK_LABEL(state->label_reboot),
+ "You cannot change computer description as you're not running with root permissions");
+ }
+
gtk_widget_show(state->label_reboot);
#if 0
return -1;
}
+ state->uid = geteuid();
+
state->ctx = ctx;
return 0;
return nt_devmode;
}
-/****************************************************************************
- Deepcopy an NT devicemode.
-****************************************************************************/
-
-NT_DEVICEMODE *dup_nt_devicemode(NT_DEVICEMODE *nt_devicemode)
-{
- NT_DEVICEMODE *new_nt_devicemode = NULL;
-
- if ( !nt_devicemode )
- return NULL;
-
- if ((new_nt_devicemode = (NT_DEVICEMODE *)memdup(nt_devicemode, sizeof(NT_DEVICEMODE))) == NULL) {
- DEBUG(0,("dup_nt_devicemode: malloc fail.\n"));
- return NULL;
- }
-
- new_nt_devicemode->nt_dev_private = NULL;
- if (nt_devicemode->nt_dev_private != NULL) {
- if ((new_nt_devicemode->nt_dev_private = (uint8 *)memdup(nt_devicemode->nt_dev_private, nt_devicemode->driverextra)) == NULL) {
- SAFE_FREE(new_nt_devicemode);
- DEBUG(0,("dup_nt_devicemode: malloc fail.\n"));
- return NULL;
- }
- }
-
- return new_nt_devicemode;
-}
-
/****************************************************************************
Clean up and deallocate a (maybe partially) allocated NT_DEVICEMODE.
****************************************************************************/
struct spoolss_PrinterInfo1 *r,
int snum)
{
- char *chaine = NULL;
r->flags = flags;
+ r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
+ ntprinter->info_2->printername,
+ ntprinter->info_2->drivername,
+ ntprinter->info_2->location);
+ W_ERROR_HAVE_NO_MEMORY(r->description);
+
if (*ntprinter->info_2->comment == '\0') {
r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
- chaine = talloc_asprintf(mem_ctx,
- "%s,%s,%s", ntprinter->info_2->printername,
- ntprinter->info_2->drivername, lp_comment(snum));
} else {
r->comment = talloc_strdup(mem_ctx, ntprinter->info_2->comment); /* saved comment */
- chaine = talloc_asprintf(mem_ctx,
- "%s,%s,%s", ntprinter->info_2->printername,
- ntprinter->info_2->drivername, ntprinter->info_2->comment);
}
- W_ERROR_HAVE_NO_MEMORY(chaine);
W_ERROR_HAVE_NO_MEMORY(r->comment);
- r->description = talloc_strdup(mem_ctx, chaine);
- W_ERROR_HAVE_NO_MEMORY(r->description);
r->name = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
W_ERROR_HAVE_NO_MEMORY(r->name);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
return ntstatus_to_werror(ndr_map_error2ntstatus(ndr_err));
}
-
blob = ndr_push_blob(ndr);
- memcpy(r->out.service, blob.data, r->in.offered);
+ memcpy(r->out.service, blob.data, MIN(blob.length, r->in.offered));
}
*r->out.needed = (buffer_size > r->in.offered) ? buffer_size : r->in.offered;
rmdir $tempdir
}
-cflags="-I. -I./../lib/replace -Iinclude"
+cflags="-I. -I../ -I./../lib/replace -Iinclude"
${CC:-gcc} -m32 $RPM_OPT_FLAGS $CFLAGS -o $tempdir/wb_pad_32 $cflags $tempdir/wb_pad.c
if [ $? -ne 0 ]; then
cleanup
/* String routines */
#include "../lib/util/safe_string.h"
+/* Thread functions. */
+#include "../lib/util/smb_threads.h"
+#include "../lib/util/smb_threads_internal.h"
+
#if 0
/* darn, we can't do this now that we don't link the ldb tools to all the smb libs */
#define TALLOC_ABORT(reason) smb_panic(reason)
+dn: CN=Default Domain Policy,CN=System,${DOMAINDN}
+objectClass: top
+objectClass: domainPolicy
+isCriticalSystemObject: TRUE
+
+dn: CN=AppCategories,CN=Default Domain Policy,CN=System,${DOMAINDN}
+objectClass: top
+objectClass: classStore
+isCriticalSystemObject: TRUE
+
dn: CN={${POLICYGUID}},CN=Policies,CN=System,${DOMAINDN}
objectClass: top
objectClass: container
r.in.ctr = NULL;
r.in.command = command;
- torture_comment(tctx, "Testing SetJob\n");
+ switch (command) {
+ case SPOOLSS_JOB_CONTROL_PAUSE:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_PAUSE\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_RESUME:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RESUME\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_CANCEL:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_CANCEL\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_RESTART:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RESTART\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_DELETE:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_DELETE\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_RETAIN:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RETAIN\n");
+ break;
+ case SPOOLSS_JOB_CONTROL_RELEASE:
+ torture_comment(tctx, "Testing SetJob: SPOOLSS_JOB_CONTROL_RELEASE\n");
+ break;
+ default:
+ torture_comment(tctx, "Testing SetJob\n");
+ break;
+ }
status = dcerpc_spoolss_SetJob(p, tctx, &r);
torture_assert_ntstatus_ok(tctx, status, "SetJob failed");
for(i = 0; i < services_returned; i++) {
+ torture_assert(tctx, service[i].service_name,
+ "Service without name returned!");
+
printf("%-20s \"%s\", Type: %d, State: %d\n",
service[i].service_name, service[i].display_name,
service[i].status.type, service[i].status.state);