Fix prototype of com_create().
[adu.git] / adu.h
diff --git a/adu.h b/adu.h
index 1118b2ca1e623c50078737aa5276328a34d4a9fe..f8ef9c2ddf53af4a6c44ff9b3193487cbf8c9838 100644 (file)
--- a/adu.h
+++ b/adu.h
@@ -1,14 +1,14 @@
 /*
- * Copyright (C) 1997-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
-/** \file para.h global paraslash definitions */
+/** \file adu.h Global definitions. */
 
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <sys/wait.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h> /* time(), localtime() */
 #include <errno.h>
 #include <limits.h>
 #include <stdarg.h>
-#include <ctype.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <sys/un.h> /* needed by create_pf_socket */
+#include <inttypes.h>
 #include <string.h>
 #include <assert.h>
 #include <osl.h>
 #include "gcc-compat.h"
 
-/** used in various contexts */
-#define MAXLINE 255
-
-/** compute the minimum of \a a and \a b */
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-/** compute the maximum of \a a and \a b */
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-/** compute the absolute value of \a a */
-#define ABS(a) ((a) > 0 ? (a) : -(a))
-
 /** debug loglevel, gets really noisy */
 #define DEBUG 1
 /** still noisy, but won't fill your disk */
 #endif
 /** \endcond */
 
-/**
- * define a standard log function that always writes to stderr
- *
- * \param loglevel_barrier If the loglevel of the current message
- * is less than that, the message is going to be ignored.
- *
- */
-#define INIT_STDERR_LOGGING(loglevel_barrier) \
-       __printf_2_3 void __log(int ll, const char* fmt,...) \
-       { \
-               va_list argp; \
-               if (ll < loglevel_barrier) \
-                       return; \
-               va_start(argp, fmt); \
-               vfprintf(stderr, fmt, argp); \
-               va_end(argp); \
-       }
-
-/** version text used by various commands if -V switch was given */
-#define VERSION_TEXT(prefix) "para_" prefix " " PACKAGE_VERSION " (" CODENAME ")" "\n" \
-       "Copyright (C) 2008 Andre Noll\n" \
-       "This is free software with ABSOLUTELY NO WARRANTY." \
-       " See COPYING for details.\n" \
-       "Written by Andre Noll.\n" \
-       "Report bugs to <maan@systemlinux.org>.\n"
-
-/** print out \p VERSION_TEXT and exit if version flag was given */
-#define HANDLE_VERSION_FLAG(_prefix, _args_info_struct) \
-       if (_args_info_struct.version_given) { \
-               printf("%s", VERSION_TEXT(_prefix)); \
-               exit(EXIT_SUCCESS); \
-       }
-/** sent by para_server for commands that expect a data file */
-#define AWAITING_DATA_MSG "\nAwaiting Data."
-/** sent by para_server if authentication was successful */
-#define PROCEED_MSG "\nProceed.\n"
-/** length of the \p PROCEED_MSG string */
-#define PROCEED_MSG_LEN strlen(PROCEED_MSG)
-/** sent by para_client to indicate the end of the command line */
-#define EOC_MSG "\nEnd of Command."
-/** sent by para_client, followed by the decrypted challenge number */
-#define CHALLENGE_RESPONSE_MSG "challenge_response:"
-
-/* exec */
-int para_exec_cmdline_pid(pid_t *pid, const char *cmdline, int *fds);
-
-/* time */
-int tv_diff(const struct timeval *b, const struct timeval *a, struct timeval *diff);
-long unsigned tv2ms(const struct timeval*);
-void d2tv(double, struct timeval*);
-void tv_add(const struct timeval*, const struct timeval *, struct timeval *);
-void tv_scale(const unsigned long, const struct timeval *, struct timeval *);
-void tv_divide(const unsigned long divisor, const struct timeval *tv,
-       struct timeval *result);
-int tv_convex_combination(const long a, const struct timeval *tv1,
-               const long b, const struct timeval *tv2,
-               struct timeval *result);
-void ms2tv(const long unsigned n, struct timeval *tv);
-void compute_chunk_time(long unsigned chunk_num,
-               struct timeval *chunk_tv, struct timeval *stream_start,
-               struct timeval *result);
-
-__printf_2_3 void __log(int, const char*, ...);
-
 /**
  * Write a log message to a dynamically allocated string.
  *
@@ -173,7 +95,7 @@ __printf_2_3 void __log(int, const char*, ...);
 { \
        int n; \
        size_t size = 100; \
-       p = para_malloc(size); \
+       p = adu_malloc(size); \
        while (1) { \
                va_list ap; \
                /* Try to print in the allocated space. */ \
