debug: Add ability to dump_data per debug class
[sfrench/samba-autobuild/.git] / lib / util / samba_util.h
index 6096722d17177b26f8f3633ca36400036d3956a1..89aa9aa7d8e5ae1a36ebea8f980de7f2fbefc096 100644 (file)
@@ -45,16 +45,14 @@ extern const char *panic_action;
 /**
  * assert macros 
  */
-#ifdef DEVELOPER
-#define SMB_ASSERT(b) do { if (!(b)) { \
-        DEBUG(0,("PANIC: assert failed at %s(%d): %s\n", \
-                __FILE__, __LINE__, #b)); smb_panic("assert failed: " #b); }} while(0)
-#else
-/* redefine the assert macro for non-developer builds */
-#define SMB_ASSERT(b) do { if (!(b)) { \
-        DEBUG(0,("PANIC: assert failed at %s(%d): %s\n", \
-           __FILE__, __LINE__, #b)); }} while (0)
-#endif
+#define SMB_ASSERT(b) \
+do { \
+       if (!(b)) { \
+               DEBUG(0,("PANIC: assert failed at %s(%d): %s\n", \
+                        __FILE__, __LINE__, #b)); \
+               smb_panic("assert failed: " #b); \
+       } \
+} while(0)
 
 #ifndef ABS
 #define ABS(a) ((a)>0?(a):(-(a)))
@@ -78,7 +76,7 @@ _PUBLIC_ void fault_configure(smb_panic_handler_t panic_handler);
 _PUBLIC_ void fault_setup(void);
 _PUBLIC_ void fault_setup_disable(void);
 _PUBLIC_ void dump_core_setup(const char *progname, const char *logfile);
-_PUBLIC_ void smb_panic(const char *reason);
+_PUBLIC_ _NORETURN_ void smb_panic(const char *reason);
 
 
 /**
@@ -633,6 +631,10 @@ _PUBLIC_ bool directory_exist(const char *dname);
 _PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid, 
                               mode_t dir_perms);
 
+_PUBLIC_ bool directory_create_or_exist_strict(const char *dname,
+                                              uid_t uid,
+                                              mode_t dir_perms);
+
 /**
  Set a fd into blocking/nonblocking mode. Uses POSIX O_NONBLOCK if available,
  else
@@ -688,6 +690,14 @@ void dump_data_file(const uint8_t *buf, int len, bool omit_zero_bytes,
  */
 _PUBLIC_ void dump_data(int level, const uint8_t *buf,int len);
 
+/**
+ * Write dump of binary data to the log file.
+ *
+ * The data is only written if the log level is at least level for
+ * debug class dbgc_class.
+ */
+_PUBLIC_ void dump_data_dbgc(int dbgc_class, int level, const uint8_t *buf, int len);
+
 /**
  * Write dump of binary data to the log file.
  *
@@ -818,6 +828,46 @@ _PUBLIC_ void close_low_fds(bool stdin_too, bool stdout_too, bool stderr_too);
 **/
 _PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout);
 
+/**
+ * @brief Get a password from the console.
+ *
+ * You should make sure that the buffer is an empty string!
+ *
+ * You can also use this function to ask for a username. Then you can fill the
+ * buffer with the username and it is shows to the users. If the users just
+ * presses enter the buffer will be untouched.
+ *
+ * @code
+ *   char username[128];
+ *
+ *   snprintf(username, sizeof(username), "john");
+ *
+ *   smb_getpass("Username:", username, sizeof(username), 1, 0);
+ * @endcode
+ *
+ * The prompt will look like this:
+ *
+ *   Username: [john]
+ *
+ * If you press enter then john is used as the username, or you can type it in
+ * to change it.
+ *
+ * @param[in]  prompt   The prompt to show to ask for the password.
+ *
+ * @param[out] buf    The buffer the password should be stored. It NEEDS to be
+ *                      empty or filled out.
+ *
+ * @param[in]  len      The length of the buffer.
+ *
+ * @param[in]  echo     Should we echo what you type.
+ *
+ * @param[in]  verify   Should we ask for the password twice.
+ *
+ * @return              0 on success, -1 on error.
+ */
+_PUBLIC_ int samba_getpass(const char *prompt, char *buf, size_t len,
+                          bool echo, bool verify);
+
 /**
  * Load a ini-style file.
  */
@@ -901,6 +951,35 @@ char *data_path(TALLOC_CTX *mem_ctx, const char *name);
 const char *shlib_ext(void);
 
 struct server_id;
+bool server_id_equal(const struct server_id *p1, const struct server_id *p2);
 char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id);
+struct server_id server_id_from_string(uint32_t local_vnn,
+                                      const char *pid_string);
+
+/**
+ * Set the serverid to the special value that represents a disconnected
+ * client for (e.g.) durable handles.
+ */
+void server_id_set_disconnected(struct server_id *id);
+
+/**
+ * check whether a serverid is the special placeholder for
+ * a disconnected client
+ */
+bool server_id_is_disconnected(const struct server_id *id);
+
+/*
+ * Samba code should use samba_tevent_context_init() instead of
+ * tevent_context_init() in order to get the debug output.
+ */
+struct tevent_context *samba_tevent_context_init(TALLOC_CTX *mem_ctx);
+
+/*
+ * if same samba code needs to use a specific tevent backend
+ * it can use something like this:
+ *
+ * samba_tevent_set_debug(ev, "pysmb_tevent");
+ */
+void samba_tevent_set_debug(struct tevent_context *ev, const char *name);
 
 #endif /* _SAMBA_UTIL_H_ */