#include "system/select.h"
#include "winbind_client.h"
-#if HAVE_PTHREAD_H
+#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#endif
+static char client_name[32];
+
/* Global context */
struct winbindd_context {
pid_t our_pid; /* calling process pid */
};
-#if HAVE_PTHREAD
+#ifdef HAVE_PTHREAD
static pthread_mutex_t wb_global_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
.our_pid = 0
};
-#if HAVE_PTHREAD
+#ifdef HAVE_PTHREAD
pthread_mutex_lock(&wb_global_ctx_mutex);
#endif
return &wb_global_ctx;
static void put_wb_global_ctx(void)
{
-#if HAVE_PTHREAD
+#ifdef HAVE_PTHREAD
pthread_mutex_unlock(&wb_global_ctx_mutex);
#endif
return;
SAFE_FREE(response->extra_data.data);
}
+void winbind_set_client_name(const char *name)
+{
+ if (name == NULL || strlen(name) == 0) {
+ return;
+ }
+
+ (void)snprintf(client_name, sizeof(client_name), "%s", name);
+}
+
+static const char *winbind_get_client_name(void)
+{
+ if (client_name[0] == '\0') {
+ const char *progname = getprogname();
+ int len;
+
+ if (progname == NULL) {
+ progname = "<unknown>";
+ }
+
+ len = snprintf(client_name,
+ sizeof(client_name),
+ "%s",
+ progname);
+ if (len <= 0) {
+ return progname;
+ }
+ }
+
+ return client_name;
+}
+
/* Initialise a request structure */
static void winbindd_init_request(struct winbindd_request *request,
request->cmd = (enum winbindd_cmd)request_type;
request->pid = getpid();
+ (void)snprintf(request->client_name,
+ sizeof(request->client_name),
+ "%s",
+ winbind_get_client_name());
}
/* Initialise a response structure */
/* Destructor for global context to ensure fd is closed */
-#if HAVE_DESTRUCTOR_ATTRIBUTE
+#ifdef HAVE_DESTRUCTOR_ATTRIBUTE
__attribute__((destructor))
#endif
static void winbind_destructor(void)