@@ -188,39 +110,89 @@ __printf_2_3 void __log(int, const char*, ...);
                        size = n + 1; /* precisely what is needed */ \
                else /* glibc 2.0 */ \
                        size *= 2; /* twice the old size */ \
-               p = para_realloc(p, size); \
+               p = adu_realloc(p, size); \
        } \
 }
 
-/**
- *  Return a random non-negative integer in an interval.
- *
- * \param max Determines maximal possible return value.
- *
- * \return An integer between zero and \p max - 1, inclusively.
- */
-static inline long int para_random(unsigned max)
-{
-       return ((max + 0.0) * (random() / (RAND_MAX + 1.0)));
-}
-
-/** Round up x to a multiple of y */
-#define ROUND_UP(x, y) (((x) + ((y) - 1) / (y)) * (y))
-
-/** Get the size of an array */
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
-/**
- * Wrapper for isspace.
- * NetBSD needs this.
- */
-/*
- * The values should be cast to an unsigned char first, then to int.
- * Why? Because the isdigit (as do all other is/to functions/macros)
- * expect a number from 0 upto and including 255 as their (int) argument.
- * Because char is signed on most systems, casting it to int immediately
- * gives the functions an argument between -128 and 127 (inclusive),
- * which they will use as an array index, and which will thus fail
- * horribly for characters which have their most significant bit set.
- */
-#define para_isspace(c) isspace((int)(unsigned char)(c))
+/** Evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y. */
+#define NUM_COMPARE(x, y) ((int)((x) < (y)) - (int)((x) > (y)))
+
+/** The columns of the directory table. */
+enum dir_table_columns {
+       /** The name of the directory. */
+       DT_NAME,
+       /** The dir count number. */
+       DT_NUM,
+       /** The number of the parent directory. */
+       DT_PARENT_NUM,
+       /** The number of bytes of all regular files. */
+       DT_BYTES,
+       /** The number of all regular files. */
+       DT_FILES,
+       /** Number of columns in this table. */
+       NUM_DT_COLUMNS
+};
+
+/** The columns of the id table. */
+enum user_table_columns {
+       /** The numer of the directory. */
+       UT_DIR_NUM,
+       /** The number of bytes of all regular files in this dir owned by this id. */
+       UT_BYTES,
+       /** The number of files in this dir owned by this id. */
+       UT_FILES,
+       /** Number of columns in this table. */
+       NUM_UT_COLUMNS
+};
+
+enum uid_info_flags {
+       /** Whether this slot of the hash table is used. */
+       UI_FL_SLOT_USED = 1,
+       /** Whether this uid should be taken into account. */
+       UI_FL_ADMISSIBLE = 2,
+};
+
+struct user_info {
+       uint32_t uid;
+       uint32_t flags;
+       char *pw_name;
+       struct osl_table *table;
+       uint64_t files;
+       uint64_t bytes;
+       uint64_t dirs;
+       struct osl_table_description *desc;
+};
+
+struct uid_range {
+       uint32_t low;
+       uint32_t high;
+};
+
+enum search_uid_flags {
+       OPEN_USER_TABLE = 1,
+       CREATE_USER_TABLE = 2,
+};
+
+extern uint32_t num_uids;
+extern struct osl_table *dir_table;
+extern struct gengetopt_args_info conf;
+
+/* adu.c */
+__printf_2_3 void __log(int, const char*, ...);
+int open_dir_table(int create);
+void check_signals(void);
+void close_all_tables(void);
+char *get_uid_list_name(void);
+void create_hash_table(unsigned bits);
+int search_uid(uint32_t uid, enum search_uid_flags flags,
+               struct user_info **ui_ptr);
+int for_each_admissible_user(int (*func)(struct user_info *, void *),
+               void *data);
+void sort_hash_table(int (*comp)(const void *, const void *));
+
+/* select.c */
+int com_select(void);
+
+/* create.h */
+int com_create(void);
+int com_interactive(void);