mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
Code indentation.
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
6505f7d6fa
commit
94bd4b1f78
@ -25,7 +25,8 @@ GTree *mc_event_get_event_group_by_name (const gchar * event_group_name, gboolea
|
||||
GPtrArray *mc_event_get_event_by_name (GTree * event_group, const gchar * event_name,
|
||||
gboolean create_new, GError ** mcerror);
|
||||
mc_event_callback_t *mc_event_is_callback_in_array (GPtrArray * callbacks,
|
||||
mc_event_callback_func_t event_callback, gpointer event_init_data);
|
||||
mc_event_callback_func_t event_callback,
|
||||
gpointer event_init_data);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_EVENT_INTERNAL_H */
|
||||
|
@ -208,7 +208,7 @@ typedef struct
|
||||
|
||||
/* Ugly hack in order to distinguish between left and right panel in menubar */
|
||||
/* Set if the command is being run from the "Right" menu */
|
||||
gboolean is_right; /* If the selected menu was the right */
|
||||
gboolean is_right; /* If the selected menu was the right */
|
||||
} widget;
|
||||
|
||||
struct
|
||||
|
@ -2,7 +2,7 @@
|
||||
Hooks.
|
||||
|
||||
Slavaz: Warning! this file is deprecated and should be replaced
|
||||
by mcevents functional.
|
||||
by mcevents functional.
|
||||
|
||||
Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
|
||||
2004, 2005, 2007, 2009, 2010, 2011
|
||||
|
@ -675,7 +675,7 @@ str_utf8_term_trim (const char *text, int width)
|
||||
|
||||
if (width < 1)
|
||||
{
|
||||
result [0] = '\0';
|
||||
result[0] = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ void tty_set_normal_attrs (void);
|
||||
|
||||
void tty_color_set_defaults (const char *, const char *, const char *);
|
||||
|
||||
extern gboolean tty_use_256colors(void);
|
||||
extern gboolean tty_use_256colors (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_COLOR_H */
|
||||
|
@ -110,7 +110,7 @@ is_8bit_printable (unsigned char c)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
resolve_symlinks (const vfs_path_t *vpath)
|
||||
resolve_symlinks (const vfs_path_t * vpath)
|
||||
{
|
||||
char *p, *p2;
|
||||
char *buf, *buf2, *q, *r, c;
|
||||
@ -164,7 +164,7 @@ resolve_symlinks (const vfs_path_t *vpath)
|
||||
canonicalize_pathname (buf);
|
||||
r = strchr (buf, 0);
|
||||
if (!*r || *(r - 1) != PATH_SEP)
|
||||
/* FIXME: this condition is always true because r points to the EOL */
|
||||
/* FIXME: this condition is always true because r points to the EOL */
|
||||
{
|
||||
*r++ = PATH_SEP;
|
||||
*r = 0;
|
||||
|
@ -174,7 +174,7 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer
|
||||
(void) defcnv;
|
||||
|
||||
g_string_assign (buffer, path);
|
||||
#endif /* HAVE_CHARSET */
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
return state;
|
||||
}
|
||||
@ -614,7 +614,7 @@ vfs_change_encoding (vfs_path_t * vpath, const char *encoding)
|
||||
|
||||
return vpath;
|
||||
}
|
||||
#endif /* HAVE_CHARSET */
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -176,7 +176,7 @@ struct vfs_s_inode *vfs_s_find_root (struct vfs_class *me, struct vfs_s_entry *e
|
||||
/* outside interface */
|
||||
void vfs_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub);
|
||||
const char *vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flags);
|
||||
struct vfs_s_super *vfs_get_super_by_vpath(const vfs_path_t * vpath);
|
||||
struct vfs_s_super *vfs_get_super_by_vpath (const vfs_path_t * vpath);
|
||||
|
||||
void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super);
|
||||
char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino);
|
||||
|
@ -365,8 +365,7 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
|
||||
int y = event->y;
|
||||
|
||||
/* close the dialog by mouse click out of dialog area */
|
||||
if (mouse_close_dialog && !h->fullscreen && ((event->buttons & GPM_B_LEFT) != 0)
|
||||
&& ((event->type & GPM_DOWN) != 0) /* left click */
|
||||
if (mouse_close_dialog && !h->fullscreen && ((event->buttons & GPM_B_LEFT) != 0) && ((event->type & GPM_DOWN) != 0) /* left click */
|
||||
&& !((x > h->x) && (x <= h->x + h->cols) && (y > h->y) && (y <= h->y + h->lines)))
|
||||
{
|
||||
h->ret_value = B_CANCEL;
|
||||
@ -766,7 +765,7 @@ default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo
|
||||
|
||||
Dlg_head *
|
||||
create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
|
||||
const int *colors, dlg_cb_fn callback, mouse_h mouse_handler,
|
||||
const int *colors, dlg_cb_fn callback, mouse_h mouse_handler,
|
||||
const char *help_ctx, const char *title, dlg_flags_t flags)
|
||||
{
|
||||
Dlg_head *new_d;
|
||||
|
@ -24,9 +24,9 @@ extern int num_history_items_recorded;
|
||||
/* read history to the mc_config, but don't save config to file */
|
||||
GList *history_get (const char *input_name);
|
||||
/* load history form the mc_config */
|
||||
GList *history_load (struct mc_config_t * cfg, const char *name);
|
||||
GList *history_load (struct mc_config_t *cfg, const char *name);
|
||||
/* save history to the mc_config, but don't save config to file */
|
||||
void history_save (struct mc_config_t * cfg, const char *name, GList * h);
|
||||
void history_save (struct mc_config_t *cfg, const char *name, GList * h);
|
||||
/* for repositioning of history dialog we should pass widget to this
|
||||
* function, as position of history dialog depends on widget's position */
|
||||
char *history_show (GList ** history, Widget * widget, int current);
|
||||
|
@ -195,7 +195,8 @@ do_show_hist (WInput * in)
|
||||
|
||||
len = get_history_length (in->history);
|
||||
|
||||
r = history_show (&in->history, &in->widget, g_list_position (in->history_current, in->history));
|
||||
r = history_show (&in->history, &in->widget,
|
||||
g_list_position (in->history_current, in->history));
|
||||
if (r != NULL)
|
||||
{
|
||||
input_assign_text (in, r);
|
||||
|
@ -123,9 +123,13 @@ listbox_draw (WListbox * l, gboolean focused)
|
||||
const Dlg_head *h = l->widget.owner;
|
||||
const gboolean disabled = (((Widget *) l)->options & W_DISABLED) != 0;
|
||||
const int normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL];
|
||||
int selc =
|
||||
disabled ? DISABLED_COLOR : focused ? h->
|
||||
color[DLG_COLOR_HOT_FOCUS] : h->color[DLG_COLOR_FOCUS];
|
||||
/* *INDENT-OFF* */
|
||||
int selc = disabled
|
||||
? DISABLED_COLOR
|
||||
: focused
|
||||
? h->color[DLG_COLOR_HOT_FOCUS]
|
||||
: h->color[DLG_COLOR_FOCUS];
|
||||
/* *INDENT-ON* */
|
||||
|
||||
GList *le;
|
||||
int pos;
|
||||
|
@ -77,8 +77,7 @@ quick_dialog_skip (QuickDialog * qd, int nskip)
|
||||
DLG_CENTER | DLG_TRYUP | DLG_REVERSE);
|
||||
else
|
||||
dd = create_dlg (TRUE, qd->ypos, qd->xpos, qd->ylen, qd->xlen,
|
||||
dialog_colors, qd->callback, qd->mouse, qd->help, qd->title,
|
||||
DLG_REVERSE);
|
||||
dialog_colors, qd->callback, qd->mouse, qd->help, qd->title, DLG_REVERSE);
|
||||
|
||||
for (qw = qd->widgets; qw->widget_type != quick_end; qw++)
|
||||
{
|
||||
|
@ -380,9 +380,10 @@ console_save (void)
|
||||
|
||||
for (i = 0; i < screen_shot.xsize * screen_shot.ysize; i++)
|
||||
{
|
||||
screen_shot.buf[i] =
|
||||
(screen_shot.buf[i] & 0xff00) | (unsigned char) revmap.
|
||||
scrmap[screen_shot.buf[i] & 0xff];
|
||||
/* *INDENT-OFF* */
|
||||
screen_shot.buf[i] = (screen_shot.buf[i] & 0xff00)
|
||||
| (unsigned char) revmap.scrmap[screen_shot.buf[i] & 0xff];
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,7 @@ void edit_insert_over (WEdit * edit);
|
||||
int edit_insert_column_of_text_from_file (WEdit * edit, int file,
|
||||
long *start_pos, long *end_pos, int *col1, int *col2);
|
||||
|
||||
char *edit_get_word_from_pos (WEdit * edit, long start_pos, long *start, gsize *len, gsize *cut);
|
||||
char *edit_get_word_from_pos (WEdit * edit, long start_pos, long *start, gsize * len, gsize * cut);
|
||||
long edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath);
|
||||
gboolean edit_load_back_cmd (WEdit * edit);
|
||||
gboolean edit_load_forward_cmd (WEdit * edit);
|
||||
|
@ -2001,7 +2001,7 @@ is_break_char (char c)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
edit_get_word_from_pos (WEdit *edit, long start_pos, long *start, gsize *len, gsize *cut)
|
||||
edit_get_word_from_pos (WEdit * edit, long start_pos, long *start, gsize * len, gsize * cut)
|
||||
{
|
||||
long word_start;
|
||||
long cut_len = 0;
|
||||
|
@ -504,7 +504,7 @@ edit_save_cmd (WEdit * edit)
|
||||
*/
|
||||
|
||||
static inline gboolean
|
||||
edit_load_file_from_filename (Dlg_head *h, const vfs_path_t *vpath)
|
||||
edit_load_file_from_filename (Dlg_head * h, const vfs_path_t * vpath)
|
||||
{
|
||||
return edit_add_window (h, h->y + 1, h->x, h->lines - 2, h->cols, vpath, 0);
|
||||
}
|
||||
@ -2146,7 +2146,7 @@ edit_load_menu_file (Dlg_head * h)
|
||||
{
|
||||
vfs_path_free (menufile_vpath);
|
||||
menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, EDIT_GLOBAL_MENU, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
switch (dir)
|
||||
{
|
||||
@ -2171,7 +2171,7 @@ edit_load_menu_file (Dlg_head * h)
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
default:
|
||||
vfs_path_free (menufile_vpath);
|
||||
return FALSE;
|
||||
}
|
||||
@ -3699,6 +3699,6 @@ edit_set_spell_lang (void)
|
||||
}
|
||||
aspell_array_clean (lang_list);
|
||||
}
|
||||
#endif /* HAVE_ASPELL */
|
||||
#endif /* HAVE_ASPELL */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -27,7 +27,7 @@ struct selection
|
||||
|
||||
void editcmd_dialog_replace_show (WEdit *, const char *, const char *, char **, char **);
|
||||
|
||||
gboolean editcmd_dialog_search_show (WEdit *edit);
|
||||
gboolean editcmd_dialog_search_show (WEdit * edit);
|
||||
|
||||
int editcmd_dialog_raw_key_query (const char *, const char *, int);
|
||||
|
||||
|
@ -176,12 +176,13 @@ create_command_menu (void)
|
||||
menu_entry_create (_("Record/Repeat &actions"), CK_RepeatStartStopRecord));
|
||||
entries = g_list_prepend (entries, menu_separator_create ());
|
||||
#ifdef HAVE_ASPELL
|
||||
entries =
|
||||
g_list_prepend (entries, menu_entry_create (_("S&pell check"), CK_SpellCheck));
|
||||
entries = g_list_prepend (entries, menu_entry_create (_("S&pell check"), CK_SpellCheck));
|
||||
entries =
|
||||
g_list_prepend (entries, menu_entry_create (_("C&heck word"), CK_SpellCheckCurrentWord));
|
||||
entries =
|
||||
g_list_prepend (entries, menu_entry_create (_("Change spelling &language"), CK_SpellCheckSelectLang));
|
||||
g_list_prepend (entries,
|
||||
menu_entry_create (_("Change spelling &language"),
|
||||
CK_SpellCheckSelectLang));
|
||||
entries = g_list_prepend (entries, menu_separator_create ());
|
||||
#endif /* HAVE_ASPELL */
|
||||
entries = g_list_prepend (entries, menu_entry_create (_("&Mail..."), CK_Mail));
|
||||
|
@ -672,7 +672,7 @@ edit_event (Gpm_Event * event, void *data)
|
||||
*/
|
||||
|
||||
static int
|
||||
edit_dialog_event (Gpm_Event *event, void *data)
|
||||
edit_dialog_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
Dlg_head *h = (Dlg_head *) data;
|
||||
Widget *w;
|
||||
@ -1081,10 +1081,11 @@ edit_file (const vfs_path_t * file_vpath, int line)
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
edit_files (const GList *files)
|
||||
edit_files (const GList * files)
|
||||
{
|
||||
static gboolean made_directory = FALSE;
|
||||
Dlg_head *edit_dlg;
|
||||
@ -1129,8 +1130,7 @@ edit_files (const GList *files)
|
||||
gboolean f_ok;
|
||||
|
||||
f_ok = edit_add_window (edit_dlg, edit_dlg->y + 1, edit_dlg->x,
|
||||
edit_dlg->lines - 2, edit_dlg->cols,
|
||||
f->file_vpath, f->line_number);
|
||||
edit_dlg->lines - 2, edit_dlg->cols, f->file_vpath, f->line_number);
|
||||
/* at least one file has been opened succefully */
|
||||
ok = ok || f_ok;
|
||||
}
|
||||
@ -1185,7 +1185,7 @@ edit_update_screen (WEdit * e)
|
||||
edit_update_curs_col (e);
|
||||
|
||||
edit_status (e, (e->force & REDRAW_COMPLETELY) != 0 &&
|
||||
(void *) e == ((Widget *) e)->owner->current->data);
|
||||
(void *) e == ((Widget *) e)->owner->current->data);
|
||||
|
||||
/* pop all events for this window for internal handling */
|
||||
if (!is_idle ())
|
||||
@ -1232,7 +1232,7 @@ edit_save_size (WEdit * edit)
|
||||
*/
|
||||
|
||||
gboolean
|
||||
edit_add_window (Dlg_head * h, int y, int x, int lines, int cols, const vfs_path_t *f, int fline)
|
||||
edit_add_window (Dlg_head * h, int y, int x, int lines, int cols, const vfs_path_t * f, int fline)
|
||||
{
|
||||
WEdit *edit;
|
||||
Widget *w;
|
||||
|
@ -72,8 +72,8 @@ static struct AspellStringEnumeration *(*mc_aspell_word_list_elements) (const st
|
||||
static const char *(*mc_aspell_config_retrieve) (struct AspellConfig * ths, const char *key);
|
||||
static void (*mc_delete_aspell_speller) (struct AspellSpeller * ths);
|
||||
/*
|
||||
static void (*mc_delete_aspell_config) (struct AspellConfig * ths);
|
||||
*/
|
||||
static void (*mc_delete_aspell_config) (struct AspellConfig * ths);
|
||||
*/
|
||||
static void (*mc_delete_aspell_can_have_error) (struct AspellCanHaveError * ths);
|
||||
static const char *(*mc_aspell_error_message) (const struct AspellCanHaveError * ths);
|
||||
static void (*mc_delete_aspell_string_enumeration) (struct AspellStringEnumeration * ths);
|
||||
@ -86,7 +86,7 @@ static const char *(*mc_aspell_string_enumeration_next) (struct AspellStringEnum
|
||||
static void (*mc_delete_aspell_dict_info_enumeration) (struct AspellDictInfoEnumeration * ths);
|
||||
static unsigned int (*mc_aspell_word_list_size) (const struct AspellWordList * ths);
|
||||
static const struct AspellError *(*mc_aspell_error) (const struct AspellCanHaveError * ths);
|
||||
static int (*mc_aspell_speller_add_to_personal) (struct AspellSpeller * ths, const char * word,
|
||||
static int (*mc_aspell_speller_add_to_personal) (struct AspellSpeller * ths, const char *word,
|
||||
int word_size);
|
||||
static int (*mc_aspell_speller_save_all_word_lists) (struct AspellSpeller * ths);
|
||||
|
||||
@ -193,8 +193,7 @@ spell_available (void)
|
||||
(void *) &mc_aspell_speller_error_message))
|
||||
goto error_ret;
|
||||
|
||||
if (!g_module_symbol (spell_module, "aspell_speller_error",
|
||||
(void *) &mc_aspell_speller_error))
|
||||
if (!g_module_symbol (spell_module, "aspell_speller_error", (void *) &mc_aspell_speller_error))
|
||||
goto error_ret;
|
||||
|
||||
if (!g_module_symbol (spell_module, "aspell_error", (void *) &mc_aspell_error))
|
||||
|
@ -16,9 +16,9 @@
|
||||
void aspell_init (void);
|
||||
void aspell_clean (void);
|
||||
gboolean aspell_check (const char *word, const int word_size);
|
||||
unsigned int aspell_suggest (GArray *suggest, const char *word, const int word_size);
|
||||
void aspell_array_clean (GArray *array);
|
||||
unsigned int aspell_get_lang_list (GArray *lang_list);
|
||||
unsigned int aspell_suggest (GArray * suggest, const char *word, const int word_size);
|
||||
void aspell_array_clean (GArray * array);
|
||||
unsigned int aspell_get_lang_list (GArray * lang_list);
|
||||
const char *aspell_get_lang (void);
|
||||
gboolean aspell_set_lang (const char *lang);
|
||||
gboolean aspell_add_to_dict (const char *word, const int word_size);
|
||||
|
@ -59,7 +59,7 @@
|
||||
*/
|
||||
|
||||
int
|
||||
spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word, GArray *suggest)
|
||||
spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word, GArray * suggest)
|
||||
{
|
||||
|
||||
int sug_dlg_h = 14; /* dialog height */
|
||||
@ -154,11 +154,11 @@ spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word
|
||||
*/
|
||||
|
||||
char *
|
||||
spell_dialog_lang_list_show (GArray *languages)
|
||||
spell_dialog_lang_list_show (GArray * languages)
|
||||
{
|
||||
|
||||
int lang_dlg_h = 12; /* dialog height */
|
||||
int lang_dlg_w = 30; /* dialog width */
|
||||
int lang_dlg_h = 12; /* dialog height */
|
||||
int lang_dlg_w = 30; /* dialog width */
|
||||
char *selected_lang = NULL;
|
||||
unsigned int i;
|
||||
int res;
|
||||
|
@ -17,8 +17,8 @@
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
int spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word,
|
||||
GArray *suggest);
|
||||
char *spell_dialog_lang_list_show (GArray *languages);
|
||||
GArray * suggest);
|
||||
char *spell_dialog_lang_list_show (GArray * languages);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
|
@ -340,7 +340,7 @@ toggle_panels (void)
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
if (mc_global.tty.use_subshell)
|
||||
{
|
||||
new_dir_p = vfs_current_is_local () ? &new_dir_vpath : NULL;
|
||||
new_dir_p = vfs_current_is_local ()? &new_dir_vpath : NULL;
|
||||
invoke_subshell (NULL, VISIBLY, new_dir_p);
|
||||
}
|
||||
else
|
||||
|
@ -83,7 +83,8 @@ WInput *cmdline;
|
||||
static char *
|
||||
examine_cd (const char *_path)
|
||||
{
|
||||
typedef enum { copy_sym, subst_var } state_t;
|
||||
typedef enum
|
||||
{ copy_sym, subst_var } state_t;
|
||||
|
||||
state_t state = copy_sym;
|
||||
char *q;
|
||||
@ -424,7 +425,7 @@ do_cd_command (char *orig_cmd)
|
||||
path = examine_cd (&cmd[operand_pos]);
|
||||
|
||||
if (*path == '\0')
|
||||
q_vpath = vfs_path_from_str (mc_config_get_home_dir());
|
||||
q_vpath = vfs_path_from_str (mc_config_get_home_dir ());
|
||||
else
|
||||
q_vpath = vfs_path_from_str_flags (path, VPF_NO_CANON);
|
||||
|
||||
|
@ -376,7 +376,7 @@ exec_extension_cd (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
exec_extension (const vfs_path_t *filename_vpath, const char *lc_data, int start_line)
|
||||
exec_extension (const vfs_path_t * filename_vpath, const char *lc_data, int start_line)
|
||||
{
|
||||
char *shell_string, *export_variables;
|
||||
vfs_path_t *temp_file_name_vpath = NULL;
|
||||
|
@ -238,7 +238,7 @@ free_link (void *data)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void *
|
||||
free_linklist (GSList *lp)
|
||||
free_linklist (GSList * lp)
|
||||
{
|
||||
g_slist_foreach (lp, (GFunc) free_link, NULL);
|
||||
g_slist_free (lp);
|
||||
@ -249,7 +249,7 @@ free_linklist (GSList *lp)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
is_in_linklist (const GSList *lp, const vfs_path_t * vpath, const struct stat *sb)
|
||||
is_in_linklist (const GSList * lp, const vfs_path_t * vpath, const struct stat *sb)
|
||||
{
|
||||
const struct vfs_class *class;
|
||||
ino_t ino = sb->st_ino;
|
||||
|
@ -57,9 +57,9 @@
|
||||
#if ((STAT_STATVFS || STAT_STATVFS64) \
|
||||
&& (HAVE_STRUCT_STATVFS_F_BASETYPE || HAVE_STRUCT_STATVFS_F_FSTYPENAME \
|
||||
|| (! HAVE_STRUCT_STATFS_F_FSTYPENAME)))
|
||||
# define USE_STATVFS 1
|
||||
#define USE_STATVFS 1
|
||||
#else
|
||||
# define USE_STATVFS 0
|
||||
#define USE_STATVFS 0
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
@ -70,36 +70,36 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if USE_STATVFS
|
||||
# include <sys/statvfs.h>
|
||||
#include <sys/statvfs.h>
|
||||
#elif HAVE_SYS_VFS_H
|
||||
# include <sys/vfs.h>
|
||||
#include <sys/vfs.h>
|
||||
#elif HAVE_SYS_MOUNT_H && HAVE_SYS_PARAM_H
|
||||
/* NOTE: freebsd5.0 needs sys/param.h and sys/mount.h for statfs.
|
||||
It does have statvfs.h, but shouldn't use it, since it doesn't
|
||||
HAVE_STRUCT_STATVFS_F_BASETYPE. So find a clean way to fix it. */
|
||||
/* NetBSD 1.5.2 needs these, for the declaration of struct statfs. */
|
||||
# include <sys/param.h>
|
||||
# include <sys/mount.h>
|
||||
# if HAVE_NFS_NFS_CLNT_H && HAVE_NFS_VFS_H
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#if HAVE_NFS_NFS_CLNT_H && HAVE_NFS_VFS_H
|
||||
/* Ultrix 4.4 needs these for the declaration of struct statfs. */
|
||||
# include <netinet/in.h>
|
||||
# include <nfs/nfs_clnt.h>
|
||||
# include <nfs/vfs.h>
|
||||
# endif
|
||||
#include <netinet/in.h>
|
||||
#include <nfs/nfs_clnt.h>
|
||||
#include <nfs/vfs.h>
|
||||
#endif
|
||||
#elif HAVE_OS_H /* BeOS */
|
||||
# include <fs_info.h>
|
||||
#include <fs_info.h>
|
||||
#endif
|
||||
|
||||
#if USE_STATVFS
|
||||
# define STRUCT_STATVFS struct statvfs
|
||||
# if ! STAT_STATVFS && STAT_STATVFS64
|
||||
# define STATFS statvfs64
|
||||
# else
|
||||
# define STATFS statvfs
|
||||
# endif
|
||||
#define STRUCT_STATVFS struct statvfs
|
||||
#if ! STAT_STATVFS && STAT_STATVFS64
|
||||
#define STATFS statvfs64
|
||||
#else
|
||||
# define STATFS statfs
|
||||
# if HAVE_OS_H /* BeOS */
|
||||
#define STATFS statvfs
|
||||
#endif
|
||||
#else
|
||||
#define STATFS statfs
|
||||
#if HAVE_OS_H /* BeOS */
|
||||
/* BeOS has a statvfs function, but it does not return sensible values
|
||||
for f_files, f_ffree and f_favail, and lacks f_type, f_basetype and
|
||||
f_fstypename. Use 'struct fs_info' instead. */
|
||||
@ -113,29 +113,27 @@ statfs (char const *filename, struct fs_info *buf)
|
||||
errno = (device == B_ENTRY_NOT_FOUND ? ENOENT
|
||||
: device == B_BAD_VALUE ? EINVAL
|
||||
: device == B_NAME_TOO_LONG ? ENAMETOOLONG
|
||||
: device == B_NO_MEMORY ? ENOMEM
|
||||
: device == B_FILE_ERROR ? EIO
|
||||
: 0);
|
||||
: device == B_NO_MEMORY ? ENOMEM : device == B_FILE_ERROR ? EIO : 0);
|
||||
return -1;
|
||||
}
|
||||
/* If successful, buf->dev will be == device. */
|
||||
return fs_stat_dev (device, buf);
|
||||
}
|
||||
|
||||
# define STRUCT_STATVFS struct fs_info
|
||||
# else
|
||||
# define STRUCT_STATVFS struct statfs
|
||||
# endif
|
||||
#define STRUCT_STATVFS struct fs_info
|
||||
#else
|
||||
#define STRUCT_STATVFS struct statfs
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HAVE_STRUCT_STATVFS_F_BASETYPE
|
||||
# define STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME f_basetype
|
||||
#define STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME f_basetype
|
||||
#else
|
||||
# if HAVE_STRUCT_STATVFS_F_FSTYPENAME || HAVE_STRUCT_STATFS_F_FSTYPENAME
|
||||
# define STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME f_fstypename
|
||||
# elif HAVE_OS_H /* BeOS */
|
||||
# define STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME fsh_name
|
||||
# endif
|
||||
#if HAVE_STRUCT_STATVFS_F_FSTYPENAME || HAVE_STRUCT_STATFS_F_FSTYPENAME
|
||||
#define STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME f_fstypename
|
||||
#elif HAVE_OS_H /* BeOS */
|
||||
#define STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME fsh_name
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
|
@ -557,7 +557,7 @@ init_layout (void)
|
||||
}
|
||||
|
||||
equal_split = panels_layout.horizontal_split ?
|
||||
panels_layout.horizontal_equal : panels_layout.vertical_equal;
|
||||
panels_layout.horizontal_equal : panels_layout.vertical_equal;
|
||||
|
||||
/* "Panel split" groupbox */
|
||||
bright_widget = button_new (6, 14, B_2RIGHT, NARROW_BUTTON, "&>", b_left_right_cback);
|
||||
|
@ -73,7 +73,7 @@ struct Widget *get_panel_widget (int idx);
|
||||
struct WPanel *get_other_panel (void);
|
||||
|
||||
void save_panel_dir (int idx);
|
||||
char *get_panel_dir_for (const struct WPanel * widget);
|
||||
char *get_panel_dir_for (const struct WPanel *widget);
|
||||
|
||||
void set_hintbar (const char *str);
|
||||
|
||||
|
@ -1600,7 +1600,7 @@ midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
midnight_event (Gpm_Event *event, void *data)
|
||||
midnight_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
Dlg_head *h = (Dlg_head *) data;
|
||||
int ret = MOU_UNHANDLED;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
Declarations for list of mounted filesystems
|
||||
*/
|
||||
*/
|
||||
|
||||
/** \file mountlist.h
|
||||
* \brief Header: list of mounted filesystems
|
||||
@ -24,8 +24,8 @@ struct my_statfs
|
||||
char *typename;
|
||||
const char *mpoint;
|
||||
const char *device;
|
||||
uintmax_t avail; /* in kB */
|
||||
uintmax_t total; /* in kB */
|
||||
uintmax_t avail; /* in kB */
|
||||
uintmax_t total; /* in kB */
|
||||
uintmax_t nfree;
|
||||
uintmax_t nodes;
|
||||
};
|
||||
|
@ -4582,7 +4582,7 @@ remove_encoding_from_path (const vfs_path_t * vpath)
|
||||
g_string_free (tmp_conv, TRUE);
|
||||
return ret_vpath;
|
||||
}
|
||||
#endif /* HAVE_CHARSET */
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
|
@ -599,8 +599,7 @@ load_panelize (void)
|
||||
|
||||
if (!profile_keys || *profile_keys == NULL)
|
||||
{
|
||||
add2panelize (g_strdup (_("Modified git files")),
|
||||
g_strdup ("git ls-files --modified"));
|
||||
add2panelize (g_strdup (_("Modified git files")), g_strdup ("git ls-files --modified"));
|
||||
add2panelize (g_strdup (_("Find rejects after patching")),
|
||||
g_strdup ("find . -name \\*.rej -print"));
|
||||
add2panelize (g_strdup (_("Find *.orig after patching")),
|
||||
|
@ -19,7 +19,7 @@ struct WEdit;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
gboolean user_menu_cmd (struct WEdit *edit_widget, const char * menu_file, int selected_entry);
|
||||
gboolean user_menu_cmd (struct WEdit *edit_widget, const char *menu_file, int selected_entry);
|
||||
char *expand_format (struct WEdit *edit_widget, char c, gboolean do_quote);
|
||||
int check_format_view (const char *);
|
||||
int check_format_var (const char *, char **);
|
||||
|
@ -373,7 +373,8 @@ learn_save (void)
|
||||
|
||||
esc_str = strutils_escape (learnkeys[i].sequence, -1, ";\\", TRUE);
|
||||
|
||||
mc_config_set_string_raw_value (mc_main_config, section, key_name_conv_tab[i].name, esc_str);
|
||||
mc_config_set_string_raw_value (mc_main_config, section, key_name_conv_tab[i].name,
|
||||
esc_str);
|
||||
|
||||
g_free (esc_str);
|
||||
}
|
||||
|
@ -108,8 +108,8 @@ char *load_anon_passwd (void);
|
||||
void load_keymap_defs (gboolean load_from_file);
|
||||
void free_keymap_defs (void);
|
||||
|
||||
void panel_load_setup (struct WPanel * panel, const char *section);
|
||||
void panel_save_setup (struct WPanel * panel, const char *section);
|
||||
void panel_load_setup (struct WPanel *panel, const char *section);
|
||||
void panel_save_setup (struct WPanel *panel, const char *section);
|
||||
|
||||
void panels_load_options (void);
|
||||
void panels_save_options (void);
|
||||
|
@ -252,7 +252,7 @@ init_subshell_child (const char *pty_name)
|
||||
|
||||
/* It simplifies things to change to our home directory here, */
|
||||
/* and the user's startup file may do a `cd' command anyway */
|
||||
chdir (mc_config_get_home_dir ()); /* FIXME? What about when we re-run the subshell? */
|
||||
chdir (mc_config_get_home_dir ()); /* FIXME? What about when we re-run the subshell? */
|
||||
|
||||
/* Set MC_SID to prevent running one mc from another */
|
||||
mc_sid = getsid (0);
|
||||
|
@ -854,7 +854,7 @@ init_cpiofs (void)
|
||||
{
|
||||
static struct vfs_s_subclass cpio_subclass;
|
||||
|
||||
cpio_subclass.flags = VFS_S_READONLY; /* FIXME: cpiofs used own temp files */
|
||||
cpio_subclass.flags = VFS_S_READONLY; /* FIXME: cpiofs used own temp files */
|
||||
cpio_subclass.archive_check = cpio_super_check;
|
||||
cpio_subclass.archive_same = cpio_super_same;
|
||||
cpio_subclass.open_archive = cpio_open_archive;
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void init_cpiofs(void);
|
||||
void init_cpiofs (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
|
@ -422,7 +422,7 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc)
|
||||
goto ret;
|
||||
}
|
||||
|
||||
tmp = name_quote ( vfs_path_get_last_path_str (name_vpath), 0);
|
||||
tmp = name_quote (vfs_path_get_last_path_str (name_vpath), 0);
|
||||
}
|
||||
|
||||
cmd = g_strconcat (info->path, info->prefix, " list ",
|
||||
|
@ -21,7 +21,7 @@ extern int fish_directory_timeout;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void init_fish(void);
|
||||
void init_fish (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void vfs_plugins_init(void);
|
||||
void vfs_plugins_init (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
|
@ -190,7 +190,8 @@ sfs_vfmake (const vfs_path_t * vpath, vfs_path_t * cache_vpath)
|
||||
COPY_CHAR;
|
||||
continue;
|
||||
}
|
||||
if (ptr != NULL) {
|
||||
if (ptr != NULL)
|
||||
{
|
||||
COPY_STRING (ptr);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <config.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h> /* atoi() */
|
||||
#include <stdlib.h> /* atoi() */
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
@ -300,7 +300,7 @@ sftpfs_get_config_entity (const vfs_path_element_t * vpath_element, GError ** er
|
||||
gboolean ok;
|
||||
|
||||
ok = sftpfs_fill_config_entity_from_config
|
||||
(ssh_config_handler, config_entity, vpath_element, error);
|
||||
(ssh_config_handler, config_entity, vpath_element, error);
|
||||
fclose (ssh_config_handler);
|
||||
|
||||
if (!ok)
|
||||
@ -380,13 +380,13 @@ void
|
||||
sftpfs_init_config_variables_patterns (void)
|
||||
{
|
||||
size_t structure_offsets[] = {
|
||||
offsetof(sftpfs_ssh_config_entity_t, user),
|
||||
offsetof(sftpfs_ssh_config_entity_t, real_host),
|
||||
offsetof(sftpfs_ssh_config_entity_t, identities_only),
|
||||
offsetof(sftpfs_ssh_config_entity_t, identity_file),
|
||||
offsetof(sftpfs_ssh_config_entity_t, port),
|
||||
offsetof(sftpfs_ssh_config_entity_t, password_auth),
|
||||
offsetof(sftpfs_ssh_config_entity_t, pubkey_auth)
|
||||
offsetof (sftpfs_ssh_config_entity_t, user),
|
||||
offsetof (sftpfs_ssh_config_entity_t, real_host),
|
||||
offsetof (sftpfs_ssh_config_entity_t, identities_only),
|
||||
offsetof (sftpfs_ssh_config_entity_t, identity_file),
|
||||
offsetof (sftpfs_ssh_config_entity_t, port),
|
||||
offsetof (sftpfs_ssh_config_entity_t, password_auth),
|
||||
offsetof (sftpfs_ssh_config_entity_t, pubkey_auth)
|
||||
};
|
||||
|
||||
int i;
|
||||
|
@ -2,7 +2,7 @@
|
||||
Unix SMB/Netbios implementation.
|
||||
Version 1.9.
|
||||
SMB Byte handling
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef _BYTEORDER_H
|
||||
#define _BYTEORDER_H
|
||||
@ -11,73 +11,73 @@
|
||||
This file implements macros for machine independent short and
|
||||
int manipulation
|
||||
|
||||
Here is a description of this file that I emailed to the samba list once:
|
||||
Here is a description of this file that I emailed to the samba list once:
|
||||
|
||||
> I am confused about the way that byteorder.h works in Samba. I have
|
||||
> looked at it, and I would have thought that you might make a distinction
|
||||
> between LE and BE machines, but you only seem to distinguish between 386
|
||||
> and all other architectures.
|
||||
>
|
||||
> Can you give me a clue?
|
||||
> I am confused about the way that byteorder.h works in Samba. I have
|
||||
> looked at it, and I would have thought that you might make a distinction
|
||||
> between LE and BE machines, but you only seem to distinguish between 386
|
||||
> and all other architectures.
|
||||
>
|
||||
> Can you give me a clue?
|
||||
|
||||
sure.
|
||||
sure.
|
||||
|
||||
The distinction between 386 and other architectures is only there as
|
||||
an optimisation. You can take it out completely and it will make no
|
||||
difference. The routines (macros) in byteorder.h are totally byteorder
|
||||
independent. The 386 optimsation just takes advantage of the fact that
|
||||
the x86 processors don't care about alignment, so we don't have to
|
||||
align ints on int boundaries etc. If there are other processors out
|
||||
there that aren't alignment sensitive then you could also define
|
||||
CAREFUL_ALIGNMENT=0 on those processors as well.
|
||||
The distinction between 386 and other architectures is only there as
|
||||
an optimisation. You can take it out completely and it will make no
|
||||
difference. The routines (macros) in byteorder.h are totally byteorder
|
||||
independent. The 386 optimsation just takes advantage of the fact that
|
||||
the x86 processors don't care about alignment, so we don't have to
|
||||
align ints on int boundaries etc. If there are other processors out
|
||||
there that aren't alignment sensitive then you could also define
|
||||
CAREFUL_ALIGNMENT=0 on those processors as well.
|
||||
|
||||
Ok, now to the macros themselves. I'll take a simple example, say we
|
||||
want to extract a 2 byte integer from a SMB packet and put it into a
|
||||
type called uint16 that is in the local machines byte order, and you
|
||||
want to do it with only the assumption that uint16 is _at_least_ 16
|
||||
bits long (this last condition is very important for architectures
|
||||
that don't have any int types that are 2 bytes long)
|
||||
Ok, now to the macros themselves. I'll take a simple example, say we
|
||||
want to extract a 2 byte integer from a SMB packet and put it into a
|
||||
type called uint16 that is in the local machines byte order, and you
|
||||
want to do it with only the assumption that uint16 is _at_least_ 16
|
||||
bits long (this last condition is very important for architectures
|
||||
that don't have any int types that are 2 bytes long)
|
||||
|
||||
You do this:
|
||||
You do this:
|
||||
|
||||
#define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
|
||||
#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
|
||||
#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
|
||||
#define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
|
||||
#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
|
||||
#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
|
||||
|
||||
then to extract a uint16 value at offset 25 in a buffer you do this:
|
||||
then to extract a uint16 value at offset 25 in a buffer you do this:
|
||||
|
||||
char *buffer = foo_bar();
|
||||
uint16 xx = SVAL(buffer,25);
|
||||
char *buffer = foo_bar();
|
||||
uint16 xx = SVAL(buffer,25);
|
||||
|
||||
We are using the byteoder independence of the ANSI C bitshifts to do
|
||||
the work. A good optimising compiler should turn this into efficient
|
||||
code, especially if it happens to have the right byteorder :-)
|
||||
We are using the byteoder independence of the ANSI C bitshifts to do
|
||||
the work. A good optimising compiler should turn this into efficient
|
||||
code, especially if it happens to have the right byteorder :-)
|
||||
|
||||
I know these macros can be made a bit tidier by removing some of the
|
||||
casts, but you need to look at byteorder.h as a whole to see the
|
||||
reasoning behind them. byteorder.h defines the following macros:
|
||||
I know these macros can be made a bit tidier by removing some of the
|
||||
casts, but you need to look at byteorder.h as a whole to see the
|
||||
reasoning behind them. byteorder.h defines the following macros:
|
||||
|
||||
SVAL(buf,pos) - extract a 2 byte SMB value
|
||||
IVAL(buf,pos) - extract a 4 byte SMB value
|
||||
SVALS(buf,pos) signed version of SVAL()
|
||||
IVALS(buf,pos) signed version of IVAL()
|
||||
SVAL(buf,pos) - extract a 2 byte SMB value
|
||||
IVAL(buf,pos) - extract a 4 byte SMB value
|
||||
SVALS(buf,pos) signed version of SVAL()
|
||||
IVALS(buf,pos) signed version of IVAL()
|
||||
|
||||
SSVAL(buf,pos,val) - put a 2 byte SMB value into a buffer
|
||||
SIVAL(buf,pos,val) - put a 4 byte SMB value into a buffer
|
||||
SSVALS(buf,pos,val) - signed version of SSVAL()
|
||||
SIVALS(buf,pos,val) - signed version of SIVAL()
|
||||
SSVAL(buf,pos,val) - put a 2 byte SMB value into a buffer
|
||||
SIVAL(buf,pos,val) - put a 4 byte SMB value into a buffer
|
||||
SSVALS(buf,pos,val) - signed version of SSVAL()
|
||||
SIVALS(buf,pos,val) - signed version of SIVAL()
|
||||
|
||||
RSVAL(buf,pos) - like SVAL() but for NMB byte ordering
|
||||
RSVALS(buf,pos) - like SVALS() but for NMB byte ordering
|
||||
RIVAL(buf,pos) - like IVAL() but for NMB byte ordering
|
||||
RIVALS(buf,pos) - like IVALS() but for NMB byte ordering
|
||||
RSSVAL(buf,pos,val) - like SSVAL() but for NMB ordering
|
||||
RSIVAL(buf,pos,val) - like SIVAL() but for NMB ordering
|
||||
RSIVALS(buf,pos,val) - like SIVALS() but for NMB ordering
|
||||
RSVAL(buf,pos) - like SVAL() but for NMB byte ordering
|
||||
RSVALS(buf,pos) - like SVALS() but for NMB byte ordering
|
||||
RIVAL(buf,pos) - like IVAL() but for NMB byte ordering
|
||||
RIVALS(buf,pos) - like IVALS() but for NMB byte ordering
|
||||
RSSVAL(buf,pos,val) - like SSVAL() but for NMB ordering
|
||||
RSIVAL(buf,pos,val) - like SIVAL() but for NMB ordering
|
||||
RSIVALS(buf,pos,val) - like SIVALS() but for NMB ordering
|
||||
|
||||
it also defines lots of intermediate macros, just ignore those :-)
|
||||
it also defines lots of intermediate macros, just ignore those :-)
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
/* some switch macros that do both store and read to and from SMB buffers */
|
||||
|
||||
@ -142,7 +142,7 @@ it also defines lots of intermediate macros, just ignore those :-)
|
||||
/*
|
||||
WARNING: This section is dependent on the length of int16 and int32
|
||||
being correct
|
||||
*/
|
||||
*/
|
||||
|
||||
/* get single value from an SMB buffer */
|
||||
#define SVAL(buf,pos) (*(uint16 *)((char *)(buf) + (pos)))
|
||||
|
@ -2,7 +2,7 @@
|
||||
Unix SMB/Netbios implementation.
|
||||
Version 1.9.
|
||||
Character set handling
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef CHARSET_C
|
||||
|
||||
@ -44,7 +44,7 @@ extern char *lower_char_map;
|
||||
/* this is used to determine if a character is safe to use in
|
||||
something that may be put on a command line */
|
||||
#define issafe(c) (isalnum((c&0xff)) || strchr("-._",c))
|
||||
#endif /* !CHARSET_C */
|
||||
#endif /* !CHARSET_C */
|
||||
|
||||
/* Dynamic codepage files defines. */
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
Unix SMB/Netbios implementation.
|
||||
Version 1.9.
|
||||
SMB parameters and setup
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef _CLIENT_H
|
||||
#define _CLIENT_H
|
||||
@ -18,25 +18,25 @@
|
||||
|
||||
typedef struct file_info
|
||||
{
|
||||
SMB_OFF_T size;
|
||||
uint16 mode;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
/* these times are normally kept in GMT */
|
||||
time_t mtime;
|
||||
time_t atime;
|
||||
time_t ctime;
|
||||
pstring name;
|
||||
SMB_OFF_T size;
|
||||
uint16 mode;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
/* these times are normally kept in GMT */
|
||||
time_t mtime;
|
||||
time_t atime;
|
||||
time_t ctime;
|
||||
pstring name;
|
||||
} file_info;
|
||||
|
||||
struct print_job_info
|
||||
{
|
||||
uint16 id;
|
||||
uint16 priority;
|
||||
size_t size;
|
||||
fstring user;
|
||||
fstring name;
|
||||
time_t t;
|
||||
uint16 id;
|
||||
uint16 priority;
|
||||
size_t size;
|
||||
fstring user;
|
||||
fstring name;
|
||||
time_t t;
|
||||
};
|
||||
|
||||
struct pwd_info
|
||||
@ -54,73 +54,74 @@ struct pwd_info
|
||||
uchar smb_nt_owf[24];
|
||||
};
|
||||
|
||||
struct cli_state {
|
||||
int port;
|
||||
int fd;
|
||||
uint16 cnum;
|
||||
uint16 pid;
|
||||
uint16 mid;
|
||||
uint16 vuid;
|
||||
int protocol;
|
||||
int sec_mode;
|
||||
int rap_error;
|
||||
int privileges;
|
||||
struct cli_state
|
||||
{
|
||||
int port;
|
||||
int fd;
|
||||
uint16 cnum;
|
||||
uint16 pid;
|
||||
uint16 mid;
|
||||
uint16 vuid;
|
||||
int protocol;
|
||||
int sec_mode;
|
||||
int rap_error;
|
||||
int privileges;
|
||||
|
||||
fstring eff_name;
|
||||
fstring desthost;
|
||||
fstring user_name;
|
||||
fstring domain;
|
||||
fstring eff_name;
|
||||
fstring desthost;
|
||||
fstring user_name;
|
||||
fstring domain;
|
||||
|
||||
/*
|
||||
* The following strings are the
|
||||
* ones returned by the server if
|
||||
* the protocol > NT1.
|
||||
*/
|
||||
fstring server_type;
|
||||
fstring server_os;
|
||||
fstring server_domain;
|
||||
/*
|
||||
* The following strings are the
|
||||
* ones returned by the server if
|
||||
* the protocol > NT1.
|
||||
*/
|
||||
fstring server_type;
|
||||
fstring server_os;
|
||||
fstring server_domain;
|
||||
|
||||
fstring share;
|
||||
fstring dev;
|
||||
struct nmb_name called;
|
||||
struct nmb_name calling;
|
||||
fstring full_dest_host_name;
|
||||
struct in_addr dest_ip;
|
||||
fstring share;
|
||||
fstring dev;
|
||||
struct nmb_name called;
|
||||
struct nmb_name calling;
|
||||
fstring full_dest_host_name;
|
||||
struct in_addr dest_ip;
|
||||
|
||||
struct pwd_info pwd;
|
||||
unsigned char cryptkey[8];
|
||||
uint32 sesskey;
|
||||
int serverzone;
|
||||
uint32 servertime;
|
||||
int readbraw_supported;
|
||||
int writebraw_supported;
|
||||
int timeout; /* in milliseconds. */
|
||||
int max_xmit;
|
||||
int max_mux;
|
||||
char *outbuf;
|
||||
char *inbuf;
|
||||
int bufsize;
|
||||
int initialised;
|
||||
int win95;
|
||||
uint32 capabilities;
|
||||
struct pwd_info pwd;
|
||||
unsigned char cryptkey[8];
|
||||
uint32 sesskey;
|
||||
int serverzone;
|
||||
uint32 servertime;
|
||||
int readbraw_supported;
|
||||
int writebraw_supported;
|
||||
int timeout; /* in milliseconds. */
|
||||
int max_xmit;
|
||||
int max_mux;
|
||||
char *outbuf;
|
||||
char *inbuf;
|
||||
int bufsize;
|
||||
int initialised;
|
||||
int win95;
|
||||
uint32 capabilities;
|
||||
|
||||
/*
|
||||
* Only used in NT domain calls.
|
||||
*/
|
||||
/*
|
||||
* Only used in NT domain calls.
|
||||
*/
|
||||
|
||||
uint32 nt_error; /* NT RPC error code. */
|
||||
uint16 nt_pipe_fnum; /* Pipe handle. */
|
||||
unsigned char sess_key[16]; /* Current session key. */
|
||||
unsigned char ntlmssp_hash[258]; /* ntlmssp data. */
|
||||
uint32 ntlmssp_cli_flgs; /* ntlmssp client flags */
|
||||
uint32 ntlmssp_srv_flgs; /* ntlmssp server flags */
|
||||
uint32 ntlmssp_seq_num; /* ntlmssp sequence number */
|
||||
DOM_CRED clnt_cred; /* Client credential. */
|
||||
fstring mach_acct; /* MYNAME$. */
|
||||
fstring srv_name_slash; /* \\remote server. */
|
||||
fstring clnt_name_slash; /* \\local client. */
|
||||
uint16 max_xmit_frag;
|
||||
uint16 max_recv_frag;
|
||||
uint32 nt_error; /* NT RPC error code. */
|
||||
uint16 nt_pipe_fnum; /* Pipe handle. */
|
||||
unsigned char sess_key[16]; /* Current session key. */
|
||||
unsigned char ntlmssp_hash[258]; /* ntlmssp data. */
|
||||
uint32 ntlmssp_cli_flgs; /* ntlmssp client flags */
|
||||
uint32 ntlmssp_srv_flgs; /* ntlmssp server flags */
|
||||
uint32 ntlmssp_seq_num; /* ntlmssp sequence number */
|
||||
DOM_CRED clnt_cred; /* Client credential. */
|
||||
fstring mach_acct; /* MYNAME$. */
|
||||
fstring srv_name_slash; /* \\remote server. */
|
||||
fstring clnt_name_slash; /* \\local client. */
|
||||
uint16 max_xmit_frag;
|
||||
uint16 max_recv_frag;
|
||||
};
|
||||
|
||||
#endif /* _CLIENT_H */
|
||||
|
@ -4,9 +4,9 @@
|
||||
Unix SMB/Netbios implementation.
|
||||
Version 1.9.
|
||||
Machine customisation and include handling
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef NO_CONFIG_H /* for some tests */
|
||||
#ifndef NO_CONFIG_H /* for some tests */
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
@ -156,7 +156,7 @@
|
||||
/* POSIX terminal handling. */
|
||||
#include <termios.h>
|
||||
|
||||
# include <dirent.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#ifdef HAVE_SYS_MMAN_H
|
||||
#include <sys/mman.h>
|
||||
@ -185,23 +185,23 @@
|
||||
#include <sys/acl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_FS_S5PARAM_H
|
||||
#ifdef HAVE_SYS_FS_S5PARAM_H
|
||||
#include <sys/fs/s5param.h>
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
|
||||
#include <sys/filsys.h>
|
||||
#include <sys/filsys.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_STATFS_H
|
||||
# include <sys/statfs.h>
|
||||
#include <sys/statfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DUSTAT_H
|
||||
#ifdef HAVE_DUSTAT_H
|
||||
#include <sys/dustat.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_STATVFS_H
|
||||
#ifdef HAVE_SYS_STATVFS_H
|
||||
#include <sys/statvfs.h>
|
||||
#endif
|
||||
|
||||
@ -219,7 +219,7 @@
|
||||
#include <sys/security.h>
|
||||
#include <prot.h>
|
||||
#define PASSWORD_LENGTH 16
|
||||
#endif /* HAVE_SYS_SECURITY_H */
|
||||
#endif /* HAVE_SYS_SECURITY_H */
|
||||
|
||||
#ifdef HAVE_COMPAT_H
|
||||
#include <compat.h>
|
||||
@ -269,7 +269,7 @@
|
||||
they actually only need to be at least 16 and 32 bits
|
||||
respectively. Thus if your word size is 8 bytes just defining them
|
||||
as signed and unsigned int will work.
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef uint8
|
||||
#define uint8 unsigned char
|
||||
@ -334,23 +334,23 @@
|
||||
*/
|
||||
|
||||
#ifndef SMB_INO_T
|
||||
# define SMB_INO_T ino_t
|
||||
#define SMB_INO_T ino_t
|
||||
#endif
|
||||
|
||||
#ifndef LARGE_SMB_INO_T
|
||||
# if defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8)
|
||||
# define LARGE_SMB_INO_T 1
|
||||
# endif
|
||||
#if defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8)
|
||||
#define LARGE_SMB_INO_T 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef LARGE_SMB_INO_T
|
||||
#define SINO_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
|
||||
#else
|
||||
#else
|
||||
#define SINO_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
|
||||
#endif
|
||||
|
||||
#ifndef SMB_OFF_T
|
||||
# define SMB_OFF_T off_t
|
||||
#define SMB_OFF_T off_t
|
||||
#endif
|
||||
|
||||
#define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
|
||||
@ -361,14 +361,14 @@
|
||||
*/
|
||||
|
||||
#ifndef LARGE_SMB_OFF_T
|
||||
# if defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8)
|
||||
# define LARGE_SMB_OFF_T 1
|
||||
# endif
|
||||
#if defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8)
|
||||
#define LARGE_SMB_OFF_T 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef LARGE_SMB_OFF_T
|
||||
#define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
|
||||
#else
|
||||
#else
|
||||
#define SOFF_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
|
||||
#endif
|
||||
|
||||
@ -377,7 +377,7 @@
|
||||
*/
|
||||
|
||||
#ifndef SMB_STRUCT_STAT
|
||||
# define SMB_STRUCT_STAT struct stat
|
||||
#define SMB_STRUCT_STAT struct stat
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -385,7 +385,7 @@
|
||||
*/
|
||||
|
||||
#ifndef SMB_STRUCT_DIRENT
|
||||
# define SMB_STRUCT_DIRENT struct dirent
|
||||
#define SMB_STRUCT_DIRENT struct dirent
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -393,19 +393,19 @@
|
||||
*/
|
||||
|
||||
#ifndef SMB_STRUCT_FLOCK
|
||||
# define SMB_STRUCT_FLOCK struct flock
|
||||
#define SMB_STRUCT_FLOCK struct flock
|
||||
#endif
|
||||
|
||||
#ifndef SMB_F_SETLKW
|
||||
# define SMB_F_SETLKW F_SETLKW
|
||||
#define SMB_F_SETLKW F_SETLKW
|
||||
#endif
|
||||
|
||||
#ifndef SMB_F_SETLK
|
||||
# define SMB_F_SETLK F_SETLK
|
||||
#define SMB_F_SETLK F_SETLK
|
||||
#endif
|
||||
|
||||
#ifndef SMB_F_GETLK
|
||||
# define SMB_F_GETLK F_GETLK
|
||||
#define SMB_F_GETLK F_GETLK
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LONGLONG)
|
||||
@ -515,7 +515,7 @@
|
||||
#endif
|
||||
|
||||
/* what is the longest significant password available on your system?
|
||||
Knowing this speeds up password searches a lot */
|
||||
Knowing this speeds up password searches a lot */
|
||||
#ifndef PASSWORD_LENGTH
|
||||
#define PASSWORD_LENGTH 8
|
||||
#endif
|
||||
@ -549,19 +549,19 @@
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INITGROUPS
|
||||
int initgroups(char *name,gid_t id);
|
||||
int initgroups (char *name, gid_t id);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_RENAME
|
||||
int rename(const char *zfrom, const char *zto);
|
||||
int rename (const char *zfrom, const char *zto);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MKTIME
|
||||
time_t mktime(struct tm *t);
|
||||
time_t mktime (struct tm *t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOUL
|
||||
unsigned long strtoul(const char *nptr, char **endptr, int base);
|
||||
unsigned long strtoul (const char *nptr, char **endptr, int base);
|
||||
#endif
|
||||
|
||||
#ifdef REPLACE_GETPASS
|
||||
|
@ -2,7 +2,7 @@
|
||||
Unix SMB/Netbios implementation.
|
||||
Version 1.9.
|
||||
Kanji Extensions
|
||||
*/
|
||||
*/
|
||||
#ifndef _KANJI_H_
|
||||
#define _KANJI_H_
|
||||
|
||||
@ -86,7 +86,7 @@
|
||||
#define is_hangul(c) ((0x81 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xfd))
|
||||
|
||||
/* For traditional Chinese (known as Big5 encoding - code page 950). */
|
||||
#define is_big5_c1(c) ((0xa1 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xf9))
|
||||
#define is_big5_c1(c) ((0xa1 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xf9))
|
||||
|
||||
/* For simplified Chinese (code page - 936). */
|
||||
#define is_simpch_c1(c) ((0xa1 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xf7))
|
||||
@ -118,14 +118,14 @@
|
||||
/* Ensure we use our definitions in all other files than kanji.c. */
|
||||
|
||||
/* Function pointers we will replace. */
|
||||
extern char *(*multibyte_strchr)(const char *s, int c);
|
||||
extern char *(*multibyte_strrchr)(const char *s, int c);
|
||||
extern char *(*multibyte_strstr)(const char *s1, const char *s2);
|
||||
extern char *(*multibyte_strtok)(char *s1, const char *s2);
|
||||
extern char *(*_dos_to_unix)(char *str, BOOL overwrite);
|
||||
extern char *(*_unix_to_dos)(char *str, BOOL overwrite);
|
||||
extern BOOL (*is_multibyte_char)(char c);
|
||||
extern int (*_skip_multibyte_char)(char c);
|
||||
extern char *(*multibyte_strchr) (const char *s, int c);
|
||||
extern char *(*multibyte_strrchr) (const char *s, int c);
|
||||
extern char *(*multibyte_strstr) (const char *s1, const char *s2);
|
||||
extern char *(*multibyte_strtok) (char *s1, const char *s2);
|
||||
extern char *(*_dos_to_unix) (char *str, BOOL overwrite);
|
||||
extern char *(*_unix_to_dos) (char *str, BOOL overwrite);
|
||||
extern BOOL (*is_multibyte_char) (char c);
|
||||
extern int (*_skip_multibyte_char) (char c);
|
||||
|
||||
#define strchr(s1, c) ((*multibyte_strchr)((s1), (c)))
|
||||
#define strrchr(s1, c) ((*multibyte_strrchr)((s1), (c)))
|
||||
|
@ -25,7 +25,7 @@
|
||||
refer to the special "printers" service */
|
||||
#define PRINTERS_NAME "printers"
|
||||
|
||||
/* Yves Gaige <yvesg@hptnodur.grenoble.hp.com> requested this set this */
|
||||
/* Yves Gaige <yvesg@hptnodur.grenoble.hp.com> requested this set this */
|
||||
/* to a maximum of 8 if old smb clients break because of long printer names. */
|
||||
#define MAXPRINTERLEN 15
|
||||
|
||||
@ -59,7 +59,7 @@
|
||||
#ifndef MAX_OPEN_FILES
|
||||
#define MAX_OPEN_FILES 10000
|
||||
#endif
|
||||
|
||||
|
||||
/* the max number of simultanous connections to the server by all clients */
|
||||
#define MAXSTATUS 100000
|
||||
|
||||
@ -80,7 +80,7 @@
|
||||
|
||||
/* shall filenames with illegal chars in them get mangled in long
|
||||
filename listings? */
|
||||
#define MANGLE_LONG_FILENAMES
|
||||
#define MANGLE_LONG_FILENAMES
|
||||
|
||||
/* define this if you want to stop spoofing with .. and soft links
|
||||
NOTE: This also slows down the server considerably */
|
||||
@ -152,7 +152,7 @@
|
||||
#define SHORT_CONNECT_TIMEOUT 5000
|
||||
|
||||
/* default socket options. Dave Miller thinks we should default to TCP_NODELAY
|
||||
given the socket IO pattern that Samba uses*/
|
||||
given the socket IO pattern that Samba uses */
|
||||
#ifdef TCP_NODELAY
|
||||
#define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
|
||||
#else
|
||||
|
@ -4,7 +4,7 @@
|
||||
Unix SMB/Netbios implementation.
|
||||
Version 1.9.
|
||||
NBT netbios header - version 2
|
||||
*/
|
||||
*/
|
||||
|
||||
#define PERMANENT_TTL 0
|
||||
|
||||
@ -12,16 +12,18 @@
|
||||
#define MAINTAIN_LIST 2
|
||||
#define ELECTION_VERSION 1
|
||||
|
||||
#define MAX_DGRAM_SIZE (576) /* tcp/ip datagram limit is 576 bytes */
|
||||
#define MAX_DGRAM_SIZE (576) /* tcp/ip datagram limit is 576 bytes */
|
||||
#define MIN_DGRAM_SIZE 12
|
||||
|
||||
/*********************************************************
|
||||
Types of reply packet.
|
||||
**********************************************************/
|
||||
|
||||
enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
|
||||
NMB_REL, NMB_WAIT_ACK, NMB_MULTIHOMED_REG,
|
||||
WINS_REG, WINS_QUERY };
|
||||
enum netbios_reply_type_code
|
||||
{ NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
|
||||
NMB_REL, NMB_WAIT_ACK, NMB_MULTIHOMED_REG,
|
||||
WINS_REG, WINS_QUERY
|
||||
};
|
||||
|
||||
/* From rfc1002, 4.2.1.2 */
|
||||
/* Question types. */
|
||||
@ -33,14 +35,14 @@ enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
|
||||
|
||||
/* Opcode definitions */
|
||||
#define NMB_NAME_QUERY_OPCODE 0x0
|
||||
#define NMB_NAME_REG_OPCODE 0x05 /* see rfc1002.txt 4.2.2,3,5,6,7,8 */
|
||||
#define NMB_NAME_RELEASE_OPCODE 0x06 /* see rfc1002.txt 4.2.9,10,11 */
|
||||
#define NMB_WACK_OPCODE 0x07 /* see rfc1002.txt 4.2.16 */
|
||||
#define NMB_NAME_REG_OPCODE 0x05 /* see rfc1002.txt 4.2.2,3,5,6,7,8 */
|
||||
#define NMB_NAME_RELEASE_OPCODE 0x06 /* see rfc1002.txt 4.2.9,10,11 */
|
||||
#define NMB_WACK_OPCODE 0x07 /* see rfc1002.txt 4.2.16 */
|
||||
/* Ambiguity in rfc1002 about which of these is correct. */
|
||||
/* WinNT uses 8 by default but can be made to use 9. */
|
||||
#define NMB_NAME_REFRESH_OPCODE_8 0x08 /* see rfc1002.txt 4.2.4 */
|
||||
#define NMB_NAME_REFRESH_OPCODE_9 0x09 /* see rfc1002.txt 4.2.4 */
|
||||
#define NMB_NAME_MULTIHOMED_REG_OPCODE 0x0F /* Invented by Microsoft. */
|
||||
#define NMB_NAME_REFRESH_OPCODE_8 0x08 /* see rfc1002.txt 4.2.4 */
|
||||
#define NMB_NAME_REFRESH_OPCODE_9 0x09 /* see rfc1002.txt 4.2.4 */
|
||||
#define NMB_NAME_MULTIHOMED_REG_OPCODE 0x0F /* Invented by Microsoft. */
|
||||
|
||||
/* XXXX what about all the other types?? 0x1, 0x2, 0x3, 0x4, 0x8? */
|
||||
|
||||
@ -60,10 +62,10 @@ enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
|
||||
#define NB_ACTIVE 0x04
|
||||
#define NB_CONFL 0x08
|
||||
#define NB_DEREG 0x10
|
||||
#define NB_BFLAG 0x00 /* Broadcast node type. */
|
||||
#define NB_PFLAG 0x20 /* Point-to-point node type. */
|
||||
#define NB_MFLAG 0x40 /* Mixed bcast & p-p node type. */
|
||||
#define NB_HFLAG 0x60 /* Microsoft 'hybrid' node type. */
|
||||
#define NB_BFLAG 0x00 /* Broadcast node type. */
|
||||
#define NB_PFLAG 0x20 /* Point-to-point node type. */
|
||||
#define NB_MFLAG 0x40 /* Mixed bcast & p-p node type. */
|
||||
#define NB_HFLAG 0x60 /* Microsoft 'hybrid' node type. */
|
||||
#define NB_NODETYPEMASK 0x60
|
||||
/* Mask applied to outgoing NetBIOS flags. */
|
||||
#define NB_FLGMSK 0xE0
|
||||
@ -81,13 +83,13 @@ enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
|
||||
#define NAME_IS_DEREGISTERING(p) ((p)->data.nb_flags & NB_DEREG)
|
||||
|
||||
/* Error codes for NetBIOS requests. */
|
||||
#define FMT_ERR 0x1 /* Packet format error. */
|
||||
#define SRV_ERR 0x2 /* Internal server error. */
|
||||
#define NAM_ERR 0x3 /* Name does not exist. */
|
||||
#define IMP_ERR 0x4 /* Request not implemented. */
|
||||
#define RFS_ERR 0x5 /* Request refused. */
|
||||
#define ACT_ERR 0x6 /* Active error - name owned by another host. */
|
||||
#define CFT_ERR 0x7 /* Name in conflict error. */
|
||||
#define FMT_ERR 0x1 /* Packet format error. */
|
||||
#define SRV_ERR 0x2 /* Internal server error. */
|
||||
#define NAM_ERR 0x3 /* Name does not exist. */
|
||||
#define IMP_ERR 0x4 /* Request not implemented. */
|
||||
#define RFS_ERR 0x5 /* Request refused. */
|
||||
#define ACT_ERR 0x6 /* Active error - name owned by another host. */
|
||||
#define CFT_ERR 0x7 /* Name in conflict error. */
|
||||
|
||||
#define REFRESH_TIME (15*60)
|
||||
#define NAME_POLL_REFRESH_TIME (5*60)
|
||||
@ -123,47 +125,51 @@ enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
|
||||
*
|
||||
*/
|
||||
|
||||
enum name_source {LMHOSTS_NAME, REGISTER_NAME, SELF_NAME, DNS_NAME,
|
||||
DNSFAIL_NAME, PERMANENT_NAME, WINS_PROXY_NAME};
|
||||
enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3};
|
||||
enum packet_type {NMB_PACKET, DGRAM_PACKET};
|
||||
enum name_source
|
||||
{ LMHOSTS_NAME, REGISTER_NAME, SELF_NAME, DNS_NAME,
|
||||
DNSFAIL_NAME, PERMANENT_NAME, WINS_PROXY_NAME
|
||||
};
|
||||
enum node_type
|
||||
{ B_NODE = 0, P_NODE = 1, M_NODE = 2, NBDD_NODE = 3 };
|
||||
enum packet_type
|
||||
{ NMB_PACKET, DGRAM_PACKET };
|
||||
|
||||
enum master_state
|
||||
{
|
||||
MST_NONE,
|
||||
MST_POTENTIAL,
|
||||
MST_BACKUP,
|
||||
MST_MSB,
|
||||
MST_BROWSER,
|
||||
MST_UNBECOMING_MASTER
|
||||
MST_NONE,
|
||||
MST_POTENTIAL,
|
||||
MST_BACKUP,
|
||||
MST_MSB,
|
||||
MST_BROWSER,
|
||||
MST_UNBECOMING_MASTER
|
||||
};
|
||||
|
||||
enum domain_state
|
||||
{
|
||||
DOMAIN_NONE,
|
||||
DOMAIN_WAIT,
|
||||
DOMAIN_MST
|
||||
DOMAIN_NONE,
|
||||
DOMAIN_WAIT,
|
||||
DOMAIN_MST
|
||||
};
|
||||
|
||||
enum logon_state
|
||||
{
|
||||
LOGON_NONE,
|
||||
LOGON_WAIT,
|
||||
LOGON_SRV
|
||||
LOGON_NONE,
|
||||
LOGON_WAIT,
|
||||
LOGON_SRV
|
||||
};
|
||||
|
||||
struct subnet_record;
|
||||
|
||||
struct nmb_data
|
||||
{
|
||||
uint16 nb_flags; /* Netbios flags. */
|
||||
int num_ips; /* Number of ip entries. */
|
||||
struct in_addr *ip; /* The ip list for this name. */
|
||||
uint16 nb_flags; /* Netbios flags. */
|
||||
int num_ips; /* Number of ip entries. */
|
||||
struct in_addr *ip; /* The ip list for this name. */
|
||||
|
||||
enum name_source source; /* Where the name came from. */
|
||||
enum name_source source; /* Where the name came from. */
|
||||
|
||||
time_t death_time; /* The time the record must be removed (do not remove if 0). */
|
||||
time_t refresh_time; /* The time the record should be refreshed. */
|
||||
time_t death_time; /* The time the record must be removed (do not remove if 0). */
|
||||
time_t refresh_time; /* The time the record should be refreshed. */
|
||||
};
|
||||
|
||||
/* This is used to hold the list of servers in my domain, and is
|
||||
@ -171,71 +177,72 @@ struct nmb_data
|
||||
|
||||
struct server_record
|
||||
{
|
||||
struct server_record *next;
|
||||
struct server_record *prev;
|
||||
struct server_record *next;
|
||||
struct server_record *prev;
|
||||
|
||||
struct subnet_record *subnet;
|
||||
struct subnet_record *subnet;
|
||||
|
||||
struct server_info_struct serv;
|
||||
time_t death_time;
|
||||
struct server_info_struct serv;
|
||||
time_t death_time;
|
||||
};
|
||||
|
||||
/* A workgroup structure. It contains a list of servers. */
|
||||
struct work_record
|
||||
{
|
||||
struct work_record *next;
|
||||
struct work_record *prev;
|
||||
struct work_record *next;
|
||||
struct work_record *prev;
|
||||
|
||||
struct subnet_record *subnet;
|
||||
struct subnet_record *subnet;
|
||||
|
||||
struct server_record *serverlist;
|
||||
struct server_record *serverlist;
|
||||
|
||||
/* Stage of development from non-local-master up to local-master browser. */
|
||||
enum master_state mst_state;
|
||||
/* Stage of development from non-local-master up to local-master browser. */
|
||||
enum master_state mst_state;
|
||||
|
||||
/* Stage of development from non-domain-master to domain-master browser. */
|
||||
enum domain_state dom_state;
|
||||
/* Stage of development from non-domain-master to domain-master browser. */
|
||||
enum domain_state dom_state;
|
||||
|
||||
/* Stage of development from non-logon-server to logon server. */
|
||||
enum logon_state log_state;
|
||||
/* Stage of development from non-logon-server to logon server. */
|
||||
enum logon_state log_state;
|
||||
|
||||
/* Work group info. */
|
||||
fstring work_group;
|
||||
int token; /* Used when communicating with backup browsers. */
|
||||
fstring local_master_browser_name; /* Current local master browser. */
|
||||
/* Work group info. */
|
||||
fstring work_group;
|
||||
int token; /* Used when communicating with backup browsers. */
|
||||
fstring local_master_browser_name; /* Current local master browser. */
|
||||
|
||||
/* Announce info. */
|
||||
time_t lastannounce_time;
|
||||
int announce_interval;
|
||||
BOOL needannounce;
|
||||
/* Announce info. */
|
||||
time_t lastannounce_time;
|
||||
int announce_interval;
|
||||
BOOL needannounce;
|
||||
|
||||
/* Timeout time for this workgroup. 0 means permanent. */
|
||||
time_t death_time;
|
||||
/* Timeout time for this workgroup. 0 means permanent. */
|
||||
time_t death_time;
|
||||
|
||||
/* Election info */
|
||||
BOOL RunningElection;
|
||||
BOOL needelection;
|
||||
int ElectionCount;
|
||||
uint32 ElectionCriterion;
|
||||
/* Election info */
|
||||
BOOL RunningElection;
|
||||
BOOL needelection;
|
||||
int ElectionCount;
|
||||
uint32 ElectionCriterion;
|
||||
|
||||
/* Domain master browser info. Used for efficient syncs. */
|
||||
struct nmb_name dmb_name;
|
||||
struct in_addr dmb_addr;
|
||||
/* Domain master browser info. Used for efficient syncs. */
|
||||
struct nmb_name dmb_name;
|
||||
struct in_addr dmb_addr;
|
||||
};
|
||||
|
||||
/* typedefs needed to define copy & free functions for userdata. */
|
||||
struct userdata_struct;
|
||||
|
||||
typedef struct userdata_struct * (*userdata_copy_fn)(struct userdata_struct *);
|
||||
typedef void (*userdata_free_fn)(struct userdata_struct *);
|
||||
typedef struct userdata_struct *(*userdata_copy_fn) (struct userdata_struct *);
|
||||
typedef void (*userdata_free_fn) (struct userdata_struct *);
|
||||
|
||||
/* Structure to define any userdata passed around. */
|
||||
|
||||
struct userdata_struct {
|
||||
userdata_copy_fn copy_fn;
|
||||
userdata_free_fn free_fn;
|
||||
unsigned int userdata_len;
|
||||
char data[16]; /* 16 is to ensure alignment/padding on all systems */
|
||||
struct userdata_struct
|
||||
{
|
||||
userdata_copy_fn copy_fn;
|
||||
userdata_free_fn free_fn;
|
||||
unsigned int userdata_len;
|
||||
char data[16]; /* 16 is to ensure alignment/padding on all systems */
|
||||
};
|
||||
|
||||
struct response_record;
|
||||
@ -243,99 +250,83 @@ struct packet_struct;
|
||||
struct res_rec;
|
||||
|
||||
/* typedef to define the function called when this response packet comes in. */
|
||||
typedef void (*response_function)(struct subnet_record *, struct response_record *,
|
||||
struct packet_struct *);
|
||||
typedef void (*response_function) (struct subnet_record *, struct response_record *,
|
||||
struct packet_struct *);
|
||||
|
||||
/* typedef to define the function called when this response record times out. */
|
||||
typedef void (*timeout_response_function)(struct subnet_record *,
|
||||
struct response_record *);
|
||||
typedef void (*timeout_response_function) (struct subnet_record *, struct response_record *);
|
||||
|
||||
/* typedef to define the function called when the request that caused this
|
||||
response record to be created is successful. */
|
||||
typedef void (*success_function)(struct subnet_record *, struct userdata_struct *, ...);
|
||||
typedef void (*success_function) (struct subnet_record *, struct userdata_struct *, ...);
|
||||
|
||||
/* typedef to define the function called when the request that caused this
|
||||
response record to be created is unsuccessful. */
|
||||
typedef void (*fail_function)(struct subnet_record *, struct response_record *, ...);
|
||||
typedef void (*fail_function) (struct subnet_record *, struct response_record *, ...);
|
||||
|
||||
/* List of typedefs for success and fail functions of the different query
|
||||
types. Used to catch any compile time prototype errors. */
|
||||
|
||||
typedef void (*register_name_success_function)( struct subnet_record *,
|
||||
typedef void (*register_name_success_function) (struct subnet_record *,
|
||||
struct userdata_struct *,
|
||||
struct nmb_name *,
|
||||
uint16,
|
||||
int,
|
||||
struct in_addr);
|
||||
typedef void (*register_name_fail_function)( struct subnet_record *,
|
||||
struct response_record *,
|
||||
struct nmb_name *);
|
||||
struct nmb_name *, uint16, int, struct in_addr);
|
||||
typedef void (*register_name_fail_function) (struct subnet_record *,
|
||||
struct response_record *, struct nmb_name *);
|
||||
|
||||
typedef void (*release_name_success_function)( struct subnet_record *,
|
||||
struct userdata_struct *,
|
||||
struct nmb_name *,
|
||||
struct in_addr);
|
||||
typedef void (*release_name_fail_function)( struct subnet_record *,
|
||||
struct response_record *,
|
||||
struct nmb_name *);
|
||||
typedef void (*release_name_success_function) (struct subnet_record *,
|
||||
struct userdata_struct *,
|
||||
struct nmb_name *, struct in_addr);
|
||||
typedef void (*release_name_fail_function) (struct subnet_record *,
|
||||
struct response_record *, struct nmb_name *);
|
||||
|
||||
typedef void (*refresh_name_success_function)( struct subnet_record *,
|
||||
struct userdata_struct *,
|
||||
struct nmb_name *,
|
||||
uint16,
|
||||
int,
|
||||
struct in_addr);
|
||||
typedef void (*refresh_name_fail_function)( struct subnet_record *,
|
||||
struct response_record *,
|
||||
struct nmb_name *);
|
||||
typedef void (*refresh_name_success_function) (struct subnet_record *,
|
||||
struct userdata_struct *,
|
||||
struct nmb_name *, uint16, int, struct in_addr);
|
||||
typedef void (*refresh_name_fail_function) (struct subnet_record *,
|
||||
struct response_record *, struct nmb_name *);
|
||||
|
||||
typedef void (*query_name_success_function)( struct subnet_record *,
|
||||
typedef void (*query_name_success_function) (struct subnet_record *,
|
||||
struct userdata_struct *,
|
||||
struct nmb_name *,
|
||||
struct in_addr,
|
||||
struct res_rec *answers);
|
||||
struct in_addr, struct res_rec * answers);
|
||||
|
||||
typedef void (*query_name_fail_function)( struct subnet_record *,
|
||||
struct response_record *,
|
||||
struct nmb_name *,
|
||||
int);
|
||||
typedef void (*query_name_fail_function) (struct subnet_record *,
|
||||
struct response_record *, struct nmb_name *, int);
|
||||
|
||||
typedef void (*node_status_success_function)( struct subnet_record *,
|
||||
typedef void (*node_status_success_function) (struct subnet_record *,
|
||||
struct userdata_struct *,
|
||||
struct res_rec *,
|
||||
struct in_addr);
|
||||
typedef void (*node_status_fail_function)( struct subnet_record *,
|
||||
struct response_record *);
|
||||
struct res_rec *, struct in_addr);
|
||||
typedef void (*node_status_fail_function) (struct subnet_record *, struct response_record *);
|
||||
|
||||
/* Initiated name queries are recorded in this list to track any responses. */
|
||||
|
||||
struct response_record
|
||||
{
|
||||
struct response_record *next;
|
||||
struct response_record *prev;
|
||||
struct response_record *next;
|
||||
struct response_record *prev;
|
||||
|
||||
uint16 response_id;
|
||||
uint16 response_id;
|
||||
|
||||
/* Callbacks for packets received or not. */
|
||||
response_function resp_fn;
|
||||
timeout_response_function timeout_fn;
|
||||
/* Callbacks for packets received or not. */
|
||||
response_function resp_fn;
|
||||
timeout_response_function timeout_fn;
|
||||
|
||||
/* Callbacks for the request succeeding or not. */
|
||||
success_function success_fn;
|
||||
fail_function fail_fn;
|
||||
|
||||
struct packet_struct *packet;
|
||||
/* Callbacks for the request succeeding or not. */
|
||||
success_function success_fn;
|
||||
fail_function fail_fn;
|
||||
|
||||
struct userdata_struct *userdata;
|
||||
struct packet_struct *packet;
|
||||
|
||||
int num_msgs;
|
||||
struct userdata_struct *userdata;
|
||||
|
||||
time_t repeat_time;
|
||||
time_t repeat_interval;
|
||||
int repeat_count;
|
||||
int num_msgs;
|
||||
|
||||
/* Recursion protection. */
|
||||
BOOL in_expiration_processing;
|
||||
time_t repeat_time;
|
||||
time_t repeat_interval;
|
||||
int repeat_count;
|
||||
|
||||
/* Recursion protection. */
|
||||
BOOL in_expiration_processing;
|
||||
};
|
||||
|
||||
/* A subnet structure. It contains a list of workgroups and netbios names. */
|
||||
@ -344,103 +335,112 @@ struct response_record
|
||||
B nodes will have their own, totally separate subnet record, with their
|
||||
own netbios name set. These do NOT interact with other subnet records'
|
||||
netbios names.
|
||||
*/
|
||||
*/
|
||||
|
||||
enum subnet_type {
|
||||
NORMAL_SUBNET = 0, /* Subnet listed in interfaces list. */
|
||||
UNICAST_SUBNET = 1, /* Subnet for unicast packets. */
|
||||
REMOTE_BROADCAST_SUBNET = 2, /* Subnet for remote broadcasts. */
|
||||
WINS_SERVER_SUBNET = 3 /* Only created if we are a WINS server. */
|
||||
enum subnet_type
|
||||
{
|
||||
NORMAL_SUBNET = 0, /* Subnet listed in interfaces list. */
|
||||
UNICAST_SUBNET = 1, /* Subnet for unicast packets. */
|
||||
REMOTE_BROADCAST_SUBNET = 2, /* Subnet for remote broadcasts. */
|
||||
WINS_SERVER_SUBNET = 3 /* Only created if we are a WINS server. */
|
||||
};
|
||||
|
||||
/* A resource record. */
|
||||
struct res_rec {
|
||||
struct nmb_name rr_name;
|
||||
int rr_type;
|
||||
int rr_class;
|
||||
int ttl;
|
||||
int rdlength;
|
||||
char rdata[MAX_DGRAM_SIZE];
|
||||
struct res_rec
|
||||
{
|
||||
struct nmb_name rr_name;
|
||||
int rr_type;
|
||||
int rr_class;
|
||||
int ttl;
|
||||
int rdlength;
|
||||
char rdata[MAX_DGRAM_SIZE];
|
||||
};
|
||||
|
||||
/* An nmb packet. */
|
||||
struct nmb_packet
|
||||
{
|
||||
struct {
|
||||
int name_trn_id;
|
||||
int opcode;
|
||||
BOOL response;
|
||||
struct {
|
||||
BOOL bcast;
|
||||
BOOL recursion_available;
|
||||
BOOL recursion_desired;
|
||||
BOOL trunc;
|
||||
BOOL authoritative;
|
||||
} nm_flags;
|
||||
int rcode;
|
||||
int qdcount;
|
||||
int ancount;
|
||||
int nscount;
|
||||
int arcount;
|
||||
} header;
|
||||
struct
|
||||
{
|
||||
int name_trn_id;
|
||||
int opcode;
|
||||
BOOL response;
|
||||
struct
|
||||
{
|
||||
BOOL bcast;
|
||||
BOOL recursion_available;
|
||||
BOOL recursion_desired;
|
||||
BOOL trunc;
|
||||
BOOL authoritative;
|
||||
} nm_flags;
|
||||
int rcode;
|
||||
int qdcount;
|
||||
int ancount;
|
||||
int nscount;
|
||||
int arcount;
|
||||
} header;
|
||||
|
||||
struct {
|
||||
struct nmb_name question_name;
|
||||
int question_type;
|
||||
int question_class;
|
||||
} question;
|
||||
struct
|
||||
{
|
||||
struct nmb_name question_name;
|
||||
int question_type;
|
||||
int question_class;
|
||||
} question;
|
||||
|
||||
struct res_rec *answers;
|
||||
struct res_rec *nsrecs;
|
||||
struct res_rec *additional;
|
||||
struct res_rec *answers;
|
||||
struct res_rec *nsrecs;
|
||||
struct res_rec *additional;
|
||||
};
|
||||
|
||||
|
||||
/* A datagram - this normally contains SMB data in the data[] array. */
|
||||
|
||||
struct dgram_packet {
|
||||
struct {
|
||||
int msg_type;
|
||||
struct {
|
||||
enum node_type node_type;
|
||||
BOOL first;
|
||||
BOOL more;
|
||||
} flags;
|
||||
int dgm_id;
|
||||
struct in_addr source_ip;
|
||||
int source_port;
|
||||
int dgm_length;
|
||||
int packet_offset;
|
||||
} header;
|
||||
struct nmb_name source_name;
|
||||
struct nmb_name dest_name;
|
||||
int datasize;
|
||||
char data[MAX_DGRAM_SIZE];
|
||||
struct dgram_packet
|
||||
{
|
||||
struct
|
||||
{
|
||||
int msg_type;
|
||||
struct
|
||||
{
|
||||
enum node_type node_type;
|
||||
BOOL first;
|
||||
BOOL more;
|
||||
} flags;
|
||||
int dgm_id;
|
||||
struct in_addr source_ip;
|
||||
int source_port;
|
||||
int dgm_length;
|
||||
int packet_offset;
|
||||
} header;
|
||||
struct nmb_name source_name;
|
||||
struct nmb_name dest_name;
|
||||
int datasize;
|
||||
char data[MAX_DGRAM_SIZE];
|
||||
};
|
||||
|
||||
/* Define a structure used to queue packets. This will be a linked
|
||||
list of nmb packets. */
|
||||
list of nmb packets. */
|
||||
|
||||
struct packet_struct
|
||||
{
|
||||
struct packet_struct *next;
|
||||
struct packet_struct *prev;
|
||||
BOOL locked;
|
||||
struct in_addr ip;
|
||||
int port;
|
||||
int fd;
|
||||
time_t timestamp;
|
||||
enum packet_type packet_type;
|
||||
union {
|
||||
struct nmb_packet nmb;
|
||||
struct dgram_packet dgram;
|
||||
} packet;
|
||||
struct packet_struct *next;
|
||||
struct packet_struct *prev;
|
||||
BOOL locked;
|
||||
struct in_addr ip;
|
||||
int port;
|
||||
int fd;
|
||||
time_t timestamp;
|
||||
enum packet_type packet_type;
|
||||
union
|
||||
{
|
||||
struct nmb_packet nmb;
|
||||
struct dgram_packet dgram;
|
||||
} packet;
|
||||
};
|
||||
|
||||
/* NETLOGON opcodes */
|
||||
|
||||
#define QUERYFORPDC 7 /* Query for PDC. */
|
||||
#define QUERYFORPDC_R 12 /* Response to Query for PDC. */
|
||||
#define QUERYFORPDC 7 /* Query for PDC. */
|
||||
#define QUERYFORPDC_R 12 /* Response to Query for PDC. */
|
||||
#define SAMLOGON 18
|
||||
#define SAMLOGON_R 19
|
||||
|
||||
@ -462,11 +462,11 @@ struct packet_struct
|
||||
/* Broadcast packet announcement intervals, in minutes. */
|
||||
|
||||
/* Attempt to add domain logon and domain master names. */
|
||||
#define CHECK_TIME_ADD_DOM_NAMES 5
|
||||
#define CHECK_TIME_ADD_DOM_NAMES 5
|
||||
|
||||
/* Search for master browsers of workgroups samba knows about,
|
||||
except default. */
|
||||
#define CHECK_TIME_MST_BROWSE 5
|
||||
#define CHECK_TIME_MST_BROWSE 5
|
||||
|
||||
/* Request backup browser announcements from other servers. */
|
||||
#define CHECK_TIME_ANNOUNCE_BACKUP 15
|
||||
@ -501,5 +501,6 @@ extern struct subnet_record *remote_broadcast_subnet;
|
||||
#define NEXT_SUBNET_INCLUDING_UNICAST(x) (get_next_subnet_maybe_unicast((x)))
|
||||
|
||||
/* To be removed. */
|
||||
enum state_type { TEST };
|
||||
enum state_type
|
||||
{ TEST };
|
||||
#endif /* _NAMESERV_H_ */
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
||||
Unix SMB/Netbios implementation.
|
||||
Version 1.9.
|
||||
SMB transaction2 handling
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef _TRANS2_H_
|
||||
#define _TRANS2_H_
|
||||
@ -243,6 +243,3 @@ Byte offset Type name description
|
||||
#define TYPE_VIRTUAL 0x40
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
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"
|
||||
#define CTRLZ 26
|
||||
@ -35,203 +35,243 @@ static BOOL mapsinited = 0;
|
||||
static char unix2dos[256];
|
||||
static char dos2unix[256];
|
||||
|
||||
static void initmaps(void) {
|
||||
static void
|
||||
initmaps (void)
|
||||
{
|
||||
int k;
|
||||
|
||||
for (k = 0; k < 256; k++) unix2dos[k] = k;
|
||||
for (k = 0; k < 256; k++) dos2unix[k] = k;
|
||||
for (k = 0; k < 256; k++)
|
||||
unix2dos[k] = k;
|
||||
for (k = 0; k < 256; k++)
|
||||
dos2unix[k] = k;
|
||||
|
||||
mapsinited = True;
|
||||
}
|
||||
|
||||
static void update_map(const char * str) {
|
||||
static void
|
||||
update_map (const char *str)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
for (p = str; *p; p++) {
|
||||
if (p[1]) {
|
||||
unix2dos[(unsigned char)*p] = p[1];
|
||||
dos2unix[(unsigned char)p[1]] = *p;
|
||||
for (p = str; *p; p++)
|
||||
{
|
||||
if (p[1])
|
||||
{
|
||||
unix2dos[(unsigned char) *p] = p[1];
|
||||
dos2unix[(unsigned char) p[1]] = *p;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void init_iso8859_1(void) {
|
||||
static void
|
||||
init_iso8859_1 (void)
|
||||
{
|
||||
|
||||
int i;
|
||||
if (!mapsinited) initmaps();
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
/* Do not map undefined characters to some accidental code */
|
||||
for (i = 128; i < 256; i++)
|
||||
for (i = 128; i < 256; i++)
|
||||
{
|
||||
unix2dos[i] = CTRLZ;
|
||||
dos2unix[i] = CTRLZ;
|
||||
unix2dos[i] = CTRLZ;
|
||||
dos2unix[i] = CTRLZ;
|
||||
}
|
||||
|
||||
/* MSDOS Code Page 850 -> ISO-8859 */
|
||||
update_map("\240\377\241\255\242\275\243\234\244\317\245\276\246\335\247\365");
|
||||
update_map("\250\371\251\270\252\246\253\256\254\252\255\360\256\251\257\356");
|
||||
update_map("\260\370\261\361\262\375\263\374\264\357\265\346\266\364\267\372");
|
||||
update_map("\270\367\271\373\272\247\273\257\274\254\275\253\276\363\277\250");
|
||||
update_map("\300\267\301\265\302\266\303\307\304\216\305\217\306\222\307\200");
|
||||
update_map("\310\324\311\220\312\322\313\323\314\336\315\326\316\327\317\330");
|
||||
update_map("\320\321\321\245\322\343\323\340\324\342\325\345\326\231\327\236");
|
||||
update_map("\330\235\331\353\332\351\333\352\334\232\335\355\336\350\337\341");
|
||||
update_map("\340\205\341\240\342\203\343\306\344\204\345\206\346\221\347\207");
|
||||
update_map("\350\212\351\202\352\210\353\211\354\215\355\241\356\214\357\213");
|
||||
update_map("\360\320\361\244\362\225\363\242\364\223\365\344\366\224\367\366");
|
||||
update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230");
|
||||
/* MSDOS Code Page 850 -> ISO-8859 */
|
||||
update_map ("\240\377\241\255\242\275\243\234\244\317\245\276\246\335\247\365");
|
||||
update_map ("\250\371\251\270\252\246\253\256\254\252\255\360\256\251\257\356");
|
||||
update_map ("\260\370\261\361\262\375\263\374\264\357\265\346\266\364\267\372");
|
||||
update_map ("\270\367\271\373\272\247\273\257\274\254\275\253\276\363\277\250");
|
||||
update_map ("\300\267\301\265\302\266\303\307\304\216\305\217\306\222\307\200");
|
||||
update_map ("\310\324\311\220\312\322\313\323\314\336\315\326\316\327\317\330");
|
||||
update_map ("\320\321\321\245\322\343\323\340\324\342\325\345\326\231\327\236");
|
||||
update_map ("\330\235\331\353\332\351\333\352\334\232\335\355\336\350\337\341");
|
||||
update_map ("\340\205\341\240\342\203\343\306\344\204\345\206\346\221\347\207");
|
||||
update_map ("\350\212\351\202\352\210\353\211\354\215\355\241\356\214\357\213");
|
||||
update_map ("\360\320\361\244\362\225\363\242\364\223\365\344\366\224\367\366");
|
||||
update_map ("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230");
|
||||
|
||||
}
|
||||
|
||||
/* Init for eastern european languages. */
|
||||
|
||||
static void init_iso8859_2(void) {
|
||||
static void
|
||||
init_iso8859_2 (void)
|
||||
{
|
||||
|
||||
int i;
|
||||
if (!mapsinited) initmaps();
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
/* Do not map undefined characters to some accidental code */
|
||||
for (i = 128; i < 256; i++)
|
||||
for (i = 128; i < 256; i++)
|
||||
{
|
||||
unix2dos[i] = CTRLZ;
|
||||
dos2unix[i] = CTRLZ;
|
||||
unix2dos[i] = CTRLZ;
|
||||
dos2unix[i] = CTRLZ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tranlation table created by Petr Hubeny <psh@capitol.cz>
|
||||
* Requires client code page = 852
|
||||
* and character set = ISO8859-2 in smb.conf
|
||||
*/
|
||||
/*
|
||||
* Tranlation table created by Petr Hubeny <psh@capitol.cz>
|
||||
* Requires client code page = 852
|
||||
* and character set = ISO8859-2 in smb.conf
|
||||
*/
|
||||
|
||||
/* MSDOS Code Page 852 -> ISO-8859-2 */
|
||||
update_map("\241\244\242\364\243\235\244\317\245\225\246\227\247\365");
|
||||
update_map("\250\371\251\346\252\270\253\233\254\215\256\246\257\275");
|
||||
update_map("\261\245\262\362\263\210\264\357\265\226\266\230\267\363");
|
||||
update_map("\270\367\271\347\272\255\273\234\274\253\275\361\276\247\277\276");
|
||||
update_map("\300\350\301\265\302\266\303\306\304\216\305\221\306\217\307\200");
|
||||
update_map("\310\254\311\220\312\250\313\323\314\267\315\326\316\327\317\322");
|
||||
update_map("\320\321\321\343\322\325\323\340\324\342\325\212\326\231\327\236");
|
||||
update_map("\330\374\331\336\332\351\333\353\334\232\335\355\336\335\337\341");
|
||||
update_map("\340\352\341\240\342\203\343\307\344\204\345\222\346\206\347\207");
|
||||
update_map("\350\237\351\202\352\251\353\211\354\330\355\241\356\214\357\324");
|
||||
update_map("\360\320\361\344\362\345\363\242\364\223\365\213\366\224\367\366");
|
||||
update_map("\370\375\371\205\372\243\373\373\374\201\375\354\376\356\377\372");
|
||||
/* MSDOS Code Page 852 -> ISO-8859-2 */
|
||||
update_map ("\241\244\242\364\243\235\244\317\245\225\246\227\247\365");
|
||||
update_map ("\250\371\251\346\252\270\253\233\254\215\256\246\257\275");
|
||||
update_map ("\261\245\262\362\263\210\264\357\265\226\266\230\267\363");
|
||||
update_map ("\270\367\271\347\272\255\273\234\274\253\275\361\276\247\277\276");
|
||||
update_map ("\300\350\301\265\302\266\303\306\304\216\305\221\306\217\307\200");
|
||||
update_map ("\310\254\311\220\312\250\313\323\314\267\315\326\316\327\317\322");
|
||||
update_map ("\320\321\321\343\322\325\323\340\324\342\325\212\326\231\327\236");
|
||||
update_map ("\330\374\331\336\332\351\333\353\334\232\335\355\336\335\337\341");
|
||||
update_map ("\340\352\341\240\342\203\343\307\344\204\345\222\346\206\347\207");
|
||||
update_map ("\350\237\351\202\352\251\353\211\354\330\355\241\356\214\357\324");
|
||||
update_map ("\360\320\361\344\362\345\363\242\364\223\365\213\366\224\367\366");
|
||||
update_map ("\370\375\371\205\372\243\373\373\374\201\375\354\376\356\377\372");
|
||||
}
|
||||
|
||||
/* Init for russian language (iso8859-5) */
|
||||
|
||||
/* Added by Max Khon <max@iclub.nsu.ru> */
|
||||
|
||||
static void init_iso8859_5(void)
|
||||
static void
|
||||
init_iso8859_5 (void)
|
||||
{
|
||||
int i;
|
||||
if (!mapsinited) initmaps();
|
||||
int i;
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
/* Do not map undefined characters to some accidental code */
|
||||
for (i = 128; i < 256; i++)
|
||||
{
|
||||
unix2dos[i] = CTRLZ;
|
||||
dos2unix[i] = CTRLZ;
|
||||
}
|
||||
/* Do not map undefined characters to some accidental code */
|
||||
for (i = 128; i < 256; i++)
|
||||
{
|
||||
unix2dos[i] = CTRLZ;
|
||||
dos2unix[i] = CTRLZ;
|
||||
}
|
||||
|
||||
/* MSDOS Code Page 866 -> ISO8859-5 */
|
||||
update_map("\260\200\261\201\262\202\263\203\264\204\265\205\266\206\267\207");
|
||||
update_map("\270\210\271\211\272\212\273\213\274\214\275\215\276\216\277\217");
|
||||
update_map("\300\220\301\221\302\222\303\223\304\224\305\225\306\226\307\227");
|
||||
update_map("\310\230\311\231\312\232\313\233\314\234\315\235\316\236\317\237");
|
||||
update_map("\320\240\321\241\322\242\323\243\324\244\325\245\326\246\327\247");
|
||||
update_map("\330\250\331\251\332\252\333\253\334\254\335\255\336\256\337\257");
|
||||
update_map("\340\340\341\341\342\342\343\343\344\344\345\345\346\346\347\347");
|
||||
update_map("\350\350\351\351\352\352\353\353\354\354\355\355\356\356\357\357");
|
||||
update_map("\241\360\361\361\244\362\364\363\247\364\367\365\256\366\376\367");
|
||||
update_map("\360\374\240\377");
|
||||
/* MSDOS Code Page 866 -> ISO8859-5 */
|
||||
update_map ("\260\200\261\201\262\202\263\203\264\204\265\205\266\206\267\207");
|
||||
update_map ("\270\210\271\211\272\212\273\213\274\214\275\215\276\216\277\217");
|
||||
update_map ("\300\220\301\221\302\222\303\223\304\224\305\225\306\226\307\227");
|
||||
update_map ("\310\230\311\231\312\232\313\233\314\234\315\235\316\236\317\237");
|
||||
update_map ("\320\240\321\241\322\242\323\243\324\244\325\245\326\246\327\247");
|
||||
update_map ("\330\250\331\251\332\252\333\253\334\254\335\255\336\256\337\257");
|
||||
update_map ("\340\340\341\341\342\342\343\343\344\344\345\345\346\346\347\347");
|
||||
update_map ("\350\350\351\351\352\352\353\353\354\354\355\355\356\356\357\357");
|
||||
update_map ("\241\360\361\361\244\362\364\363\247\364\367\365\256\366\376\367");
|
||||
update_map ("\360\374\240\377");
|
||||
}
|
||||
|
||||
/* Init for russian language (koi8) */
|
||||
|
||||
static void init_koi8_r(void)
|
||||
static void
|
||||
init_koi8_r (void)
|
||||
{
|
||||
if (!mapsinited) initmaps();
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
/* There aren't undefined characters between 128 and 255 */
|
||||
/* There aren't undefined characters between 128 and 255 */
|
||||
|
||||
/* MSDOS Code Page 866 -> KOI8-R */
|
||||
update_map("\200\304\201\263\202\332\203\277\204\300\205\331\206\303\207\264");
|
||||
update_map("\210\302\211\301\212\305\213\337\214\334\215\333\216\335\217\336");
|
||||
update_map("\220\260\221\261\222\262\223\364\224\376\225\371\226\373\227\367");
|
||||
update_map("\230\363\231\362\232\377\233\365\234\370\235\375\236\372\237\366");
|
||||
update_map("\240\315\241\272\242\325\243\361\244\326\245\311\246\270\247\267");
|
||||
update_map("\250\273\251\324\252\323\253\310\254\276\255\275\256\274\257\306");
|
||||
update_map("\260\307\261\314\262\265\263\360\264\266\265\271\266\321\267\322");
|
||||
update_map("\270\313\271\317\272\320\273\312\274\330\275\327\276\316\277\374");
|
||||
update_map("\300\356\301\240\302\241\303\346\304\244\305\245\306\344\307\243");
|
||||
update_map("\310\345\311\250\312\251\313\252\314\253\315\254\316\255\317\256");
|
||||
update_map("\320\257\321\357\322\340\323\341\324\342\325\343\326\246\327\242");
|
||||
update_map("\330\354\331\353\332\247\333\350\334\355\335\351\336\347\337\352");
|
||||
update_map("\340\236\341\200\342\201\343\226\344\204\345\205\346\224\347\203");
|
||||
update_map("\350\225\351\210\352\211\353\212\354\213\355\214\356\215\357\216");
|
||||
update_map("\360\217\361\237\362\220\363\221\364\222\365\223\366\206\367\202");
|
||||
update_map("\370\234\371\233\372\207\373\230\374\235\375\231\376\227\377\232");
|
||||
/* MSDOS Code Page 866 -> KOI8-R */
|
||||
update_map ("\200\304\201\263\202\332\203\277\204\300\205\331\206\303\207\264");
|
||||
update_map ("\210\302\211\301\212\305\213\337\214\334\215\333\216\335\217\336");
|
||||
update_map ("\220\260\221\261\222\262\223\364\224\376\225\371\226\373\227\367");
|
||||
update_map ("\230\363\231\362\232\377\233\365\234\370\235\375\236\372\237\366");
|
||||
update_map ("\240\315\241\272\242\325\243\361\244\326\245\311\246\270\247\267");
|
||||
update_map ("\250\273\251\324\252\323\253\310\254\276\255\275\256\274\257\306");
|
||||
update_map ("\260\307\261\314\262\265\263\360\264\266\265\271\266\321\267\322");
|
||||
update_map ("\270\313\271\317\272\320\273\312\274\330\275\327\276\316\277\374");
|
||||
update_map ("\300\356\301\240\302\241\303\346\304\244\305\245\306\344\307\243");
|
||||
update_map ("\310\345\311\250\312\251\313\252\314\253\315\254\316\255\317\256");
|
||||
update_map ("\320\257\321\357\322\340\323\341\324\342\325\343\326\246\327\242");
|
||||
update_map ("\330\354\331\353\332\247\333\350\334\355\335\351\336\347\337\352");
|
||||
update_map ("\340\236\341\200\342\201\343\226\344\204\345\205\346\224\347\203");
|
||||
update_map ("\350\225\351\210\352\211\353\212\354\213\355\214\356\215\357\216");
|
||||
update_map ("\360\217\361\237\362\220\363\221\364\222\365\223\366\206\367\202");
|
||||
update_map ("\370\234\371\233\372\207\373\230\374\235\375\231\376\227\377\232");
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert unix to dos
|
||||
*/
|
||||
char *unix2dos_format(char *str,BOOL overwrite)
|
||||
char *
|
||||
unix2dos_format (char *str, BOOL overwrite)
|
||||
{
|
||||
char *p;
|
||||
char *dp;
|
||||
|
||||
if (!mapsinited) initmaps();
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
if (overwrite) {
|
||||
for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p];
|
||||
return str;
|
||||
} else {
|
||||
for (p = str, dp = cvtbuf; *p && dp < &(cvtbuf[sizeof(cvtbuf) - 1]); p++,dp++)
|
||||
*dp = unix2dos[(unsigned char)*p];
|
||||
*dp = 0;
|
||||
return cvtbuf;
|
||||
}
|
||||
if (overwrite)
|
||||
{
|
||||
for (p = str; *p; p++)
|
||||
*p = unix2dos[(unsigned char) *p];
|
||||
return str;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (p = str, dp = cvtbuf; *p && dp < &(cvtbuf[sizeof (cvtbuf) - 1]); p++, dp++)
|
||||
*dp = unix2dos[(unsigned char) *p];
|
||||
*dp = 0;
|
||||
return cvtbuf;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert dos to unix
|
||||
*/
|
||||
char *dos2unix_format(char *str, BOOL overwrite)
|
||||
char *
|
||||
dos2unix_format (char *str, BOOL overwrite)
|
||||
{
|
||||
char *p;
|
||||
char *dp;
|
||||
|
||||
if (!mapsinited) initmaps();
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
if (overwrite) {
|
||||
for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p];
|
||||
return str;
|
||||
} else {
|
||||
for (p = str, dp = cvtbuf; *p && dp < &(cvtbuf[sizeof(cvtbuf) - 1]); p++,dp++)
|
||||
*dp = dos2unix[(unsigned char)*p];
|
||||
*dp = 0;
|
||||
return cvtbuf;
|
||||
}
|
||||
if (overwrite)
|
||||
{
|
||||
for (p = str; *p; p++)
|
||||
*p = dos2unix[(unsigned char) *p];
|
||||
return str;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (p = str, dp = cvtbuf; *p && dp < &(cvtbuf[sizeof (cvtbuf) - 1]); p++, dp++)
|
||||
*dp = dos2unix[(unsigned char) *p];
|
||||
*dp = 0;
|
||||
return cvtbuf;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Interpret character set.
|
||||
*/
|
||||
void interpret_character_set(const char *str)
|
||||
void
|
||||
interpret_character_set (const char *str)
|
||||
{
|
||||
if (strequal (str, "iso8859-1")) {
|
||||
init_iso8859_1();
|
||||
} else if (strequal (str, "iso8859-2")) {
|
||||
init_iso8859_2();
|
||||
} else if (strequal (str, "iso8859-5")) {
|
||||
init_iso8859_5();
|
||||
} else if (strequal (str, "koi8-r")) {
|
||||
init_koi8_r();
|
||||
} else {
|
||||
DEBUG(0,("unrecognized character set %s\n", str));
|
||||
if (strequal (str, "iso8859-1"))
|
||||
{
|
||||
init_iso8859_1 ();
|
||||
}
|
||||
else if (strequal (str, "iso8859-2"))
|
||||
{
|
||||
init_iso8859_2 ();
|
||||
}
|
||||
else if (strequal (str, "iso8859-5"))
|
||||
{
|
||||
init_iso8859_5 ();
|
||||
}
|
||||
else if (strequal (str, "koi8-r"))
|
||||
{
|
||||
init_koi8_r ();
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG (0, ("unrecognized character set %s\n", str));
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
*/
|
||||
|
||||
#define CHARSET_C
|
||||
#include "includes.h"
|
||||
@ -37,75 +37,75 @@ extern int DEBUGLEVEL;
|
||||
#if !defined(KANJI)
|
||||
/* lower->upper mapping for IBM Code Page 850 - MS-DOS Latin 1 */
|
||||
unsigned char const cp_850[][4] = {
|
||||
/* dec col/row oct hex description */
|
||||
/* 133 08/05 205 85 a grave */
|
||||
/* 183 11/07 267 B7 A grave */ {0x85,0xB7,1,1},
|
||||
/* 160 10/00 240 A0 a acute */
|
||||
/* 181 11/05 265 B5 A acute */ {0xA0,0xB5,1,1},
|
||||
/* 131 08/03 203 83 a circumflex */
|
||||
/* 182 11/06 266 B6 A circumflex */ {0x83,0xB6,1,1},
|
||||
/* 198 12/06 306 C6 a tilde */
|
||||
/* 199 12/07 307 C7 A tilde */ {0xC6,0xC7,1,1},
|
||||
/* 132 08/04 204 84 a diaeresis */
|
||||
/* 142 08/14 216 8E A diaeresis */ {0x84,0x8E,1,1},
|
||||
/* 134 08/06 206 86 a ring */
|
||||
/* 143 08/15 217 8F A ring */ {0x86,0x8F,1,1},
|
||||
/* 145 09/01 221 91 ae diphthong */
|
||||
/* 146 09/02 222 92 AE diphthong */ {0x91,0x92,1,1},
|
||||
/* 135 08/07 207 87 c cedilla */
|
||||
/* 128 08/00 200 80 C cedilla */ {0x87,0x80,1,1},
|
||||
/* 138 08/10 212 8A e grave */
|
||||
/* 212 13/04 324 D4 E grave */ {0x8A,0xD4,1,1},
|
||||
/* 130 08/02 202 82 e acute */
|
||||
/* 144 09/00 220 90 E acute */ {0x82,0x90,1,1},
|
||||
/* 136 08/08 210 88 e circumflex */
|
||||
/* 210 13/02 322 D2 E circumflex */ {0x88,0xD2,1,1},
|
||||
/* 137 08/09 211 89 e diaeresis */
|
||||
/* 211 13/03 323 D3 E diaeresis */ {0x89,0xD3,1,1},
|
||||
/* 141 08/13 215 8D i grave */
|
||||
/* 222 13/14 336 DE I grave */ {0x8D,0xDE,1,1},
|
||||
/* 161 10/01 241 A1 i acute */
|
||||
/* 214 13/06 326 D6 I acute */ {0xA1,0xD6,1,1},
|
||||
/* 140 08/12 214 8C i circumflex */
|
||||
/* 215 13/07 327 D7 I circumflex */ {0x8C,0xD7,1,1},
|
||||
/* 139 08/11 213 8B i diaeresis */
|
||||
/* 216 13/08 330 D8 I diaeresis */ {0x8B,0xD8,1,1},
|
||||
/* 208 13/00 320 D0 Icelandic eth */
|
||||
/* 209 13/01 321 D1 Icelandic Eth */ {0xD0,0xD1,1,1},
|
||||
/* 164 10/04 244 A4 n tilde */
|
||||
/* 165 10/05 245 A5 N tilde */ {0xA4,0xA5,1,1},
|
||||
/* 149 09/05 225 95 o grave */
|
||||
/* 227 14/03 343 E3 O grave */ {0x95,0xE3,1,1},
|
||||
/* 162 10/02 242 A2 o acute */
|
||||
/* 224 14/00 340 E0 O acute */ {0xA2,0xE0,1,1},
|
||||
/* 147 09/03 223 93 o circumflex */
|
||||
/* 226 14/02 342 E2 O circumflex */ {0x93,0xE2,1,1},
|
||||
/* 228 14/04 344 E4 o tilde */
|
||||
/* 229 14/05 345 E5 O tilde */ {0xE4,0xE5,1,1},
|
||||
/* 148 09/04 224 94 o diaeresis */
|
||||
/* 153 09/09 231 99 O diaeresis */ {0x94,0x99,1,1},
|
||||
/* 155 09/11 233 9B o slash */
|
||||
/* 157 09/13 235 9D O slash */ {0x9B,0x9D,1,1},
|
||||
/* 151 09/07 227 97 u grave */
|
||||
/* 235 14/11 353 EB U grave */ {0x97,0xEB,1,1},
|
||||
/* 163 10/03 243 A3 u acute */
|
||||
/* 233 14/09 351 E9 U acute */ {0xA3,0xE9,1,1},
|
||||
/* 150 09/06 226 96 u circumflex */
|
||||
/* 234 14/10 352 EA U circumflex */ {0x96,0xEA,1,1},
|
||||
/* 129 08/01 201 81 u diaeresis */
|
||||
/* 154 09/10 232 9A U diaeresis */ {0x81,0x9A,1,1},
|
||||
/* 236 14/12 354 EC y acute */
|
||||
/* 237 14/13 355 ED Y acute */ {0xEC,0xED,1,1},
|
||||
/* 231 14/07 347 E7 Icelandic thorn */
|
||||
/* 232 14/08 350 E8 Icelandic Thorn */ {0xE7,0xE8,1,1},
|
||||
|
||||
{0x9C,0,0,0}, /* Pound */
|
||||
{0,0,0,0}
|
||||
/* dec col/row oct hex description */
|
||||
/* 133 08/05 205 85 a grave */
|
||||
/* 183 11/07 267 B7 A grave */ {0x85, 0xB7, 1, 1},
|
||||
/* 160 10/00 240 A0 a acute */
|
||||
/* 181 11/05 265 B5 A acute */ {0xA0, 0xB5, 1, 1},
|
||||
/* 131 08/03 203 83 a circumflex */
|
||||
/* 182 11/06 266 B6 A circumflex */ {0x83, 0xB6, 1, 1},
|
||||
/* 198 12/06 306 C6 a tilde */
|
||||
/* 199 12/07 307 C7 A tilde */ {0xC6, 0xC7, 1, 1},
|
||||
/* 132 08/04 204 84 a diaeresis */
|
||||
/* 142 08/14 216 8E A diaeresis */ {0x84, 0x8E, 1, 1},
|
||||
/* 134 08/06 206 86 a ring */
|
||||
/* 143 08/15 217 8F A ring */ {0x86, 0x8F, 1, 1},
|
||||
/* 145 09/01 221 91 ae diphthong */
|
||||
/* 146 09/02 222 92 AE diphthong */ {0x91, 0x92, 1, 1},
|
||||
/* 135 08/07 207 87 c cedilla */
|
||||
/* 128 08/00 200 80 C cedilla */ {0x87, 0x80, 1, 1},
|
||||
/* 138 08/10 212 8A e grave */
|
||||
/* 212 13/04 324 D4 E grave */ {0x8A, 0xD4, 1, 1},
|
||||
/* 130 08/02 202 82 e acute */
|
||||
/* 144 09/00 220 90 E acute */ {0x82, 0x90, 1, 1},
|
||||
/* 136 08/08 210 88 e circumflex */
|
||||
/* 210 13/02 322 D2 E circumflex */ {0x88, 0xD2, 1, 1},
|
||||
/* 137 08/09 211 89 e diaeresis */
|
||||
/* 211 13/03 323 D3 E diaeresis */ {0x89, 0xD3, 1, 1},
|
||||
/* 141 08/13 215 8D i grave */
|
||||
/* 222 13/14 336 DE I grave */ {0x8D, 0xDE, 1, 1},
|
||||
/* 161 10/01 241 A1 i acute */
|
||||
/* 214 13/06 326 D6 I acute */ {0xA1, 0xD6, 1, 1},
|
||||
/* 140 08/12 214 8C i circumflex */
|
||||
/* 215 13/07 327 D7 I circumflex */ {0x8C, 0xD7, 1, 1},
|
||||
/* 139 08/11 213 8B i diaeresis */
|
||||
/* 216 13/08 330 D8 I diaeresis */ {0x8B, 0xD8, 1, 1},
|
||||
/* 208 13/00 320 D0 Icelandic eth */
|
||||
/* 209 13/01 321 D1 Icelandic Eth */ {0xD0, 0xD1, 1, 1},
|
||||
/* 164 10/04 244 A4 n tilde */
|
||||
/* 165 10/05 245 A5 N tilde */ {0xA4, 0xA5, 1, 1},
|
||||
/* 149 09/05 225 95 o grave */
|
||||
/* 227 14/03 343 E3 O grave */ {0x95, 0xE3, 1, 1},
|
||||
/* 162 10/02 242 A2 o acute */
|
||||
/* 224 14/00 340 E0 O acute */ {0xA2, 0xE0, 1, 1},
|
||||
/* 147 09/03 223 93 o circumflex */
|
||||
/* 226 14/02 342 E2 O circumflex */ {0x93, 0xE2, 1, 1},
|
||||
/* 228 14/04 344 E4 o tilde */
|
||||
/* 229 14/05 345 E5 O tilde */ {0xE4, 0xE5, 1, 1},
|
||||
/* 148 09/04 224 94 o diaeresis */
|
||||
/* 153 09/09 231 99 O diaeresis */ {0x94, 0x99, 1, 1},
|
||||
/* 155 09/11 233 9B o slash */
|
||||
/* 157 09/13 235 9D O slash */ {0x9B, 0x9D, 1, 1},
|
||||
/* 151 09/07 227 97 u grave */
|
||||
/* 235 14/11 353 EB U grave */ {0x97, 0xEB, 1, 1},
|
||||
/* 163 10/03 243 A3 u acute */
|
||||
/* 233 14/09 351 E9 U acute */ {0xA3, 0xE9, 1, 1},
|
||||
/* 150 09/06 226 96 u circumflex */
|
||||
/* 234 14/10 352 EA U circumflex */ {0x96, 0xEA, 1, 1},
|
||||
/* 129 08/01 201 81 u diaeresis */
|
||||
/* 154 09/10 232 9A U diaeresis */ {0x81, 0x9A, 1, 1},
|
||||
/* 236 14/12 354 EC y acute */
|
||||
/* 237 14/13 355 ED Y acute */ {0xEC, 0xED, 1, 1},
|
||||
/* 231 14/07 347 E7 Icelandic thorn */
|
||||
/* 232 14/08 350 E8 Icelandic Thorn */ {0xE7, 0xE8, 1, 1},
|
||||
|
||||
{0x9C, 0, 0, 0}, /* Pound */
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
#else /* KANJI */
|
||||
#else /* KANJI */
|
||||
/* lower->upper mapping for IBM Code Page 932 - MS-DOS Japanese SJIS */
|
||||
unsigned char const cp_932[][4] = {
|
||||
{0,0,0,0}
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
#endif /* KANJI */
|
||||
|
||||
@ -128,60 +128,69 @@ char *lower_char_map = xx_lower_char_map;
|
||||
* mapping from lower to upper, but not upper to lower.
|
||||
*/
|
||||
|
||||
static void add_dos_char(int lower, BOOL map_lower_to_upper,
|
||||
int upper, BOOL map_upper_to_lower)
|
||||
static void
|
||||
add_dos_char (int lower, BOOL map_lower_to_upper, int upper, BOOL map_upper_to_lower)
|
||||
{
|
||||
lower &= 0xff;
|
||||
upper &= 0xff;
|
||||
DEBUGADD( 6, ( "Adding chars 0x%x 0x%x (l->u = %s) (u->l = %s)\n",
|
||||
lower, upper,
|
||||
map_lower_to_upper ? "True" : "False",
|
||||
map_upper_to_lower ? "True" : "False" ) );
|
||||
if (lower) dos_char_map[lower] = 1;
|
||||
if (upper) dos_char_map[upper] = 1;
|
||||
lower_char_map[lower] = (char)lower; /* Define tolower(lower) */
|
||||
upper_char_map[upper] = (char)upper; /* Define toupper(upper) */
|
||||
if (lower && upper) {
|
||||
if(map_upper_to_lower)
|
||||
lower_char_map[upper] = (char)lower;
|
||||
if(map_lower_to_upper)
|
||||
upper_char_map[lower] = (char)upper;
|
||||
}
|
||||
lower &= 0xff;
|
||||
upper &= 0xff;
|
||||
DEBUGADD (6, ("Adding chars 0x%x 0x%x (l->u = %s) (u->l = %s)\n",
|
||||
lower, upper,
|
||||
map_lower_to_upper ? "True" : "False", map_upper_to_lower ? "True" : "False"));
|
||||
if (lower)
|
||||
dos_char_map[lower] = 1;
|
||||
if (upper)
|
||||
dos_char_map[upper] = 1;
|
||||
lower_char_map[lower] = (char) lower; /* Define tolower(lower) */
|
||||
upper_char_map[upper] = (char) upper; /* Define toupper(upper) */
|
||||
if (lower && upper)
|
||||
{
|
||||
if (map_upper_to_lower)
|
||||
lower_char_map[upper] = (char) lower;
|
||||
if (map_lower_to_upper)
|
||||
upper_char_map[lower] = (char) upper;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
initialise the charset arrays
|
||||
****************************************************************************/
|
||||
void charset_initialise(void)
|
||||
void
|
||||
charset_initialise (void)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
#ifdef LC_ALL
|
||||
/* include <locale.h> in includes.h if available for OS */
|
||||
/* we take only standard 7-bit ASCII definitions from ctype */
|
||||
setlocale(LC_ALL,"C");
|
||||
/* include <locale.h> in includes.h if available for OS */
|
||||
/* we take only standard 7-bit ASCII definitions from ctype */
|
||||
setlocale (LC_ALL, "C");
|
||||
#endif
|
||||
|
||||
for (i= 0;i<=255;i++) {
|
||||
dos_char_map[i] = 0;
|
||||
}
|
||||
|
||||
for (i=0;i<=127;i++) {
|
||||
if (isalnum(i) || strchr("._^$~!#%&-{}()@'`",(char)i))
|
||||
add_dos_char(i,False,0,False);
|
||||
}
|
||||
|
||||
for (i=0; i<=255; i++) {
|
||||
char c = (char)i;
|
||||
upper_char_map[i] = lower_char_map[i] = c;
|
||||
|
||||
/* Some systems have buggy isupper/islower for characters
|
||||
above 127. Best not to rely on them. */
|
||||
if(i < 128) {
|
||||
if (isupper((int)c)) lower_char_map[i] = tolower(c);
|
||||
if (islower((int)c)) upper_char_map[i] = toupper(c);
|
||||
for (i = 0; i <= 255; i++)
|
||||
{
|
||||
dos_char_map[i] = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i <= 127; i++)
|
||||
{
|
||||
if (isalnum (i) || strchr ("._^$~!#%&-{}()@'`", (char) i))
|
||||
add_dos_char (i, False, 0, False);
|
||||
}
|
||||
|
||||
for (i = 0; i <= 255; i++)
|
||||
{
|
||||
char c = (char) i;
|
||||
upper_char_map[i] = lower_char_map[i] = c;
|
||||
|
||||
/* Some systems have buggy isupper/islower for characters
|
||||
above 127. Best not to rely on them. */
|
||||
if (i < 128)
|
||||
{
|
||||
if (isupper ((int) c))
|
||||
lower_char_map[i] = tolower (c);
|
||||
if (islower ((int) c))
|
||||
upper_char_map[i] = toupper (c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -190,213 +199,211 @@ load the client codepage.
|
||||
|
||||
typedef const unsigned char (*codepage_p)[4];
|
||||
|
||||
static codepage_p load_client_codepage( int client_codepage )
|
||||
static codepage_p
|
||||
load_client_codepage (int client_codepage)
|
||||
{
|
||||
pstring codepage_file_name;
|
||||
unsigned char buf[8];
|
||||
FILE *fp = NULL;
|
||||
SMB_OFF_T size;
|
||||
codepage_p cp_p = NULL;
|
||||
SMB_STRUCT_STAT st;
|
||||
pstring codepage_file_name;
|
||||
unsigned char buf[8];
|
||||
FILE *fp = NULL;
|
||||
SMB_OFF_T size;
|
||||
codepage_p cp_p = NULL;
|
||||
SMB_STRUCT_STAT st;
|
||||
|
||||
DEBUG(5, ("load_client_codepage: loading codepage %d.\n", client_codepage));
|
||||
DEBUG (5, ("load_client_codepage: loading codepage %d.\n", client_codepage));
|
||||
|
||||
if(strlen(CODEPAGEDIR) + 14 > sizeof(codepage_file_name))
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: filename too long to load\n"));
|
||||
return NULL;
|
||||
}
|
||||
if (strlen (CODEPAGEDIR) + 14 > sizeof (codepage_file_name))
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: filename too long to load\n"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pstrcpy(codepage_file_name, CODEPAGEDIR);
|
||||
pstrcat(codepage_file_name, "/");
|
||||
pstrcat(codepage_file_name, "codepage.");
|
||||
slprintf(&codepage_file_name[strlen(codepage_file_name)],
|
||||
sizeof(pstring)-(strlen(codepage_file_name)+1),
|
||||
"%03d",
|
||||
client_codepage);
|
||||
pstrcpy (codepage_file_name, CODEPAGEDIR);
|
||||
pstrcat (codepage_file_name, "/");
|
||||
pstrcat (codepage_file_name, "codepage.");
|
||||
slprintf (&codepage_file_name[strlen (codepage_file_name)],
|
||||
sizeof (pstring) - (strlen (codepage_file_name) + 1), "%03d", client_codepage);
|
||||
|
||||
if(sys_stat(codepage_file_name,&st)!=0)
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: filename %s does not exist.\n",
|
||||
codepage_file_name));
|
||||
return NULL;
|
||||
}
|
||||
if (sys_stat (codepage_file_name, &st) != 0)
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: filename %s does not exist.\n", codepage_file_name));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Check if it is at least big enough to hold the required
|
||||
data. Should be 2 byte version, 2 byte codepage, 4 byte length,
|
||||
plus zero or more bytes of data. Note that the data cannot be more
|
||||
than 4 * MAXCODEPAGELINES bytes.
|
||||
*/
|
||||
size = st.st_size;
|
||||
/* Check if it is at least big enough to hold the required
|
||||
data. Should be 2 byte version, 2 byte codepage, 4 byte length,
|
||||
plus zero or more bytes of data. Note that the data cannot be more
|
||||
than 4 * MAXCODEPAGELINES bytes.
|
||||
*/
|
||||
size = st.st_size;
|
||||
|
||||
if( size < CODEPAGE_HEADER_SIZE || size > (CODEPAGE_HEADER_SIZE + 4 * MAXCODEPAGELINES))
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: file %s is an incorrect size for a \
|
||||
code page file (size=%d).\n", codepage_file_name, (int)size));
|
||||
return NULL;
|
||||
}
|
||||
if (size < CODEPAGE_HEADER_SIZE || size > (CODEPAGE_HEADER_SIZE + 4 * MAXCODEPAGELINES))
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: file %s is an incorrect size for a \
|
||||
code page file (size=%d).\n", codepage_file_name, (int) size));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Read the first 8 bytes of the codepage file - check
|
||||
the version number and code page number. All the data
|
||||
is held in little endian format.
|
||||
*/
|
||||
/* Read the first 8 bytes of the codepage file - check
|
||||
the version number and code page number. All the data
|
||||
is held in little endian format.
|
||||
*/
|
||||
|
||||
if((fp = sys_fopen( codepage_file_name, "r")) == NULL)
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: cannot open file %s. Error was %s\n",
|
||||
codepage_file_name, unix_error_string (errno)));
|
||||
return NULL;
|
||||
}
|
||||
if ((fp = sys_fopen (codepage_file_name, "r")) == NULL)
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: cannot open file %s. Error was %s\n",
|
||||
codepage_file_name, unix_error_string (errno)));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(fread( buf, 1, CODEPAGE_HEADER_SIZE, fp)!=CODEPAGE_HEADER_SIZE)
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: cannot read header from file %s. Error was %s\n",
|
||||
codepage_file_name, unix_error_string (errno)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
if (fread (buf, 1, CODEPAGE_HEADER_SIZE, fp) != CODEPAGE_HEADER_SIZE)
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: cannot read header from file %s. Error was %s\n",
|
||||
codepage_file_name, unix_error_string (errno)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
|
||||
/* Check the version value */
|
||||
if(SVAL(buf,CODEPAGE_VERSION_OFFSET) != CODEPAGE_FILE_VERSION_ID)
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: filename %s has incorrect version id. \
|
||||
Needed %hu, got %hu.\n",
|
||||
codepage_file_name, (uint16)CODEPAGE_FILE_VERSION_ID,
|
||||
SVAL(buf,CODEPAGE_VERSION_OFFSET)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
/* Check the version value */
|
||||
if (SVAL (buf, CODEPAGE_VERSION_OFFSET) != CODEPAGE_FILE_VERSION_ID)
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: filename %s has incorrect version id. \
|
||||
Needed %hu, got %hu.\n", codepage_file_name, (uint16) CODEPAGE_FILE_VERSION_ID, SVAL (buf, CODEPAGE_VERSION_OFFSET)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
|
||||
/* Check the codepage matches */
|
||||
if(SVAL(buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET) != (uint16)client_codepage)
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: filename %s has incorrect codepage. \
|
||||
Needed %hu, got %hu.\n",
|
||||
codepage_file_name, (uint16)client_codepage,
|
||||
SVAL(buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
/* Check the codepage matches */
|
||||
if (SVAL (buf, CODEPAGE_CLIENT_CODEPAGE_OFFSET) != (uint16) client_codepage)
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: filename %s has incorrect codepage. \
|
||||
Needed %hu, got %hu.\n", codepage_file_name, (uint16) client_codepage, SVAL (buf, CODEPAGE_CLIENT_CODEPAGE_OFFSET)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
|
||||
/* Check the length is correct. */
|
||||
if(IVAL(buf,CODEPAGE_LENGTH_OFFSET) != (size - CODEPAGE_HEADER_SIZE))
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: filename %s has incorrect size headers. \
|
||||
Needed %u, got %u.\n", codepage_file_name, (uint32)(size - CODEPAGE_HEADER_SIZE),
|
||||
IVAL(buf,CODEPAGE_LENGTH_OFFSET)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
/* Check the length is correct. */
|
||||
if (IVAL (buf, CODEPAGE_LENGTH_OFFSET) != (size - CODEPAGE_HEADER_SIZE))
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: filename %s has incorrect size headers. \
|
||||
Needed %u, got %u.\n", codepage_file_name, (uint32) (size - CODEPAGE_HEADER_SIZE), IVAL (buf, CODEPAGE_LENGTH_OFFSET)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
|
||||
size -= CODEPAGE_HEADER_SIZE; /* Remove header */
|
||||
size -= CODEPAGE_HEADER_SIZE; /* Remove header */
|
||||
|
||||
/* Make sure the size is a multiple of 4. */
|
||||
if((size % 4 ) != 0)
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: filename %s has a codepage size not a \
|
||||
/* Make sure the size is a multiple of 4. */
|
||||
if ((size % 4) != 0)
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: filename %s has a codepage size not a \
|
||||
multiple of 4.\n", codepage_file_name));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
goto clean_and_exit;
|
||||
}
|
||||
|
||||
/* Allocate space for the code page file and read it all in. */
|
||||
if((cp_p = (codepage_p)malloc( size + 4 )) == NULL)
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: malloc fail.\n"));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
/* Allocate space for the code page file and read it all in. */
|
||||
if ((cp_p = (codepage_p) malloc (size + 4)) == NULL)
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: malloc fail.\n"));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
|
||||
if(fread( (char *)cp_p, 1, size, fp)!=size)
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: read fail on file %s. Error was %s.\n",
|
||||
codepage_file_name, unix_error_string (errno)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
if (fread ((char *) cp_p, 1, size, fp) != size)
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: read fail on file %s. Error was %s.\n",
|
||||
codepage_file_name, unix_error_string (errno)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
|
||||
/* Ensure array is correctly terminated. */
|
||||
memset(((char *)cp_p) + size, '\0', 4);
|
||||
/* Ensure array is correctly terminated. */
|
||||
memset (((char *) cp_p) + size, '\0', 4);
|
||||
|
||||
fclose(fp);
|
||||
return cp_p;
|
||||
fclose (fp);
|
||||
return cp_p;
|
||||
|
||||
clean_and_exit:
|
||||
clean_and_exit:
|
||||
|
||||
/* pseudo destructor :-) */
|
||||
/* pseudo destructor :-) */
|
||||
|
||||
if(fp != NULL)
|
||||
fclose(fp);
|
||||
if(cp_p)
|
||||
free((char *)cp_p);
|
||||
return NULL;
|
||||
if (fp != NULL)
|
||||
fclose (fp);
|
||||
if (cp_p)
|
||||
free ((char *) cp_p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
initialise the client codepage.
|
||||
****************************************************************************/
|
||||
void codepage_initialise(int client_codepage)
|
||||
void
|
||||
codepage_initialise (int client_codepage)
|
||||
{
|
||||
int i;
|
||||
static codepage_p cp = NULL;
|
||||
int i;
|
||||
static codepage_p cp = NULL;
|
||||
|
||||
if(cp != NULL)
|
||||
{
|
||||
DEBUG(6,
|
||||
("codepage_initialise: called twice - ignoring second client code page = %d\n",
|
||||
client_codepage));
|
||||
return;
|
||||
}
|
||||
if (cp != NULL)
|
||||
{
|
||||
DEBUG (6,
|
||||
("codepage_initialise: called twice - ignoring second client code page = %d\n",
|
||||
client_codepage));
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG(6,("codepage_initialise: client code page = %d\n", client_codepage));
|
||||
DEBUG (6, ("codepage_initialise: client code page = %d\n", client_codepage));
|
||||
|
||||
/*
|
||||
* Known client codepages - these can be added to.
|
||||
*/
|
||||
cp = load_client_codepage( client_codepage );
|
||||
/*
|
||||
* Known client codepages - these can be added to.
|
||||
*/
|
||||
cp = load_client_codepage (client_codepage);
|
||||
|
||||
if(cp == NULL)
|
||||
{
|
||||
if (cp == NULL)
|
||||
{
|
||||
#ifdef KANJI
|
||||
DEBUG(6,("codepage_initialise: loading dynamic codepage file %s/codepage.%d \
|
||||
for code page %d failed. Using default client codepage 932\n",
|
||||
CODEPAGEDIR, client_codepage, client_codepage));
|
||||
cp = cp_932;
|
||||
client_codepage = KANJI_CODEPAGE;
|
||||
DEBUG (6, ("codepage_initialise: loading dynamic codepage file %s/codepage.%d \
|
||||
for code page %d failed. Using default client codepage 932\n", CODEPAGEDIR, client_codepage, client_codepage));
|
||||
cp = cp_932;
|
||||
client_codepage = KANJI_CODEPAGE;
|
||||
#else /* KANJI */
|
||||
DEBUG(6,("codepage_initialise: loading dynamic codepage file %s/codepage.%d \
|
||||
for code page %d failed. Using default client codepage 850\n",
|
||||
CODEPAGEDIR, client_codepage, client_codepage));
|
||||
cp = cp_850;
|
||||
client_codepage = MSDOS_LATIN_1_CODEPAGE;
|
||||
DEBUG (6, ("codepage_initialise: loading dynamic codepage file %s/codepage.%d \
|
||||
for code page %d failed. Using default client codepage 850\n", CODEPAGEDIR, client_codepage, client_codepage));
|
||||
cp = cp_850;
|
||||
client_codepage = MSDOS_LATIN_1_CODEPAGE;
|
||||
#endif /* KANJI */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup the function pointers for the loaded codepage.
|
||||
*/
|
||||
initialize_multibyte_vectors( client_codepage );
|
||||
/*
|
||||
* Setup the function pointers for the loaded codepage.
|
||||
*/
|
||||
initialize_multibyte_vectors (client_codepage);
|
||||
|
||||
if(cp)
|
||||
{
|
||||
for(i = 0; !((cp[i][0] == '\0') && (cp[i][1] == '\0')); i++)
|
||||
add_dos_char(cp[i][0], (BOOL)cp[i][2], cp[i][1], (BOOL)cp[i][3]);
|
||||
}
|
||||
if (cp)
|
||||
{
|
||||
for (i = 0; !((cp[i][0] == '\0') && (cp[i][1] == '\0')); i++)
|
||||
add_dos_char (cp[i][0], (BOOL) cp[i][2], cp[i][1], (BOOL) cp[i][3]);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
add characters depending on a string passed by the user
|
||||
********************************************************************/
|
||||
void add_char_string(const char *s)
|
||||
void
|
||||
add_char_string (const char *s)
|
||||
{
|
||||
char *extra_chars = (char *)strdup(s);
|
||||
char *t;
|
||||
if (!extra_chars) return;
|
||||
char *extra_chars = (char *) strdup (s);
|
||||
char *t;
|
||||
if (!extra_chars)
|
||||
return;
|
||||
|
||||
for (t=strtok(extra_chars," \t\r\n"); t; t=strtok(NULL," \t\r\n")) {
|
||||
char c1=0,c2=0;
|
||||
int i1=0,i2=0;
|
||||
if (isdigit((unsigned char)*t) || (*t)=='-') {
|
||||
sscanf(t,"%i:%i",&i1,&i2);
|
||||
add_dos_char(i1,True,i2,True);
|
||||
} else {
|
||||
sscanf(t,"%c:%c",&c1,&c2);
|
||||
add_dos_char((unsigned char)c1,True,(unsigned char)c2, True);
|
||||
for (t = strtok (extra_chars, " \t\r\n"); t; t = strtok (NULL, " \t\r\n"))
|
||||
{
|
||||
char c1 = 0, c2 = 0;
|
||||
int i1 = 0, i2 = 0;
|
||||
if (isdigit ((unsigned char) *t) || (*t) == '-')
|
||||
{
|
||||
sscanf (t, "%i:%i", &i1, &i2);
|
||||
add_dos_char (i1, True, i2, True);
|
||||
}
|
||||
else
|
||||
{
|
||||
sscanf (t, "%c:%c", &c1, &c2);
|
||||
add_dos_char ((unsigned char) c1, True, (unsigned char) c2, True);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(extra_chars);
|
||||
free (extra_chars);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
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"
|
||||
|
||||
@ -84,10 +84,10 @@
|
||||
* levels higher than DEBUGLEVEL will not be processed.
|
||||
*/
|
||||
|
||||
FILE *dbf = NULL;
|
||||
pstring debugf = "";
|
||||
BOOL append_log = False;
|
||||
int DEBUGLEVEL = 1;
|
||||
FILE *dbf = NULL;
|
||||
pstring debugf = "";
|
||||
BOOL append_log = False;
|
||||
int DEBUGLEVEL = 1;
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
@ -108,9 +108,10 @@ int DEBUGLEVEL = 1;
|
||||
* format_pos - Marks the first free byte of the format_bufr.
|
||||
*/
|
||||
|
||||
static BOOL stdout_logging = False;
|
||||
static pstring format_bufr = { '\0' };
|
||||
static size_t format_pos = 0;
|
||||
static BOOL stdout_logging = False;
|
||||
static pstring format_bufr = { '\0' };
|
||||
|
||||
static size_t format_pos = 0;
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
@ -121,15 +122,16 @@ static size_t format_pos = 0;
|
||||
* get ready for syslog stuff
|
||||
* ************************************************************************** **
|
||||
*/
|
||||
void setup_logging( const char *pname, BOOL interactive )
|
||||
{
|
||||
(void) pname;
|
||||
if( interactive )
|
||||
void
|
||||
setup_logging (const char *pname, BOOL interactive)
|
||||
{
|
||||
(void) pname;
|
||||
if (interactive)
|
||||
{
|
||||
stdout_logging = True;
|
||||
dbf = stderr;
|
||||
stdout_logging = True;
|
||||
dbf = stderr;
|
||||
}
|
||||
} /* setup_logging */
|
||||
} /* setup_logging */
|
||||
|
||||
/* ************************************************************************** **
|
||||
* Write an debug message on the debugfile.
|
||||
@ -137,68 +139,70 @@ void setup_logging( const char *pname, BOOL interactive )
|
||||
* ************************************************************************** **
|
||||
*/
|
||||
#ifdef HAVE_STDARG_H
|
||||
int Debug1( const char *format_str, ... )
|
||||
int
|
||||
Debug1 (const char *format_str, ...)
|
||||
{
|
||||
#else
|
||||
int Debug1(va_alist)
|
||||
va_dcl
|
||||
{
|
||||
const char *format_str;
|
||||
int
|
||||
Debug1 (va_alist)
|
||||
va_dcl
|
||||
{
|
||||
const char *format_str;
|
||||
#endif
|
||||
va_list ap;
|
||||
int old_errno = errno;
|
||||
va_list ap;
|
||||
int old_errno = errno;
|
||||
|
||||
if( stdout_logging )
|
||||
if (stdout_logging)
|
||||
{
|
||||
#ifdef HAVE_STDARG_H
|
||||
va_start( ap, format_str );
|
||||
va_start (ap, format_str);
|
||||
#else
|
||||
va_start( ap );
|
||||
format_str = va_arg( ap, const char * );
|
||||
va_start (ap);
|
||||
format_str = va_arg (ap, const char *);
|
||||
#endif
|
||||
(void)vfprintf( dbf, format_str, ap );
|
||||
va_end( ap );
|
||||
errno = old_errno;
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
if( !dbf && *debugf)
|
||||
{
|
||||
mode_t oldumask = umask( 022 );
|
||||
|
||||
if( append_log )
|
||||
dbf = sys_fopen( debugf, "a" );
|
||||
else
|
||||
dbf = sys_fopen( debugf, "w" );
|
||||
(void)umask( oldumask );
|
||||
if( dbf )
|
||||
{
|
||||
setbuf( dbf, NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
(void) vfprintf (dbf, format_str, ap);
|
||||
va_end (ap);
|
||||
errno = old_errno;
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (!dbf && *debugf)
|
||||
{
|
||||
mode_t oldumask = umask (022);
|
||||
|
||||
if (append_log)
|
||||
dbf = sys_fopen (debugf, "a");
|
||||
else
|
||||
dbf = sys_fopen (debugf, "w");
|
||||
(void) umask (oldumask);
|
||||
if (dbf)
|
||||
{
|
||||
setbuf (dbf, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = old_errno;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
if (dbf)
|
||||
{
|
||||
#ifdef HAVE_STDARG_H
|
||||
va_start( ap, format_str );
|
||||
va_start (ap, format_str);
|
||||
#else
|
||||
va_start( ap );
|
||||
format_str = va_arg( ap, const char * );
|
||||
va_start (ap);
|
||||
format_str = va_arg (ap, const char *);
|
||||
#endif
|
||||
(void)vfprintf( dbf, format_str, ap );
|
||||
va_end( ap );
|
||||
(void)fflush( dbf );
|
||||
(void) vfprintf (dbf, format_str, ap);
|
||||
va_end (ap);
|
||||
(void) fflush (dbf);
|
||||
}
|
||||
|
||||
errno = old_errno;
|
||||
errno = old_errno;
|
||||
|
||||
return( 0 );
|
||||
} /* Debug1 */
|
||||
return (0);
|
||||
} /* Debug1 */
|
||||
|
||||
|
||||
/* ************************************************************************** **
|
||||
@ -209,12 +213,13 @@ va_dcl
|
||||
*
|
||||
* ************************************************************************** **
|
||||
*/
|
||||
static void bufr_print( void )
|
||||
{
|
||||
format_bufr[format_pos] = '\0';
|
||||
(void)Debug1( "%s", format_bufr );
|
||||
format_pos = 0;
|
||||
} /* bufr_print */
|
||||
static void
|
||||
bufr_print (void)
|
||||
{
|
||||
format_bufr[format_pos] = '\0';
|
||||
(void) Debug1 ("%s", format_bufr);
|
||||
format_pos = 0;
|
||||
} /* bufr_print */
|
||||
|
||||
/* ************************************************************************** **
|
||||
* Format the debug message text.
|
||||
@ -233,42 +238,42 @@ static void bufr_print( void )
|
||||
*
|
||||
* ************************************************************************** **
|
||||
*/
|
||||
static void format_debug_text( char *msg )
|
||||
{
|
||||
size_t i;
|
||||
BOOL timestamp = (!stdout_logging && (lp_timestamp_logs() ||
|
||||
!(lp_loaded())));
|
||||
static void
|
||||
format_debug_text (char *msg)
|
||||
{
|
||||
size_t i;
|
||||
BOOL timestamp = (!stdout_logging && (lp_timestamp_logs () || !(lp_loaded ())));
|
||||
|
||||
for( i = 0; msg[i]; i++ )
|
||||
for (i = 0; msg[i]; i++)
|
||||
{
|
||||
/* Indent two spaces at each new line. */
|
||||
if(timestamp && 0 == format_pos)
|
||||
{
|
||||
format_bufr[0] = format_bufr[1] = ' ';
|
||||
format_pos = 2;
|
||||
}
|
||||
/* Indent two spaces at each new line. */
|
||||
if (timestamp && 0 == format_pos)
|
||||
{
|
||||
format_bufr[0] = format_bufr[1] = ' ';
|
||||
format_pos = 2;
|
||||
}
|
||||
|
||||
/* If there's room, copy the character to the format buffer. */
|
||||
if( format_pos < FORMAT_BUFR_MAX )
|
||||
format_bufr[format_pos++] = msg[i];
|
||||
/* If there's room, copy the character to the format buffer. */
|
||||
if (format_pos < FORMAT_BUFR_MAX)
|
||||
format_bufr[format_pos++] = msg[i];
|
||||
|
||||
/* If a newline is encountered, print & restart. */
|
||||
if( '\n' == msg[i] )
|
||||
bufr_print();
|
||||
/* If a newline is encountered, print & restart. */
|
||||
if ('\n' == msg[i])
|
||||
bufr_print ();
|
||||
|
||||
/* If the buffer is full dump it out, reset it, and put out a line
|
||||
* continuation indicator.
|
||||
*/
|
||||
if( format_pos >= FORMAT_BUFR_MAX )
|
||||
{
|
||||
bufr_print();
|
||||
(void)Debug1( " +>\n" );
|
||||
}
|
||||
/* If the buffer is full dump it out, reset it, and put out a line
|
||||
* continuation indicator.
|
||||
*/
|
||||
if (format_pos >= FORMAT_BUFR_MAX)
|
||||
{
|
||||
bufr_print ();
|
||||
(void) Debug1 (" +>\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* Just to be safe... */
|
||||
format_bufr[format_pos] = '\0';
|
||||
} /* format_debug_text */
|
||||
/* Just to be safe... */
|
||||
format_bufr[format_pos] = '\0';
|
||||
} /* format_debug_text */
|
||||
|
||||
/* ************************************************************************** **
|
||||
* Flush debug output, including the format buffer content.
|
||||
@ -278,11 +283,12 @@ static void format_debug_text( char *msg )
|
||||
*
|
||||
* ************************************************************************** **
|
||||
*/
|
||||
void dbgflush( void )
|
||||
{
|
||||
bufr_print();
|
||||
(void)fflush( dbf );
|
||||
} /* dbgflush */
|
||||
void
|
||||
dbgflush (void)
|
||||
{
|
||||
bufr_print ();
|
||||
(void) fflush (dbf);
|
||||
} /* dbgflush */
|
||||
|
||||
/* ************************************************************************** **
|
||||
* Print a Debug Header.
|
||||
@ -306,38 +312,38 @@ void dbgflush( void )
|
||||
*
|
||||
* ************************************************************************** **
|
||||
*/
|
||||
BOOL dbghdr( int level, const char *file, const char *func, int line )
|
||||
{
|
||||
if( format_pos )
|
||||
BOOL
|
||||
dbghdr (int level, const char *file, const char *func, int line)
|
||||
{
|
||||
if (format_pos)
|
||||
{
|
||||
/* This is a fudge. If there is stuff sitting in the format_bufr, then
|
||||
* the *right* thing to do is to call
|
||||
* format_debug_text( "\n" );
|
||||
* to write the remainder, and then proceed with the new header.
|
||||
* Unfortunately, there are several places in the code at which
|
||||
* the DEBUG() macro is used to build partial lines. That in mind,
|
||||
* we'll work under the assumption that an incomplete line indicates
|
||||
* that a new header is *not* desired.
|
||||
/* This is a fudge. If there is stuff sitting in the format_bufr, then
|
||||
* the *right* thing to do is to call
|
||||
* format_debug_text( "\n" );
|
||||
* to write the remainder, and then proceed with the new header.
|
||||
* Unfortunately, there are several places in the code at which
|
||||
* the DEBUG() macro is used to build partial lines. That in mind,
|
||||
* we'll work under the assumption that an incomplete line indicates
|
||||
* that a new header is *not* desired.
|
||||
*/
|
||||
return (True);
|
||||
}
|
||||
|
||||
/* Don't print a header if we're logging to stdout. */
|
||||
if (stdout_logging)
|
||||
return (True);
|
||||
|
||||
/* Print the header if timestamps are turned on. If parameters are
|
||||
* not yet loaded, then default to timestamps on.
|
||||
*/
|
||||
return( True );
|
||||
}
|
||||
|
||||
/* Don't print a header if we're logging to stdout. */
|
||||
if( stdout_logging )
|
||||
return( True );
|
||||
|
||||
/* Print the header if timestamps are turned on. If parameters are
|
||||
* not yet loaded, then default to timestamps on.
|
||||
*/
|
||||
if( lp_timestamp_logs() || !(lp_loaded()) )
|
||||
if (lp_timestamp_logs () || !(lp_loaded ()))
|
||||
{
|
||||
/* Print it all out at once to prevent split syslog output. */
|
||||
(void)Debug1( "[%s, %d] %s:%s(%d)\n",
|
||||
timestring(), level, file, func, line );
|
||||
/* Print it all out at once to prevent split syslog output. */
|
||||
(void) Debug1 ("[%s, %d] %s:%s(%d)\n", timestring (), level, file, func, line);
|
||||
}
|
||||
|
||||
return( True );
|
||||
} /* dbghdr */
|
||||
return (True);
|
||||
} /* dbghdr */
|
||||
|
||||
/* ************************************************************************** **
|
||||
* Add text to the body of the "current" debug message via the format buffer.
|
||||
@ -353,37 +359,39 @@ BOOL dbghdr( int level, const char *file, const char *func, int line )
|
||||
* ************************************************************************** **
|
||||
*/
|
||||
#ifdef HAVE_STDARG_H
|
||||
BOOL dbgtext( const char *format_str, ... )
|
||||
{
|
||||
va_list ap;
|
||||
pstring msgbuf;
|
||||
BOOL
|
||||
dbgtext (const char *format_str, ...)
|
||||
{
|
||||
va_list ap;
|
||||
pstring msgbuf;
|
||||
|
||||
va_start( ap, format_str );
|
||||
vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap );
|
||||
va_end( ap );
|
||||
va_start (ap, format_str);
|
||||
vslprintf (msgbuf, sizeof (msgbuf) - 1, format_str, ap);
|
||||
va_end (ap);
|
||||
|
||||
format_debug_text( msgbuf );
|
||||
format_debug_text (msgbuf);
|
||||
|
||||
return( True );
|
||||
} /* dbgtext */
|
||||
return (True);
|
||||
} /* dbgtext */
|
||||
|
||||
#else
|
||||
BOOL dbgtext( va_alist )
|
||||
va_dcl
|
||||
{
|
||||
char *format_str;
|
||||
va_list ap;
|
||||
pstring msgbuf;
|
||||
BOOL
|
||||
dbgtext (va_alist)
|
||||
va_dcl
|
||||
{
|
||||
char *format_str;
|
||||
va_list ap;
|
||||
pstring msgbuf;
|
||||
|
||||
va_start( ap );
|
||||
format_str = va_arg( ap, char * );
|
||||
vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap );
|
||||
va_end( ap );
|
||||
va_start (ap);
|
||||
format_str = va_arg (ap, char *);
|
||||
vslprintf (msgbuf, sizeof (msgbuf) - 1, format_str, ap);
|
||||
va_end (ap);
|
||||
|
||||
format_debug_text( msgbuf );
|
||||
format_debug_text (msgbuf);
|
||||
|
||||
return( True );
|
||||
} /* dbgtext */
|
||||
return (True);
|
||||
} /* dbgtext */
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
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"
|
||||
|
||||
@ -34,11 +34,11 @@ struct in_addr loopback_ip;
|
||||
static struct in_addr default_ip;
|
||||
static struct in_addr default_bcast;
|
||||
static struct in_addr default_nmask;
|
||||
static BOOL got_ip=False;
|
||||
static BOOL got_bcast=False;
|
||||
static BOOL got_nmask=False;
|
||||
static BOOL got_ip = False;
|
||||
static BOOL got_bcast = False;
|
||||
static BOOL got_nmask = False;
|
||||
|
||||
static struct interface *local_interfaces = NULL;
|
||||
static struct interface *local_interfaces = NULL;
|
||||
|
||||
struct interface *last_iface;
|
||||
|
||||
@ -47,31 +47,33 @@ struct interface *last_iface;
|
||||
/****************************************************************************
|
||||
calculate the default netmask for an address
|
||||
****************************************************************************/
|
||||
static void default_netmask(struct in_addr *inm, struct in_addr *iad)
|
||||
static void
|
||||
default_netmask (struct in_addr *inm, struct in_addr *iad)
|
||||
{
|
||||
/*
|
||||
** Guess a netmask based on the class of the IP address given.
|
||||
*/
|
||||
switch((ntohl(iad->s_addr) & 0xE0000000)) {
|
||||
case 0x00000000: /* Class A addr */
|
||||
case 0x20000000:
|
||||
case 0x40000000:
|
||||
case 0x60000000:
|
||||
inm->s_addr = htonl(0xFF000000);
|
||||
break;
|
||||
|
||||
case 0x80000000: /* Class B addr */
|
||||
case 0xA0000000:
|
||||
inm->s_addr = htonl(0xFFFF0000);
|
||||
break;
|
||||
|
||||
case 0xC0000000: /* Class C addr */
|
||||
inm->s_addr = htonl(0xFFFFFF00);
|
||||
break;
|
||||
|
||||
default: /* ??? */
|
||||
inm->s_addr = htonl(0xFFFFFFF0);
|
||||
}
|
||||
/*
|
||||
** Guess a netmask based on the class of the IP address given.
|
||||
*/
|
||||
switch ((ntohl (iad->s_addr) & 0xE0000000))
|
||||
{
|
||||
case 0x00000000: /* Class A addr */
|
||||
case 0x20000000:
|
||||
case 0x40000000:
|
||||
case 0x60000000:
|
||||
inm->s_addr = htonl (0xFF000000);
|
||||
break;
|
||||
|
||||
case 0x80000000: /* Class B addr */
|
||||
case 0xA0000000:
|
||||
inm->s_addr = htonl (0xFFFF0000);
|
||||
break;
|
||||
|
||||
case 0xC0000000: /* Class C addr */
|
||||
inm->s_addr = htonl (0xFFFFFF00);
|
||||
break;
|
||||
|
||||
default: /* ??? */
|
||||
inm->s_addr = htonl (0xFFFFFFF0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -79,48 +81,52 @@ static void default_netmask(struct in_addr *inm, struct in_addr *iad)
|
||||
get the broadcast address for our address
|
||||
(troyer@saifr00.ateng.az.honeywell.com)
|
||||
****************************************************************************/
|
||||
static void get_broadcast(struct in_addr *if_ipaddr,
|
||||
struct in_addr *if_bcast,
|
||||
struct in_addr *if_nmask)
|
||||
{
|
||||
uint32 nm;
|
||||
short onbc;
|
||||
short offbc;
|
||||
static void
|
||||
get_broadcast (struct in_addr *if_ipaddr, struct in_addr *if_bcast, struct in_addr *if_nmask)
|
||||
{
|
||||
uint32 nm;
|
||||
short onbc;
|
||||
short offbc;
|
||||
|
||||
/* get a default netmask and broadcast */
|
||||
default_netmask(if_nmask, if_ipaddr);
|
||||
/* get a default netmask and broadcast */
|
||||
default_netmask (if_nmask, if_ipaddr);
|
||||
|
||||
get_netmask(if_ipaddr, if_nmask);
|
||||
get_netmask (if_ipaddr, if_nmask);
|
||||
|
||||
/* sanity check on the netmask */
|
||||
nm = ntohl(if_nmask->s_addr);
|
||||
onbc = 0;
|
||||
offbc = 0;
|
||||
while((onbc + offbc) < 32) {
|
||||
if(nm & 0x80000000) {
|
||||
onbc++;
|
||||
if(offbc) {
|
||||
/* already found an off bit, so mask
|
||||
is wrong */
|
||||
onbc = 34;
|
||||
}
|
||||
} else {
|
||||
offbc++;
|
||||
}
|
||||
nm <<= 1;
|
||||
}
|
||||
if ((onbc < 8)||(onbc == 34)) {
|
||||
DEBUG(0,("Impossible netmask %s - using defaults\n",
|
||||
inet_ntoa(*if_nmask)));
|
||||
default_netmask(if_nmask, if_ipaddr);
|
||||
}
|
||||
/* sanity check on the netmask */
|
||||
nm = ntohl (if_nmask->s_addr);
|
||||
onbc = 0;
|
||||
offbc = 0;
|
||||
while ((onbc + offbc) < 32)
|
||||
{
|
||||
if (nm & 0x80000000)
|
||||
{
|
||||
onbc++;
|
||||
if (offbc)
|
||||
{
|
||||
/* already found an off bit, so mask
|
||||
is wrong */
|
||||
onbc = 34;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
offbc++;
|
||||
}
|
||||
nm <<= 1;
|
||||
}
|
||||
if ((onbc < 8) || (onbc == 34))
|
||||
{
|
||||
DEBUG (0, ("Impossible netmask %s - using defaults\n", inet_ntoa (*if_nmask)));
|
||||
default_netmask (if_nmask, if_ipaddr);
|
||||
}
|
||||
|
||||
/* derive the broadcast assuming a 1's broadcast, as this is what
|
||||
all MS operating systems do, we have to comply even if the unix
|
||||
box is setup differently */
|
||||
if_bcast->s_addr = MKBCADDR(if_ipaddr->s_addr, if_nmask->s_addr);
|
||||
|
||||
DEBUG(4,("Derived broadcast address %s\n", inet_ntoa(*if_bcast)));
|
||||
/* derive the broadcast assuming a 1's broadcast, as this is what
|
||||
all MS operating systems do, we have to comply even if the unix
|
||||
box is setup differently */
|
||||
if_bcast->s_addr = MKBCADDR (if_ipaddr->s_addr, if_nmask->s_addr);
|
||||
|
||||
DEBUG (4, ("Derived broadcast address %s\n", inet_ntoa (*if_bcast)));
|
||||
}
|
||||
|
||||
|
||||
@ -128,220 +134,258 @@ static void get_broadcast(struct in_addr *if_ipaddr,
|
||||
/****************************************************************************
|
||||
load a list of network interfaces
|
||||
****************************************************************************/
|
||||
static void interpret_interfaces(char *s, struct interface **interfaces,
|
||||
const char *description)
|
||||
static void
|
||||
interpret_interfaces (char *s, struct interface **interfaces, const char *description)
|
||||
{
|
||||
char *ptr;
|
||||
fstring token;
|
||||
struct interface *iface;
|
||||
struct in_addr ip;
|
||||
char *ptr;
|
||||
fstring token;
|
||||
struct interface *iface;
|
||||
struct in_addr ip;
|
||||
|
||||
ptr = s;
|
||||
ipzero = *interpret_addr2("0.0.0.0");
|
||||
allones_ip = *interpret_addr2("255.255.255.255");
|
||||
loopback_ip = *interpret_addr2("127.0.0.1");
|
||||
ptr = s;
|
||||
ipzero = *interpret_addr2 ("0.0.0.0");
|
||||
allones_ip = *interpret_addr2 ("255.255.255.255");
|
||||
loopback_ip = *interpret_addr2 ("127.0.0.1");
|
||||
|
||||
while (next_token(&ptr,token,NULL,sizeof(token))) {
|
||||
/* parse it into an IP address/netmasklength pair */
|
||||
char *p = strchr(token,'/');
|
||||
if (p) *p++ = 0;
|
||||
|
||||
ip = *interpret_addr2(token);
|
||||
|
||||
/* maybe we already have it listed */
|
||||
while (next_token (&ptr, token, NULL, sizeof (token)))
|
||||
{
|
||||
struct interface *i;
|
||||
for (i=(*interfaces);i;i=i->next)
|
||||
if (ip_equal(ip,i->ip)) break;
|
||||
if (i) continue;
|
||||
/* parse it into an IP address/netmasklength pair */
|
||||
char *p = strchr (token, '/');
|
||||
if (p)
|
||||
*p++ = 0;
|
||||
|
||||
ip = *interpret_addr2 (token);
|
||||
|
||||
/* maybe we already have it listed */
|
||||
{
|
||||
struct interface *i;
|
||||
for (i = (*interfaces); i; i = i->next)
|
||||
if (ip_equal (ip, i->ip))
|
||||
break;
|
||||
if (i)
|
||||
continue;
|
||||
}
|
||||
|
||||
iface = (struct interface *) malloc (sizeof (*iface));
|
||||
if (!iface)
|
||||
return;
|
||||
|
||||
iface->ip = ip;
|
||||
|
||||
if (p)
|
||||
{
|
||||
if (strlen (p) > 2)
|
||||
iface->nmask = *interpret_addr2 (p);
|
||||
else
|
||||
iface->nmask.s_addr = htonl (((ALLONES >> atoi (p)) ^ ALLONES));
|
||||
}
|
||||
else
|
||||
{
|
||||
default_netmask (&iface->nmask, &iface->ip);
|
||||
}
|
||||
iface->bcast.s_addr = MKBCADDR (iface->ip.s_addr, iface->nmask.s_addr);
|
||||
iface->next = NULL;
|
||||
|
||||
if (!(*interfaces))
|
||||
{
|
||||
(*interfaces) = iface;
|
||||
}
|
||||
else
|
||||
{
|
||||
last_iface->next = iface;
|
||||
}
|
||||
last_iface = iface;
|
||||
DEBUG (2, ("Added %s ip=%s ", description, inet_ntoa (iface->ip)));
|
||||
DEBUG (2, ("bcast=%s ", inet_ntoa (iface->bcast)));
|
||||
DEBUG (2, ("nmask=%s\n", inet_ntoa (iface->nmask)));
|
||||
}
|
||||
|
||||
iface = (struct interface *)malloc(sizeof(*iface));
|
||||
if (!iface) return;
|
||||
if (*interfaces)
|
||||
return;
|
||||
|
||||
iface->ip = ip;
|
||||
/* setup a default interface */
|
||||
iface = (struct interface *) malloc (sizeof (*iface));
|
||||
if (!iface)
|
||||
return;
|
||||
|
||||
if (p) {
|
||||
if (strlen(p) > 2)
|
||||
iface->nmask = *interpret_addr2(p);
|
||||
else
|
||||
iface->nmask.s_addr = htonl(((ALLONES >> atoi(p)) ^ ALLONES));
|
||||
} else {
|
||||
default_netmask(&iface->nmask,&iface->ip);
|
||||
}
|
||||
iface->bcast.s_addr = MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr);
|
||||
iface->next = NULL;
|
||||
|
||||
if (!(*interfaces)) {
|
||||
(*interfaces) = iface;
|
||||
} else {
|
||||
last_iface->next = iface;
|
||||
if (got_ip)
|
||||
{
|
||||
iface->ip = default_ip;
|
||||
}
|
||||
else
|
||||
{
|
||||
get_myname (NULL, &iface->ip);
|
||||
}
|
||||
last_iface = iface;
|
||||
DEBUG(2,("Added %s ip=%s ",description,inet_ntoa(iface->ip)));
|
||||
DEBUG(2,("bcast=%s ",inet_ntoa(iface->bcast)));
|
||||
DEBUG(2,("nmask=%s\n",inet_ntoa(iface->nmask)));
|
||||
}
|
||||
|
||||
if (*interfaces) return;
|
||||
if (got_bcast)
|
||||
{
|
||||
iface->bcast = default_bcast;
|
||||
}
|
||||
else
|
||||
{
|
||||
get_broadcast (&iface->ip, &iface->bcast, &iface->nmask);
|
||||
}
|
||||
|
||||
/* setup a default interface */
|
||||
iface = (struct interface *)malloc(sizeof(*iface));
|
||||
if (!iface) return;
|
||||
if (got_nmask)
|
||||
{
|
||||
iface->nmask = default_nmask;
|
||||
iface->bcast.s_addr = MKBCADDR (iface->ip.s_addr, iface->nmask.s_addr);
|
||||
}
|
||||
|
||||
iface->next = NULL;
|
||||
if (iface->bcast.s_addr != MKBCADDR (iface->ip.s_addr, iface->nmask.s_addr))
|
||||
{
|
||||
DEBUG (2, ("Warning: inconsistant interface %s\n", inet_ntoa (iface->ip)));
|
||||
}
|
||||
|
||||
if (got_ip) {
|
||||
iface->ip = default_ip;
|
||||
} else {
|
||||
get_myname(NULL,&iface->ip);
|
||||
}
|
||||
iface->next = NULL;
|
||||
(*interfaces) = last_iface = iface;
|
||||
|
||||
if (got_bcast) {
|
||||
iface->bcast = default_bcast;
|
||||
} else {
|
||||
get_broadcast(&iface->ip,&iface->bcast,&iface->nmask);
|
||||
}
|
||||
|
||||
if (got_nmask) {
|
||||
iface->nmask = default_nmask;
|
||||
iface->bcast.s_addr = MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr);
|
||||
}
|
||||
|
||||
if (iface->bcast.s_addr != MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr)) {
|
||||
DEBUG(2,("Warning: inconsistant interface %s\n",inet_ntoa(iface->ip)));
|
||||
}
|
||||
|
||||
iface->next = NULL;
|
||||
(*interfaces) = last_iface = iface;
|
||||
|
||||
DEBUG(2,("Added interface ip=%s ",inet_ntoa(iface->ip)));
|
||||
DEBUG(2,("bcast=%s ",inet_ntoa(iface->bcast)));
|
||||
DEBUG(2,("nmask=%s\n",inet_ntoa(iface->nmask)));
|
||||
DEBUG (2, ("Added interface ip=%s ", inet_ntoa (iface->ip)));
|
||||
DEBUG (2, ("bcast=%s ", inet_ntoa (iface->bcast)));
|
||||
DEBUG (2, ("nmask=%s\n", inet_ntoa (iface->nmask)));
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
load the remote and local interfaces
|
||||
****************************************************************************/
|
||||
void load_interfaces(void)
|
||||
void
|
||||
load_interfaces (void)
|
||||
{
|
||||
/* add the machine's interfaces to local interface structure*/
|
||||
interpret_interfaces(lp_interfaces(), &local_interfaces,"interface");
|
||||
/* add the machine's interfaces to local interface structure */
|
||||
interpret_interfaces (lp_interfaces (), &local_interfaces, "interface");
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
override the defaults
|
||||
**************************************************************************/
|
||||
void iface_set_default(char *ip,char *bcast,char *nmask)
|
||||
void
|
||||
iface_set_default (char *ip, char *bcast, char *nmask)
|
||||
{
|
||||
if (ip) {
|
||||
got_ip = True;
|
||||
default_ip = *interpret_addr2(ip);
|
||||
}
|
||||
if (ip)
|
||||
{
|
||||
got_ip = True;
|
||||
default_ip = *interpret_addr2 (ip);
|
||||
}
|
||||
|
||||
if (bcast) {
|
||||
got_bcast = True;
|
||||
default_bcast = *interpret_addr2(bcast);
|
||||
}
|
||||
if (bcast)
|
||||
{
|
||||
got_bcast = True;
|
||||
default_bcast = *interpret_addr2 (bcast);
|
||||
}
|
||||
|
||||
if (nmask) {
|
||||
got_nmask = True;
|
||||
default_nmask = *interpret_addr2(nmask);
|
||||
}
|
||||
if (nmask)
|
||||
{
|
||||
got_nmask = True;
|
||||
default_nmask = *interpret_addr2 (nmask);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
check if an IP is one of mine
|
||||
**************************************************************************/
|
||||
BOOL ismyip(struct in_addr ip)
|
||||
BOOL
|
||||
ismyip (struct in_addr ip)
|
||||
{
|
||||
struct interface *i;
|
||||
for (i=local_interfaces;i;i=i->next)
|
||||
if (ip_equal(i->ip,ip)) return True;
|
||||
return False;
|
||||
struct interface *i;
|
||||
for (i = local_interfaces; i; i = i->next)
|
||||
if (ip_equal (i->ip, ip))
|
||||
return True;
|
||||
return False;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
check if a packet is from a local (known) net
|
||||
**************************************************************************/
|
||||
BOOL is_local_net(struct in_addr from)
|
||||
BOOL
|
||||
is_local_net (struct in_addr from)
|
||||
{
|
||||
struct interface *i;
|
||||
for (i=local_interfaces;i;i=i->next)
|
||||
if((from.s_addr & i->nmask.s_addr) == (i->ip.s_addr & i->nmask.s_addr))
|
||||
return True;
|
||||
return False;
|
||||
struct interface *i;
|
||||
for (i = local_interfaces; i; i = i->next)
|
||||
if ((from.s_addr & i->nmask.s_addr) == (i->ip.s_addr & i->nmask.s_addr))
|
||||
return True;
|
||||
return False;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
how many interfaces do we have
|
||||
**************************************************************************/
|
||||
int iface_count(void)
|
||||
int
|
||||
iface_count (void)
|
||||
{
|
||||
int ret = 0;
|
||||
struct interface *i;
|
||||
int ret = 0;
|
||||
struct interface *i;
|
||||
|
||||
for (i=local_interfaces;i;i=i->next)
|
||||
ret++;
|
||||
return ret;
|
||||
for (i = local_interfaces; i; i = i->next)
|
||||
ret++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
True if we have two or more interfaces.
|
||||
**************************************************************************/
|
||||
BOOL we_are_multihomed(void)
|
||||
BOOL
|
||||
we_are_multihomed (void)
|
||||
{
|
||||
static int multi = -1;
|
||||
static int multi = -1;
|
||||
|
||||
if(multi == -1)
|
||||
multi = (iface_count() > 1 ? True : False);
|
||||
if (multi == -1)
|
||||
multi = (iface_count () > 1 ? True : False);
|
||||
|
||||
return multi;
|
||||
return multi;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
return the Nth interface
|
||||
**************************************************************************/
|
||||
struct interface *get_interface(int n)
|
||||
{
|
||||
struct interface *i;
|
||||
|
||||
for (i=local_interfaces;i && n;i=i->next)
|
||||
n--;
|
||||
struct interface *
|
||||
get_interface (int n)
|
||||
{
|
||||
struct interface *i;
|
||||
|
||||
if (i) return i;
|
||||
return NULL;
|
||||
for (i = local_interfaces; i && n; i = i->next)
|
||||
n--;
|
||||
|
||||
if (i)
|
||||
return i;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
return IP of the Nth interface
|
||||
**************************************************************************/
|
||||
struct in_addr *iface_n_ip(int n)
|
||||
struct in_addr *
|
||||
iface_n_ip (int n)
|
||||
{
|
||||
struct interface *i;
|
||||
|
||||
for (i=local_interfaces;i && n;i=i->next)
|
||||
n--;
|
||||
struct interface *i;
|
||||
|
||||
if (i) return &i->ip;
|
||||
return NULL;
|
||||
for (i = local_interfaces; i && n; i = i->next)
|
||||
n--;
|
||||
|
||||
if (i)
|
||||
return &i->ip;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Try and find an interface that matches an ip. If we cannot, return NULL
|
||||
**************************************************************************/
|
||||
static struct interface *iface_find(struct in_addr ip)
|
||||
static struct interface *
|
||||
iface_find (struct in_addr ip)
|
||||
{
|
||||
struct interface *i;
|
||||
if (zero_ip(ip)) return local_interfaces;
|
||||
struct interface *i;
|
||||
if (zero_ip (ip))
|
||||
return local_interfaces;
|
||||
|
||||
for (i=local_interfaces;i;i=i->next)
|
||||
if (same_net(i->ip,ip,i->nmask)) return i;
|
||||
for (i = local_interfaces; i; i = i->next)
|
||||
if (same_net (i->ip, ip, i->nmask))
|
||||
return i;
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -351,18 +395,20 @@ used to detect a change in interfaces to tell us whether to discard
|
||||
the current wins.dat file.
|
||||
Note that the result is independent of the order of the interfaces
|
||||
**************************************************************************/
|
||||
unsigned iface_hash(void)
|
||||
unsigned
|
||||
iface_hash (void)
|
||||
{
|
||||
unsigned ret = 0;
|
||||
struct interface *i;
|
||||
unsigned ret = 0;
|
||||
struct interface *i;
|
||||
|
||||
for (i=local_interfaces;i;i=i->next) {
|
||||
unsigned x1 = (unsigned)str_checksum(inet_ntoa(i->ip));
|
||||
unsigned x2 = (unsigned)str_checksum(inet_ntoa(i->nmask));
|
||||
ret ^= (x1 ^ x2);
|
||||
}
|
||||
for (i = local_interfaces; i; i = i->next)
|
||||
{
|
||||
unsigned x1 = (unsigned) str_checksum (inet_ntoa (i->ip));
|
||||
unsigned x2 = (unsigned) str_checksum (inet_ntoa (i->nmask));
|
||||
ret ^= (x1 ^ x2);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -371,17 +417,16 @@ unsigned iface_hash(void)
|
||||
an appropriate interface they return the requested field of the
|
||||
first known interface. */
|
||||
|
||||
struct in_addr *iface_bcast(struct in_addr ip)
|
||||
struct in_addr *
|
||||
iface_bcast (struct in_addr ip)
|
||||
{
|
||||
struct interface *i = iface_find(ip);
|
||||
return(i ? &i->bcast : &local_interfaces->bcast);
|
||||
struct interface *i = iface_find (ip);
|
||||
return (i ? &i->bcast : &local_interfaces->bcast);
|
||||
}
|
||||
|
||||
struct in_addr *iface_ip(struct in_addr ip)
|
||||
struct in_addr *
|
||||
iface_ip (struct in_addr ip)
|
||||
{
|
||||
struct interface *i = iface_find(ip);
|
||||
return(i ? &i->ip : &local_interfaces->ip);
|
||||
struct interface *i = iface_find (ip);
|
||||
return (i ? &i->ip : &local_interfaces->ip);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -22,36 +22,40 @@
|
||||
|
||||
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"
|
||||
|
||||
/* NOTE: This code makes no attempt to be fast!
|
||||
|
||||
It assumes that a int is at least 32 bits long
|
||||
*/
|
||||
*/
|
||||
|
||||
static uint32 A, B, C, D;
|
||||
|
||||
static uint32 F(uint32 X, uint32 Y, uint32 Z)
|
||||
static uint32
|
||||
F (uint32 X, uint32 Y, uint32 Z)
|
||||
{
|
||||
return (X&Y) | ((~X)&Z);
|
||||
return (X & Y) | ((~X) & Z);
|
||||
}
|
||||
|
||||
static uint32 G(uint32 X, uint32 Y, uint32 Z)
|
||||
static uint32
|
||||
G (uint32 X, uint32 Y, uint32 Z)
|
||||
{
|
||||
return (X&Y) | (X&Z) | (Y&Z);
|
||||
return (X & Y) | (X & Z) | (Y & Z);
|
||||
}
|
||||
|
||||
static uint32 H(uint32 X, uint32 Y, uint32 Z)
|
||||
static uint32
|
||||
H (uint32 X, uint32 Y, uint32 Z)
|
||||
{
|
||||
return X^Y^Z;
|
||||
return X ^ Y ^ Z;
|
||||
}
|
||||
|
||||
static uint32 lshift(uint32 x, int s)
|
||||
static uint32
|
||||
lshift (uint32 x, int s)
|
||||
{
|
||||
x &= 0xFFFFFFFF;
|
||||
return ((x<<s)&0xFFFFFFFF) | (x>>(32-s));
|
||||
x &= 0xFFFFFFFF;
|
||||
return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
|
||||
}
|
||||
|
||||
#define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s)
|
||||
@ -59,117 +63,155 @@ static uint32 lshift(uint32 x, int s)
|
||||
#define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + (uint32)0x6ED9EBA1,s)
|
||||
|
||||
/* this applies md4 to 64 byte chunks */
|
||||
static void mdfour64(uint32 *M)
|
||||
static void
|
||||
mdfour64 (uint32 * M)
|
||||
{
|
||||
int j;
|
||||
uint32 AA, BB, CC, DD;
|
||||
uint32 X[16];
|
||||
int j;
|
||||
uint32 AA, BB, CC, DD;
|
||||
uint32 X[16];
|
||||
|
||||
for (j=0;j<16;j++)
|
||||
X[j] = M[j];
|
||||
for (j = 0; j < 16; j++)
|
||||
X[j] = M[j];
|
||||
|
||||
AA = A; BB = B; CC = C; DD = D;
|
||||
AA = A;
|
||||
BB = B;
|
||||
CC = C;
|
||||
DD = D;
|
||||
|
||||
ROUND1(A,B,C,D, 0, 3); ROUND1(D,A,B,C, 1, 7);
|
||||
ROUND1(C,D,A,B, 2, 11); ROUND1(B,C,D,A, 3, 19);
|
||||
ROUND1(A,B,C,D, 4, 3); ROUND1(D,A,B,C, 5, 7);
|
||||
ROUND1(C,D,A,B, 6, 11); ROUND1(B,C,D,A, 7, 19);
|
||||
ROUND1(A,B,C,D, 8, 3); ROUND1(D,A,B,C, 9, 7);
|
||||
ROUND1(C,D,A,B, 10, 11); ROUND1(B,C,D,A, 11, 19);
|
||||
ROUND1(A,B,C,D, 12, 3); ROUND1(D,A,B,C, 13, 7);
|
||||
ROUND1(C,D,A,B, 14, 11); ROUND1(B,C,D,A, 15, 19);
|
||||
ROUND1 (A, B, C, D, 0, 3);
|
||||
ROUND1 (D, A, B, C, 1, 7);
|
||||
ROUND1 (C, D, A, B, 2, 11);
|
||||
ROUND1 (B, C, D, A, 3, 19);
|
||||
ROUND1 (A, B, C, D, 4, 3);
|
||||
ROUND1 (D, A, B, C, 5, 7);
|
||||
ROUND1 (C, D, A, B, 6, 11);
|
||||
ROUND1 (B, C, D, A, 7, 19);
|
||||
ROUND1 (A, B, C, D, 8, 3);
|
||||
ROUND1 (D, A, B, C, 9, 7);
|
||||
ROUND1 (C, D, A, B, 10, 11);
|
||||
ROUND1 (B, C, D, A, 11, 19);
|
||||
ROUND1 (A, B, C, D, 12, 3);
|
||||
ROUND1 (D, A, B, C, 13, 7);
|
||||
ROUND1 (C, D, A, B, 14, 11);
|
||||
ROUND1 (B, C, D, A, 15, 19);
|
||||
|
||||
ROUND2(A,B,C,D, 0, 3); ROUND2(D,A,B,C, 4, 5);
|
||||
ROUND2(C,D,A,B, 8, 9); ROUND2(B,C,D,A, 12, 13);
|
||||
ROUND2(A,B,C,D, 1, 3); ROUND2(D,A,B,C, 5, 5);
|
||||
ROUND2(C,D,A,B, 9, 9); ROUND2(B,C,D,A, 13, 13);
|
||||
ROUND2(A,B,C,D, 2, 3); ROUND2(D,A,B,C, 6, 5);
|
||||
ROUND2(C,D,A,B, 10, 9); ROUND2(B,C,D,A, 14, 13);
|
||||
ROUND2(A,B,C,D, 3, 3); ROUND2(D,A,B,C, 7, 5);
|
||||
ROUND2(C,D,A,B, 11, 9); ROUND2(B,C,D,A, 15, 13);
|
||||
ROUND2 (A, B, C, D, 0, 3);
|
||||
ROUND2 (D, A, B, C, 4, 5);
|
||||
ROUND2 (C, D, A, B, 8, 9);
|
||||
ROUND2 (B, C, D, A, 12, 13);
|
||||
ROUND2 (A, B, C, D, 1, 3);
|
||||
ROUND2 (D, A, B, C, 5, 5);
|
||||
ROUND2 (C, D, A, B, 9, 9);
|
||||
ROUND2 (B, C, D, A, 13, 13);
|
||||
ROUND2 (A, B, C, D, 2, 3);
|
||||
ROUND2 (D, A, B, C, 6, 5);
|
||||
ROUND2 (C, D, A, B, 10, 9);
|
||||
ROUND2 (B, C, D, A, 14, 13);
|
||||
ROUND2 (A, B, C, D, 3, 3);
|
||||
ROUND2 (D, A, B, C, 7, 5);
|
||||
ROUND2 (C, D, A, B, 11, 9);
|
||||
ROUND2 (B, C, D, A, 15, 13);
|
||||
|
||||
ROUND3(A,B,C,D, 0, 3); ROUND3(D,A,B,C, 8, 9);
|
||||
ROUND3(C,D,A,B, 4, 11); ROUND3(B,C,D,A, 12, 15);
|
||||
ROUND3(A,B,C,D, 2, 3); ROUND3(D,A,B,C, 10, 9);
|
||||
ROUND3(C,D,A,B, 6, 11); ROUND3(B,C,D,A, 14, 15);
|
||||
ROUND3(A,B,C,D, 1, 3); ROUND3(D,A,B,C, 9, 9);
|
||||
ROUND3(C,D,A,B, 5, 11); ROUND3(B,C,D,A, 13, 15);
|
||||
ROUND3(A,B,C,D, 3, 3); ROUND3(D,A,B,C, 11, 9);
|
||||
ROUND3(C,D,A,B, 7, 11); ROUND3(B,C,D,A, 15, 15);
|
||||
ROUND3 (A, B, C, D, 0, 3);
|
||||
ROUND3 (D, A, B, C, 8, 9);
|
||||
ROUND3 (C, D, A, B, 4, 11);
|
||||
ROUND3 (B, C, D, A, 12, 15);
|
||||
ROUND3 (A, B, C, D, 2, 3);
|
||||
ROUND3 (D, A, B, C, 10, 9);
|
||||
ROUND3 (C, D, A, B, 6, 11);
|
||||
ROUND3 (B, C, D, A, 14, 15);
|
||||
ROUND3 (A, B, C, D, 1, 3);
|
||||
ROUND3 (D, A, B, C, 9, 9);
|
||||
ROUND3 (C, D, A, B, 5, 11);
|
||||
ROUND3 (B, C, D, A, 13, 15);
|
||||
ROUND3 (A, B, C, D, 3, 3);
|
||||
ROUND3 (D, A, B, C, 11, 9);
|
||||
ROUND3 (C, D, A, B, 7, 11);
|
||||
ROUND3 (B, C, D, A, 15, 15);
|
||||
|
||||
A += AA; B += BB; C += CC; D += DD;
|
||||
|
||||
A &= 0xFFFFFFFF; B &= 0xFFFFFFFF;
|
||||
C &= 0xFFFFFFFF; D &= 0xFFFFFFFF;
|
||||
A += AA;
|
||||
B += BB;
|
||||
C += CC;
|
||||
D += DD;
|
||||
|
||||
for (j=0;j<16;j++)
|
||||
X[j] = 0;
|
||||
A &= 0xFFFFFFFF;
|
||||
B &= 0xFFFFFFFF;
|
||||
C &= 0xFFFFFFFF;
|
||||
D &= 0xFFFFFFFF;
|
||||
|
||||
for (j = 0; j < 16; j++)
|
||||
X[j] = 0;
|
||||
}
|
||||
|
||||
static void copy64(uint32 *M, unsigned char *in)
|
||||
static void
|
||||
copy64 (uint32 * M, unsigned char *in)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i=0;i<16;i++)
|
||||
M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) |
|
||||
(in[i*4+1]<<8) | (in[i*4+0]<<0);
|
||||
for (i = 0; i < 16; i++)
|
||||
M[i] = (in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) |
|
||||
(in[i * 4 + 1] << 8) | (in[i * 4 + 0] << 0);
|
||||
}
|
||||
|
||||
static void copy4(unsigned char *out,uint32 x)
|
||||
static void
|
||||
copy4 (unsigned char *out, uint32 x)
|
||||
{
|
||||
out[0] = x&0xFF;
|
||||
out[1] = (x>>8)&0xFF;
|
||||
out[2] = (x>>16)&0xFF;
|
||||
out[3] = (x>>24)&0xFF;
|
||||
out[0] = x & 0xFF;
|
||||
out[1] = (x >> 8) & 0xFF;
|
||||
out[2] = (x >> 16) & 0xFF;
|
||||
out[3] = (x >> 24) & 0xFF;
|
||||
}
|
||||
|
||||
/* produce a md4 message digest from data of length n bytes */
|
||||
void mdfour(unsigned char *out, unsigned char *in, int n)
|
||||
void
|
||||
mdfour (unsigned char *out, unsigned char *in, int n)
|
||||
{
|
||||
unsigned char buf[128];
|
||||
uint32 M[16];
|
||||
uint32 b = n * 8;
|
||||
int i;
|
||||
unsigned char buf[128];
|
||||
uint32 M[16];
|
||||
uint32 b = n * 8;
|
||||
int i;
|
||||
|
||||
A = 0x67452301;
|
||||
B = 0xefcdab89;
|
||||
C = 0x98badcfe;
|
||||
D = 0x10325476;
|
||||
A = 0x67452301;
|
||||
B = 0xefcdab89;
|
||||
C = 0x98badcfe;
|
||||
D = 0x10325476;
|
||||
|
||||
while (n > 64) {
|
||||
copy64(M, in);
|
||||
mdfour64(M);
|
||||
in += 64;
|
||||
n -= 64;
|
||||
}
|
||||
while (n > 64)
|
||||
{
|
||||
copy64 (M, in);
|
||||
mdfour64 (M);
|
||||
in += 64;
|
||||
n -= 64;
|
||||
}
|
||||
|
||||
for (i=0;i<128;i++)
|
||||
buf[i] = 0;
|
||||
memcpy(buf, in, n);
|
||||
buf[n] = 0x80;
|
||||
|
||||
if (n <= 55) {
|
||||
copy4(buf+56, b);
|
||||
copy64(M, buf);
|
||||
mdfour64(M);
|
||||
} else {
|
||||
copy4(buf+120, b);
|
||||
copy64(M, buf);
|
||||
mdfour64(M);
|
||||
copy64(M, buf+64);
|
||||
mdfour64(M);
|
||||
}
|
||||
for (i = 0; i < 128; i++)
|
||||
buf[i] = 0;
|
||||
memcpy (buf, in, n);
|
||||
buf[n] = 0x80;
|
||||
|
||||
for (i=0;i<128;i++)
|
||||
buf[i] = 0;
|
||||
copy64(M, buf);
|
||||
if (n <= 55)
|
||||
{
|
||||
copy4 (buf + 56, b);
|
||||
copy64 (M, buf);
|
||||
mdfour64 (M);
|
||||
}
|
||||
else
|
||||
{
|
||||
copy4 (buf + 120, b);
|
||||
copy64 (M, buf);
|
||||
mdfour64 (M);
|
||||
copy64 (M, buf + 64);
|
||||
mdfour64 (M);
|
||||
}
|
||||
|
||||
copy4(out, A);
|
||||
copy4(out+4, B);
|
||||
copy4(out+8, C);
|
||||
copy4(out+12, D);
|
||||
for (i = 0; i < 128; i++)
|
||||
buf[i] = 0;
|
||||
copy64 (M, buf);
|
||||
|
||||
A = B = C = D = 0;
|
||||
copy4 (out, A);
|
||||
copy4 (out + 4, B);
|
||||
copy4 (out + 8, C);
|
||||
copy4 (out + 12, D);
|
||||
|
||||
A = B = C = D = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
/* working out the netmask for an interface is an incredibly non-portable
|
||||
@ -34,7 +34,7 @@
|
||||
this code cannot use any of the normal Samba debug stuff or defines.
|
||||
This is standalone code.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef AUTOCONF
|
||||
#include "config.h"
|
||||
@ -63,84 +63,89 @@
|
||||
* Prototype for gcc in fussy mode.
|
||||
*/
|
||||
|
||||
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask);
|
||||
int get_netmask (struct in_addr *ipaddr, struct in_addr *nmask);
|
||||
|
||||
/****************************************************************************
|
||||
get the netmask address for a local interface
|
||||
****************************************************************************/
|
||||
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
{
|
||||
struct ifconf ifc;
|
||||
char buff[2048];
|
||||
int fd, i, n;
|
||||
struct ifreq *ifr=NULL;
|
||||
int
|
||||
get_netmask (struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
{
|
||||
struct ifconf ifc;
|
||||
char buff[2048];
|
||||
int fd, i, n;
|
||||
struct ifreq *ifr = NULL;
|
||||
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"socket failed\n");
|
||||
fprintf (stderr, "socket failed\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
ifc.ifc_len = sizeof(buff);
|
||||
ifc.ifc_buf = buff;
|
||||
if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"SIOCGIFCONF failed\n");
|
||||
#endif
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
ifr = ifc.ifc_req;
|
||||
|
||||
n = ifc.ifc_len / sizeof(struct ifreq);
|
||||
|
||||
ifc.ifc_len = sizeof (buff);
|
||||
ifc.ifc_buf = buff;
|
||||
if (ioctl (fd, SIOCGIFCONF, &ifc) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"%d interfaces - looking for %s\n",
|
||||
n, inet_ntoa(*ipaddr));
|
||||
fprintf (stderr, "SIOCGIFCONF failed\n");
|
||||
#endif
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Loop through interfaces, looking for given IP address */
|
||||
for (i=n-1;i>=0;i--) {
|
||||
if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"SIOCGIFADDR failed\n");
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
ifr = ifc.ifc_req;
|
||||
|
||||
n = ifc.ifc_len / sizeof (struct ifreq);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"interface %s\n",
|
||||
inet_ntoa((*(struct sockaddr_in *)&ifr[i].ifr_addr).sin_addr));
|
||||
#endif
|
||||
if (ipaddr->s_addr !=
|
||||
(*(struct sockaddr_in *)&ifr[i].ifr_addr).sin_addr.s_addr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"SIOCGIFNETMASK failed\n");
|
||||
#endif
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
(*nmask) = ((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"netmask %s\n", inet_ntoa(*nmask));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"interface not found\n");
|
||||
fprintf (stderr, "%d interfaces - looking for %s\n", n, inet_ntoa (*ipaddr));
|
||||
#endif
|
||||
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
/* Loop through interfaces, looking for given IP address */
|
||||
for (i = n - 1; i >= 0; i--)
|
||||
{
|
||||
if (ioctl (fd, SIOCGIFADDR, &ifr[i]) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "SIOCGIFADDR failed\n");
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "interface %s\n",
|
||||
inet_ntoa ((*(struct sockaddr_in *) &ifr[i].ifr_addr).sin_addr));
|
||||
#endif
|
||||
if (ipaddr->s_addr != (*(struct sockaddr_in *) &ifr[i].ifr_addr).sin_addr.s_addr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ioctl (fd, SIOCGIFNETMASK, &ifr[i]) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "SIOCGIFNETMASK failed\n");
|
||||
#endif
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
close (fd);
|
||||
(*nmask) = ((struct sockaddr_in *) &ifr[i].ifr_addr)->sin_addr;
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "netmask %s\n", inet_ntoa (*nmask));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "interface not found\n");
|
||||
#endif
|
||||
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#elif defined(HAVE_NETMASK_IFREQ)
|
||||
|
||||
@ -165,84 +170,90 @@ int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
/****************************************************************************
|
||||
this should cover most of the rest of systems
|
||||
****************************************************************************/
|
||||
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
int
|
||||
get_netmask (struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
{
|
||||
struct ifreq ifreq;
|
||||
struct strioctl strioctl;
|
||||
struct ifconf *ifc;
|
||||
char buff[2048];
|
||||
int fd, i, n;
|
||||
struct ifreq *ifr=NULL;
|
||||
struct ifreq ifreq;
|
||||
struct strioctl strioctl;
|
||||
struct ifconf *ifc;
|
||||
char buff[2048];
|
||||
int fd, i, n;
|
||||
struct ifreq *ifr = NULL;
|
||||
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"socket failed\n");
|
||||
fprintf (stderr, "socket failed\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
ifc = (struct ifconf *)buff;
|
||||
ifc->ifc_len = BUFSIZ - sizeof(struct ifconf);
|
||||
strioctl.ic_cmd = SIOCGIFCONF;
|
||||
strioctl.ic_dp = (char *)ifc;
|
||||
strioctl.ic_len = sizeof(buff);
|
||||
if (ioctl(fd, I_STR, &strioctl) < 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"SIOCGIFCONF failed\n");
|
||||
#endif
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ifr = (struct ifreq *)ifc->ifc_req;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Loop through interfaces, looking for given IP address */
|
||||
n = ifc->ifc_len / sizeof(struct ifreq);
|
||||
|
||||
for (i = 0; i<n; i++, ifr++) {
|
||||
ifc = (struct ifconf *) buff;
|
||||
ifc->ifc_len = BUFSIZ - sizeof (struct ifconf);
|
||||
strioctl.ic_cmd = SIOCGIFCONF;
|
||||
strioctl.ic_dp = (char *) ifc;
|
||||
strioctl.ic_len = sizeof (buff);
|
||||
if (ioctl (fd, I_STR, &strioctl) < 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"interface %s\n",
|
||||
inet_ntoa((*(struct sockaddr_in *)&ifr->ifr_addr).sin_addr.s_addr));
|
||||
fprintf (stderr, "SIOCGIFCONF failed\n");
|
||||
#endif
|
||||
if (ipaddr->s_addr ==
|
||||
(*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ifr = (struct ifreq *) ifc->ifc_req;
|
||||
|
||||
/* Loop through interfaces, looking for given IP address */
|
||||
n = ifc->ifc_len / sizeof (struct ifreq);
|
||||
|
||||
for (i = 0; i < n; i++, ifr++)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "interface %s\n",
|
||||
inet_ntoa ((*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr));
|
||||
#endif
|
||||
if (ipaddr->s_addr == (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (i == n) {
|
||||
fprintf(stderr,"interface not found\n");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
if (i == n)
|
||||
{
|
||||
fprintf (stderr, "interface not found\n");
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
ifreq = *ifr;
|
||||
|
||||
strioctl.ic_cmd = SIOCGIFNETMASK;
|
||||
strioctl.ic_dp = (char *)&ifreq;
|
||||
strioctl.ic_len = sizeof(struct ifreq);
|
||||
if (ioctl(fd, I_STR, &strioctl) != 0) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"Failed SIOCGIFNETMASK\n");
|
||||
#endif
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
ifreq = *ifr;
|
||||
|
||||
close(fd);
|
||||
*nmask = ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr;
|
||||
strioctl.ic_cmd = SIOCGIFNETMASK;
|
||||
strioctl.ic_dp = (char *) &ifreq;
|
||||
strioctl.ic_len = sizeof (struct ifreq);
|
||||
if (ioctl (fd, I_STR, &strioctl) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"netmask %s\n", inet_ntoa(*nmask));
|
||||
fprintf (stderr, "Failed SIOCGIFNETMASK\n");
|
||||
#endif
|
||||
return 0;
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
*nmask = ((struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr;
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "netmask %s\n", inet_ntoa (*nmask));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif defined(HAVE_NETMASK_AIX)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h> /* close() declaration for gcc in fussy mode */
|
||||
#include <unistd.h> /* close() declaration for gcc in fussy mode */
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
@ -259,87 +270,93 @@ this should cover most of the rest of systems
|
||||
* Prototype for gcc in fussy mode.
|
||||
*/
|
||||
|
||||
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask);
|
||||
int get_netmask (struct in_addr *ipaddr, struct in_addr *nmask);
|
||||
|
||||
/****************************************************************************
|
||||
this one is for AIX
|
||||
****************************************************************************/
|
||||
|
||||
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
int
|
||||
get_netmask (struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
{
|
||||
char buff[2048];
|
||||
int fd, i;
|
||||
struct ifconf ifc;
|
||||
struct ifreq *ifr=NULL;
|
||||
char buff[2048];
|
||||
int fd, i;
|
||||
struct ifconf ifc;
|
||||
struct ifreq *ifr = NULL;
|
||||
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"socket failed\n");
|
||||
fprintf (stderr, "socket failed\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ifc.ifc_len = sizeof(buff);
|
||||
ifc.ifc_buf = buff;
|
||||
ifc.ifc_len = sizeof (buff);
|
||||
ifc.ifc_buf = buff;
|
||||
|
||||
if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) {
|
||||
if (ioctl (fd, SIOCGIFCONF, &ifc) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"SIOCGIFCONF failed\n");
|
||||
fprintf (stderr, "SIOCGIFCONF failed\n");
|
||||
#endif
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ifr = ifc.ifc_req;
|
||||
/* Loop through interfaces, looking for given IP address */
|
||||
i = ifc.ifc_len;
|
||||
while (i > 0) {
|
||||
ifr = ifc.ifc_req;
|
||||
/* Loop through interfaces, looking for given IP address */
|
||||
i = ifc.ifc_len;
|
||||
while (i > 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"interface %s\n",
|
||||
inet_ntoa((*(struct sockaddr_in *)&ifr->ifr_addr).sin_addr));
|
||||
fprintf (stderr, "interface %s\n",
|
||||
inet_ntoa ((*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr));
|
||||
#endif
|
||||
if (ipaddr->s_addr ==
|
||||
(*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr) {
|
||||
break;
|
||||
}
|
||||
i -= ifr->ifr_addr.sa_len + IFNAMSIZ;
|
||||
ifr = (struct ifreq*) ((char*) ifr + ifr->ifr_addr.sa_len +
|
||||
IFNAMSIZ);
|
||||
}
|
||||
|
||||
if (ipaddr->s_addr == (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
i -= ifr->ifr_addr.sa_len + IFNAMSIZ;
|
||||
ifr = (struct ifreq *) ((char *) ifr + ifr->ifr_addr.sa_len + IFNAMSIZ);
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
if (i <= 0) {
|
||||
fprintf(stderr,"interface not found\n");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
if (i <= 0)
|
||||
{
|
||||
fprintf (stderr, "interface not found\n");
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) {
|
||||
if (ioctl (fd, SIOCGIFNETMASK, ifr) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"SIOCGIFNETMASK failed\n");
|
||||
fprintf (stderr, "SIOCGIFNETMASK failed\n");
|
||||
#endif
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
close (fd);
|
||||
|
||||
(*nmask) = ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr;
|
||||
(*nmask) = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"netmask %s\n", inet_ntoa(*nmask));
|
||||
fprintf (stderr, "netmask %s\n", inet_ntoa (*nmask));
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* a dummy version */
|
||||
struct in_addr; /* it may not have been declared before */
|
||||
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask);
|
||||
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
struct in_addr; /* it may not have been declared before */
|
||||
int get_netmask (struct in_addr *ipaddr, struct in_addr *nmask);
|
||||
int
|
||||
get_netmask (struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
{
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -347,29 +364,32 @@ int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask);
|
||||
#ifdef AUTOCONF
|
||||
/* this is the autoconf driver to test get_netmask() */
|
||||
|
||||
main()
|
||||
main ()
|
||||
{
|
||||
char buf[1024];
|
||||
struct hostent *hp;
|
||||
struct in_addr ip, nmask;
|
||||
char buf[1024];
|
||||
struct hostent *hp;
|
||||
struct in_addr ip, nmask;
|
||||
|
||||
if (gethostname(buf, sizeof(buf)-1) != 0) {
|
||||
fprintf(stderr,"gethostname failed\n");
|
||||
exit(1);
|
||||
}
|
||||
if (gethostname (buf, sizeof (buf) - 1) != 0)
|
||||
{
|
||||
fprintf (stderr, "gethostname failed\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
hp = gethostbyname(buf);
|
||||
hp = gethostbyname (buf);
|
||||
|
||||
if (!hp) {
|
||||
fprintf(stderr,"gethostbyname failed\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!hp)
|
||||
{
|
||||
fprintf (stderr, "gethostbyname failed\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
memcpy((char *)&ip, (char *)hp->h_addr, hp->h_length);
|
||||
memcpy ((char *) &ip, (char *) hp->h_addr, hp->h_length);
|
||||
|
||||
if (get_netmask(&ip, &nmask) == 0) exit(0);
|
||||
if (get_netmask (&ip, &nmask) == 0)
|
||||
exit (0);
|
||||
|
||||
fprintf(stderr,"get_netmask failed\n");
|
||||
exit(1);
|
||||
fprintf (stderr, "get_netmask failed\n");
|
||||
exit (1);
|
||||
}
|
||||
#endif
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
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"
|
||||
|
||||
@ -32,40 +32,44 @@ extern int DEBUGLEVEL;
|
||||
/* this is like vsnprintf but the 'n' limit does not include
|
||||
the terminating null. So if you have a 1024 byte buffer then
|
||||
pass 1023 for n */
|
||||
int vslprintf(char *str, int n, const char *format, va_list ap)
|
||||
int
|
||||
vslprintf (char *str, int n, const char *format, va_list ap)
|
||||
{
|
||||
int ret = vsnprintf(str, n, format, ap);
|
||||
if (ret > n || ret < 0) {
|
||||
str[n] = 0;
|
||||
return -1;
|
||||
}
|
||||
str[ret] = 0;
|
||||
return ret;
|
||||
int ret = vsnprintf (str, n, format, ap);
|
||||
if (ret > n || ret < 0)
|
||||
{
|
||||
str[n] = 0;
|
||||
return -1;
|
||||
}
|
||||
str[ret] = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef HAVE_STDARG_H
|
||||
int slprintf(char *str, int n, const char *format, ...)
|
||||
int
|
||||
slprintf (char *str, int n, const char *format, ...)
|
||||
{
|
||||
#else
|
||||
int slprintf(va_alist)
|
||||
va_dcl
|
||||
int
|
||||
slprintf (va_alist)
|
||||
va_dcl
|
||||
{
|
||||
char *str, *format;
|
||||
int n;
|
||||
char *str, *format;
|
||||
int n;
|
||||
#endif
|
||||
va_list ap;
|
||||
int ret;
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
#ifdef HAVE_STDARG_H
|
||||
va_start(ap, format);
|
||||
va_start (ap, format);
|
||||
#else
|
||||
va_start(ap);
|
||||
str = va_arg(ap,char *);
|
||||
n = va_arg(ap,int);
|
||||
format = va_arg(ap,char *);
|
||||
va_start (ap);
|
||||
str = va_arg (ap, char *);
|
||||
n = va_arg (ap, int);
|
||||
format = va_arg (ap, char *);
|
||||
#endif
|
||||
|
||||
ret = vslprintf(str,n,format,ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
ret = vslprintf (str, n, format, ap);
|
||||
va_end (ap);
|
||||
return ret;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
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"
|
||||
|
||||
@ -39,9 +39,9 @@ extern int DEBUGLEVEL;
|
||||
- to allow easier integration of things like the japanese extensions
|
||||
|
||||
- to support the philosophy of Samba to expose the features of
|
||||
the OS within the SMB model. In general whatever file/printer/variable
|
||||
expansions/etc make sense to the OS should be acceptable to Samba.
|
||||
*/
|
||||
the OS within the SMB model. In general whatever file/printer/variable
|
||||
expansions/etc make sense to the OS should be acceptable to Samba.
|
||||
*/
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
@ -50,96 +50,109 @@ return if some data has arrived on one of the file descriptors
|
||||
return -1 means error
|
||||
********************************************************************/
|
||||
#ifndef HAVE_SELECT
|
||||
static int pollfd(int fd)
|
||||
static int
|
||||
pollfd (int fd)
|
||||
{
|
||||
int r=0;
|
||||
int r = 0;
|
||||
|
||||
#ifdef HAS_RDCHK
|
||||
r = rdchk(fd);
|
||||
r = rdchk (fd);
|
||||
#elif defined(TCRDCHK)
|
||||
(void)ioctl(fd, TCRDCHK, &r);
|
||||
(void) ioctl (fd, TCRDCHK, &r);
|
||||
#else
|
||||
(void)ioctl(fd, FIONREAD, &r);
|
||||
(void) ioctl (fd, FIONREAD, &r);
|
||||
#endif
|
||||
|
||||
return(r);
|
||||
return (r);
|
||||
}
|
||||
|
||||
int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
|
||||
int
|
||||
sys_select (int maxfd, fd_set * fds, struct timeval *tval)
|
||||
{
|
||||
fd_set fds2;
|
||||
int counter=0;
|
||||
int found=0;
|
||||
fd_set fds2;
|
||||
int counter = 0;
|
||||
int found = 0;
|
||||
|
||||
FD_ZERO(&fds2);
|
||||
FD_ZERO (&fds2);
|
||||
|
||||
while (1)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<maxfd;i++) {
|
||||
if (FD_ISSET(i,fds) && pollfd(i)>0) {
|
||||
found++;
|
||||
FD_SET(i,&fds2);
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < maxfd; i++)
|
||||
{
|
||||
if (FD_ISSET (i, fds) && pollfd (i) > 0)
|
||||
{
|
||||
found++;
|
||||
FD_SET (i, &fds2);
|
||||
}
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
memcpy ((void *) fds, (void *) &fds2, sizeof (fds2));
|
||||
return (found);
|
||||
}
|
||||
|
||||
if (tval && tval->tv_sec < counter)
|
||||
return (0);
|
||||
sleep (1);
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (found) {
|
||||
memcpy((void *)fds,(void *)&fds2,sizeof(fds2));
|
||||
return(found);
|
||||
}
|
||||
|
||||
if (tval && tval->tv_sec < counter) return(0);
|
||||
sleep(1);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
#else /* !NO_SELECT */
|
||||
int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
|
||||
int
|
||||
sys_select (int maxfd, fd_set * fds, struct timeval *tval)
|
||||
{
|
||||
#ifdef USE_POLL
|
||||
struct pollfd pfd[256];
|
||||
int i;
|
||||
int maxpoll;
|
||||
int timeout;
|
||||
int pollrtn;
|
||||
struct pollfd pfd[256];
|
||||
int i;
|
||||
int maxpoll;
|
||||
int timeout;
|
||||
int pollrtn;
|
||||
|
||||
maxpoll = 0;
|
||||
for( i = 0; i < maxfd; i++) {
|
||||
if(FD_ISSET(i,fds)) {
|
||||
struct pollfd *pfdp = &pfd[maxpoll++];
|
||||
pfdp->fd = i;
|
||||
pfdp->events = POLLIN;
|
||||
pfdp->revents = 0;
|
||||
maxpoll = 0;
|
||||
for (i = 0; i < maxfd; i++)
|
||||
{
|
||||
if (FD_ISSET (i, fds))
|
||||
{
|
||||
struct pollfd *pfdp = &pfd[maxpoll++];
|
||||
pfdp->fd = i;
|
||||
pfdp->events = POLLIN;
|
||||
pfdp->revents = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
timeout = (tval != NULL) ? (tval->tv_sec * 1000) + (tval->tv_usec/1000) :
|
||||
-1;
|
||||
errno = 0;
|
||||
do {
|
||||
pollrtn = poll( &pfd[0], maxpoll, timeout);
|
||||
} while (pollrtn<0 && errno == EINTR);
|
||||
timeout = (tval != NULL) ? (tval->tv_sec * 1000) + (tval->tv_usec / 1000) : -1;
|
||||
errno = 0;
|
||||
do
|
||||
{
|
||||
pollrtn = poll (&pfd[0], maxpoll, timeout);
|
||||
}
|
||||
while (pollrtn < 0 && errno == EINTR);
|
||||
|
||||
FD_ZERO(fds);
|
||||
FD_ZERO (fds);
|
||||
|
||||
for( i = 0; i < maxpoll; i++)
|
||||
if( pfd[i].revents & POLLIN )
|
||||
FD_SET(pfd[i].fd,fds);
|
||||
for (i = 0; i < maxpoll; i++)
|
||||
if (pfd[i].revents & POLLIN)
|
||||
FD_SET (pfd[i].fd, fds);
|
||||
|
||||
return pollrtn;
|
||||
return pollrtn;
|
||||
#else /* USE_POLL */
|
||||
|
||||
struct timeval t2;
|
||||
int selrtn;
|
||||
struct timeval t2;
|
||||
int selrtn;
|
||||
|
||||
do {
|
||||
if (tval) memcpy((void *)&t2,(void *)tval,sizeof(t2));
|
||||
errno = 0;
|
||||
selrtn = select(maxfd,SELECT_CAST fds,NULL,NULL,tval?&t2:NULL);
|
||||
} while (selrtn<0 && errno == EINTR);
|
||||
do
|
||||
{
|
||||
if (tval)
|
||||
memcpy ((void *) &t2, (void *) tval, sizeof (t2));
|
||||
errno = 0;
|
||||
selrtn = select (maxfd, SELECT_CAST fds, NULL, NULL, tval ? &t2 : NULL);
|
||||
}
|
||||
while (selrtn < 0 && errno == EINTR);
|
||||
|
||||
return(selrtn);
|
||||
return (selrtn);
|
||||
}
|
||||
#endif /* USE_POLL */
|
||||
#endif /* NO_SELECT */
|
||||
@ -148,75 +161,84 @@ int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
|
||||
A stat() wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
|
||||
int sys_stat(const char *fname,SMB_STRUCT_STAT *sbuf)
|
||||
int
|
||||
sys_stat (const char *fname, SMB_STRUCT_STAT * sbuf)
|
||||
{
|
||||
return stat(fname, sbuf);
|
||||
return stat (fname, sbuf);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
An lstat() wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
#if 0
|
||||
int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf)
|
||||
int
|
||||
sys_lstat (const char *fname, SMB_STRUCT_STAT * sbuf)
|
||||
{
|
||||
return lstat(fname, sbuf);
|
||||
return lstat (fname, sbuf);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
An fseek() wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
|
||||
int sys_fseek(FILE *fp, SMB_OFF_T offset, int whence)
|
||||
int
|
||||
sys_fseek (FILE * fp, SMB_OFF_T offset, int whence)
|
||||
{
|
||||
return fseek(fp, offset, whence);
|
||||
return fseek (fp, offset, whence);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
An ftell() wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
|
||||
SMB_OFF_T sys_ftell(FILE *fp)
|
||||
SMB_OFF_T
|
||||
sys_ftell (FILE * fp)
|
||||
{
|
||||
return (SMB_OFF_T)ftell(fp);
|
||||
return (SMB_OFF_T) ftell (fp);
|
||||
}
|
||||
#endif /* 0 */
|
||||
/*******************************************************************
|
||||
An open() wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
|
||||
int sys_open(const char *path, int oflag, mode_t mode)
|
||||
int
|
||||
sys_open (const char *path, int oflag, mode_t mode)
|
||||
{
|
||||
return open(path, oflag, mode);
|
||||
return open (path, oflag, mode);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
An fopen() wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
|
||||
FILE *sys_fopen(const char *path, const char *type)
|
||||
FILE *
|
||||
sys_fopen (const char *path, const char *type)
|
||||
{
|
||||
return fopen(path, type);
|
||||
return fopen (path, type);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*******************************************************************
|
||||
A readdir wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
|
||||
SMB_STRUCT_DIRENT *sys_readdir(DIR *dirp)
|
||||
SMB_STRUCT_DIRENT *
|
||||
sys_readdir (DIR * dirp)
|
||||
{
|
||||
return readdir(dirp);
|
||||
return readdir (dirp);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
system wrapper for getwd
|
||||
********************************************************************/
|
||||
char *sys_getwd(char *s)
|
||||
char *
|
||||
sys_getwd (char *s)
|
||||
{
|
||||
char *wd;
|
||||
#ifdef HAVE_GETCWD
|
||||
wd = (char *)getcwd(s, sizeof (pstring));
|
||||
wd = (char *) getcwd (s, sizeof (pstring));
|
||||
#else
|
||||
wd = (char *)getwd(s);
|
||||
wd = (char *) getwd (s);
|
||||
#endif
|
||||
return wd;
|
||||
}
|
||||
@ -225,16 +247,18 @@ char *sys_getwd(char *s)
|
||||
chown isn't used much but OS/2 doesn't have it
|
||||
********************************************************************/
|
||||
|
||||
int sys_chown(const char *fname,uid_t uid,gid_t gid)
|
||||
int
|
||||
sys_chown (const char *fname, uid_t uid, gid_t gid)
|
||||
{
|
||||
#ifndef HAVE_CHOWN
|
||||
static int done;
|
||||
if (!done) {
|
||||
DEBUG(1,("WARNING: no chown!\n"));
|
||||
done=1;
|
||||
}
|
||||
static int done;
|
||||
if (!done)
|
||||
{
|
||||
DEBUG (1, ("WARNING: no chown!\n"));
|
||||
done = 1;
|
||||
}
|
||||
#else
|
||||
return(chown(fname,uid,gid));
|
||||
return (chown (fname, uid, gid));
|
||||
#endif
|
||||
}
|
||||
#endif /* 0 */
|
||||
@ -243,39 +267,40 @@ A wrapper for gethostbyname() that tries avoids looking up hostnames
|
||||
in the root domain, which can cause dial-on-demand links to come up for no
|
||||
apparent reason.
|
||||
****************************************************************************/
|
||||
struct hostent *sys_gethostbyname(const char *name)
|
||||
struct hostent *
|
||||
sys_gethostbyname (const char *name)
|
||||
{
|
||||
#ifdef REDUCE_ROOT_DNS_LOOKUPS
|
||||
char query[256], hostname[256];
|
||||
char *domain;
|
||||
char query[256], hostname[256];
|
||||
char *domain;
|
||||
|
||||
/* Does this name have any dots in it? If so, make no change */
|
||||
/* Does this name have any dots in it? If so, make no change */
|
||||
|
||||
if (strchr(name, '.'))
|
||||
return(gethostbyname(name));
|
||||
if (strchr (name, '.'))
|
||||
return (gethostbyname (name));
|
||||
|
||||
/* Get my hostname, which should have domain name
|
||||
attached. If not, just do the gethostname on the
|
||||
original string.
|
||||
*/
|
||||
/* Get my hostname, which should have domain name
|
||||
attached. If not, just do the gethostname on the
|
||||
original string.
|
||||
*/
|
||||
|
||||
gethostname(hostname, sizeof(hostname) - 1);
|
||||
hostname[sizeof(hostname) - 1] = 0;
|
||||
if ((domain = strchr(hostname, '.')) == NULL)
|
||||
return(gethostbyname(name));
|
||||
gethostname (hostname, sizeof (hostname) - 1);
|
||||
hostname[sizeof (hostname) - 1] = 0;
|
||||
if ((domain = strchr (hostname, '.')) == NULL)
|
||||
return (gethostbyname (name));
|
||||
|
||||
/* Attach domain name to query and do modified query.
|
||||
If names too large, just do gethostname on the
|
||||
original string.
|
||||
*/
|
||||
/* Attach domain name to query and do modified query.
|
||||
If names too large, just do gethostname on the
|
||||
original string.
|
||||
*/
|
||||
|
||||
if((strlen(name) + strlen(domain)) >= sizeof(query))
|
||||
return(gethostbyname(name));
|
||||
if ((strlen (name) + strlen (domain)) >= sizeof (query))
|
||||
return (gethostbyname (name));
|
||||
|
||||
slprintf(query, sizeof(query)-1, "%s%s", name, domain);
|
||||
return(gethostbyname(query));
|
||||
slprintf (query, sizeof (query) - 1, "%s%s", name, domain);
|
||||
return (gethostbyname (query));
|
||||
#else /* REDUCE_ROOT_DNS_LOOKUPS */
|
||||
return(gethostbyname(name));
|
||||
return (gethostbyname (name));
|
||||
#endif /* REDUCE_ROOT_DNS_LOOKUPS */
|
||||
}
|
||||
|
||||
@ -283,15 +308,16 @@ struct hostent *sys_gethostbyname(const char *name)
|
||||
Wrapper for random().
|
||||
****************************************************************************/
|
||||
#if 0
|
||||
long sys_random(void)
|
||||
long
|
||||
sys_random (void)
|
||||
{
|
||||
#if defined(HAVE_RANDOM)
|
||||
return (long)random();
|
||||
return (long) random ();
|
||||
#elif defined(HAVE_RAND)
|
||||
return (long)rand();
|
||||
return (long) rand ();
|
||||
#else
|
||||
DEBUG(0,("Error - no random function available !\n"));
|
||||
exit(1);
|
||||
DEBUG (0, ("Error - no random function available !\n"));
|
||||
exit (1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -299,15 +325,16 @@ long sys_random(void)
|
||||
Wrapper for srandom().
|
||||
****************************************************************************/
|
||||
|
||||
void sys_srandom(unsigned int seed)
|
||||
void
|
||||
sys_srandom (unsigned int seed)
|
||||
{
|
||||
#if defined(HAVE_SRANDOM)
|
||||
srandom(seed);
|
||||
srandom (seed);
|
||||
#elif defined(HAVE_SRAND)
|
||||
srand(seed);
|
||||
srand (seed);
|
||||
#else
|
||||
DEBUG(0,("Error - no srandom function available !\n"));
|
||||
exit(1);
|
||||
DEBUG (0, ("Error - no srandom function available !\n"));
|
||||
exit (1);
|
||||
#endif
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
@ -22,17 +22,17 @@
|
||||
|
||||
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"
|
||||
|
||||
/*
|
||||
This stuff was largely rewritten by Paul Eggert <eggert@twinsun.com>
|
||||
in May 1996
|
||||
*/
|
||||
This stuff was largely rewritten by Paul Eggert <eggert@twinsun.com>
|
||||
in May 1996
|
||||
*/
|
||||
|
||||
|
||||
int serverzone=0;
|
||||
int serverzone = 0;
|
||||
int extra_time_offset = 0;
|
||||
|
||||
extern int DEBUGLEVEL;
|
||||
@ -54,12 +54,13 @@ extern int DEBUGLEVEL;
|
||||
/*******************************************************************
|
||||
a gettimeofday wrapper
|
||||
********************************************************************/
|
||||
void GetTimeOfDay(struct timeval *tval)
|
||||
void
|
||||
GetTimeOfDay (struct timeval *tval)
|
||||
{
|
||||
#ifdef HAVE_GETTIMEOFDAY_TZ
|
||||
gettimeofday(tval,NULL);
|
||||
gettimeofday (tval, NULL);
|
||||
#else
|
||||
gettimeofday(tval);
|
||||
gettimeofday (tval);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -68,35 +69,36 @@ void GetTimeOfDay(struct timeval *tval)
|
||||
/*******************************************************************
|
||||
yield the difference between *A and *B, in seconds, ignoring leap seconds
|
||||
********************************************************************/
|
||||
static int tm_diff(struct tm *a, struct tm *b)
|
||||
static int
|
||||
tm_diff (struct tm *a, struct tm *b)
|
||||
{
|
||||
int ay = a->tm_year + (TM_YEAR_BASE - 1);
|
||||
int by = b->tm_year + (TM_YEAR_BASE - 1);
|
||||
int intervening_leap_days =
|
||||
(ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400);
|
||||
int years = ay - by;
|
||||
int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday);
|
||||
int hours = 24*days + (a->tm_hour - b->tm_hour);
|
||||
int minutes = 60*hours + (a->tm_min - b->tm_min);
|
||||
int seconds = 60*minutes + (a->tm_sec - b->tm_sec);
|
||||
int ay = a->tm_year + (TM_YEAR_BASE - 1);
|
||||
int by = b->tm_year + (TM_YEAR_BASE - 1);
|
||||
int intervening_leap_days = (ay / 4 - by / 4) - (ay / 100 - by / 100) + (ay / 400 - by / 400);
|
||||
int years = ay - by;
|
||||
int days = 365 * years + intervening_leap_days + (a->tm_yday - b->tm_yday);
|
||||
int hours = 24 * days + (a->tm_hour - b->tm_hour);
|
||||
int minutes = 60 * hours + (a->tm_min - b->tm_min);
|
||||
int seconds = 60 * minutes + (a->tm_sec - b->tm_sec);
|
||||
|
||||
return seconds;
|
||||
return seconds;
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
return the UTC offset in seconds west of UTC, or 0 if it cannot be determined
|
||||
******************************************************************/
|
||||
static int TimeZone(time_t t)
|
||||
static int
|
||||
TimeZone (time_t t)
|
||||
{
|
||||
struct tm *tm = gmtime(&t);
|
||||
struct tm tm_utc;
|
||||
if (!tm)
|
||||
return 0;
|
||||
tm_utc = *tm;
|
||||
tm = localtime(&t);
|
||||
if (!tm)
|
||||
return 0;
|
||||
return tm_diff(&tm_utc,tm);
|
||||
struct tm *tm = gmtime (&t);
|
||||
struct tm tm_utc;
|
||||
if (!tm)
|
||||
return 0;
|
||||
tm_utc = *tm;
|
||||
tm = localtime (&t);
|
||||
if (!tm)
|
||||
return 0;
|
||||
return tm_diff (&tm_utc, tm);
|
||||
|
||||
}
|
||||
|
||||
@ -104,15 +106,17 @@ static int TimeZone(time_t t)
|
||||
/*******************************************************************
|
||||
init the time differences
|
||||
********************************************************************/
|
||||
void TimeInit(void)
|
||||
void
|
||||
TimeInit (void)
|
||||
{
|
||||
serverzone = TimeZone(time(NULL));
|
||||
serverzone = TimeZone (time (NULL));
|
||||
|
||||
if ((serverzone % 60) != 0) {
|
||||
DEBUG(1,("WARNING: Your timezone is not a multiple of 1 minute.\n"));
|
||||
}
|
||||
if ((serverzone % 60) != 0)
|
||||
{
|
||||
DEBUG (1, ("WARNING: Your timezone is not a multiple of 1 minute.\n"));
|
||||
}
|
||||
|
||||
DEBUG(4,("Serverzone is %d\n",serverzone));
|
||||
DEBUG (4, ("Serverzone is %d\n", serverzone));
|
||||
}
|
||||
|
||||
|
||||
@ -124,86 +128,99 @@ call of this function. This saves a LOT of time on many unixes.
|
||||
|
||||
Updated by Paul Eggert <eggert@twinsun.com>
|
||||
********************************************************************/
|
||||
static int TimeZoneFaster(time_t t)
|
||||
static int
|
||||
TimeZoneFaster (time_t t)
|
||||
{
|
||||
static struct dst_table {time_t start,end; int zone;} *dst_table = NULL;
|
||||
static int table_size = 0;
|
||||
int i;
|
||||
int zone = 0;
|
||||
static struct dst_table
|
||||
{
|
||||
time_t start, end;
|
||||
int zone;
|
||||
} *dst_table = NULL;
|
||||
static int table_size = 0;
|
||||
int i;
|
||||
int zone = 0;
|
||||
|
||||
if (t == 0) t = time(NULL);
|
||||
if (t == 0)
|
||||
t = time (NULL);
|
||||
|
||||
/* Tunis has a 8 day DST region, we need to be careful ... */
|
||||
/* Tunis has a 8 day DST region, we need to be careful ... */
|
||||
#define MAX_DST_WIDTH (365*24*60*60)
|
||||
#define MAX_DST_SKIP (7*24*60*60)
|
||||
|
||||
for (i=0;i<table_size;i++)
|
||||
if (t >= dst_table[i].start && t <= dst_table[i].end) break;
|
||||
for (i = 0; i < table_size; i++)
|
||||
if (t >= dst_table[i].start && t <= dst_table[i].end)
|
||||
break;
|
||||
|
||||
if (i<table_size) {
|
||||
zone = dst_table[i].zone;
|
||||
} else {
|
||||
time_t low,high;
|
||||
|
||||
zone = TimeZone(t);
|
||||
dst_table = (struct dst_table *)Realloc(dst_table,
|
||||
sizeof(dst_table[0])*(i+1));
|
||||
if (!dst_table) {
|
||||
table_size = 0;
|
||||
} else {
|
||||
table_size++;
|
||||
|
||||
dst_table[i].zone = zone;
|
||||
dst_table[i].start = dst_table[i].end = t;
|
||||
|
||||
/* no entry will cover more than 6 months */
|
||||
low = t - MAX_DST_WIDTH/2;
|
||||
if (t < low)
|
||||
low = TIME_T_MIN;
|
||||
|
||||
high = t + MAX_DST_WIDTH/2;
|
||||
if (high < t)
|
||||
high = TIME_T_MAX;
|
||||
|
||||
/* widen the new entry using two bisection searches */
|
||||
while (low+60*60 < dst_table[i].start) {
|
||||
if (dst_table[i].start - low > MAX_DST_SKIP*2)
|
||||
t = dst_table[i].start - MAX_DST_SKIP;
|
||||
else
|
||||
t = low + (dst_table[i].start-low)/2;
|
||||
if (TimeZone(t) == zone)
|
||||
dst_table[i].start = t;
|
||||
else
|
||||
low = t;
|
||||
}
|
||||
|
||||
while (high-60*60 > dst_table[i].end) {
|
||||
if (high - dst_table[i].end > MAX_DST_SKIP*2)
|
||||
t = dst_table[i].end + MAX_DST_SKIP;
|
||||
else
|
||||
t = high - (high-dst_table[i].end)/2;
|
||||
if (TimeZone(t) == zone)
|
||||
dst_table[i].end = t;
|
||||
else
|
||||
high = t;
|
||||
}
|
||||
#if 0
|
||||
DEBUG(1,("Added DST entry from %s ",
|
||||
asctime(localtime(&dst_table[i].start))));
|
||||
DEBUG(1,("to %s (%d)\n",asctime(localtime(&dst_table[i].end)),
|
||||
dst_table[i].zone));
|
||||
#endif
|
||||
if (i < table_size)
|
||||
{
|
||||
zone = dst_table[i].zone;
|
||||
}
|
||||
}
|
||||
return zone;
|
||||
else
|
||||
{
|
||||
time_t low, high;
|
||||
|
||||
zone = TimeZone (t);
|
||||
dst_table = (struct dst_table *) Realloc (dst_table, sizeof (dst_table[0]) * (i + 1));
|
||||
if (!dst_table)
|
||||
{
|
||||
table_size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
table_size++;
|
||||
|
||||
dst_table[i].zone = zone;
|
||||
dst_table[i].start = dst_table[i].end = t;
|
||||
|
||||
/* no entry will cover more than 6 months */
|
||||
low = t - MAX_DST_WIDTH / 2;
|
||||
if (t < low)
|
||||
low = TIME_T_MIN;
|
||||
|
||||
high = t + MAX_DST_WIDTH / 2;
|
||||
if (high < t)
|
||||
high = TIME_T_MAX;
|
||||
|
||||
/* widen the new entry using two bisection searches */
|
||||
while (low + 60 * 60 < dst_table[i].start)
|
||||
{
|
||||
if (dst_table[i].start - low > MAX_DST_SKIP * 2)
|
||||
t = dst_table[i].start - MAX_DST_SKIP;
|
||||
else
|
||||
t = low + (dst_table[i].start - low) / 2;
|
||||
if (TimeZone (t) == zone)
|
||||
dst_table[i].start = t;
|
||||
else
|
||||
low = t;
|
||||
}
|
||||
|
||||
while (high - 60 * 60 > dst_table[i].end)
|
||||
{
|
||||
if (high - dst_table[i].end > MAX_DST_SKIP * 2)
|
||||
t = dst_table[i].end + MAX_DST_SKIP;
|
||||
else
|
||||
t = high - (high - dst_table[i].end) / 2;
|
||||
if (TimeZone (t) == zone)
|
||||
dst_table[i].end = t;
|
||||
else
|
||||
high = t;
|
||||
}
|
||||
#if 0
|
||||
DEBUG (1, ("Added DST entry from %s ", asctime (localtime (&dst_table[i].start))));
|
||||
DEBUG (1, ("to %s (%d)\n", asctime (localtime (&dst_table[i].end)), dst_table[i].zone));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return zone;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
return the UTC offset in seconds west of UTC, adjusted for extra time offset
|
||||
**************************************************************************/
|
||||
int TimeDiff(time_t t)
|
||||
int
|
||||
TimeDiff (time_t t)
|
||||
{
|
||||
return TimeZoneFaster(t) + 60*extra_time_offset;
|
||||
return TimeZoneFaster (t) + 60 * extra_time_offset;
|
||||
}
|
||||
|
||||
|
||||
@ -214,31 +231,33 @@ int TimeDiff(time_t t)
|
||||
daylight savings transitions because some local times are ambiguous.
|
||||
LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions.
|
||||
+**************************************************************************/
|
||||
static int LocTimeDiff(time_t lte)
|
||||
static int
|
||||
LocTimeDiff (time_t lte)
|
||||
{
|
||||
time_t lt = lte - 60*extra_time_offset;
|
||||
int d = TimeZoneFaster(lt);
|
||||
time_t t = lt + d;
|
||||
time_t lt = lte - 60 * extra_time_offset;
|
||||
int d = TimeZoneFaster (lt);
|
||||
time_t t = lt + d;
|
||||
|
||||
/* if overflow occurred, ignore all the adjustments so far */
|
||||
if (((lte < lt) ^ (extra_time_offset < 0)) | ((t < lt) ^ (d < 0)))
|
||||
t = lte;
|
||||
/* if overflow occurred, ignore all the adjustments so far */
|
||||
if (((lte < lt) ^ (extra_time_offset < 0)) | ((t < lt) ^ (d < 0)))
|
||||
t = lte;
|
||||
|
||||
/* now t should be close enough to the true UTC to yield the right answer */
|
||||
return TimeDiff(t);
|
||||
/* now t should be close enough to the true UTC to yield the right answer */
|
||||
return TimeDiff (t);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
try to optimise the localtime call, it can be quite expensive on some machines
|
||||
****************************************************************************/
|
||||
struct tm *LocalTime(time_t *t)
|
||||
struct tm *
|
||||
LocalTime (time_t * t)
|
||||
{
|
||||
time_t t2 = *t;
|
||||
time_t t2 = *t;
|
||||
|
||||
t2 -= TimeDiff(t2);
|
||||
t2 -= TimeDiff (t2);
|
||||
|
||||
return(gmtime(&t2));
|
||||
return (gmtime (&t2));
|
||||
}
|
||||
|
||||
#define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
|
||||
@ -252,34 +271,36 @@ its the GMT you get by taking a localtime and adding the
|
||||
serverzone. This is NOT the same as GMT in some cases. This routine
|
||||
converts this to real GMT.
|
||||
****************************************************************************/
|
||||
time_t nt_time_to_unix(NTTIME *nt)
|
||||
time_t
|
||||
nt_time_to_unix (NTTIME * nt)
|
||||
{
|
||||
double d;
|
||||
time_t ret;
|
||||
/* The next two lines are a fix needed for the
|
||||
broken SCO compiler. JRA. */
|
||||
time_t l_time_min = TIME_T_MIN;
|
||||
time_t l_time_max = TIME_T_MAX;
|
||||
double d;
|
||||
time_t ret;
|
||||
/* The next two lines are a fix needed for the
|
||||
broken SCO compiler. JRA. */
|
||||
time_t l_time_min = TIME_T_MIN;
|
||||
time_t l_time_max = TIME_T_MAX;
|
||||
|
||||
if (nt->high == 0) return(0);
|
||||
if (nt->high == 0)
|
||||
return (0);
|
||||
|
||||
d = ((double)nt->high)*4.0*(double)(1<<30);
|
||||
d += (nt->low&0xFFF00000);
|
||||
d *= 1.0e-7;
|
||||
|
||||
/* now adjust by 369 years to make the secs since 1970 */
|
||||
d -= TIME_FIXUP_CONSTANT;
|
||||
d = ((double) nt->high) * 4.0 * (double) (1 << 30);
|
||||
d += (nt->low & 0xFFF00000);
|
||||
d *= 1.0e-7;
|
||||
|
||||
if (!(l_time_min <= d && d <= l_time_max))
|
||||
return(0);
|
||||
/* now adjust by 369 years to make the secs since 1970 */
|
||||
d -= TIME_FIXUP_CONSTANT;
|
||||
|
||||
ret = (time_t)(d+0.5);
|
||||
if (!(l_time_min <= d && d <= l_time_max))
|
||||
return (0);
|
||||
|
||||
/* this takes us from kludge-GMT to real GMT */
|
||||
ret -= serverzone;
|
||||
ret += LocTimeDiff(ret);
|
||||
ret = (time_t) (d + 0.5);
|
||||
|
||||
return(ret);
|
||||
/* this takes us from kludge-GMT to real GMT */
|
||||
ret -= serverzone;
|
||||
ret += LocTimeDiff (ret);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
||||
@ -287,38 +308,40 @@ time_t nt_time_to_unix(NTTIME *nt)
|
||||
/****************************************************************************
|
||||
interprets an nt time into a unix time_t
|
||||
****************************************************************************/
|
||||
time_t interpret_long_date(char *p)
|
||||
time_t
|
||||
interpret_long_date (char *p)
|
||||
{
|
||||
NTTIME nt;
|
||||
nt.low = IVAL(p,0);
|
||||
nt.high = IVAL(p,4);
|
||||
return nt_time_to_unix(&nt);
|
||||
NTTIME nt;
|
||||
nt.low = IVAL (p, 0);
|
||||
nt.high = IVAL (p, 4);
|
||||
return nt_time_to_unix (&nt);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
put a 8 byte filetime from a time_t
|
||||
This takes real GMT as input and converts to kludge-GMT
|
||||
****************************************************************************/
|
||||
void unix_to_nt_time(NTTIME *nt, time_t t)
|
||||
void
|
||||
unix_to_nt_time (NTTIME * nt, time_t t)
|
||||
{
|
||||
double d;
|
||||
double d;
|
||||
|
||||
if (t==0)
|
||||
{
|
||||
nt->low = 0;
|
||||
nt->high = 0;
|
||||
return;
|
||||
}
|
||||
if (t == 0)
|
||||
{
|
||||
nt->low = 0;
|
||||
nt->high = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* this converts GMT to kludge-GMT */
|
||||
t -= LocTimeDiff(t) - serverzone;
|
||||
/* this converts GMT to kludge-GMT */
|
||||
t -= LocTimeDiff (t) - serverzone;
|
||||
|
||||
d = (double)(t);
|
||||
d += TIME_FIXUP_CONSTANT;
|
||||
d *= 1.0e7;
|
||||
d = (double) (t);
|
||||
d += TIME_FIXUP_CONSTANT;
|
||||
d *= 1.0e7;
|
||||
|
||||
nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
|
||||
nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
|
||||
nt->high = (uint32) (d * (1.0 / (4.0 * (double) (1 << 30))));
|
||||
nt->low = (uint32) (d - ((double) nt->high) * 4.0 * (double) (1 << 30));
|
||||
}
|
||||
|
||||
|
||||
@ -326,84 +349,91 @@ void unix_to_nt_time(NTTIME *nt, time_t t)
|
||||
take an NTTIME structure, containing high / low time. convert to unix time.
|
||||
lkclXXXX this may need 2 SIVALs not a memcpy. we'll see...
|
||||
****************************************************************************/
|
||||
void put_long_date(char *p,time_t t)
|
||||
void
|
||||
put_long_date (char *p, time_t t)
|
||||
{
|
||||
NTTIME nt;
|
||||
unix_to_nt_time(&nt, t);
|
||||
SIVAL(p, 0, nt.low);
|
||||
SIVAL(p, 4, nt.high);
|
||||
NTTIME nt;
|
||||
unix_to_nt_time (&nt, t);
|
||||
SIVAL (p, 0, nt.low);
|
||||
SIVAL (p, 4, nt.high);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
check if it's a null mtime
|
||||
****************************************************************************/
|
||||
BOOL null_mtime(time_t mtime)
|
||||
BOOL
|
||||
null_mtime (time_t mtime)
|
||||
{
|
||||
if (mtime == (time_t)0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1)
|
||||
return(True);
|
||||
return(False);
|
||||
if (mtime == (time_t) 0 || mtime == (time_t) 0xFFFFFFFF || mtime == (time_t) - 1)
|
||||
return (True);
|
||||
return (False);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
create a 16 bit dos packed date
|
||||
********************************************************************/
|
||||
static uint16 make_dos_date1(struct tm *t)
|
||||
static uint16
|
||||
make_dos_date1 (struct tm *t)
|
||||
{
|
||||
uint16 ret=0;
|
||||
ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1);
|
||||
ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5));
|
||||
return(ret);
|
||||
uint16 ret = 0;
|
||||
ret = (((unsigned) (t->tm_mon + 1)) >> 3) | ((t->tm_year - 80) << 1);
|
||||
ret = ((ret & 0xFF) << 8) | (t->tm_mday | (((t->tm_mon + 1) & 0x7) << 5));
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
create a 16 bit dos packed time
|
||||
********************************************************************/
|
||||
static uint16 make_dos_time1(struct tm *t)
|
||||
static uint16
|
||||
make_dos_time1 (struct tm *t)
|
||||
{
|
||||
uint16 ret=0;
|
||||
ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3));
|
||||
ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5));
|
||||
return(ret);
|
||||
uint16 ret = 0;
|
||||
ret = ((((unsigned) t->tm_min >> 3) & 0x7) | (((unsigned) t->tm_hour) << 3));
|
||||
ret = ((ret & 0xFF) << 8) | ((t->tm_sec / 2) | ((t->tm_min & 0x7) << 5));
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
create a 32 bit dos packed date/time from some parameters
|
||||
This takes a GMT time and returns a packed localtime structure
|
||||
********************************************************************/
|
||||
static uint32 make_dos_date(time_t unixdate)
|
||||
static uint32
|
||||
make_dos_date (time_t unixdate)
|
||||
{
|
||||
struct tm *t;
|
||||
uint32 ret=0;
|
||||
struct tm *t;
|
||||
uint32 ret = 0;
|
||||
|
||||
t = LocalTime(&unixdate);
|
||||
if (!t)
|
||||
return 0xFFFFFFFF;
|
||||
t = LocalTime (&unixdate);
|
||||
if (!t)
|
||||
return 0xFFFFFFFF;
|
||||
|
||||
ret = make_dos_date1(t);
|
||||
ret = ((ret&0xFFFF)<<16) | make_dos_time1(t);
|
||||
ret = make_dos_date1 (t);
|
||||
ret = ((ret & 0xFFFF) << 16) | make_dos_time1 (t);
|
||||
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
put a dos date into a buffer (time/date format)
|
||||
This takes GMT time and puts local time in the buffer
|
||||
********************************************************************/
|
||||
void put_dos_date(char *buf,int offset,time_t unixdate)
|
||||
void
|
||||
put_dos_date (char *buf, int offset, time_t unixdate)
|
||||
{
|
||||
uint32 x = make_dos_date(unixdate);
|
||||
SIVAL(buf,offset,x);
|
||||
uint32 x = make_dos_date (unixdate);
|
||||
SIVAL (buf, offset, x);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
put a dos date into a buffer (date/time format)
|
||||
This takes GMT time and puts local time in the buffer
|
||||
********************************************************************/
|
||||
void put_dos_date2(char *buf,int offset,time_t unixdate)
|
||||
void
|
||||
put_dos_date2 (char *buf, int offset, time_t unixdate)
|
||||
{
|
||||
uint32 x = make_dos_date(unixdate);
|
||||
x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
|
||||
SIVAL(buf,offset,x);
|
||||
uint32 x = make_dos_date (unixdate);
|
||||
x = ((x & 0xFFFF) << 16) | ((x & 0xFFFF0000) >> 16);
|
||||
SIVAL (buf, offset, x);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
@ -411,95 +441,105 @@ put a dos 32 bit "unix like" date into a buffer. This routine takes
|
||||
GMT and converts it to LOCAL time before putting it (most SMBs assume
|
||||
localtime for this sort of date)
|
||||
********************************************************************/
|
||||
void put_dos_date3(char *buf,int offset,time_t unixdate)
|
||||
void
|
||||
put_dos_date3 (char *buf, int offset, time_t unixdate)
|
||||
{
|
||||
if (!null_mtime(unixdate))
|
||||
unixdate -= TimeDiff(unixdate);
|
||||
SIVAL(buf,offset,unixdate);
|
||||
if (!null_mtime (unixdate))
|
||||
unixdate -= TimeDiff (unixdate);
|
||||
SIVAL (buf, offset, unixdate);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
interpret a 32 bit dos packed date/time to some parameters
|
||||
********************************************************************/
|
||||
static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second)
|
||||
static void
|
||||
interpret_dos_date (uint32 date, int *year, int *month, int *day, int *hour, int *minute,
|
||||
int *second)
|
||||
{
|
||||
uint32 p0,p1,p2,p3;
|
||||
uint32 p0, p1, p2, p3;
|
||||
|
||||
p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF;
|
||||
p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF;
|
||||
p0 = date & 0xFF;
|
||||
p1 = ((date & 0xFF00) >> 8) & 0xFF;
|
||||
p2 = ((date & 0xFF0000) >> 16) & 0xFF;
|
||||
p3 = ((date & 0xFF000000) >> 24) & 0xFF;
|
||||
|
||||
*second = 2*(p0 & 0x1F);
|
||||
*minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3);
|
||||
*hour = (p1>>3)&0xFF;
|
||||
*day = (p2&0x1F);
|
||||
*month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1;
|
||||
*year = ((p3>>1)&0xFF) + 80;
|
||||
*second = 2 * (p0 & 0x1F);
|
||||
*minute = ((p0 >> 5) & 0xFF) + ((p1 & 0x7) << 3);
|
||||
*hour = (p1 >> 3) & 0xFF;
|
||||
*day = (p2 & 0x1F);
|
||||
*month = ((p2 >> 5) & 0xFF) + ((p3 & 0x1) << 3) - 1;
|
||||
*year = ((p3 >> 1) & 0xFF) + 80;
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
create a unix date (int GMT) from a dos date (which is actually in
|
||||
localtime)
|
||||
********************************************************************/
|
||||
time_t make_unix_date(void *date_ptr)
|
||||
time_t
|
||||
make_unix_date (void *date_ptr)
|
||||
{
|
||||
uint32 dos_date=0;
|
||||
struct tm t;
|
||||
time_t ret;
|
||||
uint32 dos_date = 0;
|
||||
struct tm t;
|
||||
time_t ret;
|
||||
|
||||
dos_date = IVAL(date_ptr,0);
|
||||
dos_date = IVAL (date_ptr, 0);
|
||||
|
||||
if (dos_date == 0) return(0);
|
||||
|
||||
interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon,
|
||||
&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec);
|
||||
t.tm_isdst = -1;
|
||||
|
||||
/* mktime() also does the local to GMT time conversion for us */
|
||||
ret = mktime(&t);
|
||||
if (dos_date == 0)
|
||||
return (0);
|
||||
|
||||
return(ret);
|
||||
interpret_dos_date (dos_date, &t.tm_year, &t.tm_mon,
|
||||
&t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec);
|
||||
t.tm_isdst = -1;
|
||||
|
||||
/* mktime() also does the local to GMT time conversion for us */
|
||||
ret = mktime (&t);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
like make_unix_date() but the words are reversed
|
||||
********************************************************************/
|
||||
time_t make_unix_date2(void *date_ptr)
|
||||
time_t
|
||||
make_unix_date2 (void *date_ptr)
|
||||
{
|
||||
uint32 x,x2;
|
||||
uint32 x, x2;
|
||||
|
||||
x = IVAL(date_ptr,0);
|
||||
x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
|
||||
SIVAL(&x,0,x2);
|
||||
x = IVAL (date_ptr, 0);
|
||||
x2 = ((x & 0xFFFF) << 16) | ((x & 0xFFFF0000) >> 16);
|
||||
SIVAL (&x, 0, x2);
|
||||
|
||||
return(make_unix_date((void *)&x));
|
||||
return (make_unix_date ((void *) &x));
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
create a unix GMT date from a dos date in 32 bit "unix like" format
|
||||
these generally arrive as localtimes, with corresponding DST
|
||||
******************************************************************/
|
||||
time_t make_unix_date3(void *date_ptr)
|
||||
time_t
|
||||
make_unix_date3 (void *date_ptr)
|
||||
{
|
||||
time_t t = (time_t)IVAL(date_ptr,0);
|
||||
if (!null_mtime(t))
|
||||
t += LocTimeDiff(t);
|
||||
return(t);
|
||||
time_t t = (time_t) IVAL (date_ptr, 0);
|
||||
if (!null_mtime (t))
|
||||
t += LocTimeDiff (t);
|
||||
return (t);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/***************************************************************************
|
||||
return a HTTP/1.0 time string
|
||||
***************************************************************************/
|
||||
char *http_timestring(time_t t)
|
||||
char *
|
||||
http_timestring (time_t t)
|
||||
{
|
||||
static fstring buf;
|
||||
struct tm *tm = LocalTime(&t);
|
||||
static fstring buf;
|
||||
struct tm *tm = LocalTime (&t);
|
||||
|
||||
if (!tm)
|
||||
slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t);
|
||||
else
|
||||
strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm);
|
||||
return buf;
|
||||
if (!tm)
|
||||
slprintf (buf, sizeof (buf) - 1, "%ld seconds since the Epoch", (long) t);
|
||||
else
|
||||
strftime (buf, sizeof (buf) - 1, "%a, %d %b %Y %H:%M:%S %Z", tm);
|
||||
return buf;
|
||||
}
|
||||
#endif /*0 */
|
||||
|
||||
@ -507,18 +547,22 @@ char *http_timestring(time_t t)
|
||||
/****************************************************************************
|
||||
return the date and time as a string
|
||||
****************************************************************************/
|
||||
char *timestring(void )
|
||||
char *
|
||||
timestring (void)
|
||||
{
|
||||
static fstring TimeBuf;
|
||||
time_t t = time(NULL);
|
||||
struct tm *tm = LocalTime(&t);
|
||||
static fstring TimeBuf;
|
||||
time_t t = time (NULL);
|
||||
struct tm *tm = LocalTime (&t);
|
||||
|
||||
if (!tm) {
|
||||
slprintf(TimeBuf,sizeof(TimeBuf)-1,"%ld seconds since the Epoch",(long)t);
|
||||
} else {
|
||||
strftime(TimeBuf,100,"%Y/%m/%d %H:%M:%S",tm);
|
||||
}
|
||||
return(TimeBuf);
|
||||
if (!tm)
|
||||
{
|
||||
slprintf (TimeBuf, sizeof (TimeBuf) - 1, "%ld seconds since the Epoch", (long) t);
|
||||
}
|
||||
else
|
||||
{
|
||||
strftime (TimeBuf, 100, "%Y/%m/%d %H:%M:%S", tm);
|
||||
}
|
||||
return (TimeBuf);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -526,23 +570,23 @@ char *timestring(void )
|
||||
structure.
|
||||
****************************************************************************/
|
||||
|
||||
time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs)
|
||||
time_t
|
||||
get_create_time (SMB_STRUCT_STAT * st, BOOL fake_dirs)
|
||||
{
|
||||
time_t ret, ret1;
|
||||
time_t ret, ret1;
|
||||
|
||||
if(S_ISDIR(st->st_mode) && fake_dirs)
|
||||
return (time_t)315493200L; /* 1/1/1980 */
|
||||
|
||||
ret = MIN(st->st_ctime, st->st_mtime);
|
||||
ret1 = MIN(ret, st->st_atime);
|
||||
if (S_ISDIR (st->st_mode) && fake_dirs)
|
||||
return (time_t) 315493200L; /* 1/1/1980 */
|
||||
|
||||
if(ret1 != (time_t)0)
|
||||
return ret1;
|
||||
ret = MIN (st->st_ctime, st->st_mtime);
|
||||
ret1 = MIN (ret, st->st_atime);
|
||||
|
||||
/*
|
||||
* One of ctime, mtime or atime was zero (probably atime).
|
||||
* Just return MIN(ctime, mtime).
|
||||
*/
|
||||
return ret;
|
||||
if (ret1 != (time_t) 0)
|
||||
return ret1;
|
||||
|
||||
/*
|
||||
* One of ctime, mtime or atime was zero (probably atime).
|
||||
* Just return MIN(ctime, mtime).
|
||||
*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -22,30 +22,34 @@
|
||||
|
||||
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"
|
||||
extern int DEBUGLEVEL;
|
||||
|
||||
/* internal functions */
|
||||
static struct passwd *uname_string_combinations(char *s, struct passwd * (*fn) (const char *), int N);
|
||||
static struct passwd *uname_string_combinations2(char *s, int offset, struct passwd * (*fn) (const char *), int N);
|
||||
static struct passwd *uname_string_combinations (char *s, struct passwd *(*fn) (const char *),
|
||||
int N);
|
||||
static struct passwd *uname_string_combinations2 (char *s, int offset,
|
||||
struct passwd *(*fn) (const char *), int N);
|
||||
|
||||
/****************************************************************************
|
||||
get a users home directory.
|
||||
****************************************************************************/
|
||||
const char *get_home_dir(char *user)
|
||||
const char *
|
||||
get_home_dir (char *user)
|
||||
{
|
||||
struct passwd *pass;
|
||||
struct passwd *pass;
|
||||
|
||||
pass = Get_Pwnam(user);
|
||||
pass = Get_Pwnam (user);
|
||||
|
||||
if (!pass) return(NULL);
|
||||
return(pass->pw_dir);
|
||||
if (!pass)
|
||||
return (NULL);
|
||||
return (pass->pw_dir);
|
||||
}
|
||||
|
||||
|
||||
#if 0 /* Fix possible buffer overflow in sscanf(unixname,"%s",user) if uncomment */
|
||||
#if 0 /* Fix possible buffer overflow in sscanf(unixname,"%s",user) if uncomment */
|
||||
/*******************************************************************
|
||||
map a username from a dos name to a unix name by looking in the username
|
||||
map. Note that this modifies the name in place.
|
||||
@ -56,123 +60,133 @@ function. Previously, the map_username was being called
|
||||
every time Get_Pwnam was called.
|
||||
Returns True if username was changed, false otherwise.
|
||||
********************************************************************/
|
||||
BOOL map_username(const char *user)
|
||||
BOOL
|
||||
map_username (const char *user)
|
||||
{
|
||||
static BOOL initialised=False;
|
||||
static fstring last_from,last_to;
|
||||
FILE *f;
|
||||
char *mapfile = lp_username_map();
|
||||
char *s;
|
||||
pstring buf;
|
||||
BOOL mapped_user = False;
|
||||
static BOOL initialised = False;
|
||||
static fstring last_from, last_to;
|
||||
FILE *f;
|
||||
char *mapfile = lp_username_map ();
|
||||
char *s;
|
||||
pstring buf;
|
||||
BOOL mapped_user = False;
|
||||
|
||||
if (!*user)
|
||||
return False;
|
||||
if (!*user)
|
||||
return False;
|
||||
|
||||
if (!*mapfile)
|
||||
return False;
|
||||
|
||||
if (!initialised) {
|
||||
*last_from = *last_to = 0;
|
||||
initialised = True;
|
||||
}
|
||||
|
||||
if (strequal(user,last_to))
|
||||
return False;
|
||||
|
||||
if (strequal(user,last_from)) {
|
||||
DEBUG(3,("Mapped user %s to %s\n",user,last_to));
|
||||
fstrcpy(user,last_to);
|
||||
return True;
|
||||
}
|
||||
|
||||
f = sys_fopen(mapfile,"r");
|
||||
if (!f) {
|
||||
DEBUG(0,("can't open username map %s\n",mapfile));
|
||||
return False;
|
||||
}
|
||||
|
||||
DEBUG(4,("Scanning username map %s\n",mapfile));
|
||||
|
||||
while((s=fgets_slash(buf,sizeof(buf),f))!=NULL) {
|
||||
char *unixname = s;
|
||||
char *dosname = strchr(unixname,'=');
|
||||
BOOL return_if_mapped = False;
|
||||
|
||||
if (!dosname)
|
||||
continue;
|
||||
|
||||
*dosname++ = 0;
|
||||
|
||||
while (isspace(*unixname))
|
||||
unixname++;
|
||||
if ('!' == *unixname) {
|
||||
return_if_mapped = True;
|
||||
unixname++;
|
||||
while (*unixname && isspace(*unixname))
|
||||
unixname++;
|
||||
}
|
||||
|
||||
if (!*unixname || strchr("#;",*unixname))
|
||||
continue;
|
||||
if (!*mapfile)
|
||||
return False;
|
||||
|
||||
if (!initialised)
|
||||
{
|
||||
int l = strlen(unixname);
|
||||
while (l && isspace(unixname[l-1])) {
|
||||
unixname[l-1] = 0;
|
||||
l--;
|
||||
}
|
||||
*last_from = *last_to = 0;
|
||||
initialised = True;
|
||||
}
|
||||
|
||||
if (strchr(dosname,'*') || user_in_list(user,dosname)) {
|
||||
DEBUG(3,("Mapped user %s to %s\n",user,unixname));
|
||||
mapped_user = True;
|
||||
fstrcpy(last_from,user);
|
||||
sscanf(unixname,"%s",user);
|
||||
fstrcpy(last_to,user);
|
||||
if(return_if_mapped) {
|
||||
fclose(f);
|
||||
if (strequal (user, last_to))
|
||||
return False;
|
||||
|
||||
if (strequal (user, last_from))
|
||||
{
|
||||
DEBUG (3, ("Mapped user %s to %s\n", user, last_to));
|
||||
fstrcpy (user, last_to);
|
||||
return True;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
f = sys_fopen (mapfile, "r");
|
||||
if (!f)
|
||||
{
|
||||
DEBUG (0, ("can't open username map %s\n", mapfile));
|
||||
return False;
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup the last_from and last_to as an optimization so
|
||||
* that we don't scan the file again for the same user.
|
||||
*/
|
||||
fstrcpy(last_from,user);
|
||||
fstrcpy(last_to,user);
|
||||
DEBUG (4, ("Scanning username map %s\n", mapfile));
|
||||
|
||||
return mapped_user;
|
||||
while ((s = fgets_slash (buf, sizeof (buf), f)) != NULL)
|
||||
{
|
||||
char *unixname = s;
|
||||
char *dosname = strchr (unixname, '=');
|
||||
BOOL return_if_mapped = False;
|
||||
|
||||
if (!dosname)
|
||||
continue;
|
||||
|
||||
*dosname++ = 0;
|
||||
|
||||
while (isspace (*unixname))
|
||||
unixname++;
|
||||
if ('!' == *unixname)
|
||||
{
|
||||
return_if_mapped = True;
|
||||
unixname++;
|
||||
while (*unixname && isspace (*unixname))
|
||||
unixname++;
|
||||
}
|
||||
|
||||
if (!*unixname || strchr ("#;", *unixname))
|
||||
continue;
|
||||
|
||||
{
|
||||
int l = strlen (unixname);
|
||||
while (l && isspace (unixname[l - 1]))
|
||||
{
|
||||
unixname[l - 1] = 0;
|
||||
l--;
|
||||
}
|
||||
}
|
||||
|
||||
if (strchr (dosname, '*') || user_in_list (user, dosname))
|
||||
{
|
||||
DEBUG (3, ("Mapped user %s to %s\n", user, unixname));
|
||||
mapped_user = True;
|
||||
fstrcpy (last_from, user);
|
||||
sscanf (unixname, "%s", user);
|
||||
fstrcpy (last_to, user);
|
||||
if (return_if_mapped)
|
||||
{
|
||||
fclose (f);
|
||||
return True;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
/*
|
||||
* Setup the last_from and last_to as an optimization so
|
||||
* that we don't scan the file again for the same user.
|
||||
*/
|
||||
fstrcpy (last_from, user);
|
||||
fstrcpy (last_to, user);
|
||||
|
||||
return mapped_user;
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
/****************************************************************************
|
||||
Get_Pwnam wrapper
|
||||
****************************************************************************/
|
||||
static struct passwd *_Get_Pwnam(const char *s)
|
||||
static struct passwd *
|
||||
_Get_Pwnam (const char *s)
|
||||
{
|
||||
struct passwd *ret;
|
||||
struct passwd *ret;
|
||||
|
||||
ret = getpwnam(s);
|
||||
if (ret)
|
||||
ret = getpwnam (s);
|
||||
if (ret)
|
||||
{
|
||||
#ifdef HAVE_GETPWANAM
|
||||
struct passwd_adjunct *pwret;
|
||||
pwret = getpwanam(s);
|
||||
if (pwret)
|
||||
{
|
||||
free(ret->pw_passwd);
|
||||
ret->pw_passwd = pwret->pwa_passwd;
|
||||
}
|
||||
struct passwd_adjunct *pwret;
|
||||
pwret = getpwanam (s);
|
||||
if (pwret)
|
||||
{
|
||||
free (ret->pw_passwd);
|
||||
ret->pw_passwd = pwret->pwa_passwd;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
||||
@ -180,191 +194,198 @@ static struct passwd *_Get_Pwnam(const char *s)
|
||||
a wrapper for getpwnam() that tries with all lower and all upper case
|
||||
if the initial name fails. Also tried with first letter capitalised
|
||||
****************************************************************************/
|
||||
struct passwd *Get_Pwnam(const char *a_user)
|
||||
struct passwd *
|
||||
Get_Pwnam (const char *a_user)
|
||||
{
|
||||
fstring user;
|
||||
int last_char;
|
||||
int usernamelevel = lp_usernamelevel();
|
||||
fstring user;
|
||||
int last_char;
|
||||
int usernamelevel = lp_usernamelevel ();
|
||||
|
||||
struct passwd *ret;
|
||||
struct passwd *ret;
|
||||
|
||||
if (!a_user || !(*a_user))
|
||||
return(NULL);
|
||||
if (!a_user || !(*a_user))
|
||||
return (NULL);
|
||||
|
||||
StrnCpy(user,a_user,sizeof(user)-1);
|
||||
StrnCpy (user, a_user, sizeof (user) - 1);
|
||||
|
||||
ret = _Get_Pwnam(user);
|
||||
if (ret) return(ret);
|
||||
ret = _Get_Pwnam (user);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
strlower(user);
|
||||
ret = _Get_Pwnam(user);
|
||||
if (ret) return(ret);
|
||||
strlower (user);
|
||||
ret = _Get_Pwnam (user);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
strupper(user);
|
||||
ret = _Get_Pwnam(user);
|
||||
if (ret) return(ret);
|
||||
strupper (user);
|
||||
ret = _Get_Pwnam (user);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
/* try with first letter capitalised */
|
||||
if (strlen(user) > 1)
|
||||
strlower(user+1);
|
||||
ret = _Get_Pwnam(user);
|
||||
if (ret) return(ret);
|
||||
/* try with first letter capitalised */
|
||||
if (strlen (user) > 1)
|
||||
strlower (user + 1);
|
||||
ret = _Get_Pwnam (user);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
/* try with last letter capitalised */
|
||||
strlower(user);
|
||||
last_char = strlen(user)-1;
|
||||
user[last_char] = toupper(user[last_char]);
|
||||
ret = _Get_Pwnam(user);
|
||||
if (ret) return(ret);
|
||||
/* try with last letter capitalised */
|
||||
strlower (user);
|
||||
last_char = strlen (user) - 1;
|
||||
user[last_char] = toupper (user[last_char]);
|
||||
ret = _Get_Pwnam (user);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
/* try all combinations up to usernamelevel */
|
||||
strlower(user);
|
||||
ret = uname_string_combinations(user, _Get_Pwnam, usernamelevel);
|
||||
if (ret) return(ret);
|
||||
/* try all combinations up to usernamelevel */
|
||||
strlower (user);
|
||||
ret = uname_string_combinations (user, _Get_Pwnam, usernamelevel);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/****************************************************************************
|
||||
check if a user is in a netgroup user list
|
||||
****************************************************************************/
|
||||
static BOOL user_in_netgroup_list(char *user,char *ngname)
|
||||
static BOOL
|
||||
user_in_netgroup_list (char *user, char *ngname)
|
||||
{
|
||||
#ifdef HAVE_NETGROUP
|
||||
static char *mydomain = NULL;
|
||||
if (mydomain == NULL)
|
||||
yp_get_default_domain(&mydomain);
|
||||
static char *mydomain = NULL;
|
||||
if (mydomain == NULL)
|
||||
yp_get_default_domain (&mydomain);
|
||||
|
||||
if(mydomain == NULL)
|
||||
{
|
||||
DEBUG(5,("Unable to get default yp domain\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG(5,("looking for user %s of domain %s in netgroup %s\n",
|
||||
user, mydomain, ngname));
|
||||
DEBUG(5,("innetgr is %s\n",
|
||||
innetgr(ngname, NULL, user, mydomain)
|
||||
? "TRUE" : "FALSE"));
|
||||
if (mydomain == NULL)
|
||||
{
|
||||
DEBUG (5, ("Unable to get default yp domain\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG (5, ("looking for user %s of domain %s in netgroup %s\n", user, mydomain, ngname));
|
||||
DEBUG (5, ("innetgr is %s\n", innetgr (ngname, NULL, user, mydomain) ? "TRUE" : "FALSE"));
|
||||
|
||||
if (innetgr(ngname, NULL, user, mydomain))
|
||||
return (True);
|
||||
}
|
||||
if (innetgr (ngname, NULL, user, mydomain))
|
||||
return (True);
|
||||
}
|
||||
#endif /* HAVE_NETGROUP */
|
||||
return False;
|
||||
return False;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
check if a user is in a UNIX user list
|
||||
****************************************************************************/
|
||||
static BOOL user_in_group_list(char *user,char *gname)
|
||||
static BOOL
|
||||
user_in_group_list (char *user, char *gname)
|
||||
{
|
||||
#ifdef HAVE_GETGRNAM
|
||||
struct group *gptr;
|
||||
char **member;
|
||||
struct passwd *pass = Get_Pwnam(user,False);
|
||||
#ifdef HAVE_GETGRNAM
|
||||
struct group *gptr;
|
||||
char **member;
|
||||
struct passwd *pass = Get_Pwnam (user, False);
|
||||
|
||||
if (pass)
|
||||
{
|
||||
gptr = getgrgid(pass->pw_gid);
|
||||
if (gptr && strequal(gptr->gr_name,gname))
|
||||
return(True);
|
||||
}
|
||||
|
||||
gptr = (struct group *)getgrnam(gname);
|
||||
|
||||
if (gptr)
|
||||
{
|
||||
member = gptr->gr_mem;
|
||||
while (member && *member)
|
||||
if (pass)
|
||||
{
|
||||
if (strequal(*member,user))
|
||||
return(True);
|
||||
member++;
|
||||
gptr = getgrgid (pass->pw_gid);
|
||||
if (gptr && strequal (gptr->gr_name, gname))
|
||||
return (True);
|
||||
}
|
||||
|
||||
gptr = (struct group *) getgrnam (gname);
|
||||
|
||||
if (gptr)
|
||||
{
|
||||
member = gptr->gr_mem;
|
||||
while (member && *member)
|
||||
{
|
||||
if (strequal (*member, user))
|
||||
return (True);
|
||||
member++;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_GETGRNAM */
|
||||
return False;
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
check if a user is in a user list - can check combinations of UNIX
|
||||
and netgroup lists.
|
||||
****************************************************************************/
|
||||
BOOL user_in_list(char *user,char *list)
|
||||
BOOL
|
||||
user_in_list (char *user, char *list)
|
||||
{
|
||||
pstring tok;
|
||||
char *p=list;
|
||||
pstring tok;
|
||||
char *p = list;
|
||||
|
||||
while (next_token(&p,tok,LIST_SEP, sizeof(tok)))
|
||||
{
|
||||
/*
|
||||
* Check raw username.
|
||||
*/
|
||||
if (strequal(user,tok))
|
||||
return(True);
|
||||
while (next_token (&p, tok, LIST_SEP, sizeof (tok)))
|
||||
{
|
||||
/*
|
||||
* Check raw username.
|
||||
*/
|
||||
if (strequal (user, tok))
|
||||
return (True);
|
||||
|
||||
/*
|
||||
* Now check to see if any combination
|
||||
* of UNIX and netgroups has been specified.
|
||||
*/
|
||||
/*
|
||||
* Now check to see if any combination
|
||||
* of UNIX and netgroups has been specified.
|
||||
*/
|
||||
|
||||
if(*tok == '@')
|
||||
{
|
||||
/*
|
||||
* Old behaviour. Check netgroup list
|
||||
* followed by UNIX list.
|
||||
*/
|
||||
if(user_in_netgroup_list(user,&tok[1]))
|
||||
return True;
|
||||
if(user_in_group_list(user,&tok[1]))
|
||||
return True;
|
||||
if (*tok == '@')
|
||||
{
|
||||
/*
|
||||
* Old behaviour. Check netgroup list
|
||||
* followed by UNIX list.
|
||||
*/
|
||||
if (user_in_netgroup_list (user, &tok[1]))
|
||||
return True;
|
||||
if (user_in_group_list (user, &tok[1]))
|
||||
return True;
|
||||
}
|
||||
else if (*tok == '+')
|
||||
{
|
||||
if (tok[1] == '&')
|
||||
{
|
||||
/*
|
||||
* Search UNIX list followed by netgroup.
|
||||
*/
|
||||
if (user_in_group_list (user, &tok[2]))
|
||||
return True;
|
||||
if (user_in_netgroup_list (user, &tok[2]))
|
||||
return True;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Just search UNIX list.
|
||||
*/
|
||||
if (user_in_group_list (user, &tok[1]))
|
||||
return True;
|
||||
}
|
||||
}
|
||||
else if (*tok == '&')
|
||||
{
|
||||
if (tok[1] == '&')
|
||||
{
|
||||
/*
|
||||
* Search netgroup list followed by UNIX list.
|
||||
*/
|
||||
if (user_in_netgroup_list (user, &tok[2]))
|
||||
return True;
|
||||
if (user_in_group_list (user, &tok[2]))
|
||||
return True;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Just search netgroup list.
|
||||
*/
|
||||
if (user_in_netgroup_list (user, &tok[1]))
|
||||
return True;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (*tok == '+')
|
||||
{
|
||||
if(tok[1] == '&')
|
||||
{
|
||||
/*
|
||||
* Search UNIX list followed by netgroup.
|
||||
*/
|
||||
if(user_in_group_list(user,&tok[2]))
|
||||
return True;
|
||||
if(user_in_netgroup_list(user,&tok[2]))
|
||||
return True;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Just search UNIX list.
|
||||
*/
|
||||
if(user_in_group_list(user,&tok[1]))
|
||||
return True;
|
||||
}
|
||||
}
|
||||
else if (*tok == '&')
|
||||
{
|
||||
if(tok[1] == '&')
|
||||
{
|
||||
/*
|
||||
* Search netgroup list followed by UNIX list.
|
||||
*/
|
||||
if(user_in_netgroup_list(user,&tok[2]))
|
||||
return True;
|
||||
if(user_in_group_list(user,&tok[2]))
|
||||
return True;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Just search netgroup list.
|
||||
*/
|
||||
if(user_in_netgroup_list(user,&tok[1]))
|
||||
return True;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(False);
|
||||
return (False);
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
@ -376,31 +397,34 @@ try all combinations with N uppercase letters.
|
||||
offset is the first char to try and change (start with 0)
|
||||
it assumes the string starts lowercased
|
||||
****************************************************************************/
|
||||
static struct passwd *uname_string_combinations2(char *s,int offset,struct passwd *(*fn)(const char *),int N)
|
||||
static struct passwd *
|
||||
uname_string_combinations2 (char *s, int offset, struct passwd *(*fn) (const char *), int N)
|
||||
{
|
||||
int len = strlen(s);
|
||||
int i;
|
||||
struct passwd *ret;
|
||||
int len = strlen (s);
|
||||
int i;
|
||||
struct passwd *ret;
|
||||
|
||||
#ifdef PASSWORD_LENGTH
|
||||
len = MIN(len,PASSWORD_LENGTH);
|
||||
len = MIN (len, PASSWORD_LENGTH);
|
||||
#endif
|
||||
|
||||
if (N <= 0 || offset >= len)
|
||||
return(fn(s));
|
||||
if (N <= 0 || offset >= len)
|
||||
return (fn (s));
|
||||
|
||||
|
||||
for (i=offset;i<(len-(N-1));i++)
|
||||
for (i = offset; i < (len - (N - 1)); i++)
|
||||
|
||||
{
|
||||
char c = s[i];
|
||||
if (!islower(c)) continue;
|
||||
s[i] = toupper(c);
|
||||
ret = uname_string_combinations2(s,i+1,fn,N-1);
|
||||
if(ret) return(ret);
|
||||
s[i] = c;
|
||||
char c = s[i];
|
||||
if (!islower (c))
|
||||
continue;
|
||||
s[i] = toupper (c);
|
||||
ret = uname_string_combinations2 (s, i + 1, fn, N - 1);
|
||||
if (ret)
|
||||
return (ret);
|
||||
s[i] = c;
|
||||
}
|
||||
return(NULL);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -410,15 +434,17 @@ try all combinations with up to N uppercase letters.
|
||||
offset is the first char to try and change (start with 0)
|
||||
it assumes the string starts lowercased
|
||||
****************************************************************************/
|
||||
static struct passwd * uname_string_combinations(char *s,struct passwd * (*fn)(const char *),int N)
|
||||
static struct passwd *
|
||||
uname_string_combinations (char *s, struct passwd *(*fn) (const char *), int N)
|
||||
{
|
||||
int n;
|
||||
struct passwd *ret;
|
||||
int n;
|
||||
struct passwd *ret;
|
||||
|
||||
for (n=1;n<=N;n++)
|
||||
{
|
||||
ret = uname_string_combinations2(s,0,fn,n);
|
||||
if(ret) return(ret);
|
||||
}
|
||||
return(NULL);
|
||||
for (n = 1; n <= N; n++)
|
||||
{
|
||||
ret = uname_string_combinations2 (s, 0, fn, n);
|
||||
if (ret)
|
||||
return (ret);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
@ -33,9 +33,10 @@ static int gotalarm;
|
||||
Signal function to tell us we timed out.
|
||||
****************************************************************/
|
||||
|
||||
static void gotalarm_sig(void)
|
||||
static void
|
||||
gotalarm_sig (void)
|
||||
{
|
||||
gotalarm = 1;
|
||||
gotalarm = 1;
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@ -43,74 +44,78 @@ static void gotalarm_sig(void)
|
||||
seconds.
|
||||
****************************************************************/
|
||||
|
||||
BOOL do_file_lock(int fd, int waitsecs, int type)
|
||||
BOOL
|
||||
do_file_lock (int fd, int waitsecs, int type)
|
||||
{
|
||||
SMB_STRUCT_FLOCK lock;
|
||||
int ret;
|
||||
SMB_STRUCT_FLOCK lock;
|
||||
int ret;
|
||||
|
||||
gotalarm = 0;
|
||||
CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
|
||||
gotalarm = 0;
|
||||
CatchSignal (SIGALRM, SIGNAL_CAST gotalarm_sig);
|
||||
|
||||
lock.l_type = type;
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 1;
|
||||
lock.l_pid = 0;
|
||||
lock.l_type = type;
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 1;
|
||||
lock.l_pid = 0;
|
||||
|
||||
alarm(waitsecs);
|
||||
ret = fcntl(fd, SMB_F_SETLKW, &lock);
|
||||
alarm(0);
|
||||
CatchSignal(SIGALRM, SIGNAL_CAST SIG_DFL);
|
||||
alarm (waitsecs);
|
||||
ret = fcntl (fd, SMB_F_SETLKW, &lock);
|
||||
alarm (0);
|
||||
CatchSignal (SIGALRM, SIGNAL_CAST SIG_DFL);
|
||||
|
||||
if (gotalarm) {
|
||||
DEBUG(0, ("do_file_lock: failed to %s file.\n",
|
||||
type == F_UNLCK ? "unlock" : "lock"));
|
||||
return False;
|
||||
}
|
||||
if (gotalarm)
|
||||
{
|
||||
DEBUG (0, ("do_file_lock: failed to %s file.\n", type == F_UNLCK ? "unlock" : "lock"));
|
||||
return False;
|
||||
}
|
||||
|
||||
return (ret == 0);
|
||||
return (ret == 0);
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
Lock an fd. Abandon after waitsecs seconds.
|
||||
****************************************************************/
|
||||
|
||||
BOOL file_lock(int fd, int type, int secs, int *plock_depth)
|
||||
BOOL
|
||||
file_lock (int fd, int type, int secs, int *plock_depth)
|
||||
{
|
||||
if (fd < 0)
|
||||
return False;
|
||||
if (fd < 0)
|
||||
return False;
|
||||
|
||||
(*plock_depth)++;
|
||||
(*plock_depth)++;
|
||||
|
||||
if ((*plock_depth) == 0)
|
||||
{
|
||||
if (!do_file_lock(fd, secs, type)) {
|
||||
DEBUG(10,("file_lock: locking file failed, error = %s.\n",
|
||||
unix_error_string (errno)));
|
||||
return False;
|
||||
if ((*plock_depth) == 0)
|
||||
{
|
||||
if (!do_file_lock (fd, secs, type))
|
||||
{
|
||||
DEBUG (10, ("file_lock: locking file failed, error = %s.\n",
|
||||
unix_error_string (errno)));
|
||||
return False;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return True;
|
||||
return True;
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
Unlock an fd. Abandon after waitsecs seconds.
|
||||
****************************************************************/
|
||||
|
||||
BOOL file_unlock(int fd, int *plock_depth)
|
||||
BOOL
|
||||
file_unlock (int fd, int *plock_depth)
|
||||
{
|
||||
BOOL ret=True;
|
||||
BOOL ret = True;
|
||||
|
||||
if(*plock_depth == 1)
|
||||
ret = do_file_lock(fd, 5, F_UNLCK);
|
||||
if (*plock_depth == 1)
|
||||
ret = do_file_lock (fd, 5, F_UNLCK);
|
||||
|
||||
(*plock_depth)--;
|
||||
(*plock_depth)--;
|
||||
|
||||
if(!ret)
|
||||
DEBUG(10,("file_unlock: unlocking file failed, error = %s.\n",
|
||||
unix_error_string (errno)));
|
||||
return ret;
|
||||
if (!ret)
|
||||
DEBUG (10, ("file_unlock: unlocking file failed, error = %s.\n",
|
||||
unix_error_string (errno)));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
@ -118,52 +123,54 @@ BOOL file_unlock(int fd, int *plock_depth)
|
||||
update to be set = True if modification is required.
|
||||
****************************************************************/
|
||||
|
||||
void *startfilepwent(char *pfile, char *s_readbuf, int bufsize,
|
||||
int *file_lock_depth, BOOL update)
|
||||
void *
|
||||
startfilepwent (char *pfile, char *s_readbuf, int bufsize, int *file_lock_depth, BOOL update)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
FILE *fp = NULL;
|
||||
|
||||
if (!*pfile)
|
||||
{
|
||||
DEBUG(0, ("startfilepwent: No file set\n"));
|
||||
return (NULL);
|
||||
}
|
||||
DEBUG(10, ("startfilepwent: opening file %s\n", pfile));
|
||||
if (!*pfile)
|
||||
{
|
||||
DEBUG (0, ("startfilepwent: No file set\n"));
|
||||
return (NULL);
|
||||
}
|
||||
DEBUG (10, ("startfilepwent: opening file %s\n", pfile));
|
||||
|
||||
fp = sys_fopen(pfile, update ? "r+b" : "rb");
|
||||
fp = sys_fopen (pfile, update ? "r+b" : "rb");
|
||||
|
||||
if (fp == NULL) {
|
||||
DEBUG(0, ("startfilepwent: unable to open file %s\n", pfile));
|
||||
return NULL;
|
||||
}
|
||||
if (fp == NULL)
|
||||
{
|
||||
DEBUG (0, ("startfilepwent: unable to open file %s\n", pfile));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Set a buffer to do more efficient reads */
|
||||
setvbuf(fp, s_readbuf, _IOFBF, bufsize);
|
||||
/* Set a buffer to do more efficient reads */
|
||||
setvbuf (fp, s_readbuf, _IOFBF, bufsize);
|
||||
|
||||
if (!file_lock(fileno(fp), (update ? F_WRLCK : F_RDLCK), 5, file_lock_depth))
|
||||
{
|
||||
DEBUG(0, ("startfilepwent: unable to lock file %s\n", pfile));
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
if (!file_lock (fileno (fp), (update ? F_WRLCK : F_RDLCK), 5, file_lock_depth))
|
||||
{
|
||||
DEBUG (0, ("startfilepwent: unable to lock file %s\n", pfile));
|
||||
fclose (fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Make sure it is only rw by the owner */
|
||||
chmod(pfile, 0600);
|
||||
/* Make sure it is only rw by the owner */
|
||||
chmod (pfile, 0600);
|
||||
|
||||
/* We have a lock on the file. */
|
||||
return (void *)fp;
|
||||
/* We have a lock on the file. */
|
||||
return (void *) fp;
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
End enumeration of the file.
|
||||
****************************************************************/
|
||||
void endfilepwent(void *vp, int *file_lock_depth)
|
||||
void
|
||||
endfilepwent (void *vp, int *file_lock_depth)
|
||||
{
|
||||
FILE *fp = (FILE *)vp;
|
||||
FILE *fp = (FILE *) vp;
|
||||
|
||||
file_unlock(fileno(fp), file_lock_depth);
|
||||
fclose(fp);
|
||||
DEBUG(7, ("endfilepwent: closed file.\n"));
|
||||
file_unlock (fileno (fp), file_lock_depth);
|
||||
fclose (fp);
|
||||
DEBUG (7, ("endfilepwent: closed file.\n"));
|
||||
}
|
||||
|
||||
|
||||
@ -171,18 +178,20 @@ void endfilepwent(void *vp, int *file_lock_depth)
|
||||
Return the current position in the file list as an SMB_BIG_UINT.
|
||||
This must be treated as an opaque token.
|
||||
*************************************************************************/
|
||||
SMB_BIG_UINT getfilepwpos(void *vp)
|
||||
SMB_BIG_UINT
|
||||
getfilepwpos (void *vp)
|
||||
{
|
||||
return (SMB_BIG_UINT)sys_ftell((FILE *)vp);
|
||||
return (SMB_BIG_UINT) sys_ftell ((FILE *) vp);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
Set the current position in the file list from an SMB_BIG_UINT.
|
||||
This must be treated as an opaque token.
|
||||
*************************************************************************/
|
||||
BOOL setfilepwpos(void *vp, SMB_BIG_UINT tok)
|
||||
BOOL
|
||||
setfilepwpos (void *vp, SMB_BIG_UINT tok)
|
||||
{
|
||||
return !sys_fseek((FILE *)vp, (SMB_OFF_T)tok, SEEK_SET);
|
||||
return !sys_fseek ((FILE *) vp, (SMB_OFF_T) tok, SEEK_SET);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
@ -190,146 +199,149 @@ BOOL setfilepwpos(void *vp, SMB_BIG_UINT tok)
|
||||
line is of format "xxxx:xxxxxx:xxxxx:".
|
||||
lines with "#" at the front are ignored.
|
||||
*************************************************************************/
|
||||
int getfileline(void *vp, char *linebuf, int linebuf_size)
|
||||
int
|
||||
getfileline (void *vp, char *linebuf, int linebuf_size)
|
||||
{
|
||||
/* Static buffers we will return. */
|
||||
FILE *fp = (FILE *)vp;
|
||||
unsigned char c;
|
||||
unsigned char *p;
|
||||
size_t linebuf_len;
|
||||
/* Static buffers we will return. */
|
||||
FILE *fp = (FILE *) vp;
|
||||
unsigned char c;
|
||||
unsigned char *p;
|
||||
size_t linebuf_len;
|
||||
|
||||
if (fp == NULL)
|
||||
{
|
||||
DEBUG(0,("getfileline: Bad file pointer.\n"));
|
||||
return -1;
|
||||
}
|
||||
if (fp == NULL)
|
||||
{
|
||||
DEBUG (0, ("getfileline: Bad file pointer.\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan the file, a line at a time.
|
||||
*/
|
||||
while (!feof(fp))
|
||||
{
|
||||
linebuf[0] = '\0';
|
||||
/*
|
||||
* Scan the file, a line at a time.
|
||||
*/
|
||||
while (!feof (fp))
|
||||
{
|
||||
linebuf[0] = '\0';
|
||||
|
||||
fgets(linebuf, linebuf_size, fp);
|
||||
if (ferror(fp))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
fgets (linebuf, linebuf_size, fp);
|
||||
if (ferror (fp))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the string is terminated with a newline - if not
|
||||
* then we must keep reading and discard until we get one.
|
||||
*/
|
||||
/*
|
||||
* Check if the string is terminated with a newline - if not
|
||||
* then we must keep reading and discard until we get one.
|
||||
*/
|
||||
|
||||
linebuf_len = strlen(linebuf);
|
||||
if (linebuf[linebuf_len - 1] != '\n')
|
||||
{
|
||||
c = '\0';
|
||||
while (!ferror(fp) && !feof(fp))
|
||||
{
|
||||
c = fgetc(fp);
|
||||
if (c == '\n')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
linebuf[linebuf_len - 1] = '\0';
|
||||
}
|
||||
linebuf_len = strlen (linebuf);
|
||||
if (linebuf[linebuf_len - 1] != '\n')
|
||||
{
|
||||
c = '\0';
|
||||
while (!ferror (fp) && !feof (fp))
|
||||
{
|
||||
c = fgetc (fp);
|
||||
if (c == '\n')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
linebuf[linebuf_len - 1] = '\0';
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PASSWORD
|
||||
DEBUG(100, ("getfileline: got line |%s|\n", linebuf));
|
||||
DEBUG (100, ("getfileline: got line |%s|\n", linebuf));
|
||||
#endif
|
||||
if ((linebuf[0] == 0) && feof(fp))
|
||||
{
|
||||
DEBUG(4, ("getfileline: end of file reached\n"));
|
||||
return 0;
|
||||
}
|
||||
if ((linebuf[0] == 0) && feof (fp))
|
||||
{
|
||||
DEBUG (4, ("getfileline: end of file reached\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (linebuf[0] == '#' || linebuf[0] == '\0')
|
||||
{
|
||||
DEBUG(6, ("getfileline: skipping comment or blank line\n"));
|
||||
continue;
|
||||
}
|
||||
if (linebuf[0] == '#' || linebuf[0] == '\0')
|
||||
{
|
||||
DEBUG (6, ("getfileline: skipping comment or blank line\n"));
|
||||
continue;
|
||||
}
|
||||
|
||||
p = (unsigned char *) strchr(linebuf, ':');
|
||||
if (p == NULL)
|
||||
{
|
||||
DEBUG(0, ("getfileline: malformed line entry (no :)\n"));
|
||||
continue;
|
||||
}
|
||||
return linebuf_len;
|
||||
}
|
||||
return -1;
|
||||
p = (unsigned char *) strchr (linebuf, ':');
|
||||
if (p == NULL)
|
||||
{
|
||||
DEBUG (0, ("getfileline: malformed line entry (no :)\n"));
|
||||
continue;
|
||||
}
|
||||
return linebuf_len;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif /* 0 */
|
||||
#endif /* 0 */
|
||||
|
||||
/****************************************************************************
|
||||
read a line from a file with possible \ continuation chars.
|
||||
Blanks at the start or end of a line are stripped.
|
||||
The string will be allocated if s2 is NULL
|
||||
****************************************************************************/
|
||||
char *fgets_slash(char *s2,int maxlen,FILE *f)
|
||||
char *
|
||||
fgets_slash (char *s2, int maxlen, FILE * f)
|
||||
{
|
||||
char *s=s2;
|
||||
int len = 0;
|
||||
int c;
|
||||
BOOL start_of_line = True;
|
||||
char *s = s2;
|
||||
int len = 0;
|
||||
int c;
|
||||
BOOL start_of_line = True;
|
||||
|
||||
if (feof(f))
|
||||
return(NULL);
|
||||
if (feof (f))
|
||||
return (NULL);
|
||||
|
||||
if (!s2)
|
||||
if (!s2)
|
||||
{
|
||||
maxlen = MIN(maxlen,8);
|
||||
s = (char *)Realloc(s,maxlen);
|
||||
maxlen = MIN (maxlen, 8);
|
||||
s = (char *) Realloc (s, maxlen);
|
||||
}
|
||||
|
||||
if (!s || maxlen < 2) return(NULL);
|
||||
if (!s || maxlen < 2)
|
||||
return (NULL);
|
||||
|
||||
*s = 0;
|
||||
*s = 0;
|
||||
|
||||
while (len < maxlen-1)
|
||||
while (len < maxlen - 1)
|
||||
{
|
||||
c = getc(f);
|
||||
switch (c)
|
||||
{
|
||||
case '\r':
|
||||
break;
|
||||
case '\n':
|
||||
while (len > 0 && s[len-1] == ' ')
|
||||
{
|
||||
s[--len] = 0;
|
||||
}
|
||||
if (len > 0 && s[len-1] == '\\')
|
||||
{
|
||||
s[--len] = 0;
|
||||
start_of_line = True;
|
||||
break;
|
||||
}
|
||||
return(s);
|
||||
case EOF:
|
||||
if (len <= 0 && !s2)
|
||||
free(s);
|
||||
return(len>0?s:NULL);
|
||||
case ' ':
|
||||
if (start_of_line)
|
||||
break;
|
||||
default:
|
||||
start_of_line = False;
|
||||
s[len++] = c;
|
||||
s[len] = 0;
|
||||
}
|
||||
if (!s2 && len > maxlen-3)
|
||||
{
|
||||
maxlen *= 2;
|
||||
s = (char *)Realloc(s,maxlen);
|
||||
if (!s) return(NULL);
|
||||
}
|
||||
c = getc (f);
|
||||
switch (c)
|
||||
{
|
||||
case '\r':
|
||||
break;
|
||||
case '\n':
|
||||
while (len > 0 && s[len - 1] == ' ')
|
||||
{
|
||||
s[--len] = 0;
|
||||
}
|
||||
if (len > 0 && s[len - 1] == '\\')
|
||||
{
|
||||
s[--len] = 0;
|
||||
start_of_line = True;
|
||||
break;
|
||||
}
|
||||
return (s);
|
||||
case EOF:
|
||||
if (len <= 0 && !s2)
|
||||
free (s);
|
||||
return (len > 0 ? s : NULL);
|
||||
case ' ':
|
||||
if (start_of_line)
|
||||
break;
|
||||
default:
|
||||
start_of_line = False;
|
||||
s[len++] = c;
|
||||
s[len] = 0;
|
||||
}
|
||||
if (!s2 && len > maxlen - 3)
|
||||
{
|
||||
maxlen *= 2;
|
||||
s = (char *) Realloc (s, maxlen);
|
||||
if (!s)
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
return(s);
|
||||
return (s);
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -22,7 +22,7 @@
|
||||
|
||||
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"
|
||||
|
||||
@ -36,54 +36,68 @@ const BOOL global_in_nmbd = False;
|
||||
/****************************************************************************
|
||||
interpret a node status response
|
||||
****************************************************************************/
|
||||
static void _interpret_node_status(char *p, char *master,char *rname)
|
||||
static void
|
||||
_interpret_node_status (char *p, char *master, char *rname)
|
||||
{
|
||||
int numnames = CVAL(p,0);
|
||||
DEBUG(1,("received %d names\n",numnames));
|
||||
int numnames = CVAL (p, 0);
|
||||
DEBUG (1, ("received %d names\n", numnames));
|
||||
|
||||
if (rname) *rname = 0;
|
||||
if (master) *master = 0;
|
||||
if (rname)
|
||||
*rname = 0;
|
||||
if (master)
|
||||
*master = 0;
|
||||
|
||||
p += 1;
|
||||
while (numnames--)
|
||||
p += 1;
|
||||
while (numnames--)
|
||||
{
|
||||
char qname[17];
|
||||
int type;
|
||||
fstring flags;
|
||||
int i;
|
||||
*flags = 0;
|
||||
StrnCpy(qname,p,15);
|
||||
type = CVAL(p,15);
|
||||
p += 16;
|
||||
char qname[17];
|
||||
int type;
|
||||
fstring flags;
|
||||
int i;
|
||||
*flags = 0;
|
||||
StrnCpy (qname, p, 15);
|
||||
type = CVAL (p, 15);
|
||||
p += 16;
|
||||
|
||||
fstrcat(flags, (p[0] & 0x80) ? "<GROUP> " : " ");
|
||||
if ((p[0] & 0x60) == 0x00) fstrcat(flags,"B ");
|
||||
if ((p[0] & 0x60) == 0x20) fstrcat(flags,"P ");
|
||||
if ((p[0] & 0x60) == 0x40) fstrcat(flags,"M ");
|
||||
if ((p[0] & 0x60) == 0x60) fstrcat(flags,"H ");
|
||||
if (p[0] & 0x10) fstrcat(flags,"<DEREGISTERING> ");
|
||||
if (p[0] & 0x08) fstrcat(flags,"<CONFLICT> ");
|
||||
if (p[0] & 0x04) fstrcat(flags,"<ACTIVE> ");
|
||||
if (p[0] & 0x02) fstrcat(flags,"<PERMANENT> ");
|
||||
fstrcat (flags, (p[0] & 0x80) ? "<GROUP> " : " ");
|
||||
if ((p[0] & 0x60) == 0x00)
|
||||
fstrcat (flags, "B ");
|
||||
if ((p[0] & 0x60) == 0x20)
|
||||
fstrcat (flags, "P ");
|
||||
if ((p[0] & 0x60) == 0x40)
|
||||
fstrcat (flags, "M ");
|
||||
if ((p[0] & 0x60) == 0x60)
|
||||
fstrcat (flags, "H ");
|
||||
if (p[0] & 0x10)
|
||||
fstrcat (flags, "<DEREGISTERING> ");
|
||||
if (p[0] & 0x08)
|
||||
fstrcat (flags, "<CONFLICT> ");
|
||||
if (p[0] & 0x04)
|
||||
fstrcat (flags, "<ACTIVE> ");
|
||||
if (p[0] & 0x02)
|
||||
fstrcat (flags, "<PERMANENT> ");
|
||||
|
||||
if (master && !*master && type == 0x1d) {
|
||||
StrnCpy(master,qname,15);
|
||||
trim_string(master,NULL," ");
|
||||
}
|
||||
if (master && !*master && type == 0x1d)
|
||||
{
|
||||
StrnCpy (master, qname, 15);
|
||||
trim_string (master, NULL, " ");
|
||||
}
|
||||
|
||||
if (rname && !*rname && type == 0x20 && !(p[0]&0x80)) {
|
||||
StrnCpy(rname,qname,15);
|
||||
trim_string(rname,NULL," ");
|
||||
}
|
||||
|
||||
for (i = strlen( qname) ; --i >= 0 ; ) {
|
||||
if (!isprint((int)qname[i])) qname[i] = '.';
|
||||
}
|
||||
DEBUG(1,("\t%-15s <%02x> - %s\n",qname,type,flags));
|
||||
p+=2;
|
||||
if (rname && !*rname && type == 0x20 && !(p[0] & 0x80))
|
||||
{
|
||||
StrnCpy (rname, qname, 15);
|
||||
trim_string (rname, NULL, " ");
|
||||
}
|
||||
|
||||
for (i = strlen (qname); --i >= 0;)
|
||||
{
|
||||
if (!isprint ((int) qname[i]))
|
||||
qname[i] = '.';
|
||||
}
|
||||
DEBUG (1, ("\t%-15s <%02x> - %s\n", qname, type, flags));
|
||||
p += 2;
|
||||
}
|
||||
DEBUG(1,("num_good_sends=%d num_good_receives=%d\n",
|
||||
IVAL(p,20),IVAL(p,24)));
|
||||
DEBUG (1, ("num_good_sends=%d num_good_receives=%d\n", IVAL (p, 20), IVAL (p, 24)));
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
@ -92,289 +106,295 @@ static void _interpret_node_status(char *p, char *master,char *rname)
|
||||
returns an array of IP addresses or NULL if none
|
||||
*count will be set to the number of addresses returned
|
||||
****************************************************************************/
|
||||
struct in_addr *name_query(int fd,const char *name,int name_type, BOOL bcast,BOOL recurse,
|
||||
struct in_addr to_ip, int *count, void (*fn)(struct packet_struct *))
|
||||
struct in_addr *
|
||||
name_query (int fd, const char *name, int name_type, BOOL bcast, BOOL recurse,
|
||||
struct in_addr to_ip, int *count, void (*fn) (struct packet_struct *))
|
||||
{
|
||||
BOOL found=False;
|
||||
int i, retries = 3;
|
||||
int retry_time = bcast?250:2000;
|
||||
struct timeval tval;
|
||||
struct packet_struct p;
|
||||
struct packet_struct *p2;
|
||||
struct nmb_packet *nmb = &p.packet.nmb;
|
||||
static int name_trn_id = 0;
|
||||
struct in_addr *ip_list = NULL;
|
||||
BOOL found = False;
|
||||
int i, retries = 3;
|
||||
int retry_time = bcast ? 250 : 2000;
|
||||
struct timeval tval;
|
||||
struct packet_struct p;
|
||||
struct packet_struct *p2;
|
||||
struct nmb_packet *nmb = &p.packet.nmb;
|
||||
static int name_trn_id = 0;
|
||||
struct in_addr *ip_list = NULL;
|
||||
|
||||
memset((char *)&p,'\0',sizeof(p));
|
||||
(*count) = 0;
|
||||
memset ((char *) &p, '\0', sizeof (p));
|
||||
(*count) = 0;
|
||||
|
||||
if (!name_trn_id) name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) +
|
||||
((unsigned)getpid()%(unsigned)100);
|
||||
name_trn_id = (name_trn_id+1) % (unsigned)0x7FFF;
|
||||
if (!name_trn_id)
|
||||
name_trn_id = ((unsigned) time (NULL) % (unsigned) 0x7FFF) +
|
||||
((unsigned) getpid () % (unsigned) 100);
|
||||
name_trn_id = (name_trn_id + 1) % (unsigned) 0x7FFF;
|
||||
|
||||
nmb->header.name_trn_id = name_trn_id;
|
||||
nmb->header.opcode = 0;
|
||||
nmb->header.response = False;
|
||||
nmb->header.nm_flags.bcast = bcast;
|
||||
nmb->header.nm_flags.recursion_available = False;
|
||||
nmb->header.nm_flags.recursion_desired = recurse;
|
||||
nmb->header.nm_flags.trunc = False;
|
||||
nmb->header.nm_flags.authoritative = False;
|
||||
nmb->header.rcode = 0;
|
||||
nmb->header.qdcount = 1;
|
||||
nmb->header.ancount = 0;
|
||||
nmb->header.nscount = 0;
|
||||
nmb->header.arcount = 0;
|
||||
nmb->header.name_trn_id = name_trn_id;
|
||||
nmb->header.opcode = 0;
|
||||
nmb->header.response = False;
|
||||
nmb->header.nm_flags.bcast = bcast;
|
||||
nmb->header.nm_flags.recursion_available = False;
|
||||
nmb->header.nm_flags.recursion_desired = recurse;
|
||||
nmb->header.nm_flags.trunc = False;
|
||||
nmb->header.nm_flags.authoritative = False;
|
||||
nmb->header.rcode = 0;
|
||||
nmb->header.qdcount = 1;
|
||||
nmb->header.ancount = 0;
|
||||
nmb->header.nscount = 0;
|
||||
nmb->header.arcount = 0;
|
||||
|
||||
make_nmb_name(&nmb->question.question_name,name,name_type);
|
||||
make_nmb_name (&nmb->question.question_name, name, name_type);
|
||||
|
||||
nmb->question.question_type = 0x20;
|
||||
nmb->question.question_class = 0x1;
|
||||
nmb->question.question_type = 0x20;
|
||||
nmb->question.question_class = 0x1;
|
||||
|
||||
p.ip = to_ip;
|
||||
p.port = NMB_PORT;
|
||||
p.fd = fd;
|
||||
p.timestamp = time(NULL);
|
||||
p.packet_type = NMB_PACKET;
|
||||
p.ip = to_ip;
|
||||
p.port = NMB_PORT;
|
||||
p.fd = fd;
|
||||
p.timestamp = time (NULL);
|
||||
p.packet_type = NMB_PACKET;
|
||||
|
||||
GetTimeOfDay(&tval);
|
||||
GetTimeOfDay (&tval);
|
||||
|
||||
if (!send_packet(&p))
|
||||
return NULL;
|
||||
|
||||
retries--;
|
||||
|
||||
while (1)
|
||||
{
|
||||
struct timeval tval2;
|
||||
GetTimeOfDay(&tval2);
|
||||
if (TvalDiff(&tval,&tval2) > retry_time)
|
||||
{
|
||||
if (!retries)
|
||||
break;
|
||||
if (!found && !send_packet(&p))
|
||||
if (!send_packet (&p))
|
||||
return NULL;
|
||||
GetTimeOfDay(&tval);
|
||||
retries--;
|
||||
}
|
||||
|
||||
if ((p2=receive_packet(fd,NMB_PACKET,90)))
|
||||
{
|
||||
struct nmb_packet *nmb2 = &p2->packet.nmb;
|
||||
debug_nmb_packet(p2);
|
||||
retries--;
|
||||
|
||||
if (nmb->header.name_trn_id != nmb2->header.name_trn_id ||
|
||||
!nmb2->header.response)
|
||||
{
|
||||
/*
|
||||
* Its not for us - maybe deal with it later
|
||||
* (put it on the queue?).
|
||||
*/
|
||||
if (fn)
|
||||
fn(p2);
|
||||
else
|
||||
free_packet(p2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nmb2->header.opcode != 0 ||
|
||||
nmb2->header.nm_flags.bcast ||
|
||||
nmb2->header.rcode ||
|
||||
!nmb2->header.ancount)
|
||||
{
|
||||
/*
|
||||
* XXXX what do we do with this? Could be a redirect, but
|
||||
* we'll discard it for the moment.
|
||||
*/
|
||||
free_packet(p2);
|
||||
continue;
|
||||
}
|
||||
|
||||
ip_list = (struct in_addr *)Realloc(ip_list, sizeof(ip_list[0]) *
|
||||
((*count)+nmb2->answers->rdlength/6));
|
||||
if (ip_list)
|
||||
{
|
||||
DEBUG(fn?3:2,("Got a positive name query response from %s ( ",
|
||||
inet_ntoa(p2->ip)));
|
||||
for (i=0;i<nmb2->answers->rdlength/6;i++)
|
||||
while (1)
|
||||
{
|
||||
struct timeval tval2;
|
||||
GetTimeOfDay (&tval2);
|
||||
if (TvalDiff (&tval, &tval2) > retry_time)
|
||||
{
|
||||
putip((char *)&ip_list[(*count)],&nmb2->answers->rdata[2+i*6]);
|
||||
DEBUG(fn?3:2,("%s ",inet_ntoa(ip_list[(*count)])));
|
||||
(*count)++;
|
||||
if (!retries)
|
||||
break;
|
||||
if (!found && !send_packet (&p))
|
||||
return NULL;
|
||||
GetTimeOfDay (&tval);
|
||||
retries--;
|
||||
}
|
||||
DEBUG(fn?3:2,(")\n"));
|
||||
}
|
||||
|
||||
found=True;
|
||||
retries=0;
|
||||
free_packet(p2);
|
||||
if (fn)
|
||||
break;
|
||||
if ((p2 = receive_packet (fd, NMB_PACKET, 90)))
|
||||
{
|
||||
struct nmb_packet *nmb2 = &p2->packet.nmb;
|
||||
debug_nmb_packet (p2);
|
||||
|
||||
/*
|
||||
* If we're doing a unicast lookup we only
|
||||
* expect one reply. Don't wait the full 2
|
||||
* seconds if we got one. JRA.
|
||||
*/
|
||||
if(!bcast && found)
|
||||
break;
|
||||
if (nmb->header.name_trn_id != nmb2->header.name_trn_id || !nmb2->header.response)
|
||||
{
|
||||
/*
|
||||
* Its not for us - maybe deal with it later
|
||||
* (put it on the queue?).
|
||||
*/
|
||||
if (fn)
|
||||
fn (p2);
|
||||
else
|
||||
free_packet (p2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nmb2->header.opcode != 0 ||
|
||||
nmb2->header.nm_flags.bcast || nmb2->header.rcode || !nmb2->header.ancount)
|
||||
{
|
||||
/*
|
||||
* XXXX what do we do with this? Could be a redirect, but
|
||||
* we'll discard it for the moment.
|
||||
*/
|
||||
free_packet (p2);
|
||||
continue;
|
||||
}
|
||||
|
||||
ip_list = (struct in_addr *) Realloc (ip_list, sizeof (ip_list[0]) *
|
||||
((*count) + nmb2->answers->rdlength / 6));
|
||||
if (ip_list)
|
||||
{
|
||||
DEBUG (fn ? 3 : 2, ("Got a positive name query response from %s ( ",
|
||||
inet_ntoa (p2->ip)));
|
||||
for (i = 0; i < nmb2->answers->rdlength / 6; i++)
|
||||
{
|
||||
putip ((char *) &ip_list[(*count)], &nmb2->answers->rdata[2 + i * 6]);
|
||||
DEBUG (fn ? 3 : 2, ("%s ", inet_ntoa (ip_list[(*count)])));
|
||||
(*count)++;
|
||||
}
|
||||
DEBUG (fn ? 3 : 2, (")\n"));
|
||||
}
|
||||
|
||||
found = True;
|
||||
retries = 0;
|
||||
free_packet (p2);
|
||||
if (fn)
|
||||
break;
|
||||
|
||||
/*
|
||||
* If we're doing a unicast lookup we only
|
||||
* expect one reply. Don't wait the full 2
|
||||
* seconds if we got one. JRA.
|
||||
*/
|
||||
if (!bcast && found)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ip_list;
|
||||
return ip_list;
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
Start parsing the lmhosts file.
|
||||
*********************************************************/
|
||||
|
||||
FILE *startlmhosts(const char *fname)
|
||||
FILE *
|
||||
startlmhosts (const char *fname)
|
||||
{
|
||||
FILE *fp = sys_fopen(fname,"r");
|
||||
if (!fp) {
|
||||
DEBUG(4,("startlmhosts: Cannot open lmhosts file %s. Error was %s\n",
|
||||
fname, unix_error_string (errno)));
|
||||
return NULL;
|
||||
}
|
||||
return fp;
|
||||
FILE *fp = sys_fopen (fname, "r");
|
||||
if (!fp)
|
||||
{
|
||||
DEBUG (4, ("startlmhosts: Cannot open lmhosts file %s. Error was %s\n",
|
||||
fname, unix_error_string (errno)));
|
||||
return NULL;
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
Parse the next line in the lmhosts file.
|
||||
*********************************************************/
|
||||
BOOL getlmhostsent( FILE *fp, pstring name, int *name_type, struct in_addr *ipaddr)
|
||||
BOOL
|
||||
getlmhostsent (FILE * fp, pstring name, int *name_type, struct in_addr * ipaddr)
|
||||
{
|
||||
pstring line;
|
||||
pstring line;
|
||||
|
||||
while(!feof(fp) && !ferror(fp)) {
|
||||
pstring ip,flags,extra;
|
||||
char *ptr;
|
||||
int count = 0;
|
||||
|
||||
*name_type = -1;
|
||||
|
||||
if (!fgets_slash(line,sizeof(pstring),fp))
|
||||
continue;
|
||||
|
||||
if (*line == '#')
|
||||
continue;
|
||||
|
||||
pstrcpy(ip,"");
|
||||
pstrcpy(name,"");
|
||||
pstrcpy(flags,"");
|
||||
|
||||
ptr = line;
|
||||
|
||||
if (next_token(&ptr,ip ,NULL,sizeof(ip)))
|
||||
++count;
|
||||
if (next_token(&ptr,name ,NULL, sizeof(pstring)))
|
||||
++count;
|
||||
if (next_token(&ptr,flags,NULL, sizeof(flags)))
|
||||
++count;
|
||||
if (next_token(&ptr,extra,NULL, sizeof(extra)))
|
||||
++count;
|
||||
|
||||
if (count <= 0)
|
||||
continue;
|
||||
|
||||
if (count > 0 && count < 2)
|
||||
while (!feof (fp) && !ferror (fp))
|
||||
{
|
||||
DEBUG(0,("getlmhostsent: Ill formed hosts line [%s]\n",line));
|
||||
continue;
|
||||
pstring ip, flags, extra;
|
||||
char *ptr;
|
||||
int count = 0;
|
||||
|
||||
*name_type = -1;
|
||||
|
||||
if (!fgets_slash (line, sizeof (pstring), fp))
|
||||
continue;
|
||||
|
||||
if (*line == '#')
|
||||
continue;
|
||||
|
||||
pstrcpy (ip, "");
|
||||
pstrcpy (name, "");
|
||||
pstrcpy (flags, "");
|
||||
|
||||
ptr = line;
|
||||
|
||||
if (next_token (&ptr, ip, NULL, sizeof (ip)))
|
||||
++count;
|
||||
if (next_token (&ptr, name, NULL, sizeof (pstring)))
|
||||
++count;
|
||||
if (next_token (&ptr, flags, NULL, sizeof (flags)))
|
||||
++count;
|
||||
if (next_token (&ptr, extra, NULL, sizeof (extra)))
|
||||
++count;
|
||||
|
||||
if (count <= 0)
|
||||
continue;
|
||||
|
||||
if (count > 0 && count < 2)
|
||||
{
|
||||
DEBUG (0, ("getlmhostsent: Ill formed hosts line [%s]\n", line));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (count >= 4)
|
||||
{
|
||||
DEBUG (0, ("getlmhostsent: too many columns in lmhosts file (obsolete syntax)\n"));
|
||||
continue;
|
||||
}
|
||||
|
||||
DEBUG (4, ("getlmhostsent: lmhost entry: %s %s %s\n", ip, name, flags));
|
||||
|
||||
if (strchr (flags, 'G') || strchr (flags, 'S'))
|
||||
{
|
||||
DEBUG (0, ("getlmhostsent: group flag in lmhosts ignored (obsolete)\n"));
|
||||
continue;
|
||||
}
|
||||
|
||||
*ipaddr = *interpret_addr2 (ip);
|
||||
|
||||
/* Extra feature. If the name ends in '#XX', where XX is a hex number,
|
||||
then only add that name type. */
|
||||
if ((ptr = strchr (name, '#')) != NULL)
|
||||
{
|
||||
char *endptr;
|
||||
|
||||
ptr++;
|
||||
*name_type = (int) strtol (ptr, &endptr, 16);
|
||||
|
||||
if (!*ptr || (endptr == ptr))
|
||||
{
|
||||
DEBUG (0, ("getlmhostsent: invalid name %s containing '#'.\n", name));
|
||||
continue;
|
||||
}
|
||||
|
||||
*(--ptr) = '\0'; /* Truncate at the '#' */
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
if (count >= 4)
|
||||
{
|
||||
DEBUG(0,("getlmhostsent: too many columns in lmhosts file (obsolete syntax)\n"));
|
||||
continue;
|
||||
}
|
||||
|
||||
DEBUG(4, ("getlmhostsent: lmhost entry: %s %s %s\n", ip, name, flags));
|
||||
|
||||
if (strchr(flags,'G') || strchr(flags,'S'))
|
||||
{
|
||||
DEBUG(0,("getlmhostsent: group flag in lmhosts ignored (obsolete)\n"));
|
||||
continue;
|
||||
}
|
||||
|
||||
*ipaddr = *interpret_addr2(ip);
|
||||
|
||||
/* Extra feature. If the name ends in '#XX', where XX is a hex number,
|
||||
then only add that name type. */
|
||||
if((ptr = strchr(name, '#')) != NULL)
|
||||
{
|
||||
char *endptr;
|
||||
|
||||
ptr++;
|
||||
*name_type = (int)strtol(ptr, &endptr, 16);
|
||||
|
||||
if(!*ptr || (endptr == ptr))
|
||||
{
|
||||
DEBUG(0,("getlmhostsent: invalid name %s containing '#'.\n", name));
|
||||
continue;
|
||||
}
|
||||
|
||||
*(--ptr) = '\0'; /* Truncate at the '#' */
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
return False;
|
||||
return False;
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
Finish parsing the lmhosts file.
|
||||
*********************************************************/
|
||||
|
||||
void endlmhosts(FILE *fp)
|
||||
void
|
||||
endlmhosts (FILE * fp)
|
||||
{
|
||||
fclose(fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
/********************************************************
|
||||
resolve via "bcast" method
|
||||
*********************************************************/
|
||||
static BOOL resolve_bcast(const char *name, struct in_addr *return_ip, int name_type)
|
||||
static BOOL
|
||||
resolve_bcast (const char *name, struct in_addr *return_ip, int name_type)
|
||||
{
|
||||
int sock, i;
|
||||
|
||||
/*
|
||||
* "bcast" means do a broadcast lookup on all the local interfaces.
|
||||
*/
|
||||
int sock, i;
|
||||
|
||||
DEBUG(3,("resolve_name: Attempting broadcast lookup for name %s<0x%x>\n", name, name_type));
|
||||
/*
|
||||
* "bcast" means do a broadcast lookup on all the local interfaces.
|
||||
*/
|
||||
|
||||
sock = open_socket_in( SOCK_DGRAM, 0, 3,
|
||||
interpret_addr(lp_socket_address()), True );
|
||||
DEBUG (3, ("resolve_name: Attempting broadcast lookup for name %s<0x%x>\n", name, name_type));
|
||||
|
||||
if (sock != -1) {
|
||||
struct in_addr *iplist = NULL;
|
||||
int count;
|
||||
int num_interfaces = iface_count();
|
||||
static char so_broadcast[] = "SO_BROADCAST";
|
||||
set_socket_options(sock, so_broadcast);
|
||||
/*
|
||||
* Lookup the name on all the interfaces, return on
|
||||
* the first successful match.
|
||||
*/
|
||||
for( i = 0; i < num_interfaces; i++) {
|
||||
struct in_addr sendto_ip;
|
||||
/* Done this way to fix compiler error on IRIX 5.x */
|
||||
sendto_ip = *iface_bcast(*iface_n_ip(i));
|
||||
iplist = name_query(sock, name, name_type, True,
|
||||
True, sendto_ip, &count, NULL);
|
||||
if(iplist != NULL) {
|
||||
*return_ip = iplist[0];
|
||||
free((char *)iplist);
|
||||
close(sock);
|
||||
return True;
|
||||
}
|
||||
}
|
||||
close(sock);
|
||||
}
|
||||
sock = open_socket_in (SOCK_DGRAM, 0, 3, interpret_addr (lp_socket_address ()), True);
|
||||
|
||||
return False;
|
||||
if (sock != -1)
|
||||
{
|
||||
struct in_addr *iplist = NULL;
|
||||
int count;
|
||||
int num_interfaces = iface_count ();
|
||||
static char so_broadcast[] = "SO_BROADCAST";
|
||||
set_socket_options (sock, so_broadcast);
|
||||
/*
|
||||
* Lookup the name on all the interfaces, return on
|
||||
* the first successful match.
|
||||
*/
|
||||
for (i = 0; i < num_interfaces; i++)
|
||||
{
|
||||
struct in_addr sendto_ip;
|
||||
/* Done this way to fix compiler error on IRIX 5.x */
|
||||
sendto_ip = *iface_bcast (*iface_n_ip (i));
|
||||
iplist = name_query (sock, name, name_type, True, True, sendto_ip, &count, NULL);
|
||||
if (iplist != NULL)
|
||||
{
|
||||
*return_ip = iplist[0];
|
||||
free ((char *) iplist);
|
||||
close (sock);
|
||||
return True;
|
||||
}
|
||||
}
|
||||
close (sock);
|
||||
}
|
||||
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
@ -382,101 +402,108 @@ static BOOL resolve_bcast(const char *name, struct in_addr *return_ip, int name_
|
||||
/********************************************************
|
||||
resolve via "wins" method
|
||||
*********************************************************/
|
||||
static BOOL resolve_wins(const char *name, struct in_addr *return_ip, int name_type)
|
||||
static BOOL
|
||||
resolve_wins (const char *name, struct in_addr *return_ip, int name_type)
|
||||
{
|
||||
int sock;
|
||||
struct in_addr wins_ip;
|
||||
BOOL wins_ismyip;
|
||||
int sock;
|
||||
struct in_addr wins_ip;
|
||||
BOOL wins_ismyip;
|
||||
|
||||
/*
|
||||
* "wins" means do a unicast lookup to the WINS server.
|
||||
* Ignore if there is no WINS server specified or if the
|
||||
* WINS server is one of our interfaces (if we're being
|
||||
* called from within nmbd - we can't do this call as we
|
||||
* would then block).
|
||||
*/
|
||||
/*
|
||||
* "wins" means do a unicast lookup to the WINS server.
|
||||
* Ignore if there is no WINS server specified or if the
|
||||
* WINS server is one of our interfaces (if we're being
|
||||
* called from within nmbd - we can't do this call as we
|
||||
* would then block).
|
||||
*/
|
||||
|
||||
DEBUG(3,("resolve_name: Attempting wins lookup for name %s<0x%x>\n", name, name_type));
|
||||
DEBUG (3, ("resolve_name: Attempting wins lookup for name %s<0x%x>\n", name, name_type));
|
||||
|
||||
if(!*lp_wins_server()) {
|
||||
DEBUG(3,("resolve_name: WINS server resolution selected and no WINS server present.\n"));
|
||||
return False;
|
||||
}
|
||||
if (!*lp_wins_server ())
|
||||
{
|
||||
DEBUG (3, ("resolve_name: WINS server resolution selected and no WINS server present.\n"));
|
||||
return False;
|
||||
}
|
||||
|
||||
wins_ip = *interpret_addr2(lp_wins_server());
|
||||
wins_ismyip = ismyip(wins_ip);
|
||||
wins_ip = *interpret_addr2 (lp_wins_server ());
|
||||
wins_ismyip = ismyip (wins_ip);
|
||||
|
||||
if((wins_ismyip && !global_in_nmbd) || !wins_ismyip) {
|
||||
sock = open_socket_in( SOCK_DGRAM, 0, 3,
|
||||
interpret_addr(lp_socket_address()), True );
|
||||
|
||||
if (sock != -1) {
|
||||
struct in_addr *iplist = NULL;
|
||||
int count;
|
||||
iplist = name_query(sock, name, name_type, False,
|
||||
True, wins_ip, &count, NULL);
|
||||
if(iplist != NULL) {
|
||||
*return_ip = iplist[0];
|
||||
free((char *)iplist);
|
||||
close(sock);
|
||||
return True;
|
||||
}
|
||||
close(sock);
|
||||
}
|
||||
}
|
||||
if ((wins_ismyip && !global_in_nmbd) || !wins_ismyip)
|
||||
{
|
||||
sock = open_socket_in (SOCK_DGRAM, 0, 3, interpret_addr (lp_socket_address ()), True);
|
||||
|
||||
return False;
|
||||
if (sock != -1)
|
||||
{
|
||||
struct in_addr *iplist = NULL;
|
||||
int count;
|
||||
iplist = name_query (sock, name, name_type, False, True, wins_ip, &count, NULL);
|
||||
if (iplist != NULL)
|
||||
{
|
||||
*return_ip = iplist[0];
|
||||
free ((char *) iplist);
|
||||
close (sock);
|
||||
return True;
|
||||
}
|
||||
close (sock);
|
||||
}
|
||||
}
|
||||
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************
|
||||
resolve via "lmhosts" method
|
||||
*********************************************************/
|
||||
static BOOL resolve_lmhosts(const char *name, struct in_addr *return_ip, int name_type)
|
||||
static BOOL
|
||||
resolve_lmhosts (const char *name, struct in_addr *return_ip, int name_type)
|
||||
{
|
||||
/*
|
||||
* "lmhosts" means parse the local lmhosts file.
|
||||
*/
|
||||
|
||||
FILE *fp;
|
||||
pstring lmhost_name;
|
||||
int name_type2;
|
||||
/*
|
||||
* "lmhosts" means parse the local lmhosts file.
|
||||
*/
|
||||
|
||||
DEBUG(3,("resolve_name: Attempting lmhosts lookup for name %s<0x%x>\n", name, name_type));
|
||||
FILE *fp;
|
||||
pstring lmhost_name;
|
||||
int name_type2;
|
||||
|
||||
fp = startlmhosts( LMHOSTSFILE );
|
||||
if(fp) {
|
||||
while (getlmhostsent(fp, lmhost_name, &name_type2, return_ip)) {
|
||||
if (strequal(name, lmhost_name) &&
|
||||
((name_type2 == -1) || (name_type == name_type2))
|
||||
) {
|
||||
endlmhosts(fp);
|
||||
return True;
|
||||
}
|
||||
}
|
||||
endlmhosts(fp);
|
||||
}
|
||||
return False;
|
||||
DEBUG (3, ("resolve_name: Attempting lmhosts lookup for name %s<0x%x>\n", name, name_type));
|
||||
|
||||
fp = startlmhosts (LMHOSTSFILE);
|
||||
if (fp)
|
||||
{
|
||||
while (getlmhostsent (fp, lmhost_name, &name_type2, return_ip))
|
||||
{
|
||||
if (strequal (name, lmhost_name) && ((name_type2 == -1) || (name_type == name_type2)))
|
||||
{
|
||||
endlmhosts (fp);
|
||||
return True;
|
||||
}
|
||||
}
|
||||
endlmhosts (fp);
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************
|
||||
resolve via "hosts" method
|
||||
*********************************************************/
|
||||
static BOOL resolve_hosts(const char *name, struct in_addr *return_ip)
|
||||
static BOOL
|
||||
resolve_hosts (const char *name, struct in_addr *return_ip)
|
||||
{
|
||||
/*
|
||||
* "host" means do a localhost, or dns lookup.
|
||||
*/
|
||||
struct hostent *hp;
|
||||
/*
|
||||
* "host" means do a localhost, or dns lookup.
|
||||
*/
|
||||
struct hostent *hp;
|
||||
|
||||
DEBUG(3,("resolve_name: Attempting host lookup for name %s<0x20>\n", name));
|
||||
|
||||
if (((hp = Get_Hostbyname(name)) != NULL) && (hp->h_addr != NULL)) {
|
||||
putip((char *)return_ip,(char *)hp->h_addr);
|
||||
return True;
|
||||
}
|
||||
return False;
|
||||
DEBUG (3, ("resolve_name: Attempting host lookup for name %s<0x20>\n", name));
|
||||
|
||||
if (((hp = Get_Hostbyname (name)) != NULL) && (hp->h_addr != NULL))
|
||||
{
|
||||
putip ((char *) return_ip, (char *) hp->h_addr);
|
||||
return True;
|
||||
}
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
@ -486,63 +513,80 @@ static BOOL resolve_hosts(const char *name, struct in_addr *return_ip)
|
||||
or NetBIOS name. This uses the name switch in the
|
||||
smb.conf to determine the order of name resolution.
|
||||
*********************************************************/
|
||||
BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type)
|
||||
BOOL
|
||||
resolve_name (const char *name, struct in_addr * return_ip, int name_type)
|
||||
{
|
||||
int i;
|
||||
BOOL pure_address = True;
|
||||
pstring name_resolve_list;
|
||||
fstring tok;
|
||||
char *ptr;
|
||||
int i;
|
||||
BOOL pure_address = True;
|
||||
pstring name_resolve_list;
|
||||
fstring tok;
|
||||
char *ptr;
|
||||
|
||||
if (strcmp(name,"0.0.0.0") == 0) {
|
||||
return_ip->s_addr = 0;
|
||||
return True;
|
||||
}
|
||||
if (strcmp(name,"255.255.255.255") == 0) {
|
||||
return_ip->s_addr = 0xFFFFFFFF;
|
||||
return True;
|
||||
}
|
||||
|
||||
for (i=0; pure_address && name[i]; i++)
|
||||
if (!(isdigit((int)name[i]) || name[i] == '.'))
|
||||
pure_address = False;
|
||||
|
||||
/* if it's in the form of an IP address then get the lib to interpret it */
|
||||
if (pure_address) {
|
||||
return_ip->s_addr = inet_addr(name);
|
||||
return True;
|
||||
}
|
||||
if (strcmp (name, "0.0.0.0") == 0)
|
||||
{
|
||||
return_ip->s_addr = 0;
|
||||
return True;
|
||||
}
|
||||
if (strcmp (name, "255.255.255.255") == 0)
|
||||
{
|
||||
return_ip->s_addr = 0xFFFFFFFF;
|
||||
return True;
|
||||
}
|
||||
|
||||
pstrcpy(name_resolve_list, lp_name_resolve_order());
|
||||
if (name_resolve_list == NULL || *name_resolve_list == '\0')
|
||||
pstrcpy(name_resolve_list, "host");
|
||||
ptr = name_resolve_list;
|
||||
for (i = 0; pure_address && name[i]; i++)
|
||||
if (!(isdigit ((int) name[i]) || name[i] == '.'))
|
||||
pure_address = False;
|
||||
|
||||
while (next_token(&ptr, tok, LIST_SEP, sizeof(tok))) {
|
||||
if((strequal(tok, "host") || strequal(tok, "hosts"))) {
|
||||
if (name_type == 0x20 && resolve_hosts(name, return_ip)) {
|
||||
return True;
|
||||
}
|
||||
} else if(strequal( tok, "lmhosts")) {
|
||||
if (resolve_lmhosts(name, return_ip, name_type)) {
|
||||
return True;
|
||||
}
|
||||
} else if(strequal( tok, "wins")) {
|
||||
/* don't resolve 1D via WINS */
|
||||
if (name_type != 0x1D &&
|
||||
resolve_wins(name, return_ip, name_type)) {
|
||||
return True;
|
||||
}
|
||||
} else if(strequal( tok, "bcast")) {
|
||||
if (resolve_bcast(name, return_ip, name_type)) {
|
||||
return True;
|
||||
}
|
||||
} else {
|
||||
DEBUG(0,("resolve_name: unknown name switch type %s\n", tok));
|
||||
}
|
||||
}
|
||||
/* if it's in the form of an IP address then get the lib to interpret it */
|
||||
if (pure_address)
|
||||
{
|
||||
return_ip->s_addr = inet_addr (name);
|
||||
return True;
|
||||
}
|
||||
|
||||
return False;
|
||||
pstrcpy (name_resolve_list, lp_name_resolve_order ());
|
||||
if (name_resolve_list == NULL || *name_resolve_list == '\0')
|
||||
pstrcpy (name_resolve_list, "host");
|
||||
ptr = name_resolve_list;
|
||||
|
||||
while (next_token (&ptr, tok, LIST_SEP, sizeof (tok)))
|
||||
{
|
||||
if ((strequal (tok, "host") || strequal (tok, "hosts")))
|
||||
{
|
||||
if (name_type == 0x20 && resolve_hosts (name, return_ip))
|
||||
{
|
||||
return True;
|
||||
}
|
||||
}
|
||||
else if (strequal (tok, "lmhosts"))
|
||||
{
|
||||
if (resolve_lmhosts (name, return_ip, name_type))
|
||||
{
|
||||
return True;
|
||||
}
|
||||
}
|
||||
else if (strequal (tok, "wins"))
|
||||
{
|
||||
/* don't resolve 1D via WINS */
|
||||
if (name_type != 0x1D && resolve_wins (name, return_ip, name_type))
|
||||
{
|
||||
return True;
|
||||
}
|
||||
}
|
||||
else if (strequal (tok, "bcast"))
|
||||
{
|
||||
if (resolve_bcast (name, return_ip, name_type))
|
||||
{
|
||||
return True;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG (0, ("resolve_name: unknown name switch type %s\n", tok));
|
||||
}
|
||||
}
|
||||
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
@ -550,10 +594,12 @@ BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type)
|
||||
/********************************************************
|
||||
find the IP address of the master browser or DMB for a workgroup
|
||||
*********************************************************/
|
||||
BOOL find_master_ip(char *group, struct in_addr *master_ip)
|
||||
BOOL
|
||||
find_master_ip (char *group, struct in_addr * master_ip)
|
||||
{
|
||||
if (resolve_name(group, master_ip, 0x1D)) return True;
|
||||
if (resolve_name (group, master_ip, 0x1D))
|
||||
return True;
|
||||
|
||||
return resolve_name(group, master_ip, 0x1B);
|
||||
return resolve_name (group, master_ip, 0x1B);
|
||||
}
|
||||
#endif /* 0 */
|
||||
#endif /* 0 */
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -22,7 +22,7 @@
|
||||
|
||||
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"
|
||||
|
||||
@ -32,23 +32,25 @@ extern int DEBUGLEVEL;
|
||||
/****************************************************************************
|
||||
initialises a password structure
|
||||
****************************************************************************/
|
||||
void pwd_init(struct pwd_info *pwd)
|
||||
void
|
||||
pwd_init (struct pwd_info *pwd)
|
||||
{
|
||||
memset((char *)pwd->password , '\0', sizeof(pwd->password ));
|
||||
memset((char *)pwd->smb_lm_pwd, '\0', sizeof(pwd->smb_lm_pwd));
|
||||
memset((char *)pwd->smb_nt_pwd, '\0', sizeof(pwd->smb_nt_pwd));
|
||||
memset((char *)pwd->smb_lm_owf, '\0', sizeof(pwd->smb_lm_owf));
|
||||
memset((char *)pwd->smb_nt_owf, '\0', sizeof(pwd->smb_nt_owf));
|
||||
memset ((char *) pwd->password, '\0', sizeof (pwd->password));
|
||||
memset ((char *) pwd->smb_lm_pwd, '\0', sizeof (pwd->smb_lm_pwd));
|
||||
memset ((char *) pwd->smb_nt_pwd, '\0', sizeof (pwd->smb_nt_pwd));
|
||||
memset ((char *) pwd->smb_lm_owf, '\0', sizeof (pwd->smb_lm_owf));
|
||||
memset ((char *) pwd->smb_nt_owf, '\0', sizeof (pwd->smb_nt_owf));
|
||||
|
||||
pwd->null_pwd = True; /* safest option... */
|
||||
pwd->cleartext = False;
|
||||
pwd->crypted = False;
|
||||
pwd->null_pwd = True; /* safest option... */
|
||||
pwd->cleartext = False;
|
||||
pwd->crypted = False;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
de-obfuscates a password
|
||||
****************************************************************************/
|
||||
static void pwd_deobfuscate(struct pwd_info *pwd)
|
||||
static void
|
||||
pwd_deobfuscate (struct pwd_info *pwd)
|
||||
{
|
||||
(void) pwd;
|
||||
}
|
||||
@ -56,7 +58,8 @@ static void pwd_deobfuscate(struct pwd_info *pwd)
|
||||
/****************************************************************************
|
||||
obfuscates a password
|
||||
****************************************************************************/
|
||||
static void pwd_obfuscate(struct pwd_info *pwd)
|
||||
static void
|
||||
pwd_obfuscate (struct pwd_info *pwd)
|
||||
{
|
||||
(void) pwd;
|
||||
}
|
||||
@ -64,7 +67,8 @@ static void pwd_obfuscate(struct pwd_info *pwd)
|
||||
/****************************************************************************
|
||||
sets the obfuscation key info
|
||||
****************************************************************************/
|
||||
void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key)
|
||||
void
|
||||
pwd_obfuscate_key (struct pwd_info *pwd, uint32 int_key, char *str_key)
|
||||
{
|
||||
(void) pwd;
|
||||
(void) int_key;
|
||||
@ -75,185 +79,194 @@ void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key)
|
||||
/****************************************************************************
|
||||
reads a password
|
||||
****************************************************************************/
|
||||
void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt)
|
||||
void
|
||||
pwd_read (struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt)
|
||||
{
|
||||
/* grab a password */
|
||||
char *user_pass;
|
||||
/* grab a password */
|
||||
char *user_pass;
|
||||
|
||||
pwd_init(pwd);
|
||||
pwd_init (pwd);
|
||||
|
||||
user_pass = (char*)getpass(passwd_report);
|
||||
user_pass = (char *) getpass (passwd_report);
|
||||
|
||||
if (user_pass == NULL || user_pass[0] == 0)
|
||||
{
|
||||
pwd_set_nullpwd(pwd);
|
||||
}
|
||||
else if (do_encrypt)
|
||||
{
|
||||
pwd_make_lm_nt_16(pwd, user_pass);
|
||||
}
|
||||
else
|
||||
{
|
||||
pwd_set_cleartext(pwd, user_pass);
|
||||
}
|
||||
if (user_pass == NULL || user_pass[0] == 0)
|
||||
{
|
||||
pwd_set_nullpwd (pwd);
|
||||
}
|
||||
else if (do_encrypt)
|
||||
{
|
||||
pwd_make_lm_nt_16 (pwd, user_pass);
|
||||
}
|
||||
else
|
||||
{
|
||||
pwd_set_cleartext (pwd, user_pass);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
stores a cleartext password
|
||||
****************************************************************************/
|
||||
void pwd_set_nullpwd(struct pwd_info *pwd)
|
||||
void
|
||||
pwd_set_nullpwd (struct pwd_info *pwd)
|
||||
{
|
||||
pwd_init(pwd);
|
||||
pwd_init (pwd);
|
||||
|
||||
pwd->cleartext = False;
|
||||
pwd->null_pwd = True;
|
||||
pwd->crypted = False;
|
||||
pwd->cleartext = False;
|
||||
pwd->null_pwd = True;
|
||||
pwd->crypted = False;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
stores a cleartext password
|
||||
****************************************************************************/
|
||||
void pwd_set_cleartext(struct pwd_info *pwd, char *clr)
|
||||
void
|
||||
pwd_set_cleartext (struct pwd_info *pwd, char *clr)
|
||||
{
|
||||
pwd_init(pwd);
|
||||
fstrcpy(pwd->password, clr);
|
||||
pwd->cleartext = True;
|
||||
pwd->null_pwd = False;
|
||||
pwd->crypted = False;
|
||||
pwd_init (pwd);
|
||||
fstrcpy (pwd->password, clr);
|
||||
pwd->cleartext = True;
|
||||
pwd->null_pwd = False;
|
||||
pwd->crypted = False;
|
||||
|
||||
pwd_obfuscate(pwd);
|
||||
pwd_obfuscate (pwd);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
gets a cleartext password
|
||||
****************************************************************************/
|
||||
void pwd_get_cleartext(struct pwd_info *pwd, char *clr)
|
||||
void
|
||||
pwd_get_cleartext (struct pwd_info *pwd, char *clr)
|
||||
{
|
||||
pwd_deobfuscate(pwd);
|
||||
if (pwd->cleartext)
|
||||
{
|
||||
fstrcpy(clr, pwd->password);
|
||||
}
|
||||
else
|
||||
{
|
||||
clr[0] = 0;
|
||||
}
|
||||
pwd_obfuscate(pwd);
|
||||
pwd_deobfuscate (pwd);
|
||||
if (pwd->cleartext)
|
||||
{
|
||||
fstrcpy (clr, pwd->password);
|
||||
}
|
||||
else
|
||||
{
|
||||
clr[0] = 0;
|
||||
}
|
||||
pwd_obfuscate (pwd);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
stores lm and nt hashed passwords
|
||||
****************************************************************************/
|
||||
void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
|
||||
void
|
||||
pwd_set_lm_nt_16 (struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
|
||||
{
|
||||
pwd_init(pwd);
|
||||
pwd_init (pwd);
|
||||
|
||||
if (lm_pwd)
|
||||
{
|
||||
memcpy(pwd->smb_lm_pwd, lm_pwd, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset((char *)pwd->smb_lm_pwd, '\0', 16);
|
||||
}
|
||||
if (lm_pwd)
|
||||
{
|
||||
memcpy (pwd->smb_lm_pwd, lm_pwd, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset ((char *) pwd->smb_lm_pwd, '\0', 16);
|
||||
}
|
||||
|
||||
if (nt_pwd)
|
||||
{
|
||||
memcpy(pwd->smb_nt_pwd, nt_pwd, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset((char *)pwd->smb_nt_pwd, '\0', 16);
|
||||
}
|
||||
if (nt_pwd)
|
||||
{
|
||||
memcpy (pwd->smb_nt_pwd, nt_pwd, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset ((char *) pwd->smb_nt_pwd, '\0', 16);
|
||||
}
|
||||
|
||||
pwd->null_pwd = False;
|
||||
pwd->cleartext = False;
|
||||
pwd->crypted = False;
|
||||
pwd->null_pwd = False;
|
||||
pwd->cleartext = False;
|
||||
pwd->crypted = False;
|
||||
|
||||
pwd_obfuscate(pwd);
|
||||
pwd_obfuscate (pwd);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
gets lm and nt hashed passwords
|
||||
****************************************************************************/
|
||||
void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
|
||||
void
|
||||
pwd_get_lm_nt_16 (struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
|
||||
{
|
||||
pwd_deobfuscate(pwd);
|
||||
if (lm_pwd != NULL)
|
||||
{
|
||||
memcpy(lm_pwd, pwd->smb_lm_pwd, 16);
|
||||
}
|
||||
if (nt_pwd != NULL)
|
||||
{
|
||||
memcpy(nt_pwd, pwd->smb_nt_pwd, 16);
|
||||
}
|
||||
pwd_obfuscate(pwd);
|
||||
pwd_deobfuscate (pwd);
|
||||
if (lm_pwd != NULL)
|
||||
{
|
||||
memcpy (lm_pwd, pwd->smb_lm_pwd, 16);
|
||||
}
|
||||
if (nt_pwd != NULL)
|
||||
{
|
||||
memcpy (nt_pwd, pwd->smb_nt_pwd, 16);
|
||||
}
|
||||
pwd_obfuscate (pwd);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
makes lm and nt hashed passwords
|
||||
****************************************************************************/
|
||||
void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr)
|
||||
void
|
||||
pwd_make_lm_nt_16 (struct pwd_info *pwd, char *clr)
|
||||
{
|
||||
pwd_init(pwd);
|
||||
pwd_init (pwd);
|
||||
|
||||
nt_lm_owf_gen(clr, pwd->smb_nt_pwd, pwd->smb_lm_pwd);
|
||||
pwd->null_pwd = False;
|
||||
pwd->cleartext = False;
|
||||
pwd->crypted = False;
|
||||
nt_lm_owf_gen (clr, pwd->smb_nt_pwd, pwd->smb_lm_pwd);
|
||||
pwd->null_pwd = False;
|
||||
pwd->cleartext = False;
|
||||
pwd->crypted = False;
|
||||
|
||||
pwd_obfuscate(pwd);
|
||||
pwd_obfuscate (pwd);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
makes lm and nt OWF crypts
|
||||
****************************************************************************/
|
||||
void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8])
|
||||
void
|
||||
pwd_make_lm_nt_owf (struct pwd_info *pwd, uchar cryptkey[8])
|
||||
{
|
||||
pwd_deobfuscate(pwd);
|
||||
pwd_deobfuscate (pwd);
|
||||
|
||||
#ifdef DEBUG_PASSWORD
|
||||
DEBUG(100,("client cryptkey: "));
|
||||
dump_data(100, (char *)cryptkey, 8);
|
||||
DEBUG (100, ("client cryptkey: "));
|
||||
dump_data (100, (char *) cryptkey, 8);
|
||||
#endif
|
||||
|
||||
SMBOWFencrypt(pwd->smb_nt_pwd, cryptkey, pwd->smb_nt_owf);
|
||||
SMBOWFencrypt (pwd->smb_nt_pwd, cryptkey, pwd->smb_nt_owf);
|
||||
|
||||
#ifdef DEBUG_PASSWORD
|
||||
DEBUG(100,("nt_owf_passwd: "));
|
||||
dump_data(100, (char *)pwd->smb_nt_owf, sizeof(pwd->smb_nt_owf));
|
||||
DEBUG(100,("nt_sess_pwd: "));
|
||||
dump_data(100, (char *)pwd->smb_nt_pwd, sizeof(pwd->smb_nt_pwd));
|
||||
DEBUG (100, ("nt_owf_passwd: "));
|
||||
dump_data (100, (char *) pwd->smb_nt_owf, sizeof (pwd->smb_nt_owf));
|
||||
DEBUG (100, ("nt_sess_pwd: "));
|
||||
dump_data (100, (char *) pwd->smb_nt_pwd, sizeof (pwd->smb_nt_pwd));
|
||||
#endif
|
||||
|
||||
SMBOWFencrypt(pwd->smb_lm_pwd, cryptkey, pwd->smb_lm_owf);
|
||||
SMBOWFencrypt (pwd->smb_lm_pwd, cryptkey, pwd->smb_lm_owf);
|
||||
|
||||
#ifdef DEBUG_PASSWORD
|
||||
DEBUG(100,("lm_owf_passwd: "));
|
||||
dump_data(100, (char *)pwd->smb_lm_owf, sizeof(pwd->smb_lm_owf));
|
||||
DEBUG(100,("lm_sess_pwd: "));
|
||||
dump_data(100, (char *)pwd->smb_lm_pwd, sizeof(pwd->smb_lm_pwd));
|
||||
DEBUG (100, ("lm_owf_passwd: "));
|
||||
dump_data (100, (char *) pwd->smb_lm_owf, sizeof (pwd->smb_lm_owf));
|
||||
DEBUG (100, ("lm_sess_pwd: "));
|
||||
dump_data (100, (char *) pwd->smb_lm_pwd, sizeof (pwd->smb_lm_pwd));
|
||||
#endif
|
||||
|
||||
pwd->crypted = True;
|
||||
pwd->crypted = True;
|
||||
|
||||
pwd_obfuscate(pwd);
|
||||
pwd_obfuscate (pwd);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
gets lm and nt crypts
|
||||
****************************************************************************/
|
||||
void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24])
|
||||
void
|
||||
pwd_get_lm_nt_owf (struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24])
|
||||
{
|
||||
pwd_deobfuscate(pwd);
|
||||
if (lm_owf != NULL)
|
||||
{
|
||||
memcpy(lm_owf, pwd->smb_lm_owf, 24);
|
||||
}
|
||||
if (nt_owf != NULL)
|
||||
{
|
||||
memcpy(nt_owf, pwd->smb_nt_owf, 24);
|
||||
}
|
||||
pwd_obfuscate(pwd);
|
||||
pwd_deobfuscate (pwd);
|
||||
if (lm_owf != NULL)
|
||||
{
|
||||
memcpy (lm_owf, pwd->smb_lm_owf, 24);
|
||||
}
|
||||
if (nt_owf != NULL)
|
||||
{
|
||||
memcpy (nt_owf, pwd->smb_nt_owf, 24);
|
||||
}
|
||||
pwd_obfuscate (pwd);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
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"
|
||||
|
||||
@ -48,356 +48,386 @@
|
||||
about the applicability of ITAR regulations to this code then you
|
||||
should confirm it for yourself (and maybe let me know if you come
|
||||
up with a different answer to the one above)
|
||||
*/
|
||||
*/
|
||||
|
||||
#undef uchar
|
||||
#define uchar const unsigned char
|
||||
|
||||
static uchar perm1[56] = {57, 49, 41, 33, 25, 17, 9,
|
||||
1, 58, 50, 42, 34, 26, 18,
|
||||
10, 2, 59, 51, 43, 35, 27,
|
||||
19, 11, 3, 60, 52, 44, 36,
|
||||
63, 55, 47, 39, 31, 23, 15,
|
||||
7, 62, 54, 46, 38, 30, 22,
|
||||
14, 6, 61, 53, 45, 37, 29,
|
||||
21, 13, 5, 28, 20, 12, 4};
|
||||
static uchar perm1[56] = { 57, 49, 41, 33, 25, 17, 9,
|
||||
1, 58, 50, 42, 34, 26, 18,
|
||||
10, 2, 59, 51, 43, 35, 27,
|
||||
19, 11, 3, 60, 52, 44, 36,
|
||||
63, 55, 47, 39, 31, 23, 15,
|
||||
7, 62, 54, 46, 38, 30, 22,
|
||||
14, 6, 61, 53, 45, 37, 29,
|
||||
21, 13, 5, 28, 20, 12, 4
|
||||
};
|
||||
|
||||
static uchar perm2[48] = {14, 17, 11, 24, 1, 5,
|
||||
3, 28, 15, 6, 21, 10,
|
||||
23, 19, 12, 4, 26, 8,
|
||||
16, 7, 27, 20, 13, 2,
|
||||
41, 52, 31, 37, 47, 55,
|
||||
30, 40, 51, 45, 33, 48,
|
||||
44, 49, 39, 56, 34, 53,
|
||||
46, 42, 50, 36, 29, 32};
|
||||
static uchar perm2[48] = { 14, 17, 11, 24, 1, 5,
|
||||
3, 28, 15, 6, 21, 10,
|
||||
23, 19, 12, 4, 26, 8,
|
||||
16, 7, 27, 20, 13, 2,
|
||||
41, 52, 31, 37, 47, 55,
|
||||
30, 40, 51, 45, 33, 48,
|
||||
44, 49, 39, 56, 34, 53,
|
||||
46, 42, 50, 36, 29, 32
|
||||
};
|
||||
|
||||
static uchar perm3[64] = {58, 50, 42, 34, 26, 18, 10, 2,
|
||||
60, 52, 44, 36, 28, 20, 12, 4,
|
||||
62, 54, 46, 38, 30, 22, 14, 6,
|
||||
64, 56, 48, 40, 32, 24, 16, 8,
|
||||
57, 49, 41, 33, 25, 17, 9, 1,
|
||||
59, 51, 43, 35, 27, 19, 11, 3,
|
||||
61, 53, 45, 37, 29, 21, 13, 5,
|
||||
63, 55, 47, 39, 31, 23, 15, 7};
|
||||
static uchar perm3[64] = { 58, 50, 42, 34, 26, 18, 10, 2,
|
||||
60, 52, 44, 36, 28, 20, 12, 4,
|
||||
62, 54, 46, 38, 30, 22, 14, 6,
|
||||
64, 56, 48, 40, 32, 24, 16, 8,
|
||||
57, 49, 41, 33, 25, 17, 9, 1,
|
||||
59, 51, 43, 35, 27, 19, 11, 3,
|
||||
61, 53, 45, 37, 29, 21, 13, 5,
|
||||
63, 55, 47, 39, 31, 23, 15, 7
|
||||
};
|
||||
|
||||
static uchar perm4[48] = { 32, 1, 2, 3, 4, 5,
|
||||
4, 5, 6, 7, 8, 9,
|
||||
8, 9, 10, 11, 12, 13,
|
||||
12, 13, 14, 15, 16, 17,
|
||||
16, 17, 18, 19, 20, 21,
|
||||
20, 21, 22, 23, 24, 25,
|
||||
24, 25, 26, 27, 28, 29,
|
||||
28, 29, 30, 31, 32, 1};
|
||||
static uchar perm4[48] = { 32, 1, 2, 3, 4, 5,
|
||||
4, 5, 6, 7, 8, 9,
|
||||
8, 9, 10, 11, 12, 13,
|
||||
12, 13, 14, 15, 16, 17,
|
||||
16, 17, 18, 19, 20, 21,
|
||||
20, 21, 22, 23, 24, 25,
|
||||
24, 25, 26, 27, 28, 29,
|
||||
28, 29, 30, 31, 32, 1
|
||||
};
|
||||
|
||||
static uchar perm5[32] = { 16, 7, 20, 21,
|
||||
29, 12, 28, 17,
|
||||
1, 15, 23, 26,
|
||||
5, 18, 31, 10,
|
||||
2, 8, 24, 14,
|
||||
32, 27, 3, 9,
|
||||
19, 13, 30, 6,
|
||||
22, 11, 4, 25};
|
||||
static uchar perm5[32] = { 16, 7, 20, 21,
|
||||
29, 12, 28, 17,
|
||||
1, 15, 23, 26,
|
||||
5, 18, 31, 10,
|
||||
2, 8, 24, 14,
|
||||
32, 27, 3, 9,
|
||||
19, 13, 30, 6,
|
||||
22, 11, 4, 25
|
||||
};
|
||||
|
||||
|
||||
static uchar perm6[64] ={ 40, 8, 48, 16, 56, 24, 64, 32,
|
||||
39, 7, 47, 15, 55, 23, 63, 31,
|
||||
38, 6, 46, 14, 54, 22, 62, 30,
|
||||
37, 5, 45, 13, 53, 21, 61, 29,
|
||||
36, 4, 44, 12, 52, 20, 60, 28,
|
||||
35, 3, 43, 11, 51, 19, 59, 27,
|
||||
34, 2, 42, 10, 50, 18, 58, 26,
|
||||
33, 1, 41, 9, 49, 17, 57, 25};
|
||||
static uchar perm6[64] = { 40, 8, 48, 16, 56, 24, 64, 32,
|
||||
39, 7, 47, 15, 55, 23, 63, 31,
|
||||
38, 6, 46, 14, 54, 22, 62, 30,
|
||||
37, 5, 45, 13, 53, 21, 61, 29,
|
||||
36, 4, 44, 12, 52, 20, 60, 28,
|
||||
35, 3, 43, 11, 51, 19, 59, 27,
|
||||
34, 2, 42, 10, 50, 18, 58, 26,
|
||||
33, 1, 41, 9, 49, 17, 57, 25
|
||||
};
|
||||
|
||||
|
||||
static uchar sc[16] = {1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1};
|
||||
static uchar sc[16] = { 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 };
|
||||
|
||||
static uchar sbox[8][4][16] = {
|
||||
{{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7},
|
||||
{0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8},
|
||||
{4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0},
|
||||
{15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}},
|
||||
{{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7},
|
||||
{0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8},
|
||||
{4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0},
|
||||
{15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}},
|
||||
|
||||
{{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10},
|
||||
{3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5},
|
||||
{0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15},
|
||||
{13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}},
|
||||
{{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10},
|
||||
{3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5},
|
||||
{0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15},
|
||||
{13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}},
|
||||
|
||||
{{10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8},
|
||||
{13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1},
|
||||
{13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7},
|
||||
{1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}},
|
||||
{{10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8},
|
||||
{13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1},
|
||||
{13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7},
|
||||
{1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}},
|
||||
|
||||
{{7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15},
|
||||
{13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9},
|
||||
{10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4},
|
||||
{3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}},
|
||||
{{7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15},
|
||||
{13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9},
|
||||
{10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4},
|
||||
{3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}},
|
||||
|
||||
{{2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9},
|
||||
{14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6},
|
||||
{4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14},
|
||||
{11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}},
|
||||
{{2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9},
|
||||
{14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6},
|
||||
{4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14},
|
||||
{11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}},
|
||||
|
||||
{{12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11},
|
||||
{10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8},
|
||||
{9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6},
|
||||
{4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}},
|
||||
{{12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11},
|
||||
{10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8},
|
||||
{9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6},
|
||||
{4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}},
|
||||
|
||||
{{4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1},
|
||||
{13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6},
|
||||
{1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2},
|
||||
{6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}},
|
||||
{{4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1},
|
||||
{13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6},
|
||||
{1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2},
|
||||
{6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}},
|
||||
|
||||
{{13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7},
|
||||
{1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2},
|
||||
{7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8},
|
||||
{2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}}};
|
||||
{{13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7},
|
||||
{1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2},
|
||||
{7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8},
|
||||
{2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}}
|
||||
};
|
||||
|
||||
static void permute(char *out, char *in, uchar *p, int n)
|
||||
static void
|
||||
permute (char *out, char *in, uchar * p, int n)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<n;i++)
|
||||
out[i] = in[p[i]-1];
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
out[i] = in[p[i] - 1];
|
||||
}
|
||||
|
||||
static void lshift(char *d, int count, int n)
|
||||
static void
|
||||
lshift (char *d, int count, int n)
|
||||
{
|
||||
char out[64];
|
||||
int i;
|
||||
for (i=0;i<n;i++)
|
||||
out[i] = d[(i+count)%n];
|
||||
for (i=0;i<n;i++)
|
||||
d[i] = out[i];
|
||||
char out[64];
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
out[i] = d[(i + count) % n];
|
||||
for (i = 0; i < n; i++)
|
||||
d[i] = out[i];
|
||||
}
|
||||
|
||||
static void concat(char *out, char *in1, char *in2, int l1, int l2)
|
||||
static void
|
||||
concat (char *out, char *in1, char *in2, int l1, int l2)
|
||||
{
|
||||
while (l1--)
|
||||
*out++ = *in1++;
|
||||
while (l2--)
|
||||
*out++ = *in2++;
|
||||
while (l1--)
|
||||
*out++ = *in1++;
|
||||
while (l2--)
|
||||
*out++ = *in2++;
|
||||
}
|
||||
|
||||
static void xor(char *out, char *in1, char *in2, int n)
|
||||
static void
|
||||
xor (char *out, char *in1, char *in2, int n)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<n;i++)
|
||||
out[i] = in1[i] ^ in2[i];
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
out[i] = in1[i] ^ in2[i];
|
||||
}
|
||||
|
||||
static void dohash(char *out, char *in, char *key, int forw)
|
||||
static void
|
||||
dohash (char *out, char *in, char *key, int forw)
|
||||
{
|
||||
int i, j, k;
|
||||
char pk1[56];
|
||||
char c[28];
|
||||
char d[28];
|
||||
char cd[56];
|
||||
char ki[16][48];
|
||||
char pd1[64];
|
||||
char l[32], r[32];
|
||||
char rl[64];
|
||||
int i, j, k;
|
||||
char pk1[56];
|
||||
char c[28];
|
||||
char d[28];
|
||||
char cd[56];
|
||||
char ki[16][48];
|
||||
char pd1[64];
|
||||
char l[32], r[32];
|
||||
char rl[64];
|
||||
|
||||
permute(pk1, key, perm1, 56);
|
||||
permute (pk1, key, perm1, 56);
|
||||
|
||||
for (i=0;i<28;i++)
|
||||
c[i] = pk1[i];
|
||||
for (i=0;i<28;i++)
|
||||
d[i] = pk1[i+28];
|
||||
for (i = 0; i < 28; i++)
|
||||
c[i] = pk1[i];
|
||||
for (i = 0; i < 28; i++)
|
||||
d[i] = pk1[i + 28];
|
||||
|
||||
for (i=0;i<16;i++) {
|
||||
lshift(c, sc[i], 28);
|
||||
lshift(d, sc[i], 28);
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
lshift (c, sc[i], 28);
|
||||
lshift (d, sc[i], 28);
|
||||
|
||||
concat(cd, c, d, 28, 28);
|
||||
permute(ki[i], cd, perm2, 48);
|
||||
}
|
||||
concat (cd, c, d, 28, 28);
|
||||
permute (ki[i], cd, perm2, 48);
|
||||
}
|
||||
|
||||
permute(pd1, in, perm3, 64);
|
||||
permute (pd1, in, perm3, 64);
|
||||
|
||||
for (j=0;j<32;j++) {
|
||||
l[j] = pd1[j];
|
||||
r[j] = pd1[j+32];
|
||||
}
|
||||
for (j = 0; j < 32; j++)
|
||||
{
|
||||
l[j] = pd1[j];
|
||||
r[j] = pd1[j + 32];
|
||||
}
|
||||
|
||||
for (i=0;i<16;i++) {
|
||||
char er[48];
|
||||
char erk[48];
|
||||
char b[8][6];
|
||||
char cb[32];
|
||||
char pcb[32];
|
||||
char r2[32];
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
char er[48];
|
||||
char erk[48];
|
||||
char b[8][6];
|
||||
char cb[32];
|
||||
char pcb[32];
|
||||
char r2[32];
|
||||
|
||||
permute(er, r, perm4, 48);
|
||||
permute (er, r, perm4, 48);
|
||||
|
||||
xor(erk, er, ki[forw ? i : 15 - i], 48);
|
||||
xor (erk, er, ki[forw ? i : 15 - i], 48);
|
||||
|
||||
for (j=0;j<8;j++)
|
||||
for (k=0;k<6;k++)
|
||||
b[j][k] = erk[j*6 + k];
|
||||
for (j = 0; j < 8; j++)
|
||||
for (k = 0; k < 6; k++)
|
||||
b[j][k] = erk[j * 6 + k];
|
||||
|
||||
for (j=0;j<8;j++) {
|
||||
int m, n;
|
||||
m = (b[j][0]<<1) | b[j][5];
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
int m, n;
|
||||
m = (b[j][0] << 1) | b[j][5];
|
||||
|
||||
n = (b[j][1]<<3) | (b[j][2]<<2) | (b[j][3]<<1) | b[j][4];
|
||||
n = (b[j][1] << 3) | (b[j][2] << 2) | (b[j][3] << 1) | b[j][4];
|
||||
|
||||
for (k=0;k<4;k++)
|
||||
b[j][k] = (sbox[j][m][n] & (1<<(3-k)))?1:0;
|
||||
}
|
||||
for (k = 0; k < 4; k++)
|
||||
b[j][k] = (sbox[j][m][n] & (1 << (3 - k))) ? 1 : 0;
|
||||
}
|
||||
|
||||
for (j=0;j<8;j++)
|
||||
for (k=0;k<4;k++)
|
||||
cb[j*4+k] = b[j][k];
|
||||
permute(pcb, cb, perm5, 32);
|
||||
for (j = 0; j < 8; j++)
|
||||
for (k = 0; k < 4; k++)
|
||||
cb[j * 4 + k] = b[j][k];
|
||||
permute (pcb, cb, perm5, 32);
|
||||
|
||||
xor(r2, l, pcb, 32);
|
||||
xor (r2, l, pcb, 32);
|
||||
|
||||
for (j=0;j<32;j++)
|
||||
l[j] = r[j];
|
||||
for (j = 0; j < 32; j++)
|
||||
l[j] = r[j];
|
||||
|
||||
for (j=0;j<32;j++)
|
||||
r[j] = r2[j];
|
||||
}
|
||||
for (j = 0; j < 32; j++)
|
||||
r[j] = r2[j];
|
||||
}
|
||||
|
||||
concat(rl, r, l, 32, 32);
|
||||
concat (rl, r, l, 32, 32);
|
||||
|
||||
permute(out, rl, perm6, 64);
|
||||
permute (out, rl, perm6, 64);
|
||||
}
|
||||
|
||||
static void str_to_key(unsigned char *str,unsigned char *key)
|
||||
static void
|
||||
str_to_key (unsigned char *str, unsigned char *key)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
key[0] = str[0]>>1;
|
||||
key[1] = ((str[0]&0x01)<<6) | (str[1]>>2);
|
||||
key[2] = ((str[1]&0x03)<<5) | (str[2]>>3);
|
||||
key[3] = ((str[2]&0x07)<<4) | (str[3]>>4);
|
||||
key[4] = ((str[3]&0x0F)<<3) | (str[4]>>5);
|
||||
key[5] = ((str[4]&0x1F)<<2) | (str[5]>>6);
|
||||
key[6] = ((str[5]&0x3F)<<1) | (str[6]>>7);
|
||||
key[7] = str[6]&0x7F;
|
||||
for (i=0;i<8;i++) {
|
||||
key[i] = (key[i]<<1);
|
||||
}
|
||||
key[0] = str[0] >> 1;
|
||||
key[1] = ((str[0] & 0x01) << 6) | (str[1] >> 2);
|
||||
key[2] = ((str[1] & 0x03) << 5) | (str[2] >> 3);
|
||||
key[3] = ((str[2] & 0x07) << 4) | (str[3] >> 4);
|
||||
key[4] = ((str[3] & 0x0F) << 3) | (str[4] >> 5);
|
||||
key[5] = ((str[4] & 0x1F) << 2) | (str[5] >> 6);
|
||||
key[6] = ((str[5] & 0x3F) << 1) | (str[6] >> 7);
|
||||
key[7] = str[6] & 0x7F;
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
key[i] = (key[i] << 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void smbhash(unsigned char *out, unsigned char *in, unsigned char *key, int forw)
|
||||
static void
|
||||
smbhash (unsigned char *out, unsigned char *in, unsigned char *key, int forw)
|
||||
{
|
||||
int i;
|
||||
char outb[64];
|
||||
char inb[64];
|
||||
char keyb[64];
|
||||
unsigned char key2[8];
|
||||
int i;
|
||||
char outb[64];
|
||||
char inb[64];
|
||||
char keyb[64];
|
||||
unsigned char key2[8];
|
||||
|
||||
str_to_key(key, key2);
|
||||
str_to_key (key, key2);
|
||||
|
||||
for (i=0;i<64;i++) {
|
||||
inb[i] = (in[i/8] & (1<<(7-(i%8)))) ? 1 : 0;
|
||||
keyb[i] = (key2[i/8] & (1<<(7-(i%8)))) ? 1 : 0;
|
||||
outb[i] = 0;
|
||||
}
|
||||
for (i = 0; i < 64; i++)
|
||||
{
|
||||
inb[i] = (in[i / 8] & (1 << (7 - (i % 8)))) ? 1 : 0;
|
||||
keyb[i] = (key2[i / 8] & (1 << (7 - (i % 8)))) ? 1 : 0;
|
||||
outb[i] = 0;
|
||||
}
|
||||
|
||||
dohash(outb, inb, keyb, forw);
|
||||
dohash (outb, inb, keyb, forw);
|
||||
|
||||
for (i=0;i<8;i++) {
|
||||
out[i] = 0;
|
||||
}
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
out[i] = 0;
|
||||
}
|
||||
|
||||
for (i=0;i<64;i++) {
|
||||
if (outb[i])
|
||||
out[i/8] |= (1<<(7-(i%8)));
|
||||
}
|
||||
for (i = 0; i < 64; i++)
|
||||
{
|
||||
if (outb[i])
|
||||
out[i / 8] |= (1 << (7 - (i % 8)));
|
||||
}
|
||||
}
|
||||
|
||||
void E_P16(unsigned char *p14,unsigned char *p16)
|
||||
void
|
||||
E_P16 (unsigned char *p14, unsigned char *p16)
|
||||
{
|
||||
unsigned char sp8[8] = {0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
|
||||
smbhash(p16, sp8, p14, 1);
|
||||
smbhash(p16+8, sp8, p14+7, 1);
|
||||
unsigned char sp8[8] = { 0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 };
|
||||
smbhash (p16, sp8, p14, 1);
|
||||
smbhash (p16 + 8, sp8, p14 + 7, 1);
|
||||
}
|
||||
|
||||
void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24)
|
||||
void
|
||||
E_P24 (unsigned char *p21, unsigned char *c8, unsigned char *p24)
|
||||
{
|
||||
smbhash(p24, c8, p21, 1);
|
||||
smbhash(p24+8, c8, p21+7, 1);
|
||||
smbhash(p24+16, c8, p21+14, 1);
|
||||
smbhash (p24, c8, p21, 1);
|
||||
smbhash (p24 + 8, c8, p21 + 7, 1);
|
||||
smbhash (p24 + 16, c8, p21 + 14, 1);
|
||||
}
|
||||
|
||||
void D_P16(unsigned char *p14, unsigned char *in, unsigned char *out)
|
||||
void
|
||||
D_P16 (unsigned char *p14, unsigned char *in, unsigned char *out)
|
||||
{
|
||||
smbhash(out, in, p14, 0);
|
||||
smbhash(out+8, in+8, p14+7, 0);
|
||||
smbhash (out, in, p14, 0);
|
||||
smbhash (out + 8, in + 8, p14 + 7, 0);
|
||||
}
|
||||
|
||||
void E_old_pw_hash( unsigned char *p14, unsigned char *in, unsigned char *out)
|
||||
void
|
||||
E_old_pw_hash (unsigned char *p14, unsigned char *in, unsigned char *out)
|
||||
{
|
||||
smbhash(out, in, p14, 1);
|
||||
smbhash(out+8, in+8, p14+7, 1);
|
||||
smbhash (out, in, p14, 1);
|
||||
smbhash (out + 8, in + 8, p14 + 7, 1);
|
||||
}
|
||||
|
||||
void cred_hash1(unsigned char *out,unsigned char *in,unsigned char *key)
|
||||
void
|
||||
cred_hash1 (unsigned char *out, unsigned char *in, unsigned char *key)
|
||||
{
|
||||
unsigned char buf[8];
|
||||
unsigned char buf[8];
|
||||
|
||||
smbhash(buf, in, key, 1);
|
||||
smbhash(out, buf, key+9, 1);
|
||||
smbhash (buf, in, key, 1);
|
||||
smbhash (out, buf, key + 9, 1);
|
||||
}
|
||||
|
||||
void cred_hash2(unsigned char *out,unsigned char *in,unsigned char *key)
|
||||
void
|
||||
cred_hash2 (unsigned char *out, unsigned char *in, unsigned char *key)
|
||||
{
|
||||
unsigned char buf[8];
|
||||
static unsigned char key2[8];
|
||||
unsigned char buf[8];
|
||||
static unsigned char key2[8];
|
||||
|
||||
smbhash(buf, in, key, 1);
|
||||
key2[0] = key[7];
|
||||
smbhash(out, buf, key2, 1);
|
||||
smbhash (buf, in, key, 1);
|
||||
key2[0] = key[7];
|
||||
smbhash (out, buf, key2, 1);
|
||||
}
|
||||
|
||||
void cred_hash3(unsigned char *out,unsigned char *in,unsigned char *key, int forw)
|
||||
void
|
||||
cred_hash3 (unsigned char *out, unsigned char *in, unsigned char *key, int forw)
|
||||
{
|
||||
static unsigned char key2[8];
|
||||
static unsigned char key2[8];
|
||||
|
||||
smbhash(out, in, key, forw);
|
||||
key2[0] = key[7];
|
||||
smbhash(out + 8, in + 8, key2, forw);
|
||||
smbhash (out, in, key, forw);
|
||||
key2[0] = key[7];
|
||||
smbhash (out + 8, in + 8, key2, forw);
|
||||
}
|
||||
|
||||
void SamOEMhash( unsigned char *data, unsigned char *key, int val)
|
||||
void
|
||||
SamOEMhash (unsigned char *data, unsigned char *key, int val)
|
||||
{
|
||||
unsigned char s_box[256];
|
||||
unsigned char index_i = 0;
|
||||
unsigned char index_j = 0;
|
||||
unsigned char j = 0;
|
||||
int ind;
|
||||
unsigned char s_box[256];
|
||||
unsigned char index_i = 0;
|
||||
unsigned char index_j = 0;
|
||||
unsigned char j = 0;
|
||||
int ind;
|
||||
|
||||
for (ind = 0; ind < 256; ind++)
|
||||
{
|
||||
s_box[ind] = (unsigned char)ind;
|
||||
}
|
||||
for (ind = 0; ind < 256; ind++)
|
||||
{
|
||||
s_box[ind] = (unsigned char) ind;
|
||||
}
|
||||
|
||||
for( ind = 0; ind < 256; ind++)
|
||||
{
|
||||
unsigned char tc;
|
||||
for (ind = 0; ind < 256; ind++)
|
||||
{
|
||||
unsigned char tc;
|
||||
|
||||
j += (s_box[ind] + key[ind%16]);
|
||||
j += (s_box[ind] + key[ind % 16]);
|
||||
|
||||
tc = s_box[ind];
|
||||
s_box[ind] = s_box[j];
|
||||
s_box[j] = tc;
|
||||
}
|
||||
for( ind = 0; ind < (val ? 516 : 16); ind++)
|
||||
{
|
||||
unsigned char tc;
|
||||
unsigned char t;
|
||||
tc = s_box[ind];
|
||||
s_box[ind] = s_box[j];
|
||||
s_box[j] = tc;
|
||||
}
|
||||
for (ind = 0; ind < (val ? 516 : 16); ind++)
|
||||
{
|
||||
unsigned char tc;
|
||||
unsigned char t;
|
||||
|
||||
index_i++;
|
||||
index_j += s_box[index_i];
|
||||
index_i++;
|
||||
index_j += s_box[index_i];
|
||||
|
||||
tc = s_box[index_i];
|
||||
s_box[index_i] = s_box[index_j];
|
||||
s_box[index_j] = tc;
|
||||
tc = s_box[index_i];
|
||||
s_box[index_i] = s_box[index_j];
|
||||
s_box[index_j] = tc;
|
||||
|
||||
t = s_box[index_i] + s_box[index_j];
|
||||
data[ind] = data[ind] ^ s_box[t];
|
||||
}
|
||||
t = s_box[index_i] + s_box[index_j];
|
||||
data[ind] = data[ind] ^ s_box[t];
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
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"
|
||||
|
||||
@ -36,34 +36,36 @@ extern int DEBUGLEVEL;
|
||||
This implements the X/Open SMB password encryption
|
||||
It takes a password, a 8 byte "crypt key" and puts 24 bytes of
|
||||
encrypted password into p24 */
|
||||
void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24)
|
||||
void
|
||||
SMBencrypt (uchar * passwd, uchar * c8, uchar * p24)
|
||||
{
|
||||
uchar p14[15], p21[21];
|
||||
uchar p14[15], p21[21];
|
||||
|
||||
memset(p21,'\0',21);
|
||||
memset(p14,'\0',14);
|
||||
StrnCpy((char *)p14,(char *)passwd,14);
|
||||
memset (p21, '\0', 21);
|
||||
memset (p14, '\0', 14);
|
||||
StrnCpy ((char *) p14, (char *) passwd, 14);
|
||||
|
||||
strupper((char *)p14);
|
||||
E_P16(p14, p21);
|
||||
strupper ((char *) p14);
|
||||
E_P16 (p14, p21);
|
||||
|
||||
SMBOWFencrypt(p21, c8, p24);
|
||||
SMBOWFencrypt (p21, c8, p24);
|
||||
|
||||
#ifdef DEBUG_PASSWORD
|
||||
DEBUG(100,("SMBencrypt: lm#, challenge, response\n"));
|
||||
dump_data(100, (char *)p21, 16);
|
||||
dump_data(100, (char *)c8, 8);
|
||||
dump_data(100, (char *)p24, 24);
|
||||
DEBUG (100, ("SMBencrypt: lm#, challenge, response\n"));
|
||||
dump_data (100, (char *) p21, 16);
|
||||
dump_data (100, (char *) c8, 8);
|
||||
dump_data (100, (char *) p24, 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Routines for Windows NT MD4 Hash functions. */
|
||||
static int _my_wcslen(int16 *str)
|
||||
static int
|
||||
_my_wcslen (int16 * str)
|
||||
{
|
||||
int len = 0;
|
||||
while(*str++ != 0)
|
||||
len++;
|
||||
return len;
|
||||
int len = 0;
|
||||
while (*str++ != 0)
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -72,126 +74,133 @@ static int _my_wcslen(int16 *str)
|
||||
* this must be in intel (little-endian)
|
||||
* format.
|
||||
*/
|
||||
|
||||
static int _my_mbstowcs(int16 *dst, uchar *src, int len)
|
||||
|
||||
static int
|
||||
_my_mbstowcs (int16 * dst, uchar * src, int len)
|
||||
{
|
||||
int i;
|
||||
int16 val;
|
||||
|
||||
for(i = 0; i < len; i++) {
|
||||
val = *src;
|
||||
SSVAL(dst,0,val);
|
||||
dst++;
|
||||
src++;
|
||||
if(val == 0)
|
||||
break;
|
||||
}
|
||||
return i;
|
||||
int i;
|
||||
int16 val;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
val = *src;
|
||||
SSVAL (dst, 0, val);
|
||||
dst++;
|
||||
src++;
|
||||
if (val == 0)
|
||||
break;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates the MD4 Hash of the users password in NT UNICODE.
|
||||
*/
|
||||
|
||||
void E_md4hash(uchar *passwd, uchar *p16)
|
||||
{
|
||||
int len;
|
||||
int16 wpwd[129];
|
||||
|
||||
/* Password cannot be longer than 128 characters */
|
||||
len = strlen((char *)passwd);
|
||||
if(len > 128)
|
||||
len = 128;
|
||||
/* Password must be converted to NT unicode */
|
||||
_my_mbstowcs(wpwd, passwd, len);
|
||||
wpwd[len] = 0; /* Ensure string is null terminated */
|
||||
/* Calculate length in bytes */
|
||||
len = _my_wcslen(wpwd) * sizeof(int16);
|
||||
|
||||
mdfour(p16, (unsigned char *)wpwd, len);
|
||||
void
|
||||
E_md4hash (uchar * passwd, uchar * p16)
|
||||
{
|
||||
int len;
|
||||
int16 wpwd[129];
|
||||
|
||||
/* Password cannot be longer than 128 characters */
|
||||
len = strlen ((char *) passwd);
|
||||
if (len > 128)
|
||||
len = 128;
|
||||
/* Password must be converted to NT unicode */
|
||||
_my_mbstowcs (wpwd, passwd, len);
|
||||
wpwd[len] = 0; /* Ensure string is null terminated */
|
||||
/* Calculate length in bytes */
|
||||
len = _my_wcslen (wpwd) * sizeof (int16);
|
||||
|
||||
mdfour (p16, (unsigned char *) wpwd, len);
|
||||
}
|
||||
|
||||
/* Does both the NT and LM owfs of a user's password */
|
||||
void nt_lm_owf_gen(char *pwd, uchar nt_p16[16], uchar p16[16])
|
||||
void
|
||||
nt_lm_owf_gen (char *pwd, uchar nt_p16[16], uchar p16[16])
|
||||
{
|
||||
char passwd[130];
|
||||
char passwd[130];
|
||||
|
||||
memset(passwd,'\0',130);
|
||||
safe_strcpy( passwd, pwd, sizeof(passwd)-1);
|
||||
memset (passwd, '\0', 130);
|
||||
safe_strcpy (passwd, pwd, sizeof (passwd) - 1);
|
||||
|
||||
/* Calculate the MD4 hash (NT compatible) of the password */
|
||||
memset(nt_p16, '\0', 16);
|
||||
E_md4hash((uchar *)passwd, nt_p16);
|
||||
/* Calculate the MD4 hash (NT compatible) of the password */
|
||||
memset (nt_p16, '\0', 16);
|
||||
E_md4hash ((uchar *) passwd, nt_p16);
|
||||
|
||||
#ifdef DEBUG_PASSWORD
|
||||
DEBUG(100,("nt_lm_owf_gen: pwd, nt#\n"));
|
||||
dump_data(120, passwd, strlen(passwd));
|
||||
dump_data(100, (char *)nt_p16, 16);
|
||||
DEBUG (100, ("nt_lm_owf_gen: pwd, nt#\n"));
|
||||
dump_data (120, passwd, strlen (passwd));
|
||||
dump_data (100, (char *) nt_p16, 16);
|
||||
#endif
|
||||
|
||||
/* Mangle the passwords into Lanman format */
|
||||
passwd[14] = '\0';
|
||||
strupper(passwd);
|
||||
/* Mangle the passwords into Lanman format */
|
||||
passwd[14] = '\0';
|
||||
strupper (passwd);
|
||||
|
||||
/* Calculate the SMB (lanman) hash functions of the password */
|
||||
/* Calculate the SMB (lanman) hash functions of the password */
|
||||
|
||||
memset(p16, '\0', 16);
|
||||
E_P16((uchar *) passwd, (uchar *)p16);
|
||||
memset (p16, '\0', 16);
|
||||
E_P16 ((uchar *) passwd, (uchar *) p16);
|
||||
|
||||
#ifdef DEBUG_PASSWORD
|
||||
DEBUG(100,("nt_lm_owf_gen: pwd, lm#\n"));
|
||||
dump_data(120, passwd, strlen(passwd));
|
||||
dump_data(100, (char *)p16, 16);
|
||||
DEBUG (100, ("nt_lm_owf_gen: pwd, lm#\n"));
|
||||
dump_data (120, passwd, strlen (passwd));
|
||||
dump_data (100, (char *) p16, 16);
|
||||
#endif
|
||||
/* clear out local copy of user's password (just being paranoid). */
|
||||
memset(passwd, '\0', sizeof(passwd));
|
||||
/* clear out local copy of user's password (just being paranoid). */
|
||||
memset (passwd, '\0', sizeof (passwd));
|
||||
}
|
||||
|
||||
/* Does the des encryption from the NT or LM MD4 hash. */
|
||||
void SMBOWFencrypt(uchar passwd[16], uchar *c8, uchar p24[24])
|
||||
void
|
||||
SMBOWFencrypt (uchar passwd[16], uchar * c8, uchar p24[24])
|
||||
{
|
||||
uchar p21[21];
|
||||
|
||||
memset(p21,'\0',21);
|
||||
|
||||
memcpy(p21, passwd, 16);
|
||||
E_P24(p21, c8, p24);
|
||||
uchar p21[21];
|
||||
|
||||
memset (p21, '\0', 21);
|
||||
|
||||
memcpy (p21, passwd, 16);
|
||||
E_P24 (p21, c8, p24);
|
||||
}
|
||||
|
||||
/* Does the des encryption from the FIRST 8 BYTES of the NT or LM MD4 hash. */
|
||||
void NTLMSSPOWFencrypt(uchar passwd[8], uchar *ntlmchalresp, uchar p24[24])
|
||||
void
|
||||
NTLMSSPOWFencrypt (uchar passwd[8], uchar * ntlmchalresp, uchar p24[24])
|
||||
{
|
||||
uchar p21[21];
|
||||
|
||||
memset(p21,'\0',21);
|
||||
memcpy(p21, passwd, 8);
|
||||
memset(p21 + 8, 0xbd, 8);
|
||||
uchar p21[21];
|
||||
|
||||
E_P24(p21, ntlmchalresp, p24);
|
||||
memset (p21, '\0', 21);
|
||||
memcpy (p21, passwd, 8);
|
||||
memset (p21 + 8, 0xbd, 8);
|
||||
|
||||
E_P24 (p21, ntlmchalresp, p24);
|
||||
#ifdef DEBUG_PASSWORD
|
||||
DEBUG(100,("NTLMSSPOWFencrypt: p21, c8, p24\n"));
|
||||
dump_data(100, (char *)p21, 21);
|
||||
dump_data(100, (char *)ntlmchalresp, 8);
|
||||
dump_data(100, (char *)p24, 24);
|
||||
DEBUG (100, ("NTLMSSPOWFencrypt: p21, c8, p24\n"));
|
||||
dump_data (100, (char *) p21, 21);
|
||||
dump_data (100, (char *) ntlmchalresp, 8);
|
||||
dump_data (100, (char *) p24, 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Does the NT MD4 hash then des encryption. */
|
||||
|
||||
void SMBNTencrypt(uchar *passwd, uchar *c8, uchar *p24)
|
||||
|
||||
void
|
||||
SMBNTencrypt (uchar * passwd, uchar * c8, uchar * p24)
|
||||
{
|
||||
uchar p21[21];
|
||||
|
||||
memset(p21,'\0',21);
|
||||
|
||||
E_md4hash(passwd, p21);
|
||||
SMBOWFencrypt(p21, c8, p24);
|
||||
uchar p21[21];
|
||||
|
||||
memset (p21, '\0', 21);
|
||||
|
||||
E_md4hash (passwd, p21);
|
||||
SMBOWFencrypt (p21, c8, p24);
|
||||
|
||||
#ifdef DEBUG_PASSWORD
|
||||
DEBUG(100,("SMBNTencrypt: nt#, challenge, response\n"));
|
||||
dump_data(100, (char *)p21, 16);
|
||||
dump_data(100, (char *)c8, 8);
|
||||
dump_data(100, (char *)p24, 24);
|
||||
DEBUG (100, ("SMBNTencrypt: nt#, challenge, response\n"));
|
||||
dump_data (100, (char *) p21, 16);
|
||||
dump_data (100, (char *) c8, 8);
|
||||
dump_data (100, (char *) p24, 24);
|
||||
#endif
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
*/
|
||||
|
||||
#define NO_SYSLOG
|
||||
|
||||
@ -34,153 +34,170 @@ extern int DEBUGLEVEL;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *name;
|
||||
int code;
|
||||
const char *message;
|
||||
const char *name;
|
||||
int code;
|
||||
const char *message;
|
||||
} err_code_struct;
|
||||
|
||||
/* Dos Error Messages */
|
||||
static err_code_struct const dos_msgs[] = {
|
||||
{"ERRbadfunc",1,"Invalid function."},
|
||||
{"ERRbadfile",2,"File not found."},
|
||||
{"ERRbadpath",3,"Directory invalid."},
|
||||
{"ERRnofids",4,"No file descriptors available"},
|
||||
{"ERRnoaccess",5,"Access denied."},
|
||||
{"ERRbadfid",6,"Invalid file handle."},
|
||||
{"ERRbadmcb",7,"Memory control blocks destroyed."},
|
||||
{"ERRnomem",8,"Insufficient server memory to perform the requested function."},
|
||||
{"ERRbadmem",9,"Invalid memory block address."},
|
||||
{"ERRbadenv",10,"Invalid environment."},
|
||||
{"ERRbadformat",11,"Invalid format."},
|
||||
{"ERRbadaccess",12,"Invalid open mode."},
|
||||
{"ERRbaddata",13,"Invalid data."},
|
||||
{"ERR",14,"reserved."},
|
||||
{"ERRbaddrive",15,"Invalid drive specified."},
|
||||
{"ERRremcd",16,"A Delete Directory request attempted to remove the server's current directory."},
|
||||
{"ERRdiffdevice",17,"Not same device."},
|
||||
{"ERRnofiles",18,"A File Search command can find no more files matching the specified criteria."},
|
||||
{"ERRbadshare",32,"The sharing mode specified for an Open conflicts with existing FIDs on the file."},
|
||||
{"ERRlock",33,"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."},
|
||||
{"ERRunsup", 50, "The operation is unsupported"},
|
||||
{"ERRnosuchshare", 67, "You specified an invalid share name"},
|
||||
{"ERRfilexists",80,"The file named in a Create Directory, Make New File or Link request already exists."},
|
||||
{"ERRbadpipe",230,"Pipe invalid."},
|
||||
{"ERRpipebusy",231,"All instances of the requested pipe are busy."},
|
||||
{"ERRpipeclosing",232,"Pipe close in progress."},
|
||||
{"ERRnotconnected",233,"No process on other end of pipe."},
|
||||
{"ERRmoredata",234,"There is more data to be returned."},
|
||||
{"ERRinvgroup",2455,"Invalid workgroup (try the -W option)"},
|
||||
{NULL,-1,NULL}};
|
||||
{"ERRbadfunc", 1, "Invalid function."},
|
||||
{"ERRbadfile", 2, "File not found."},
|
||||
{"ERRbadpath", 3, "Directory invalid."},
|
||||
{"ERRnofids", 4, "No file descriptors available"},
|
||||
{"ERRnoaccess", 5, "Access denied."},
|
||||
{"ERRbadfid", 6, "Invalid file handle."},
|
||||
{"ERRbadmcb", 7, "Memory control blocks destroyed."},
|
||||
{"ERRnomem", 8, "Insufficient server memory to perform the requested function."},
|
||||
{"ERRbadmem", 9, "Invalid memory block address."},
|
||||
{"ERRbadenv", 10, "Invalid environment."},
|
||||
{"ERRbadformat", 11, "Invalid format."},
|
||||
{"ERRbadaccess", 12, "Invalid open mode."},
|
||||
{"ERRbaddata", 13, "Invalid data."},
|
||||
{"ERR", 14, "reserved."},
|
||||
{"ERRbaddrive", 15, "Invalid drive specified."},
|
||||
{"ERRremcd", 16,
|
||||
"A Delete Directory request attempted to remove the server's current directory."},
|
||||
{"ERRdiffdevice", 17, "Not same device."},
|
||||
{"ERRnofiles", 18,
|
||||
"A File Search command can find no more files matching the specified criteria."},
|
||||
{"ERRbadshare", 32,
|
||||
"The sharing mode specified for an Open conflicts with existing FIDs on the file."},
|
||||
{"ERRlock", 33,
|
||||
"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."},
|
||||
{"ERRunsup", 50, "The operation is unsupported"},
|
||||
{"ERRnosuchshare", 67, "You specified an invalid share name"},
|
||||
{"ERRfilexists", 80,
|
||||
"The file named in a Create Directory, Make New File or Link request already exists."},
|
||||
{"ERRbadpipe", 230, "Pipe invalid."},
|
||||
{"ERRpipebusy", 231, "All instances of the requested pipe are busy."},
|
||||
{"ERRpipeclosing", 232, "Pipe close in progress."},
|
||||
{"ERRnotconnected", 233, "No process on other end of pipe."},
|
||||
{"ERRmoredata", 234, "There is more data to be returned."},
|
||||
{"ERRinvgroup", 2455, "Invalid workgroup (try the -W option)"},
|
||||
{NULL, -1, NULL}
|
||||
};
|
||||
|
||||
/* Server Error Messages */
|
||||
static err_code_struct const server_msgs[] = {
|
||||
{"ERRerror",1,"Non-specific error code."},
|
||||
{"ERRbadpw",2,"Bad password - name/password pair in a Tree Connect or Session Setup are invalid."},
|
||||
{"ERRbadtype",3,"reserved."},
|
||||
{"ERRaccess",4,"The requester does not have the necessary access rights within the specified context for the requested function. The context is defined by the TID or the UID."},
|
||||
{"ERRinvnid",5,"The tree ID (TID) specified in a command was invalid."},
|
||||
{"ERRinvnetname",6,"Invalid network name in tree connect."},
|
||||
{"ERRinvdevice",7,"Invalid device - printer request made to non-printer connection or non-printer request made to printer connection."},
|
||||
{"ERRqfull",49,"Print queue full (files) -- returned by open print file."},
|
||||
{"ERRqtoobig",50,"Print queue full -- no space."},
|
||||
{"ERRqeof",51,"EOF on print queue dump."},
|
||||
{"ERRinvpfid",52,"Invalid print file FID."},
|
||||
{"ERRsmbcmd",64,"The server did not recognize the command received."},
|
||||
{"ERRsrverror",65,"The server encountered an internal error, e.g., system file unavailable."},
|
||||
{"ERRfilespecs",67,"The file handle (FID) and pathname parameters contained an invalid combination of values."},
|
||||
{"ERRreserved",68,"reserved."},
|
||||
{"ERRbadpermits",69,"The access permissions specified for a file or directory are not a valid combination. The server cannot set the requested attribute."},
|
||||
{"ERRreserved",70,"reserved."},
|
||||
{"ERRsetattrmode",71,"The attribute mode in the Set File Attribute request is invalid."},
|
||||
{"ERRpaused",81,"Server is paused."},
|
||||
{"ERRmsgoff",82,"Not receiving messages."},
|
||||
{"ERRnoroom",83,"No room to buffer message."},
|
||||
{"ERRrmuns",87,"Too many remote user names."},
|
||||
{"ERRtimeout",88,"Operation timed out."},
|
||||
{"ERRnoresource",89,"No resources currently available for request."},
|
||||
{"ERRtoomanyuids",90,"Too many UIDs active on this session."},
|
||||
{"ERRbaduid",91,"The UID is not known as a valid ID on this session."},
|
||||
{"ERRusempx",250,"Temp unable to support Raw, use MPX mode."},
|
||||
{"ERRusestd",251,"Temp unable to support Raw, use standard read/write."},
|
||||
{"ERRcontmpx",252,"Continue in MPX mode."},
|
||||
{"ERRreserved",253,"reserved."},
|
||||
{"ERRreserved",254,"reserved."},
|
||||
{"ERRnosupport",0xFFFF,"Function not supported."},
|
||||
{NULL,-1,NULL}};
|
||||
{"ERRerror", 1, "Non-specific error code."},
|
||||
{"ERRbadpw", 2,
|
||||
"Bad password - name/password pair in a Tree Connect or Session Setup are invalid."},
|
||||
{"ERRbadtype", 3, "reserved."},
|
||||
{"ERRaccess", 4,
|
||||
"The requester does not have the necessary access rights within the specified context for the requested function. The context is defined by the TID or the UID."},
|
||||
{"ERRinvnid", 5, "The tree ID (TID) specified in a command was invalid."},
|
||||
{"ERRinvnetname", 6, "Invalid network name in tree connect."},
|
||||
{"ERRinvdevice", 7,
|
||||
"Invalid device - printer request made to non-printer connection or non-printer request made to printer connection."},
|
||||
{"ERRqfull", 49, "Print queue full (files) -- returned by open print file."},
|
||||
{"ERRqtoobig", 50, "Print queue full -- no space."},
|
||||
{"ERRqeof", 51, "EOF on print queue dump."},
|
||||
{"ERRinvpfid", 52, "Invalid print file FID."},
|
||||
{"ERRsmbcmd", 64, "The server did not recognize the command received."},
|
||||
{"ERRsrverror", 65, "The server encountered an internal error, e.g., system file unavailable."},
|
||||
{"ERRfilespecs", 67,
|
||||
"The file handle (FID) and pathname parameters contained an invalid combination of values."},
|
||||
{"ERRreserved", 68, "reserved."},
|
||||
{"ERRbadpermits", 69,
|
||||
"The access permissions specified for a file or directory are not a valid combination. The server cannot set the requested attribute."},
|
||||
{"ERRreserved", 70, "reserved."},
|
||||
{"ERRsetattrmode", 71, "The attribute mode in the Set File Attribute request is invalid."},
|
||||
{"ERRpaused", 81, "Server is paused."},
|
||||
{"ERRmsgoff", 82, "Not receiving messages."},
|
||||
{"ERRnoroom", 83, "No room to buffer message."},
|
||||
{"ERRrmuns", 87, "Too many remote user names."},
|
||||
{"ERRtimeout", 88, "Operation timed out."},
|
||||
{"ERRnoresource", 89, "No resources currently available for request."},
|
||||
{"ERRtoomanyuids", 90, "Too many UIDs active on this session."},
|
||||
{"ERRbaduid", 91, "The UID is not known as a valid ID on this session."},
|
||||
{"ERRusempx", 250, "Temp unable to support Raw, use MPX mode."},
|
||||
{"ERRusestd", 251, "Temp unable to support Raw, use standard read/write."},
|
||||
{"ERRcontmpx", 252, "Continue in MPX mode."},
|
||||
{"ERRreserved", 253, "reserved."},
|
||||
{"ERRreserved", 254, "reserved."},
|
||||
{"ERRnosupport", 0xFFFF, "Function not supported."},
|
||||
{NULL, -1, NULL}
|
||||
};
|
||||
|
||||
/* Hard Error Messages */
|
||||
static err_code_struct const hard_msgs[] = {
|
||||
{"ERRnowrite",19,"Attempt to write on write-protected diskette."},
|
||||
{"ERRbadunit",20,"Unknown unit."},
|
||||
{"ERRnotready",21,"Drive not ready."},
|
||||
{"ERRbadcmd",22,"Unknown command."},
|
||||
{"ERRdata",23,"Data error (CRC)."},
|
||||
{"ERRbadreq",24,"Bad request structure length."},
|
||||
{"ERRseek",25 ,"Seek error."},
|
||||
{"ERRbadmedia",26,"Unknown media type."},
|
||||
{"ERRbadsector",27,"Sector not found."},
|
||||
{"ERRnopaper",28,"Printer out of paper."},
|
||||
{"ERRwrite",29,"Write fault."},
|
||||
{"ERRread",30,"Read fault."},
|
||||
{"ERRgeneral",31,"General failure."},
|
||||
{"ERRbadshare",32,"An open conflicts with an existing open."},
|
||||
{"ERRlock",33,"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."},
|
||||
{"ERRwrongdisk",34,"The wrong disk was found in a drive."},
|
||||
{"ERRFCBUnavail",35,"No FCBs are available to process request."},
|
||||
{"ERRsharebufexc",36,"A sharing buffer has been exceeded."},
|
||||
{NULL,-1,NULL}};
|
||||
{"ERRnowrite", 19, "Attempt to write on write-protected diskette."},
|
||||
{"ERRbadunit", 20, "Unknown unit."},
|
||||
{"ERRnotready", 21, "Drive not ready."},
|
||||
{"ERRbadcmd", 22, "Unknown command."},
|
||||
{"ERRdata", 23, "Data error (CRC)."},
|
||||
{"ERRbadreq", 24, "Bad request structure length."},
|
||||
{"ERRseek", 25, "Seek error."},
|
||||
{"ERRbadmedia", 26, "Unknown media type."},
|
||||
{"ERRbadsector", 27, "Sector not found."},
|
||||
{"ERRnopaper", 28, "Printer out of paper."},
|
||||
{"ERRwrite", 29, "Write fault."},
|
||||
{"ERRread", 30, "Read fault."},
|
||||
{"ERRgeneral", 31, "General failure."},
|
||||
{"ERRbadshare", 32, "An open conflicts with an existing open."},
|
||||
{"ERRlock", 33,
|
||||
"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."},
|
||||
{"ERRwrongdisk", 34, "The wrong disk was found in a drive."},
|
||||
{"ERRFCBUnavail", 35, "No FCBs are available to process request."},
|
||||
{"ERRsharebufexc", 36, "A sharing buffer has been exceeded."},
|
||||
{NULL, -1, NULL}
|
||||
};
|
||||
|
||||
|
||||
struct
|
||||
{
|
||||
int code;
|
||||
const char *class;
|
||||
err_code_struct const *err_msgs;
|
||||
} const err_classes [] = {
|
||||
{0,"SUCCESS",NULL},
|
||||
{0x01,"ERRDOS",dos_msgs},
|
||||
{0x02,"ERRSRV",server_msgs},
|
||||
{0x03,"ERRHRD",hard_msgs},
|
||||
{0x04,"ERRXOS",NULL},
|
||||
{0xE1,"ERRRMX1",NULL},
|
||||
{0xE2,"ERRRMX2",NULL},
|
||||
{0xE3,"ERRRMX3",NULL},
|
||||
{0xFF,"ERRCMD",NULL},
|
||||
{-1,NULL,NULL}};
|
||||
int code;
|
||||
const char *class;
|
||||
err_code_struct const *err_msgs;
|
||||
} const err_classes[] = {
|
||||
{0, "SUCCESS", NULL},
|
||||
{0x01, "ERRDOS", dos_msgs},
|
||||
{0x02, "ERRSRV", server_msgs},
|
||||
{0x03, "ERRHRD", hard_msgs},
|
||||
{0x04, "ERRXOS", NULL},
|
||||
{0xE1, "ERRRMX1", NULL},
|
||||
{0xE2, "ERRRMX2", NULL},
|
||||
{0xE3, "ERRRMX3", NULL},
|
||||
{0xFF, "ERRCMD", NULL},
|
||||
{-1, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
return a SMB error string from a SMB buffer
|
||||
****************************************************************************/
|
||||
char *smb_errstr(char *inbuf)
|
||||
char *
|
||||
smb_errstr (char *inbuf)
|
||||
{
|
||||
static pstring ret;
|
||||
int class = CVAL(inbuf,smb_rcls);
|
||||
int num = SVAL(inbuf,smb_err);
|
||||
int i,j;
|
||||
static pstring ret;
|
||||
int class = CVAL (inbuf, smb_rcls);
|
||||
int num = SVAL (inbuf, smb_err);
|
||||
int i, j;
|
||||
|
||||
for (i=0;err_classes[i].class;i++)
|
||||
if (err_classes[i].code == class)
|
||||
{
|
||||
if (err_classes[i].err_msgs)
|
||||
{
|
||||
const err_code_struct *err = err_classes[i].err_msgs;
|
||||
for (j=0;err[j].name;j++)
|
||||
if (num == err[j].code)
|
||||
{
|
||||
if (DEBUGLEVEL > 0)
|
||||
slprintf(ret, sizeof(ret) - 1, "%s - %s (%s)",err_classes[i].class,
|
||||
err[j].name,err[j].message);
|
||||
else
|
||||
slprintf(ret, sizeof(ret) - 1, "%s - %s",err_classes[i].class,err[j].name);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
for (i = 0; err_classes[i].class; i++)
|
||||
if (err_classes[i].code == class)
|
||||
{
|
||||
if (err_classes[i].err_msgs)
|
||||
{
|
||||
const err_code_struct *err = err_classes[i].err_msgs;
|
||||
for (j = 0; err[j].name; j++)
|
||||
if (num == err[j].code)
|
||||
{
|
||||
if (DEBUGLEVEL > 0)
|
||||
slprintf (ret, sizeof (ret) - 1, "%s - %s (%s)", err_classes[i].class,
|
||||
err[j].name, err[j].message);
|
||||
else
|
||||
slprintf (ret, sizeof (ret) - 1, "%s - %s", err_classes[i].class,
|
||||
err[j].name);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
slprintf(ret, sizeof(ret) - 1, "%s - %d",err_classes[i].class,num);
|
||||
return ret;
|
||||
}
|
||||
|
||||
slprintf(ret, sizeof(ret) - 1, "Error: Unknown error (%d,%d)",class,num);
|
||||
return(ret);
|
||||
slprintf (ret, sizeof (ret) - 1, "%s - %d", err_classes[i].class, num);
|
||||
return ret;
|
||||
}
|
||||
|
||||
slprintf (ret, sizeof (ret) - 1, "Error: Unknown error (%d,%d)", class, num);
|
||||
return (ret);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -8,22 +8,22 @@
|
||||
* This module Copyright (C) 1997-1998 by the University of Minnesota
|
||||
* -------------------------------------------------------------------------- **
|
||||
*
|
||||
This file is part of the Midnight Commander.
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
The Midnight Commander 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.
|
||||
The Midnight Commander 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.
|
||||
|
||||
The Midnight Commander 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.
|
||||
The Midnight Commander 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/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------------------------- **
|
||||
@ -105,14 +105,15 @@ const char *unix_error_string (int error_num);
|
||||
|
||||
extern int DEBUGLEVEL;
|
||||
|
||||
static char *bufr = NULL;
|
||||
static int bSize = 0;
|
||||
static char *bufr = NULL;
|
||||
static int bSize = 0;
|
||||
|
||||
/* -------------------------------------------------------------------------- **
|
||||
* Functions...
|
||||
*/
|
||||
|
||||
static int EatWhitespace( FILE *InFile )
|
||||
static int
|
||||
EatWhitespace (FILE * InFile)
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Scan past whitespace (see ctype(3C)) and return the first non-whitespace
|
||||
* character, or newline, or EOF.
|
||||
@ -129,15 +130,16 @@ static int EatWhitespace( FILE *InFile )
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
{
|
||||
int c;
|
||||
{
|
||||
int c;
|
||||
|
||||
for( c = getc( InFile ); isspace( c ) && ('\n' != c); c = getc( InFile ) )
|
||||
;
|
||||
return( c );
|
||||
} /* EatWhitespace */
|
||||
for (c = getc (InFile); isspace (c) && ('\n' != c); c = getc (InFile))
|
||||
;
|
||||
return (c);
|
||||
} /* EatWhitespace */
|
||||
|
||||
static int EatComment( FILE *InFile )
|
||||
static int
|
||||
EatComment (FILE * InFile)
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Scan to the end of a comment.
|
||||
*
|
||||
@ -154,15 +156,16 @@ static int EatComment( FILE *InFile )
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
{
|
||||
int c;
|
||||
{
|
||||
int c;
|
||||
|
||||
for( c = getc( InFile ); ('\n'!=c) && (EOF!=c) && (c>0); c = getc( InFile ) )
|
||||
;
|
||||
return( c );
|
||||
} /* EatComment */
|
||||
for (c = getc (InFile); ('\n' != c) && (EOF != c) && (c > 0); c = getc (InFile))
|
||||
;
|
||||
return (c);
|
||||
} /* EatComment */
|
||||
|
||||
static int Continuation( char *line, int pos )
|
||||
static int
|
||||
Continuation (char *line, int pos)
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Scan backards within a string to discover if the last non-whitespace
|
||||
* character is a line-continuation character ('\\').
|
||||
@ -177,16 +180,17 @@ static int Continuation( char *line, int pos )
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
{
|
||||
pos--;
|
||||
while( (pos >= 0) && isspace(line[pos]) )
|
||||
pos--;
|
||||
{
|
||||
pos--;
|
||||
while ((pos >= 0) && isspace (line[pos]))
|
||||
pos--;
|
||||
|
||||
return( ((pos >= 0) && ('\\' == line[pos])) ? pos : -1 );
|
||||
} /* Continuation */
|
||||
return (((pos >= 0) && ('\\' == line[pos])) ? pos : -1);
|
||||
} /* Continuation */
|
||||
|
||||
|
||||
static BOOL Section( FILE *InFile, BOOL (*sfunc)(const char *) )
|
||||
static BOOL
|
||||
Section (FILE * InFile, BOOL (*sfunc) (const char *))
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Scan a section name, and pass the name to function sfunc().
|
||||
*
|
||||
@ -200,86 +204,86 @@ static BOOL Section( FILE *InFile, BOOL (*sfunc)(const char *) )
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
{
|
||||
int c;
|
||||
int i;
|
||||
int end;
|
||||
const char *func = "params.c:Section() -";
|
||||
{
|
||||
int c;
|
||||
int i;
|
||||
int end;
|
||||
const char *func = "params.c:Section() -";
|
||||
|
||||
i = 0; /* <i> is the offset of the next free byte in bufr[] and */
|
||||
end = 0; /* <end> is the current "end of string" offset. In most */
|
||||
/* cases these will be the same, but if the last */
|
||||
/* character written to bufr[] is a space, then <end> */
|
||||
/* will be one less than <i>. */
|
||||
i = 0; /* <i> is the offset of the next free byte in bufr[] and */
|
||||
end = 0; /* <end> is the current "end of string" offset. In most */
|
||||
/* cases these will be the same, but if the last */
|
||||
/* character written to bufr[] is a space, then <end> */
|
||||
/* will be one less than <i>. */
|
||||
|
||||
c = EatWhitespace( InFile ); /* We've already got the '['. Scan */
|
||||
/* past initial white space. */
|
||||
c = EatWhitespace (InFile); /* We've already got the '['. Scan */
|
||||
/* past initial white space. */
|
||||
|
||||
while( (EOF != c) && (c > 0) )
|
||||
while ((EOF != c) && (c > 0))
|
||||
{
|
||||
|
||||
/* Check that the buffer is big enough for the next character. */
|
||||
if( i > (bSize - 2) )
|
||||
{
|
||||
bSize += BUFR_INC;
|
||||
bufr = Realloc( bufr, bSize );
|
||||
if( NULL == bufr )
|
||||
/* Check that the buffer is big enough for the next character. */
|
||||
if (i > (bSize - 2))
|
||||
{
|
||||
DEBUG(0, ("%s Memory re-allocation failure.", func) );
|
||||
return( False );
|
||||
bSize += BUFR_INC;
|
||||
bufr = Realloc (bufr, bSize);
|
||||
if (NULL == bufr)
|
||||
{
|
||||
DEBUG (0, ("%s Memory re-allocation failure.", func));
|
||||
return (False);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle a single character. */
|
||||
switch( c )
|
||||
{
|
||||
case ']': /* Found the closing bracket. */
|
||||
bufr[end] = '\0';
|
||||
if( 0 == end ) /* Don't allow an empty name. */
|
||||
{
|
||||
DEBUG(0, ("%s Empty section name in configuration file.\n", func ));
|
||||
return( False );
|
||||
}
|
||||
if( !sfunc( bufr ) ) /* Got a valid name. Deal with it. */
|
||||
return( False );
|
||||
(void)EatComment( InFile ); /* Finish off the line. */
|
||||
return( True );
|
||||
/* Handle a single character. */
|
||||
switch (c)
|
||||
{
|
||||
case ']': /* Found the closing bracket. */
|
||||
bufr[end] = '\0';
|
||||
if (0 == end) /* Don't allow an empty name. */
|
||||
{
|
||||
DEBUG (0, ("%s Empty section name in configuration file.\n", func));
|
||||
return (False);
|
||||
}
|
||||
if (!sfunc (bufr)) /* Got a valid name. Deal with it. */
|
||||
return (False);
|
||||
(void) EatComment (InFile); /* Finish off the line. */
|
||||
return (True);
|
||||
|
||||
case '\n': /* Got newline before closing ']'. */
|
||||
i = Continuation( bufr, i ); /* Check for line continuation. */
|
||||
if( i < 0 )
|
||||
{
|
||||
bufr[end] = '\0';
|
||||
DEBUG(0, ("%s Badly formed line in configuration file: %s\n",
|
||||
func, bufr ));
|
||||
return( False );
|
||||
}
|
||||
end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i);
|
||||
c = getc( InFile ); /* Continue with next line. */
|
||||
break;
|
||||
case '\n': /* Got newline before closing ']'. */
|
||||
i = Continuation (bufr, i); /* Check for line continuation. */
|
||||
if (i < 0)
|
||||
{
|
||||
bufr[end] = '\0';
|
||||
DEBUG (0, ("%s Badly formed line in configuration file: %s\n", func, bufr));
|
||||
return (False);
|
||||
}
|
||||
end = ((i > 0) && (' ' == bufr[i - 1])) ? (i - 1) : (i);
|
||||
c = getc (InFile); /* Continue with next line. */
|
||||
break;
|
||||
|
||||
default: /* All else are a valid name chars. */
|
||||
if( isspace( c ) ) /* One space per whitespace region. */
|
||||
{
|
||||
bufr[end] = ' ';
|
||||
i = end + 1;
|
||||
c = EatWhitespace( InFile );
|
||||
}
|
||||
else /* All others copy verbatim. */
|
||||
{
|
||||
bufr[i++] = c;
|
||||
end = i;
|
||||
c = getc( InFile );
|
||||
}
|
||||
}
|
||||
default: /* All else are a valid name chars. */
|
||||
if (isspace (c)) /* One space per whitespace region. */
|
||||
{
|
||||
bufr[end] = ' ';
|
||||
i = end + 1;
|
||||
c = EatWhitespace (InFile);
|
||||
}
|
||||
else /* All others copy verbatim. */
|
||||
{
|
||||
bufr[i++] = c;
|
||||
end = i;
|
||||
c = getc (InFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* We arrive here if we've met the EOF before the closing bracket. */
|
||||
DEBUG(0, ("%s Unexpected EOF in the configuration file: %s\n", func, bufr ));
|
||||
return( False );
|
||||
} /* Section */
|
||||
/* We arrive here if we've met the EOF before the closing bracket. */
|
||||
DEBUG (0, ("%s Unexpected EOF in the configuration file: %s\n", func, bufr));
|
||||
return (False);
|
||||
} /* Section */
|
||||
|
||||
static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(const char *, const char *), int c )
|
||||
static BOOL
|
||||
Parameter (FILE * InFile, BOOL (*pfunc) (const char *, const char *), int c)
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Scan a parameter name and value, and pass these two fields to pfunc().
|
||||
*
|
||||
@ -303,126 +307,125 @@ static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(const char *, const char *),
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
{
|
||||
int i = 0; /* Position within bufr. */
|
||||
int end = 0; /* bufr[end] is current end-of-string. */
|
||||
int vstart = 0; /* Starting position of the parameter value. */
|
||||
const char *func = "params.c:Parameter() -";
|
||||
{
|
||||
int i = 0; /* Position within bufr. */
|
||||
int end = 0; /* bufr[end] is current end-of-string. */
|
||||
int vstart = 0; /* Starting position of the parameter value. */
|
||||
const char *func = "params.c:Parameter() -";
|
||||
|
||||
/* Read the parameter name. */
|
||||
while( 0 == vstart ) /* Loop until we've found the start of the value. */
|
||||
/* Read the parameter name. */
|
||||
while (0 == vstart) /* Loop until we've found the start of the value. */
|
||||
{
|
||||
|
||||
if( i > (bSize - 2) ) /* Ensure there's space for next char. */
|
||||
{
|
||||
bSize += BUFR_INC;
|
||||
bufr = Realloc( bufr, bSize );
|
||||
if( NULL == bufr )
|
||||
if (i > (bSize - 2)) /* Ensure there's space for next char. */
|
||||
{
|
||||
DEBUG(0, ("%s Memory re-allocation failure.", func) );
|
||||
return( False );
|
||||
bSize += BUFR_INC;
|
||||
bufr = Realloc (bufr, bSize);
|
||||
if (NULL == bufr)
|
||||
{
|
||||
DEBUG (0, ("%s Memory re-allocation failure.", func));
|
||||
return (False);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch( c )
|
||||
{
|
||||
case '=': /* Equal sign marks end of param name. */
|
||||
if( 0 == end ) /* Don't allow an empty name. */
|
||||
{
|
||||
DEBUG(0, ("%s Invalid parameter name in config. file.\n", func ));
|
||||
return( False );
|
||||
}
|
||||
bufr[end++] = '\0'; /* Mark end of string & advance. */
|
||||
i = end; /* New string starts here. */
|
||||
vstart = end; /* New string is parameter value. */
|
||||
bufr[i] = '\0'; /* New string is nul, for now. */
|
||||
break;
|
||||
switch (c)
|
||||
{
|
||||
case '=': /* Equal sign marks end of param name. */
|
||||
if (0 == end) /* Don't allow an empty name. */
|
||||
{
|
||||
DEBUG (0, ("%s Invalid parameter name in config. file.\n", func));
|
||||
return (False);
|
||||
}
|
||||
bufr[end++] = '\0'; /* Mark end of string & advance. */
|
||||
i = end; /* New string starts here. */
|
||||
vstart = end; /* New string is parameter value. */
|
||||
bufr[i] = '\0'; /* New string is nul, for now. */
|
||||
break;
|
||||
|
||||
case '\n': /* Find continuation char, else error. */
|
||||
i = Continuation( bufr, i );
|
||||
if( i < 0 )
|
||||
{
|
||||
bufr[end] = '\0';
|
||||
DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n",
|
||||
func, bufr ));
|
||||
return( True );
|
||||
}
|
||||
end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i);
|
||||
c = getc( InFile ); /* Read past eoln. */
|
||||
break;
|
||||
case '\n': /* Find continuation char, else error. */
|
||||
i = Continuation (bufr, i);
|
||||
if (i < 0)
|
||||
{
|
||||
bufr[end] = '\0';
|
||||
DEBUG (1, ("%s Ignoring badly formed line in configuration file: %s\n",
|
||||
func, bufr));
|
||||
return (True);
|
||||
}
|
||||
end = ((i > 0) && (' ' == bufr[i - 1])) ? (i - 1) : (i);
|
||||
c = getc (InFile); /* Read past eoln. */
|
||||
break;
|
||||
|
||||
case '\0': /* Shouldn't have EOF within param name. */
|
||||
case EOF:
|
||||
bufr[i] = '\0';
|
||||
DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, bufr ));
|
||||
return( True );
|
||||
case '\0': /* Shouldn't have EOF within param name. */
|
||||
case EOF:
|
||||
bufr[i] = '\0';
|
||||
DEBUG (1, ("%s Unexpected end-of-file at: %s\n", func, bufr));
|
||||
return (True);
|
||||
|
||||
default:
|
||||
if( isspace( c ) ) /* One ' ' per whitespace region. */
|
||||
{
|
||||
bufr[end] = ' ';
|
||||
i = end + 1;
|
||||
c = EatWhitespace( InFile );
|
||||
}
|
||||
else /* All others verbatim. */
|
||||
{
|
||||
bufr[i++] = c;
|
||||
end = i;
|
||||
c = getc( InFile );
|
||||
}
|
||||
}
|
||||
default:
|
||||
if (isspace (c)) /* One ' ' per whitespace region. */
|
||||
{
|
||||
bufr[end] = ' ';
|
||||
i = end + 1;
|
||||
c = EatWhitespace (InFile);
|
||||
}
|
||||
else /* All others verbatim. */
|
||||
{
|
||||
bufr[i++] = c;
|
||||
end = i;
|
||||
c = getc (InFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Now parse the value. */
|
||||
c = EatWhitespace( InFile ); /* Again, trim leading whitespace. */
|
||||
while( (EOF !=c) && (c > 0) )
|
||||
/* Now parse the value. */
|
||||
c = EatWhitespace (InFile); /* Again, trim leading whitespace. */
|
||||
while ((EOF != c) && (c > 0))
|
||||
{
|
||||
|
||||
if( i > (bSize - 2) ) /* Make sure there's enough room. */
|
||||
{
|
||||
bSize += BUFR_INC;
|
||||
bufr = Realloc( bufr, bSize );
|
||||
if( NULL == bufr )
|
||||
if (i > (bSize - 2)) /* Make sure there's enough room. */
|
||||
{
|
||||
DEBUG(0, ("%s Memory re-allocation failure.", func) );
|
||||
return( False );
|
||||
bSize += BUFR_INC;
|
||||
bufr = Realloc (bufr, bSize);
|
||||
if (NULL == bufr)
|
||||
{
|
||||
DEBUG (0, ("%s Memory re-allocation failure.", func));
|
||||
return (False);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch( c )
|
||||
{
|
||||
case '\r': /* Explicitly remove '\r' because the older */
|
||||
c = getc( InFile ); /* version called fgets_slash() which also */
|
||||
break; /* removes them. */
|
||||
switch (c)
|
||||
{
|
||||
case '\r': /* Explicitly remove '\r' because the older */
|
||||
c = getc (InFile); /* version called fgets_slash() which also */
|
||||
break; /* removes them. */
|
||||
|
||||
case '\n': /* Marks end of value unless there's a '\'. */
|
||||
i = Continuation( bufr, i );
|
||||
if( i < 0 )
|
||||
c = 0;
|
||||
else
|
||||
{
|
||||
for( end = i; (end >= 0) && isspace(bufr[end]); end-- )
|
||||
;
|
||||
c = getc( InFile );
|
||||
}
|
||||
break;
|
||||
case '\n': /* Marks end of value unless there's a '\'. */
|
||||
i = Continuation (bufr, i);
|
||||
if (i < 0)
|
||||
c = 0;
|
||||
else
|
||||
{
|
||||
for (end = i; (end >= 0) && isspace (bufr[end]); end--)
|
||||
;
|
||||
c = getc (InFile);
|
||||
}
|
||||
break;
|
||||
|
||||
default: /* All others verbatim. Note that spaces do */
|
||||
bufr[i++] = c; /* not advance <end>. This allows trimming */
|
||||
if( !isspace( c ) ) /* of whitespace at the end of the line. */
|
||||
end = i;
|
||||
c = getc( InFile );
|
||||
break;
|
||||
}
|
||||
default: /* All others verbatim. Note that spaces do */
|
||||
bufr[i++] = c; /* not advance <end>. This allows trimming */
|
||||
if (!isspace (c)) /* of whitespace at the end of the line. */
|
||||
end = i;
|
||||
c = getc (InFile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
bufr[end] = '\0'; /* End of value. */
|
||||
bufr[end] = '\0'; /* End of value. */
|
||||
|
||||
return( pfunc( bufr, &bufr[vstart] ) ); /* Pass name & value to pfunc(). */
|
||||
} /* Parameter */
|
||||
return (pfunc (bufr, &bufr[vstart])); /* Pass name & value to pfunc(). */
|
||||
} /* Parameter */
|
||||
|
||||
static BOOL Parse( FILE *InFile,
|
||||
BOOL (*sfunc)(const char *),
|
||||
BOOL (*pfunc)(const char *, const char *) )
|
||||
static BOOL
|
||||
Parse (FILE * InFile, BOOL (*sfunc) (const char *), BOOL (*pfunc) (const char *, const char *))
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Scan & parse the input.
|
||||
*
|
||||
@ -444,44 +447,45 @@ static BOOL Parse( FILE *InFile,
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
{
|
||||
int c;
|
||||
{
|
||||
int c;
|
||||
|
||||
c = EatWhitespace( InFile );
|
||||
while( (EOF != c) && (c > 0) )
|
||||
c = EatWhitespace (InFile);
|
||||
while ((EOF != c) && (c > 0))
|
||||
{
|
||||
switch( c )
|
||||
{
|
||||
case '\n': /* Blank line. */
|
||||
c = EatWhitespace( InFile );
|
||||
break;
|
||||
switch (c)
|
||||
{
|
||||
case '\n': /* Blank line. */
|
||||
c = EatWhitespace (InFile);
|
||||
break;
|
||||
|
||||
case ';': /* Comment line. */
|
||||
case '#':
|
||||
c = EatComment( InFile );
|
||||
break;
|
||||
case ';': /* Comment line. */
|
||||
case '#':
|
||||
c = EatComment (InFile);
|
||||
break;
|
||||
|
||||
case '[': /* Section Header. */
|
||||
if( !Section( InFile, sfunc ) )
|
||||
return( False );
|
||||
c = EatWhitespace( InFile );
|
||||
break;
|
||||
case '[': /* Section Header. */
|
||||
if (!Section (InFile, sfunc))
|
||||
return (False);
|
||||
c = EatWhitespace (InFile);
|
||||
break;
|
||||
|
||||
case '\\': /* Bogus backslash. */
|
||||
c = EatWhitespace( InFile );
|
||||
break;
|
||||
case '\\': /* Bogus backslash. */
|
||||
c = EatWhitespace (InFile);
|
||||
break;
|
||||
|
||||
default: /* Parameter line. */
|
||||
if( !Parameter( InFile, pfunc, c ) )
|
||||
return( False );
|
||||
c = EatWhitespace( InFile );
|
||||
break;
|
||||
}
|
||||
default: /* Parameter line. */
|
||||
if (!Parameter (InFile, pfunc, c))
|
||||
return (False);
|
||||
c = EatWhitespace (InFile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return( True );
|
||||
} /* Parse */
|
||||
return (True);
|
||||
} /* Parse */
|
||||
|
||||
static FILE *OpenConfFile( const char *FileName )
|
||||
static FILE *
|
||||
OpenConfFile (const char *FileName)
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Open a configuration file.
|
||||
*
|
||||
@ -492,32 +496,32 @@ static FILE *OpenConfFile( const char *FileName )
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
{
|
||||
FILE *OpenedFile;
|
||||
const char *func = "params.c:OpenConfFile() -";
|
||||
extern BOOL in_client;
|
||||
int lvl = in_client?1:0;
|
||||
{
|
||||
FILE *OpenedFile;
|
||||
const char *func = "params.c:OpenConfFile() -";
|
||||
extern BOOL in_client;
|
||||
int lvl = in_client ? 1 : 0;
|
||||
|
||||
if( NULL == FileName || 0 == *FileName )
|
||||
if (NULL == FileName || 0 == *FileName)
|
||||
{
|
||||
DEBUG( lvl, ("%s No configuration filename specified.\n", func) );
|
||||
return( NULL );
|
||||
DEBUG (lvl, ("%s No configuration filename specified.\n", func));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
OpenedFile = sys_fopen( FileName, "r" );
|
||||
if( NULL == OpenedFile )
|
||||
OpenedFile = sys_fopen (FileName, "r");
|
||||
if (NULL == OpenedFile)
|
||||
{
|
||||
DEBUG( lvl,
|
||||
("%s Unable to open configuration file \"%s\":\n\t%s\n",
|
||||
func, FileName, unix_error_string (errno)) );
|
||||
DEBUG (lvl,
|
||||
("%s Unable to open configuration file \"%s\":\n\t%s\n",
|
||||
func, FileName, unix_error_string (errno)));
|
||||
}
|
||||
|
||||
return( OpenedFile );
|
||||
} /* OpenConfFile */
|
||||
return (OpenedFile);
|
||||
} /* OpenConfFile */
|
||||
|
||||
BOOL pm_process( const char *FileName,
|
||||
BOOL (*sfunc)(const char *),
|
||||
BOOL (*pfunc)(const char *, const char *) )
|
||||
BOOL
|
||||
pm_process (const char *FileName,
|
||||
BOOL (*sfunc) (const char *), BOOL (*pfunc) (const char *, const char *))
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Process the named parameter file.
|
||||
*
|
||||
@ -531,46 +535,46 @@ BOOL pm_process( const char *FileName,
|
||||
*
|
||||
* ------------------------------------------------------------------------ **
|
||||
*/
|
||||
{
|
||||
int result;
|
||||
FILE *InFile;
|
||||
const char *func = "params.c:pm_process() -";
|
||||
{
|
||||
int result;
|
||||
FILE *InFile;
|
||||
const char *func = "params.c:pm_process() -";
|
||||
|
||||
InFile = OpenConfFile( FileName ); /* Open the config file. */
|
||||
if( NULL == InFile )
|
||||
return( False );
|
||||
InFile = OpenConfFile (FileName); /* Open the config file. */
|
||||
if (NULL == InFile)
|
||||
return (False);
|
||||
|
||||
DEBUG( 3, ("%s Processing configuration file \"%s\"\n", func, FileName) );
|
||||
DEBUG (3, ("%s Processing configuration file \"%s\"\n", func, FileName));
|
||||
|
||||
if( NULL != bufr ) /* If we already have a buffer */
|
||||
result = Parse( InFile, sfunc, pfunc ); /* (recursive call), then just */
|
||||
/* use it. */
|
||||
if (NULL != bufr) /* If we already have a buffer */
|
||||
result = Parse (InFile, sfunc, pfunc); /* (recursive call), then just */
|
||||
/* use it. */
|
||||
|
||||
else /* If we don't have a buffer */
|
||||
{ /* allocate one, then parse, */
|
||||
bSize = BUFR_INC; /* then free. */
|
||||
bufr = (char *)malloc( bSize );
|
||||
if( NULL == bufr )
|
||||
{
|
||||
DEBUG(0,("%s memory allocation failure.\n", func));
|
||||
fclose(InFile);
|
||||
return( False );
|
||||
}
|
||||
result = Parse( InFile, sfunc, pfunc );
|
||||
free( bufr );
|
||||
bufr = NULL;
|
||||
bSize = 0;
|
||||
else /* If we don't have a buffer */
|
||||
{ /* allocate one, then parse, */
|
||||
bSize = BUFR_INC; /* then free. */
|
||||
bufr = (char *) malloc (bSize);
|
||||
if (NULL == bufr)
|
||||
{
|
||||
DEBUG (0, ("%s memory allocation failure.\n", func));
|
||||
fclose (InFile);
|
||||
return (False);
|
||||
}
|
||||
result = Parse (InFile, sfunc, pfunc);
|
||||
free (bufr);
|
||||
bufr = NULL;
|
||||
bSize = 0;
|
||||
}
|
||||
|
||||
fclose(InFile);
|
||||
fclose (InFile);
|
||||
|
||||
if( !result ) /* Generic failure. */
|
||||
if (!result) /* Generic failure. */
|
||||
{
|
||||
DEBUG(0,("%s Failed. Error returned from params.c:parse().\n", func));
|
||||
return( False );
|
||||
DEBUG (0, ("%s Failed. Error returned from params.c:parse().\n", func));
|
||||
return (False);
|
||||
}
|
||||
|
||||
return( True ); /* Generic success. */
|
||||
} /* pm_process */
|
||||
return (True); /* Generic success. */
|
||||
} /* pm_process */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void init_tarfs(void);
|
||||
void init_tarfs (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void init_undelfs(void);
|
||||
void init_undelfs (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
|
@ -344,7 +344,7 @@ mcview_load_next_prev (mcview_t * view, int direction)
|
||||
view->dir_count = dir_count;
|
||||
view->dir_idx = dir_idx;
|
||||
|
||||
view->dpy_bbar_dirty = FALSE; /* FIXME */
|
||||
view->dpy_bbar_dirty = FALSE; /* FIXME */
|
||||
view->dirty++;
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define BUF_TRUNC_LEN 5 /* The length of the line displays the file size */
|
||||
#define BUF_TRUNC_LEN 5 /* The length of the line displays the file size */
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
|
@ -42,8 +42,7 @@ extern struct mcview_struct *mcview_new (int y, int x, int lines, int cols, gboo
|
||||
/* Shows {file} or the output of {command} in the internal viewer,
|
||||
* starting in line {start_line}.
|
||||
*/
|
||||
extern gboolean mcview_viewer (const char *command, const vfs_path_t * file_vpath,
|
||||
int start_line);
|
||||
extern gboolean mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_line);
|
||||
|
||||
extern gboolean mcview_load (struct mcview_struct *, const char *, const char *, int);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user