1
1
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
Slava Zanko 2012-07-06 13:56:29 +03:00 коммит произвёл Andrew Borodin
родитель 6505f7d6fa
Коммит 94bd4b1f78
85 изменённых файлов: 12974 добавлений и 11689 удалений

Просмотреть файл

@ -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, GPtrArray *mc_event_get_event_by_name (GTree * event_group, const gchar * event_name,
gboolean create_new, GError ** mcerror); gboolean create_new, GError ** mcerror);
mc_event_callback_t *mc_event_is_callback_in_array (GPtrArray * callbacks, 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 ****************************************************************************/ /*** inline functions ****************************************************************************/
#endif /* MC_EVENT_INTERNAL_H */ #endif /* MC_EVENT_INTERNAL_H */

Просмотреть файл

@ -208,7 +208,7 @@ typedef struct
/* Ugly hack in order to distinguish between left and right panel in menubar */ /* Ugly hack in order to distinguish between left and right panel in menubar */
/* Set if the command is being run from the "Right" menu */ /* 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; } widget;
struct struct

Просмотреть файл

@ -2,7 +2,7 @@
Hooks. Hooks.
Slavaz: Warning! this file is deprecated and should be replaced 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, Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2007, 2009, 2010, 2011 2004, 2005, 2007, 2009, 2010, 2011

Просмотреть файл

@ -675,7 +675,7 @@ str_utf8_term_trim (const char *text, int width)
if (width < 1) if (width < 1)
{ {
result [0] = '\0'; result[0] = '\0';
return result; return result;
} }

Просмотреть файл

@ -47,7 +47,7 @@ void tty_set_normal_attrs (void);
void tty_color_set_defaults (const char *, const char *, const char *); 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 ****************************************************************************/ /*** inline functions ****************************************************************************/
#endif /* MC_COLOR_H */ #endif /* MC_COLOR_H */

Просмотреть файл

@ -110,7 +110,7 @@ is_8bit_printable (unsigned char c)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static char * static char *
resolve_symlinks (const vfs_path_t *vpath) resolve_symlinks (const vfs_path_t * vpath)
{ {
char *p, *p2; char *p, *p2;
char *buf, *buf2, *q, *r, c; char *buf, *buf2, *q, *r, c;
@ -164,7 +164,7 @@ resolve_symlinks (const vfs_path_t *vpath)
canonicalize_pathname (buf); canonicalize_pathname (buf);
r = strchr (buf, 0); r = strchr (buf, 0);
if (!*r || *(r - 1) != PATH_SEP) 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++ = PATH_SEP;
*r = 0; *r = 0;

Просмотреть файл

@ -174,7 +174,7 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer
(void) defcnv; (void) defcnv;
g_string_assign (buffer, path); g_string_assign (buffer, path);
#endif /* HAVE_CHARSET */ #endif /* HAVE_CHARSET */
return state; return state;
} }
@ -614,7 +614,7 @@ vfs_change_encoding (vfs_path_t * vpath, const char *encoding)
return vpath; 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 */ /* outside interface */
void vfs_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub); 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); 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); 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); 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; int y = event->y;
/* close the dialog by mouse click out of dialog area */ /* close the dialog by mouse click out of dialog area */
if (mouse_close_dialog && !h->fullscreen && ((event->buttons & GPM_B_LEFT) != 0) if (mouse_close_dialog && !h->fullscreen && ((event->buttons & GPM_B_LEFT) != 0) && ((event->type & GPM_DOWN) != 0) /* left click */
&& ((event->type & GPM_DOWN) != 0) /* left click */
&& !((x > h->x) && (x <= h->x + h->cols) && (y > h->y) && (y <= h->y + h->lines))) && !((x > h->x) && (x <= h->x + h->cols) && (y > h->y) && (y <= h->y + h->lines)))
{ {
h->ret_value = B_CANCEL; 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 * Dlg_head *
create_dlg (gboolean modal, int y1, int x1, int lines, int cols, 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) const char *help_ctx, const char *title, dlg_flags_t flags)
{ {
Dlg_head *new_d; 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 */ /* read history to the mc_config, but don't save config to file */
GList *history_get (const char *input_name); GList *history_get (const char *input_name);
/* load history form the mc_config */ /* 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 */ /* 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 /* for repositioning of history dialog we should pass widget to this
* function, as position of history dialog depends on widget's position */ * function, as position of history dialog depends on widget's position */
char *history_show (GList ** history, Widget * widget, int current); char *history_show (GList ** history, Widget * widget, int current);

Просмотреть файл

@ -195,7 +195,8 @@ do_show_hist (WInput * in)
len = get_history_length (in->history); 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) if (r != NULL)
{ {
input_assign_text (in, r); input_assign_text (in, r);

Просмотреть файл

@ -123,9 +123,13 @@ listbox_draw (WListbox * l, gboolean focused)
const Dlg_head *h = l->widget.owner; const Dlg_head *h = l->widget.owner;
const gboolean disabled = (((Widget *) l)->options & W_DISABLED) != 0; const gboolean disabled = (((Widget *) l)->options & W_DISABLED) != 0;
const int normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]; const int normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL];
int selc = /* *INDENT-OFF* */
disabled ? DISABLED_COLOR : focused ? h-> int selc = disabled
color[DLG_COLOR_HOT_FOCUS] : h->color[DLG_COLOR_FOCUS]; ? DISABLED_COLOR
: focused
? h->color[DLG_COLOR_HOT_FOCUS]
: h->color[DLG_COLOR_FOCUS];
/* *INDENT-ON* */
GList *le; GList *le;
int pos; int pos;

Просмотреть файл

@ -77,8 +77,7 @@ quick_dialog_skip (QuickDialog * qd, int nskip)
DLG_CENTER | DLG_TRYUP | DLG_REVERSE); DLG_CENTER | DLG_TRYUP | DLG_REVERSE);
else else
dd = create_dlg (TRUE, qd->ypos, qd->xpos, qd->ylen, qd->xlen, dd = create_dlg (TRUE, qd->ypos, qd->xpos, qd->ylen, qd->xlen,
dialog_colors, qd->callback, qd->mouse, qd->help, qd->title, dialog_colors, qd->callback, qd->mouse, qd->help, qd->title, DLG_REVERSE);
DLG_REVERSE);
for (qw = qd->widgets; qw->widget_type != quick_end; qw++) 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++) for (i = 0; i < screen_shot.xsize * screen_shot.ysize; i++)
{ {
screen_shot.buf[i] = /* *INDENT-OFF* */
(screen_shot.buf[i] & 0xff00) | (unsigned char) revmap. screen_shot.buf[i] = (screen_shot.buf[i] & 0xff00)
scrmap[screen_shot.buf[i] & 0xff]; | (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, int edit_insert_column_of_text_from_file (WEdit * edit, int file,
long *start_pos, long *end_pos, int *col1, int *col2); 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); long edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath);
gboolean edit_load_back_cmd (WEdit * edit); gboolean edit_load_back_cmd (WEdit * edit);
gboolean edit_load_forward_cmd (WEdit * edit); gboolean edit_load_forward_cmd (WEdit * edit);

Просмотреть файл

@ -2001,7 +2001,7 @@ is_break_char (char c)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
char * 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 word_start;
long cut_len = 0; long cut_len = 0;

Просмотреть файл

@ -504,7 +504,7 @@ edit_save_cmd (WEdit * edit)
*/ */
static inline gboolean 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); 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); vfs_path_free (menufile_vpath);
menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, EDIT_GLOBAL_MENU, NULL); menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, EDIT_GLOBAL_MENU, NULL);
} }
switch (dir) switch (dir)
{ {
@ -2171,7 +2171,7 @@ edit_load_menu_file (Dlg_head * h)
} }
break; break;
default: default:
vfs_path_free (menufile_vpath); vfs_path_free (menufile_vpath);
return FALSE; return FALSE;
} }
@ -3699,6 +3699,6 @@ edit_set_spell_lang (void)
} }
aspell_array_clean (lang_list); 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 **); 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); 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)); menu_entry_create (_("Record/Repeat &actions"), CK_RepeatStartStopRecord));
entries = g_list_prepend (entries, menu_separator_create ()); entries = g_list_prepend (entries, menu_separator_create ());
#ifdef HAVE_ASPELL #ifdef HAVE_ASPELL
entries = entries = g_list_prepend (entries, menu_entry_create (_("S&pell check"), CK_SpellCheck));
g_list_prepend (entries, menu_entry_create (_("S&pell check"), CK_SpellCheck));
entries = entries =
g_list_prepend (entries, menu_entry_create (_("C&heck word"), CK_SpellCheckCurrentWord)); g_list_prepend (entries, menu_entry_create (_("C&heck word"), CK_SpellCheckCurrentWord));
entries = 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 ()); entries = g_list_prepend (entries, menu_separator_create ());
#endif /* HAVE_ASPELL */ #endif /* HAVE_ASPELL */
entries = g_list_prepend (entries, menu_entry_create (_("&Mail..."), CK_Mail)); entries = g_list_prepend (entries, menu_entry_create (_("&Mail..."), CK_Mail));

Просмотреть файл

@ -672,7 +672,7 @@ edit_event (Gpm_Event * event, void *data)
*/ */
static int static int
edit_dialog_event (Gpm_Event *event, void *data) edit_dialog_event (Gpm_Event * event, void *data)
{ {
Dlg_head *h = (Dlg_head *) data; Dlg_head *h = (Dlg_head *) data;
Widget *w; Widget *w;
@ -1081,10 +1081,11 @@ edit_file (const vfs_path_t * file_vpath, int line)
return ok; return ok;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
gboolean gboolean
edit_files (const GList *files) edit_files (const GList * files)
{ {
static gboolean made_directory = FALSE; static gboolean made_directory = FALSE;
Dlg_head *edit_dlg; Dlg_head *edit_dlg;
@ -1129,8 +1130,7 @@ edit_files (const GList *files)
gboolean f_ok; gboolean f_ok;
f_ok = edit_add_window (edit_dlg, edit_dlg->y + 1, edit_dlg->x, f_ok = edit_add_window (edit_dlg, edit_dlg->y + 1, edit_dlg->x,
edit_dlg->lines - 2, edit_dlg->cols, edit_dlg->lines - 2, edit_dlg->cols, f->file_vpath, f->line_number);
f->file_vpath, f->line_number);
/* at least one file has been opened succefully */ /* at least one file has been opened succefully */
ok = ok || f_ok; ok = ok || f_ok;
} }
@ -1185,7 +1185,7 @@ edit_update_screen (WEdit * e)
edit_update_curs_col (e); edit_update_curs_col (e);
edit_status (e, (e->force & REDRAW_COMPLETELY) != 0 && 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 */ /* pop all events for this window for internal handling */
if (!is_idle ()) if (!is_idle ())
@ -1232,7 +1232,7 @@ edit_save_size (WEdit * edit)
*/ */
gboolean 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; WEdit *edit;
Widget *w; 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 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_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 void (*mc_delete_aspell_can_have_error) (struct AspellCanHaveError * ths);
static const char *(*mc_aspell_error_message) (const struct AspellCanHaveError * ths); static const char *(*mc_aspell_error_message) (const struct AspellCanHaveError * ths);
static void (*mc_delete_aspell_string_enumeration) (struct AspellStringEnumeration * 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 void (*mc_delete_aspell_dict_info_enumeration) (struct AspellDictInfoEnumeration * ths);
static unsigned int (*mc_aspell_word_list_size) (const struct AspellWordList * 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 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); int word_size);
static int (*mc_aspell_speller_save_all_word_lists) (struct AspellSpeller * ths); 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)) (void *) &mc_aspell_speller_error_message))
goto error_ret; goto error_ret;
if (!g_module_symbol (spell_module, "aspell_speller_error", if (!g_module_symbol (spell_module, "aspell_speller_error", (void *) &mc_aspell_speller_error))
(void *) &mc_aspell_speller_error))
goto error_ret; goto error_ret;
if (!g_module_symbol (spell_module, "aspell_error", (void *) &mc_aspell_error)) if (!g_module_symbol (spell_module, "aspell_error", (void *) &mc_aspell_error))

Просмотреть файл

@ -16,9 +16,9 @@
void aspell_init (void); void aspell_init (void);
void aspell_clean (void); void aspell_clean (void);
gboolean aspell_check (const char *word, const int word_size); gboolean aspell_check (const char *word, const int word_size);
unsigned int aspell_suggest (GArray *suggest, 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); void aspell_array_clean (GArray * array);
unsigned int aspell_get_lang_list (GArray *lang_list); unsigned int aspell_get_lang_list (GArray * lang_list);
const char *aspell_get_lang (void); const char *aspell_get_lang (void);
gboolean aspell_set_lang (const char *lang); gboolean aspell_set_lang (const char *lang);
gboolean aspell_add_to_dict (const char *word, const int word_size); gboolean aspell_add_to_dict (const char *word, const int word_size);

Просмотреть файл

@ -59,7 +59,7 @@
*/ */
int 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 */ 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 * 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_h = 12; /* dialog height */
int lang_dlg_w = 30; /* dialog width */ int lang_dlg_w = 30; /* dialog width */
char *selected_lang = NULL; char *selected_lang = NULL;
unsigned int i; unsigned int i;
int res; int res;

Просмотреть файл

@ -17,8 +17,8 @@
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
int spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word, int spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word,
GArray *suggest); GArray * suggest);
char *spell_dialog_lang_list_show (GArray *languages); char *spell_dialog_lang_list_show (GArray * languages);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/

Просмотреть файл

@ -340,7 +340,7 @@ toggle_panels (void)
#ifdef HAVE_SUBSHELL_SUPPORT #ifdef HAVE_SUBSHELL_SUPPORT
if (mc_global.tty.use_subshell) 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); invoke_subshell (NULL, VISIBLY, new_dir_p);
} }
else else

Просмотреть файл

@ -83,7 +83,8 @@ WInput *cmdline;
static char * static char *
examine_cd (const char *_path) 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; state_t state = copy_sym;
char *q; char *q;
@ -424,7 +425,7 @@ do_cd_command (char *orig_cmd)
path = examine_cd (&cmd[operand_pos]); path = examine_cd (&cmd[operand_pos]);
if (*path == '\0') 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 else
q_vpath = vfs_path_from_str_flags (path, VPF_NO_CANON); q_vpath = vfs_path_from_str_flags (path, VPF_NO_CANON);

Просмотреть файл

@ -376,7 +376,7 @@ exec_extension_cd (void)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static 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; char *shell_string, *export_variables;
vfs_path_t *temp_file_name_vpath = NULL; vfs_path_t *temp_file_name_vpath = NULL;

Просмотреть файл

@ -238,7 +238,7 @@ free_link (void *data)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static void * static void *
free_linklist (GSList *lp) free_linklist (GSList * lp)
{ {
g_slist_foreach (lp, (GFunc) free_link, NULL); g_slist_foreach (lp, (GFunc) free_link, NULL);
g_slist_free (lp); g_slist_free (lp);
@ -249,7 +249,7 @@ free_linklist (GSList *lp)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static gboolean 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; const struct vfs_class *class;
ino_t ino = sb->st_ino; ino_t ino = sb->st_ino;

Просмотреть файл

@ -57,9 +57,9 @@
#if ((STAT_STATVFS || STAT_STATVFS64) \ #if ((STAT_STATVFS || STAT_STATVFS64) \
&& (HAVE_STRUCT_STATVFS_F_BASETYPE || HAVE_STRUCT_STATVFS_F_FSTYPENAME \ && (HAVE_STRUCT_STATVFS_F_BASETYPE || HAVE_STRUCT_STATVFS_F_FSTYPENAME \
|| (! HAVE_STRUCT_STATFS_F_FSTYPENAME))) || (! HAVE_STRUCT_STATFS_F_FSTYPENAME)))
# define USE_STATVFS 1 #define USE_STATVFS 1
#else #else
# define USE_STATVFS 0 #define USE_STATVFS 0
#endif #endif
#include <errno.h> #include <errno.h>
@ -70,36 +70,36 @@
#include <sys/stat.h> #include <sys/stat.h>
#if USE_STATVFS #if USE_STATVFS
# include <sys/statvfs.h> #include <sys/statvfs.h>
#elif HAVE_SYS_VFS_H #elif HAVE_SYS_VFS_H
# include <sys/vfs.h> #include <sys/vfs.h>
#elif HAVE_SYS_MOUNT_H && HAVE_SYS_PARAM_H #elif HAVE_SYS_MOUNT_H && HAVE_SYS_PARAM_H
/* NOTE: freebsd5.0 needs sys/param.h and sys/mount.h for statfs. /* 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 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. */ 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. */ /* NetBSD 1.5.2 needs these, for the declaration of struct statfs. */
# include <sys/param.h> #include <sys/param.h>
# include <sys/mount.h> #include <sys/mount.h>
# if HAVE_NFS_NFS_CLNT_H && HAVE_NFS_VFS_H #if HAVE_NFS_NFS_CLNT_H && HAVE_NFS_VFS_H
/* Ultrix 4.4 needs these for the declaration of struct statfs. */ /* Ultrix 4.4 needs these for the declaration of struct statfs. */
# include <netinet/in.h> #include <netinet/in.h>
# include <nfs/nfs_clnt.h> #include <nfs/nfs_clnt.h>
# include <nfs/vfs.h> #include <nfs/vfs.h>
# endif #endif
#elif HAVE_OS_H /* BeOS */ #elif HAVE_OS_H /* BeOS */
# include <fs_info.h> #include <fs_info.h>
#endif #endif
#if USE_STATVFS #if USE_STATVFS
# define STRUCT_STATVFS struct statvfs #define STRUCT_STATVFS struct statvfs
# if ! STAT_STATVFS && STAT_STATVFS64 #if ! STAT_STATVFS && STAT_STATVFS64
# define STATFS statvfs64 #define STATFS statvfs64
# else
# define STATFS statvfs
# endif
#else #else
# define STATFS statfs #define STATFS statvfs
# if HAVE_OS_H /* BeOS */ #endif
#else
#define STATFS statfs
#if HAVE_OS_H /* BeOS */
/* BeOS has a statvfs function, but it does not return sensible values /* 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 for f_files, f_ffree and f_favail, and lacks f_type, f_basetype and
f_fstypename. Use 'struct fs_info' instead. */ 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 errno = (device == B_ENTRY_NOT_FOUND ? ENOENT
: device == B_BAD_VALUE ? EINVAL : device == B_BAD_VALUE ? EINVAL
: device == B_NAME_TOO_LONG ? ENAMETOOLONG : device == B_NAME_TOO_LONG ? ENAMETOOLONG
: device == B_NO_MEMORY ? ENOMEM : device == B_NO_MEMORY ? ENOMEM : device == B_FILE_ERROR ? EIO : 0);
: device == B_FILE_ERROR ? EIO
: 0);
return -1; return -1;
} }
/* If successful, buf->dev will be == device. */ /* If successful, buf->dev will be == device. */
return fs_stat_dev (device, buf); return fs_stat_dev (device, buf);
} }
# define STRUCT_STATVFS struct fs_info #define STRUCT_STATVFS struct fs_info
# else #else
# define STRUCT_STATVFS struct statfs #define STRUCT_STATVFS struct statfs
# endif #endif
#endif #endif
#if HAVE_STRUCT_STATVFS_F_BASETYPE #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 #else
# if HAVE_STRUCT_STATVFS_F_FSTYPENAME || HAVE_STRUCT_STATFS_F_FSTYPENAME #if HAVE_STRUCT_STATVFS_F_FSTYPENAME || HAVE_STRUCT_STATFS_F_FSTYPENAME
# define STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME f_fstypename #define STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME f_fstypename
# elif HAVE_OS_H /* BeOS */ #elif HAVE_OS_H /* BeOS */
# define STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME fsh_name #define STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME fsh_name
# endif #endif
#endif #endif
#include <unistd.h> #include <unistd.h>

Просмотреть файл

@ -557,7 +557,7 @@ init_layout (void)
} }
equal_split = panels_layout.horizontal_split ? 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 */ /* "Panel split" groupbox */
bright_widget = button_new (6, 14, B_2RIGHT, NARROW_BUTTON, "&>", b_left_right_cback); 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); struct WPanel *get_other_panel (void);
void save_panel_dir (int idx); 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); 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 static int
midnight_event (Gpm_Event *event, void *data) midnight_event (Gpm_Event * event, void *data)
{ {
Dlg_head *h = (Dlg_head *) data; Dlg_head *h = (Dlg_head *) data;
int ret = MOU_UNHANDLED; int ret = MOU_UNHANDLED;

Просмотреть файл

@ -1,6 +1,6 @@
/* /*
Declarations for list of mounted filesystems Declarations for list of mounted filesystems
*/ */
/** \file mountlist.h /** \file mountlist.h
* \brief Header: list of mounted filesystems * \brief Header: list of mounted filesystems
@ -24,8 +24,8 @@ struct my_statfs
char *typename; char *typename;
const char *mpoint; const char *mpoint;
const char *device; const char *device;
uintmax_t avail; /* in kB */ uintmax_t avail; /* in kB */
uintmax_t total; /* in kB */ uintmax_t total; /* in kB */
uintmax_t nfree; uintmax_t nfree;
uintmax_t nodes; uintmax_t nodes;
}; };

Просмотреть файл

@ -4582,7 +4582,7 @@ remove_encoding_from_path (const vfs_path_t * vpath)
g_string_free (tmp_conv, TRUE); g_string_free (tmp_conv, TRUE);
return ret_vpath; return ret_vpath;
} }
#endif /* HAVE_CHARSET */ #endif /* HAVE_CHARSET */
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** /**

Просмотреть файл

@ -599,8 +599,7 @@ load_panelize (void)
if (!profile_keys || *profile_keys == NULL) if (!profile_keys || *profile_keys == NULL)
{ {
add2panelize (g_strdup (_("Modified git files")), add2panelize (g_strdup (_("Modified git files")), g_strdup ("git ls-files --modified"));
g_strdup ("git ls-files --modified"));
add2panelize (g_strdup (_("Find rejects after patching")), add2panelize (g_strdup (_("Find rejects after patching")),
g_strdup ("find . -name \\*.rej -print")); g_strdup ("find . -name \\*.rej -print"));
add2panelize (g_strdup (_("Find *.orig after patching")), add2panelize (g_strdup (_("Find *.orig after patching")),

Просмотреть файл

@ -19,7 +19,7 @@ struct WEdit;
/*** declarations of public functions ************************************************************/ /*** 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); char *expand_format (struct WEdit *edit_widget, char c, gboolean do_quote);
int check_format_view (const char *); int check_format_view (const char *);
int check_format_var (const char *, char **); int check_format_var (const char *, char **);

Просмотреть файл

@ -373,7 +373,8 @@ learn_save (void)
esc_str = strutils_escape (learnkeys[i].sequence, -1, ";\\", TRUE); 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); g_free (esc_str);
} }

Просмотреть файл

@ -108,8 +108,8 @@ char *load_anon_passwd (void);
void load_keymap_defs (gboolean load_from_file); void load_keymap_defs (gboolean load_from_file);
void free_keymap_defs (void); void free_keymap_defs (void);
void panel_load_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 panel_save_setup (struct WPanel *panel, const char *section);
void panels_load_options (void); void panels_load_options (void);
void panels_save_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, */ /* It simplifies things to change to our home directory here, */
/* and the user's startup file may do a `cd' command anyway */ /* 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 */ /* Set MC_SID to prevent running one mc from another */
mc_sid = getsid (0); mc_sid = getsid (0);

Просмотреть файл

@ -854,7 +854,7 @@ init_cpiofs (void)
{ {
static struct vfs_s_subclass cpio_subclass; 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_check = cpio_super_check;
cpio_subclass.archive_same = cpio_super_same; cpio_subclass.archive_same = cpio_super_same;
cpio_subclass.open_archive = cpio_open_archive; cpio_subclass.open_archive = cpio_open_archive;

Просмотреть файл

@ -11,7 +11,7 @@
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
void init_cpiofs(void); void init_cpiofs (void);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/

Просмотреть файл

@ -422,7 +422,7 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc)
goto ret; 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 ", cmd = g_strconcat (info->path, info->prefix, " list ",

Просмотреть файл

@ -21,7 +21,7 @@ extern int fish_directory_timeout;
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
void init_fish(void); void init_fish (void);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/

Просмотреть файл

@ -11,7 +11,7 @@
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
void vfs_plugins_init(void); void vfs_plugins_init (void);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/

Просмотреть файл

@ -190,7 +190,8 @@ sfs_vfmake (const vfs_path_t * vpath, vfs_path_t * cache_vpath)
COPY_CHAR; COPY_CHAR;
continue; continue;
} }
if (ptr != NULL) { if (ptr != NULL)
{
COPY_STRING (ptr); COPY_STRING (ptr);
} }
} }

Просмотреть файл

@ -27,7 +27,7 @@
#include <config.h> #include <config.h>
#include <errno.h> #include <errno.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> /* atoi() */ #include <stdlib.h> /* atoi() */
#include "lib/global.h" #include "lib/global.h"
@ -300,7 +300,7 @@ sftpfs_get_config_entity (const vfs_path_element_t * vpath_element, GError ** er
gboolean ok; gboolean ok;
ok = sftpfs_fill_config_entity_from_config 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); fclose (ssh_config_handler);
if (!ok) if (!ok)
@ -380,13 +380,13 @@ void
sftpfs_init_config_variables_patterns (void) sftpfs_init_config_variables_patterns (void)
{ {
size_t structure_offsets[] = { size_t structure_offsets[] = {
offsetof(sftpfs_ssh_config_entity_t, user), offsetof (sftpfs_ssh_config_entity_t, user),
offsetof(sftpfs_ssh_config_entity_t, real_host), offsetof (sftpfs_ssh_config_entity_t, real_host),
offsetof(sftpfs_ssh_config_entity_t, identities_only), offsetof (sftpfs_ssh_config_entity_t, identities_only),
offsetof(sftpfs_ssh_config_entity_t, identity_file), offsetof (sftpfs_ssh_config_entity_t, identity_file),
offsetof(sftpfs_ssh_config_entity_t, port), offsetof (sftpfs_ssh_config_entity_t, port),
offsetof(sftpfs_ssh_config_entity_t, password_auth), offsetof (sftpfs_ssh_config_entity_t, password_auth),
offsetof(sftpfs_ssh_config_entity_t, pubkey_auth) offsetof (sftpfs_ssh_config_entity_t, pubkey_auth)
}; };
int i; int i;

Просмотреть файл

@ -2,7 +2,7 @@
Unix SMB/Netbios implementation. Unix SMB/Netbios implementation.
Version 1.9. Version 1.9.
SMB Byte handling SMB Byte handling
*/ */
#ifndef _BYTEORDER_H #ifndef _BYTEORDER_H
#define _BYTEORDER_H #define _BYTEORDER_H
@ -11,73 +11,73 @@
This file implements macros for machine independent short and This file implements macros for machine independent short and
int manipulation 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 > 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 > 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 > between LE and BE machines, but you only seem to distinguish between 386
> and all other architectures. > and all other architectures.
> >
> Can you give me a clue? > Can you give me a clue?
sure. sure.
The distinction between 386 and other architectures is only there as The distinction between 386 and other architectures is only there as
an optimisation. You can take it out completely and it will make no an optimisation. You can take it out completely and it will make no
difference. The routines (macros) in byteorder.h are totally byteorder difference. The routines (macros) in byteorder.h are totally byteorder
independent. The 386 optimsation just takes advantage of the fact that 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 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 align ints on int boundaries etc. If there are other processors out
there that aren't alignment sensitive then you could also define there that aren't alignment sensitive then you could also define
CAREFUL_ALIGNMENT=0 on those processors as well. CAREFUL_ALIGNMENT=0 on those processors as well.
Ok, now to the macros themselves. I'll take a simple example, say we 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 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 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 want to do it with only the assumption that uint16 is _at_least_ 16
bits long (this last condition is very important for architectures bits long (this last condition is very important for architectures
that don't have any int types that are 2 bytes long) 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 CVAL(buf,pos) (((unsigned char *)(buf))[pos])
#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos)) #define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) #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(); char *buffer = foo_bar();
uint16 xx = SVAL(buffer,25); uint16 xx = SVAL(buffer,25);
We are using the byteoder independence of the ANSI C bitshifts to do We are using the byteoder independence of the ANSI C bitshifts to do
the work. A good optimising compiler should turn this into efficient the work. A good optimising compiler should turn this into efficient
code, especially if it happens to have the right byteorder :-) 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 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 casts, but you need to look at byteorder.h as a whole to see the
reasoning behind them. byteorder.h defines the following macros: reasoning behind them. byteorder.h defines the following macros:
SVAL(buf,pos) - extract a 2 byte SMB value SVAL(buf,pos) - extract a 2 byte SMB value
IVAL(buf,pos) - extract a 4 byte SMB value IVAL(buf,pos) - extract a 4 byte SMB value
SVALS(buf,pos) signed version of SVAL() SVALS(buf,pos) signed version of SVAL()
IVALS(buf,pos) signed version of IVAL() IVALS(buf,pos) signed version of IVAL()
SSVAL(buf,pos,val) - put a 2 byte SMB value into a buffer 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 SIVAL(buf,pos,val) - put a 4 byte SMB value into a buffer
SSVALS(buf,pos,val) - signed version of SSVAL() SSVALS(buf,pos,val) - signed version of SSVAL()
SIVALS(buf,pos,val) - signed version of SIVAL() SIVALS(buf,pos,val) - signed version of SIVAL()
RSVAL(buf,pos) - like SVAL() but for NMB byte ordering RSVAL(buf,pos) - like SVAL() but for NMB byte ordering
RSVALS(buf,pos) - like SVALS() 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 RIVAL(buf,pos) - like IVAL() but for NMB byte ordering
RIVALS(buf,pos) - like IVALS() 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 RSSVAL(buf,pos,val) - like SSVAL() but for NMB ordering
RSIVAL(buf,pos,val) - like SIVAL() but for NMB ordering RSIVAL(buf,pos,val) - like SIVAL() but for NMB ordering
RSIVALS(buf,pos,val) - like SIVALS() 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 */ /* 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 WARNING: This section is dependent on the length of int16 and int32
being correct being correct
*/ */
/* get single value from an SMB buffer */ /* get single value from an SMB buffer */
#define SVAL(buf,pos) (*(uint16 *)((char *)(buf) + (pos))) #define SVAL(buf,pos) (*(uint16 *)((char *)(buf) + (pos)))

Просмотреть файл

@ -2,7 +2,7 @@
Unix SMB/Netbios implementation. Unix SMB/Netbios implementation.
Version 1.9. Version 1.9.
Character set handling Character set handling
*/ */
#ifndef CHARSET_C #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 /* this is used to determine if a character is safe to use in
something that may be put on a command line */ something that may be put on a command line */
#define issafe(c) (isalnum((c&0xff)) || strchr("-._",c)) #define issafe(c) (isalnum((c&0xff)) || strchr("-._",c))
#endif /* !CHARSET_C */ #endif /* !CHARSET_C */
/* Dynamic codepage files defines. */ /* Dynamic codepage files defines. */

Просмотреть файл

@ -2,7 +2,7 @@
Unix SMB/Netbios implementation. Unix SMB/Netbios implementation.
Version 1.9. Version 1.9.
SMB parameters and setup SMB parameters and setup
*/ */
#ifndef _CLIENT_H #ifndef _CLIENT_H
#define _CLIENT_H #define _CLIENT_H
@ -18,25 +18,25 @@
typedef struct file_info typedef struct file_info
{ {
SMB_OFF_T size; SMB_OFF_T size;
uint16 mode; uint16 mode;
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
/* these times are normally kept in GMT */ /* these times are normally kept in GMT */
time_t mtime; time_t mtime;
time_t atime; time_t atime;
time_t ctime; time_t ctime;
pstring name; pstring name;
} file_info; } file_info;
struct print_job_info struct print_job_info
{ {
uint16 id; uint16 id;
uint16 priority; uint16 priority;
size_t size; size_t size;
fstring user; fstring user;
fstring name; fstring name;
time_t t; time_t t;
}; };
struct pwd_info struct pwd_info
@ -54,73 +54,74 @@ struct pwd_info
uchar smb_nt_owf[24]; uchar smb_nt_owf[24];
}; };
struct cli_state { struct cli_state
int port; {
int fd; int port;
uint16 cnum; int fd;
uint16 pid; uint16 cnum;
uint16 mid; uint16 pid;
uint16 vuid; uint16 mid;
int protocol; uint16 vuid;
int sec_mode; int protocol;
int rap_error; int sec_mode;
int privileges; int rap_error;
int privileges;
fstring eff_name; fstring eff_name;
fstring desthost; fstring desthost;
fstring user_name; fstring user_name;
fstring domain; fstring domain;
/* /*
* The following strings are the * The following strings are the
* ones returned by the server if * ones returned by the server if
* the protocol > NT1. * the protocol > NT1.
*/ */
fstring server_type; fstring server_type;
fstring server_os; fstring server_os;
fstring server_domain; fstring server_domain;
fstring share; fstring share;
fstring dev; fstring dev;
struct nmb_name called; struct nmb_name called;
struct nmb_name calling; struct nmb_name calling;
fstring full_dest_host_name; fstring full_dest_host_name;
struct in_addr dest_ip; struct in_addr dest_ip;
struct pwd_info pwd; struct pwd_info pwd;
unsigned char cryptkey[8]; unsigned char cryptkey[8];
uint32 sesskey; uint32 sesskey;
int serverzone; int serverzone;
uint32 servertime; uint32 servertime;
int readbraw_supported; int readbraw_supported;
int writebraw_supported; int writebraw_supported;
int timeout; /* in milliseconds. */ int timeout; /* in milliseconds. */
int max_xmit; int max_xmit;
int max_mux; int max_mux;
char *outbuf; char *outbuf;
char *inbuf; char *inbuf;
int bufsize; int bufsize;
int initialised; int initialised;
int win95; int win95;
uint32 capabilities; uint32 capabilities;
/* /*
* Only used in NT domain calls. * Only used in NT domain calls.
*/ */
uint32 nt_error; /* NT RPC error code. */ uint32 nt_error; /* NT RPC error code. */
uint16 nt_pipe_fnum; /* Pipe handle. */ uint16 nt_pipe_fnum; /* Pipe handle. */
unsigned char sess_key[16]; /* Current session key. */ unsigned char sess_key[16]; /* Current session key. */
unsigned char ntlmssp_hash[258]; /* ntlmssp data. */ unsigned char ntlmssp_hash[258]; /* ntlmssp data. */
uint32 ntlmssp_cli_flgs; /* ntlmssp client flags */ uint32 ntlmssp_cli_flgs; /* ntlmssp client flags */
uint32 ntlmssp_srv_flgs; /* ntlmssp server flags */ uint32 ntlmssp_srv_flgs; /* ntlmssp server flags */
uint32 ntlmssp_seq_num; /* ntlmssp sequence number */ uint32 ntlmssp_seq_num; /* ntlmssp sequence number */
DOM_CRED clnt_cred; /* Client credential. */ DOM_CRED clnt_cred; /* Client credential. */
fstring mach_acct; /* MYNAME$. */ fstring mach_acct; /* MYNAME$. */
fstring srv_name_slash; /* \\remote server. */ fstring srv_name_slash; /* \\remote server. */
fstring clnt_name_slash; /* \\local client. */ fstring clnt_name_slash; /* \\local client. */
uint16 max_xmit_frag; uint16 max_xmit_frag;
uint16 max_recv_frag; uint16 max_recv_frag;
}; };
#endif /* _CLIENT_H */ #endif /* _CLIENT_H */

Просмотреть файл

@ -4,9 +4,9 @@
Unix SMB/Netbios implementation. Unix SMB/Netbios implementation.
Version 1.9. Version 1.9.
Machine customisation and include handling Machine customisation and include handling
*/ */
#ifndef NO_CONFIG_H /* for some tests */ #ifndef NO_CONFIG_H /* for some tests */
#include "config.h" #include "config.h"
#endif #endif
@ -156,7 +156,7 @@
/* POSIX terminal handling. */ /* POSIX terminal handling. */
#include <termios.h> #include <termios.h>
# include <dirent.h> #include <dirent.h>
#ifdef HAVE_SYS_MMAN_H #ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h> #include <sys/mman.h>
@ -185,23 +185,23 @@
#include <sys/acl.h> #include <sys/acl.h>
#endif #endif
#ifdef HAVE_SYS_FS_S5PARAM_H #ifdef HAVE_SYS_FS_S5PARAM_H
#include <sys/fs/s5param.h> #include <sys/fs/s5param.h>
#endif #endif
#if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY) #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
#include <sys/filsys.h> #include <sys/filsys.h>
#endif #endif
#ifdef HAVE_SYS_STATFS_H #ifdef HAVE_SYS_STATFS_H
# include <sys/statfs.h> #include <sys/statfs.h>
#endif #endif
#ifdef HAVE_DUSTAT_H #ifdef HAVE_DUSTAT_H
#include <sys/dustat.h> #include <sys/dustat.h>
#endif #endif
#ifdef HAVE_SYS_STATVFS_H #ifdef HAVE_SYS_STATVFS_H
#include <sys/statvfs.h> #include <sys/statvfs.h>
#endif #endif
@ -219,7 +219,7 @@
#include <sys/security.h> #include <sys/security.h>
#include <prot.h> #include <prot.h>
#define PASSWORD_LENGTH 16 #define PASSWORD_LENGTH 16
#endif /* HAVE_SYS_SECURITY_H */ #endif /* HAVE_SYS_SECURITY_H */
#ifdef HAVE_COMPAT_H #ifdef HAVE_COMPAT_H
#include <compat.h> #include <compat.h>
@ -269,7 +269,7 @@
they actually only need to be at least 16 and 32 bits they actually only need to be at least 16 and 32 bits
respectively. Thus if your word size is 8 bytes just defining them respectively. Thus if your word size is 8 bytes just defining them
as signed and unsigned int will work. as signed and unsigned int will work.
*/ */
#ifndef uint8 #ifndef uint8
#define uint8 unsigned char #define uint8 unsigned char
@ -334,23 +334,23 @@
*/ */
#ifndef SMB_INO_T #ifndef SMB_INO_T
# define SMB_INO_T ino_t #define SMB_INO_T ino_t
#endif #endif
#ifndef LARGE_SMB_INO_T #ifndef LARGE_SMB_INO_T
# if defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8) #if defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8)
# define LARGE_SMB_INO_T 1 #define LARGE_SMB_INO_T 1
# endif #endif
#endif #endif
#ifdef LARGE_SMB_INO_T #ifdef LARGE_SMB_INO_T
#define SINO_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32)) #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)) #define SINO_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
#endif #endif
#ifndef SMB_OFF_T #ifndef SMB_OFF_T
# define SMB_OFF_T off_t #define SMB_OFF_T off_t
#endif #endif
#define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8) #define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
@ -361,14 +361,14 @@
*/ */
#ifndef LARGE_SMB_OFF_T #ifndef LARGE_SMB_OFF_T
# if defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8) #if defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8)
# define LARGE_SMB_OFF_T 1 #define LARGE_SMB_OFF_T 1
# endif #endif
#endif #endif
#ifdef LARGE_SMB_OFF_T #ifdef LARGE_SMB_OFF_T
#define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32)) #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)) #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
#endif #endif
@ -377,7 +377,7 @@
*/ */
#ifndef SMB_STRUCT_STAT #ifndef SMB_STRUCT_STAT
# define SMB_STRUCT_STAT struct stat #define SMB_STRUCT_STAT struct stat
#endif #endif
/* /*
@ -385,7 +385,7 @@
*/ */
#ifndef SMB_STRUCT_DIRENT #ifndef SMB_STRUCT_DIRENT
# define SMB_STRUCT_DIRENT struct dirent #define SMB_STRUCT_DIRENT struct dirent
#endif #endif
/* /*
@ -393,19 +393,19 @@
*/ */
#ifndef SMB_STRUCT_FLOCK #ifndef SMB_STRUCT_FLOCK
# define SMB_STRUCT_FLOCK struct flock #define SMB_STRUCT_FLOCK struct flock
#endif #endif
#ifndef SMB_F_SETLKW #ifndef SMB_F_SETLKW
# define SMB_F_SETLKW F_SETLKW #define SMB_F_SETLKW F_SETLKW
#endif #endif
#ifndef SMB_F_SETLK #ifndef SMB_F_SETLK
# define SMB_F_SETLK F_SETLK #define SMB_F_SETLK F_SETLK
#endif #endif
#ifndef SMB_F_GETLK #ifndef SMB_F_GETLK
# define SMB_F_GETLK F_GETLK #define SMB_F_GETLK F_GETLK
#endif #endif
#if defined(HAVE_LONGLONG) #if defined(HAVE_LONGLONG)
@ -515,7 +515,7 @@
#endif #endif
/* what is the longest significant password available on your system? /* 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 #ifndef PASSWORD_LENGTH
#define PASSWORD_LENGTH 8 #define PASSWORD_LENGTH 8
#endif #endif
@ -549,19 +549,19 @@
#endif #endif
#ifndef HAVE_INITGROUPS #ifndef HAVE_INITGROUPS
int initgroups(char *name,gid_t id); int initgroups (char *name, gid_t id);
#endif #endif
#ifndef HAVE_RENAME #ifndef HAVE_RENAME
int rename(const char *zfrom, const char *zto); int rename (const char *zfrom, const char *zto);
#endif #endif
#ifndef HAVE_MKTIME #ifndef HAVE_MKTIME
time_t mktime(struct tm *t); time_t mktime (struct tm *t);
#endif #endif
#ifndef HAVE_STRTOUL #ifndef HAVE_STRTOUL
unsigned long strtoul(const char *nptr, char **endptr, int base); unsigned long strtoul (const char *nptr, char **endptr, int base);
#endif #endif
#ifdef REPLACE_GETPASS #ifdef REPLACE_GETPASS

Просмотреть файл

@ -2,7 +2,7 @@
Unix SMB/Netbios implementation. Unix SMB/Netbios implementation.
Version 1.9. Version 1.9.
Kanji Extensions Kanji Extensions
*/ */
#ifndef _KANJI_H_ #ifndef _KANJI_H_
#define _KANJI_H_ #define _KANJI_H_
@ -86,7 +86,7 @@
#define is_hangul(c) ((0x81 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xfd)) #define is_hangul(c) ((0x81 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xfd))
/* For traditional Chinese (known as Big5 encoding - code page 950). */ /* 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). */ /* For simplified Chinese (code page - 936). */
#define is_simpch_c1(c) ((0xa1 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xf7)) #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. */ /* Ensure we use our definitions in all other files than kanji.c. */
/* Function pointers we will replace. */ /* Function pointers we will replace. */
extern char *(*multibyte_strchr)(const char *s, int c); extern char *(*multibyte_strchr) (const char *s, int c);
extern char *(*multibyte_strrchr)(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_strstr) (const char *s1, const char *s2);
extern char *(*multibyte_strtok)(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 *(*_dos_to_unix) (char *str, BOOL overwrite);
extern char *(*_unix_to_dos)(char *str, BOOL overwrite); extern char *(*_unix_to_dos) (char *str, BOOL overwrite);
extern BOOL (*is_multibyte_char)(char c); extern BOOL (*is_multibyte_char) (char c);
extern int (*_skip_multibyte_char)(char c); extern int (*_skip_multibyte_char) (char c);
#define strchr(s1, c) ((*multibyte_strchr)((s1), (c))) #define strchr(s1, c) ((*multibyte_strchr)((s1), (c)))
#define strrchr(s1, c) ((*multibyte_strrchr)((s1), (c))) #define strrchr(s1, c) ((*multibyte_strrchr)((s1), (c)))

Просмотреть файл

@ -25,7 +25,7 @@
refer to the special "printers" service */ refer to the special "printers" service */
#define PRINTERS_NAME "printers" #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. */ /* to a maximum of 8 if old smb clients break because of long printer names. */
#define MAXPRINTERLEN 15 #define MAXPRINTERLEN 15
@ -59,7 +59,7 @@
#ifndef MAX_OPEN_FILES #ifndef MAX_OPEN_FILES
#define MAX_OPEN_FILES 10000 #define MAX_OPEN_FILES 10000
#endif #endif
/* the max number of simultanous connections to the server by all clients */ /* the max number of simultanous connections to the server by all clients */
#define MAXSTATUS 100000 #define MAXSTATUS 100000
@ -80,7 +80,7 @@
/* shall filenames with illegal chars in them get mangled in long /* shall filenames with illegal chars in them get mangled in long
filename listings? */ filename listings? */
#define MANGLE_LONG_FILENAMES #define MANGLE_LONG_FILENAMES
/* define this if you want to stop spoofing with .. and soft links /* define this if you want to stop spoofing with .. and soft links
NOTE: This also slows down the server considerably */ NOTE: This also slows down the server considerably */
@ -152,7 +152,7 @@
#define SHORT_CONNECT_TIMEOUT 5000 #define SHORT_CONNECT_TIMEOUT 5000
/* default socket options. Dave Miller thinks we should default to TCP_NODELAY /* 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 #ifdef TCP_NODELAY
#define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY" #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
#else #else

Просмотреть файл

@ -4,7 +4,7 @@
Unix SMB/Netbios implementation. Unix SMB/Netbios implementation.
Version 1.9. Version 1.9.
NBT netbios header - version 2 NBT netbios header - version 2
*/ */
#define PERMANENT_TTL 0 #define PERMANENT_TTL 0
@ -12,16 +12,18 @@
#define MAINTAIN_LIST 2 #define MAINTAIN_LIST 2
#define ELECTION_VERSION 1 #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 #define MIN_DGRAM_SIZE 12
/********************************************************* /*********************************************************
Types of reply packet. Types of reply packet.
**********************************************************/ **********************************************************/
enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH, enum netbios_reply_type_code
NMB_REL, NMB_WAIT_ACK, NMB_MULTIHOMED_REG, { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
WINS_REG, WINS_QUERY }; NMB_REL, NMB_WAIT_ACK, NMB_MULTIHOMED_REG,
WINS_REG, WINS_QUERY
};
/* From rfc1002, 4.2.1.2 */ /* From rfc1002, 4.2.1.2 */
/* Question types. */ /* Question types. */
@ -33,14 +35,14 @@ enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
/* Opcode definitions */ /* Opcode definitions */
#define NMB_NAME_QUERY_OPCODE 0x0 #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_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_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_WACK_OPCODE 0x07 /* see rfc1002.txt 4.2.16 */
/* Ambiguity in rfc1002 about which of these is correct. */ /* Ambiguity in rfc1002 about which of these is correct. */
/* WinNT uses 8 by default but can be made to use 9. */ /* 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_8 0x08 /* see rfc1002.txt 4.2.4 */
#define NMB_NAME_REFRESH_OPCODE_9 0x09 /* 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_MULTIHOMED_REG_OPCODE 0x0F /* Invented by Microsoft. */
/* XXXX what about all the other types?? 0x1, 0x2, 0x3, 0x4, 0x8? */ /* 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_ACTIVE 0x04
#define NB_CONFL 0x08 #define NB_CONFL 0x08
#define NB_DEREG 0x10 #define NB_DEREG 0x10
#define NB_BFLAG 0x00 /* Broadcast node type. */ #define NB_BFLAG 0x00 /* Broadcast node type. */
#define NB_PFLAG 0x20 /* Point-to-point node type. */ #define NB_PFLAG 0x20 /* Point-to-point node type. */
#define NB_MFLAG 0x40 /* Mixed bcast & p-p node type. */ #define NB_MFLAG 0x40 /* Mixed bcast & p-p node type. */
#define NB_HFLAG 0x60 /* Microsoft 'hybrid' node type. */ #define NB_HFLAG 0x60 /* Microsoft 'hybrid' node type. */
#define NB_NODETYPEMASK 0x60 #define NB_NODETYPEMASK 0x60
/* Mask applied to outgoing NetBIOS flags. */ /* Mask applied to outgoing NetBIOS flags. */
#define NB_FLGMSK 0xE0 #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) #define NAME_IS_DEREGISTERING(p) ((p)->data.nb_flags & NB_DEREG)
/* Error codes for NetBIOS requests. */ /* Error codes for NetBIOS requests. */
#define FMT_ERR 0x1 /* Packet format error. */ #define FMT_ERR 0x1 /* Packet format error. */
#define SRV_ERR 0x2 /* Internal server error. */ #define SRV_ERR 0x2 /* Internal server error. */
#define NAM_ERR 0x3 /* Name does not exist. */ #define NAM_ERR 0x3 /* Name does not exist. */
#define IMP_ERR 0x4 /* Request not implemented. */ #define IMP_ERR 0x4 /* Request not implemented. */
#define RFS_ERR 0x5 /* Request refused. */ #define RFS_ERR 0x5 /* Request refused. */
#define ACT_ERR 0x6 /* Active error - name owned by another host. */ #define ACT_ERR 0x6 /* Active error - name owned by another host. */
#define CFT_ERR 0x7 /* Name in conflict error. */ #define CFT_ERR 0x7 /* Name in conflict error. */
#define REFRESH_TIME (15*60) #define REFRESH_TIME (15*60)
#define NAME_POLL_REFRESH_TIME (5*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, enum name_source
DNSFAIL_NAME, PERMANENT_NAME, WINS_PROXY_NAME}; { LMHOSTS_NAME, REGISTER_NAME, SELF_NAME, DNS_NAME,
enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3}; DNSFAIL_NAME, PERMANENT_NAME, WINS_PROXY_NAME
enum packet_type {NMB_PACKET, DGRAM_PACKET}; };
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 enum master_state
{ {
MST_NONE, MST_NONE,
MST_POTENTIAL, MST_POTENTIAL,
MST_BACKUP, MST_BACKUP,
MST_MSB, MST_MSB,
MST_BROWSER, MST_BROWSER,
MST_UNBECOMING_MASTER MST_UNBECOMING_MASTER
}; };
enum domain_state enum domain_state
{ {
DOMAIN_NONE, DOMAIN_NONE,
DOMAIN_WAIT, DOMAIN_WAIT,
DOMAIN_MST DOMAIN_MST
}; };
enum logon_state enum logon_state
{ {
LOGON_NONE, LOGON_NONE,
LOGON_WAIT, LOGON_WAIT,
LOGON_SRV LOGON_SRV
}; };
struct subnet_record; struct subnet_record;
struct nmb_data struct nmb_data
{ {
uint16 nb_flags; /* Netbios flags. */ uint16 nb_flags; /* Netbios flags. */
int num_ips; /* Number of ip entries. */ int num_ips; /* Number of ip entries. */
struct in_addr *ip; /* The ip list for this name. */ 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 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 refresh_time; /* The time the record should be refreshed. */
}; };
/* This is used to hold the list of servers in my domain, and is /* 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
{ {
struct server_record *next; struct server_record *next;
struct server_record *prev; struct server_record *prev;
struct subnet_record *subnet; struct subnet_record *subnet;
struct server_info_struct serv; struct server_info_struct serv;
time_t death_time; time_t death_time;
}; };
/* A workgroup structure. It contains a list of servers. */ /* A workgroup structure. It contains a list of servers. */
struct work_record struct work_record
{ {
struct work_record *next; struct work_record *next;
struct work_record *prev; 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. */ /* Stage of development from non-local-master up to local-master browser. */
enum master_state mst_state; enum master_state mst_state;
/* Stage of development from non-domain-master to domain-master browser. */ /* Stage of development from non-domain-master to domain-master browser. */
enum domain_state dom_state; enum domain_state dom_state;
/* Stage of development from non-logon-server to logon server. */ /* Stage of development from non-logon-server to logon server. */
enum logon_state log_state; enum logon_state log_state;
/* Work group info. */ /* Work group info. */
fstring work_group; fstring work_group;
int token; /* Used when communicating with backup browsers. */ int token; /* Used when communicating with backup browsers. */
fstring local_master_browser_name; /* Current local master browser. */ fstring local_master_browser_name; /* Current local master browser. */
/* Announce info. */ /* Announce info. */
time_t lastannounce_time; time_t lastannounce_time;
int announce_interval; int announce_interval;
BOOL needannounce; BOOL needannounce;
/* Timeout time for this workgroup. 0 means permanent. */ /* Timeout time for this workgroup. 0 means permanent. */
time_t death_time; time_t death_time;
/* Election info */ /* Election info */
BOOL RunningElection; BOOL RunningElection;
BOOL needelection; BOOL needelection;
int ElectionCount; int ElectionCount;
uint32 ElectionCriterion; uint32 ElectionCriterion;
/* Domain master browser info. Used for efficient syncs. */ /* Domain master browser info. Used for efficient syncs. */
struct nmb_name dmb_name; struct nmb_name dmb_name;
struct in_addr dmb_addr; struct in_addr dmb_addr;
}; };
/* typedefs needed to define copy & free functions for userdata. */ /* typedefs needed to define copy & free functions for userdata. */
struct userdata_struct; struct userdata_struct;
typedef struct userdata_struct * (*userdata_copy_fn)(struct userdata_struct *); typedef struct userdata_struct *(*userdata_copy_fn) (struct userdata_struct *);
typedef void (*userdata_free_fn)(struct userdata_struct *); typedef void (*userdata_free_fn) (struct userdata_struct *);
/* Structure to define any userdata passed around. */ /* Structure to define any userdata passed around. */
struct userdata_struct { struct userdata_struct
userdata_copy_fn copy_fn; {
userdata_free_fn free_fn; userdata_copy_fn copy_fn;
unsigned int userdata_len; userdata_free_fn free_fn;
char data[16]; /* 16 is to ensure alignment/padding on all systems */ unsigned int userdata_len;
char data[16]; /* 16 is to ensure alignment/padding on all systems */
}; };
struct response_record; struct response_record;
@ -243,99 +250,83 @@ struct packet_struct;
struct res_rec; struct res_rec;
/* typedef to define the function called when this response packet comes in. */ /* typedef to define the function called when this response packet comes in. */
typedef void (*response_function)(struct subnet_record *, struct response_record *, typedef void (*response_function) (struct subnet_record *, struct response_record *,
struct packet_struct *); struct packet_struct *);
/* typedef to define the function called when this response record times out. */ /* typedef to define the function called when this response record times out. */
typedef void (*timeout_response_function)(struct subnet_record *, typedef void (*timeout_response_function) (struct subnet_record *, struct response_record *);
struct response_record *);
/* typedef to define the function called when the request that caused this /* typedef to define the function called when the request that caused this
response record to be created is successful. */ 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 /* typedef to define the function called when the request that caused this
response record to be created is unsuccessful. */ 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 /* List of typedefs for success and fail functions of the different query
types. Used to catch any compile time prototype errors. */ 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 userdata_struct *,
struct nmb_name *, struct nmb_name *, uint16, int, struct in_addr);
uint16, typedef void (*register_name_fail_function) (struct subnet_record *,
int, struct response_record *, struct nmb_name *);
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 *, typedef void (*release_name_success_function) (struct subnet_record *,
struct userdata_struct *, struct userdata_struct *,
struct nmb_name *, struct nmb_name *, struct in_addr);
struct in_addr); typedef void (*release_name_fail_function) (struct subnet_record *,
typedef void (*release_name_fail_function)( struct subnet_record *, struct response_record *, struct nmb_name *);
struct response_record *,
struct nmb_name *);
typedef void (*refresh_name_success_function)( struct subnet_record *, typedef void (*refresh_name_success_function) (struct subnet_record *,
struct userdata_struct *, struct userdata_struct *,
struct nmb_name *, struct nmb_name *, uint16, int, struct in_addr);
uint16, typedef void (*refresh_name_fail_function) (struct subnet_record *,
int, struct response_record *, struct nmb_name *);
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 userdata_struct *,
struct nmb_name *, struct nmb_name *,
struct in_addr, struct in_addr, struct res_rec * answers);
struct res_rec *answers);
typedef void (*query_name_fail_function)( struct subnet_record *, typedef void (*query_name_fail_function) (struct subnet_record *,
struct response_record *, struct response_record *, struct nmb_name *, int);
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 userdata_struct *,
struct res_rec *, struct res_rec *, struct in_addr);
struct in_addr); typedef void (*node_status_fail_function) (struct subnet_record *, struct response_record *);
typedef void (*node_status_fail_function)( struct subnet_record *,
struct response_record *);
/* Initiated name queries are recorded in this list to track any responses. */ /* Initiated name queries are recorded in this list to track any responses. */
struct response_record struct response_record
{ {
struct response_record *next; struct response_record *next;
struct response_record *prev; struct response_record *prev;
uint16 response_id; uint16 response_id;
/* Callbacks for packets received or not. */ /* Callbacks for packets received or not. */
response_function resp_fn; response_function resp_fn;
timeout_response_function timeout_fn; timeout_response_function timeout_fn;
/* Callbacks for the request succeeding or not. */ /* Callbacks for the request succeeding or not. */
success_function success_fn; success_function success_fn;
fail_function fail_fn; fail_function fail_fn;
struct packet_struct *packet;
struct userdata_struct *userdata; struct packet_struct *packet;
int num_msgs; struct userdata_struct *userdata;
time_t repeat_time; int num_msgs;
time_t repeat_interval;
int repeat_count;
/* Recursion protection. */ time_t repeat_time;
BOOL in_expiration_processing; 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. */ /* 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 B nodes will have their own, totally separate subnet record, with their
own netbios name set. These do NOT interact with other subnet records' own netbios name set. These do NOT interact with other subnet records'
netbios names. netbios names.
*/ */
enum subnet_type { enum subnet_type
NORMAL_SUBNET = 0, /* Subnet listed in interfaces list. */ {
UNICAST_SUBNET = 1, /* Subnet for unicast packets. */ NORMAL_SUBNET = 0, /* Subnet listed in interfaces list. */
REMOTE_BROADCAST_SUBNET = 2, /* Subnet for remote broadcasts. */ UNICAST_SUBNET = 1, /* Subnet for unicast packets. */
WINS_SERVER_SUBNET = 3 /* Only created if we are a WINS server. */ REMOTE_BROADCAST_SUBNET = 2, /* Subnet for remote broadcasts. */
WINS_SERVER_SUBNET = 3 /* Only created if we are a WINS server. */
}; };
/* A resource record. */ /* A resource record. */
struct res_rec { struct res_rec
struct nmb_name rr_name; {
int rr_type; struct nmb_name rr_name;
int rr_class; int rr_type;
int ttl; int rr_class;
int rdlength; int ttl;
char rdata[MAX_DGRAM_SIZE]; int rdlength;
char rdata[MAX_DGRAM_SIZE];
}; };
/* An nmb packet. */ /* An nmb packet. */
struct nmb_packet struct nmb_packet
{ {
struct { struct
int name_trn_id; {
int opcode; int name_trn_id;
BOOL response; int opcode;
struct { BOOL response;
BOOL bcast; struct
BOOL recursion_available; {
BOOL recursion_desired; BOOL bcast;
BOOL trunc; BOOL recursion_available;
BOOL authoritative; BOOL recursion_desired;
} nm_flags; BOOL trunc;
int rcode; BOOL authoritative;
int qdcount; } nm_flags;
int ancount; int rcode;
int nscount; int qdcount;
int arcount; int ancount;
} header; int nscount;
int arcount;
} header;
struct { struct
struct nmb_name question_name; {
int question_type; struct nmb_name question_name;
int question_class; int question_type;
} question; int question_class;
} question;
struct res_rec *answers; struct res_rec *answers;
struct res_rec *nsrecs; struct res_rec *nsrecs;
struct res_rec *additional; struct res_rec *additional;
}; };
/* A datagram - this normally contains SMB data in the data[] array. */ /* A datagram - this normally contains SMB data in the data[] array. */
struct dgram_packet { struct dgram_packet
struct { {
int msg_type; struct
struct { {
enum node_type node_type; int msg_type;
BOOL first; struct
BOOL more; {
} flags; enum node_type node_type;
int dgm_id; BOOL first;
struct in_addr source_ip; BOOL more;
int source_port; } flags;
int dgm_length; int dgm_id;
int packet_offset; struct in_addr source_ip;
} header; int source_port;
struct nmb_name source_name; int dgm_length;
struct nmb_name dest_name; int packet_offset;
int datasize; } header;
char data[MAX_DGRAM_SIZE]; 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 /* 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
{ {
struct packet_struct *next; struct packet_struct *next;
struct packet_struct *prev; struct packet_struct *prev;
BOOL locked; BOOL locked;
struct in_addr ip; struct in_addr ip;
int port; int port;
int fd; int fd;
time_t timestamp; time_t timestamp;
enum packet_type packet_type; enum packet_type packet_type;
union { union
struct nmb_packet nmb; {
struct dgram_packet dgram; struct nmb_packet nmb;
} packet; struct dgram_packet dgram;
} packet;
}; };
/* NETLOGON opcodes */ /* NETLOGON opcodes */
#define QUERYFORPDC 7 /* Query for PDC. */ #define QUERYFORPDC 7 /* Query for PDC. */
#define QUERYFORPDC_R 12 /* Response to Query for PDC. */ #define QUERYFORPDC_R 12 /* Response to Query for PDC. */
#define SAMLOGON 18 #define SAMLOGON 18
#define SAMLOGON_R 19 #define SAMLOGON_R 19
@ -462,11 +462,11 @@ struct packet_struct
/* Broadcast packet announcement intervals, in minutes. */ /* Broadcast packet announcement intervals, in minutes. */
/* Attempt to add domain logon and domain master names. */ /* 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, /* Search for master browsers of workgroups samba knows about,
except default. */ except default. */
#define CHECK_TIME_MST_BROWSE 5 #define CHECK_TIME_MST_BROWSE 5
/* Request backup browser announcements from other servers. */ /* Request backup browser announcements from other servers. */
#define CHECK_TIME_ANNOUNCE_BACKUP 15 #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))) #define NEXT_SUBNET_INCLUDING_UNICAST(x) (get_next_subnet_maybe_unicast((x)))
/* To be removed. */ /* To be removed. */
enum state_type { TEST }; enum state_type
{ TEST };
#endif /* _NAMESERV_H_ */ #endif /* _NAMESERV_H_ */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -2,7 +2,7 @@
Unix SMB/Netbios implementation. Unix SMB/Netbios implementation.
Version 1.9. Version 1.9.
SMB transaction2 handling SMB transaction2 handling
*/ */
#ifndef _TRANS2_H_ #ifndef _TRANS2_H_
#define _TRANS2_H_ #define _TRANS2_H_
@ -243,6 +243,3 @@ Byte offset Type name description
#define TYPE_VIRTUAL 0x40 #define TYPE_VIRTUAL 0x40
#endif #endif

Просмотреть файл

@ -22,7 +22,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
#define CTRLZ 26 #define CTRLZ 26
@ -35,203 +35,243 @@ static BOOL mapsinited = 0;
static char unix2dos[256]; static char unix2dos[256];
static char dos2unix[256]; static char dos2unix[256];
static void initmaps(void) { static void
initmaps (void)
{
int k; int k;
for (k = 0; k < 256; k++) unix2dos[k] = k; for (k = 0; k < 256; k++)
for (k = 0; k < 256; k++) dos2unix[k] = k; unix2dos[k] = k;
for (k = 0; k < 256; k++)
dos2unix[k] = k;
mapsinited = True; mapsinited = True;
} }
static void update_map(const char * str) { static void
update_map (const char *str)
{
const char *p; const char *p;
for (p = str; *p; p++) { for (p = str; *p; p++)
if (p[1]) { {
unix2dos[(unsigned char)*p] = p[1]; if (p[1])
dos2unix[(unsigned char)p[1]] = *p; {
unix2dos[(unsigned char) *p] = p[1];
dos2unix[(unsigned char) p[1]] = *p;
p++; p++;
} }
} }
} }
static void init_iso8859_1(void) { static void
init_iso8859_1 (void)
{
int i; int i;
if (!mapsinited) initmaps(); if (!mapsinited)
initmaps ();
/* Do not map undefined characters to some accidental code */ /* Do not map undefined characters to some accidental code */
for (i = 128; i < 256; i++) for (i = 128; i < 256; i++)
{ {
unix2dos[i] = CTRLZ; unix2dos[i] = CTRLZ;
dos2unix[i] = CTRLZ; dos2unix[i] = CTRLZ;
} }
/* MSDOS Code Page 850 -> ISO-8859 */ /* 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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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"); update_map ("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230");
} }
/* Init for eastern european languages. */ /* Init for eastern european languages. */
static void init_iso8859_2(void) { static void
init_iso8859_2 (void)
{
int i; int i;
if (!mapsinited) initmaps(); if (!mapsinited)
initmaps ();
/* Do not map undefined characters to some accidental code */ /* Do not map undefined characters to some accidental code */
for (i = 128; i < 256; i++) for (i = 128; i < 256; i++)
{ {
unix2dos[i] = CTRLZ; unix2dos[i] = CTRLZ;
dos2unix[i] = CTRLZ; dos2unix[i] = CTRLZ;
} }
/* /*
* Tranlation table created by Petr Hubeny <psh@capitol.cz> * Tranlation table created by Petr Hubeny <psh@capitol.cz>
* Requires client code page = 852 * Requires client code page = 852
* and character set = ISO8859-2 in smb.conf * and character set = ISO8859-2 in smb.conf
*/ */
/* MSDOS Code Page 852 -> ISO-8859-2 */ /* 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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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"); update_map ("\370\375\371\205\372\243\373\373\374\201\375\354\376\356\377\372");
} }
/* Init for russian language (iso8859-5) */ /* Init for russian language (iso8859-5) */
/* Added by Max Khon <max@iclub.nsu.ru> */ /* Added by Max Khon <max@iclub.nsu.ru> */
static void init_iso8859_5(void) static void
init_iso8859_5 (void)
{ {
int i; int i;
if (!mapsinited) initmaps(); if (!mapsinited)
initmaps ();
/* Do not map undefined characters to some accidental code */ /* Do not map undefined characters to some accidental code */
for (i = 128; i < 256; i++) for (i = 128; i < 256; i++)
{ {
unix2dos[i] = CTRLZ; unix2dos[i] = CTRLZ;
dos2unix[i] = CTRLZ; dos2unix[i] = CTRLZ;
} }
/* MSDOS Code Page 866 -> ISO8859-5 */ /* 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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\241\360\361\361\244\362\364\363\247\364\367\365\256\366\376\367");
update_map("\360\374\240\377"); update_map ("\360\374\240\377");
} }
/* Init for russian language (koi8) */ /* 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 */ /* 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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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 ("\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"); update_map ("\370\234\371\233\372\207\373\230\374\235\375\231\376\227\377\232");
} }
/* /*
* Convert unix to dos * Convert unix to dos
*/ */
char *unix2dos_format(char *str,BOOL overwrite) char *
unix2dos_format (char *str, BOOL overwrite)
{ {
char *p; char *p;
char *dp; char *dp;
if (!mapsinited) initmaps(); if (!mapsinited)
initmaps ();
if (overwrite) { if (overwrite)
for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p]; {
return str; for (p = str; *p; p++)
} else { *p = unix2dos[(unsigned char) *p];
for (p = str, dp = cvtbuf; *p && dp < &(cvtbuf[sizeof(cvtbuf) - 1]); p++,dp++) return str;
*dp = unix2dos[(unsigned char)*p]; }
*dp = 0; else
return cvtbuf; {
} 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 * Convert dos to unix
*/ */
char *dos2unix_format(char *str, BOOL overwrite) char *
dos2unix_format (char *str, BOOL overwrite)
{ {
char *p; char *p;
char *dp; char *dp;
if (!mapsinited) initmaps(); if (!mapsinited)
initmaps ();
if (overwrite) { if (overwrite)
for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p]; {
return str; for (p = str; *p; p++)
} else { *p = dos2unix[(unsigned char) *p];
for (p = str, dp = cvtbuf; *p && dp < &(cvtbuf[sizeof(cvtbuf) - 1]); p++,dp++) return str;
*dp = dos2unix[(unsigned char)*p]; }
*dp = 0; else
return cvtbuf; {
} 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. * Interpret character set.
*/ */
void interpret_character_set(const char *str) void
interpret_character_set (const char *str)
{ {
if (strequal (str, "iso8859-1")) { if (strequal (str, "iso8859-1"))
init_iso8859_1(); {
} else if (strequal (str, "iso8859-2")) { init_iso8859_1 ();
init_iso8859_2(); }
} else if (strequal (str, "iso8859-5")) { else if (strequal (str, "iso8859-2"))
init_iso8859_5(); {
} else if (strequal (str, "koi8-r")) { init_iso8859_2 ();
init_koi8_r(); }
} else { else if (strequal (str, "iso8859-5"))
DEBUG(0,("unrecognized character set %s\n", str)); {
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 You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define CHARSET_C #define CHARSET_C
#include "includes.h" #include "includes.h"
@ -37,75 +37,75 @@ extern int DEBUGLEVEL;
#if !defined(KANJI) #if !defined(KANJI)
/* lower->upper mapping for IBM Code Page 850 - MS-DOS Latin 1 */ /* lower->upper mapping for IBM Code Page 850 - MS-DOS Latin 1 */
unsigned char const cp_850[][4] = { unsigned char const cp_850[][4] = {
/* dec col/row oct hex description */ /* dec col/row oct hex description */
/* 133 08/05 205 85 a grave */ /* 133 08/05 205 85 a grave */
/* 183 11/07 267 B7 A grave */ {0x85,0xB7,1,1}, /* 183 11/07 267 B7 A grave */ {0x85, 0xB7, 1, 1},
/* 160 10/00 240 A0 a acute */ /* 160 10/00 240 A0 a acute */
/* 181 11/05 265 B5 A acute */ {0xA0,0xB5,1,1}, /* 181 11/05 265 B5 A acute */ {0xA0, 0xB5, 1, 1},
/* 131 08/03 203 83 a circumflex */ /* 131 08/03 203 83 a circumflex */
/* 182 11/06 266 B6 A circumflex */ {0x83,0xB6,1,1}, /* 182 11/06 266 B6 A circumflex */ {0x83, 0xB6, 1, 1},
/* 198 12/06 306 C6 a tilde */ /* 198 12/06 306 C6 a tilde */
/* 199 12/07 307 C7 A tilde */ {0xC6,0xC7,1,1}, /* 199 12/07 307 C7 A tilde */ {0xC6, 0xC7, 1, 1},
/* 132 08/04 204 84 a diaeresis */ /* 132 08/04 204 84 a diaeresis */
/* 142 08/14 216 8E A diaeresis */ {0x84,0x8E,1,1}, /* 142 08/14 216 8E A diaeresis */ {0x84, 0x8E, 1, 1},
/* 134 08/06 206 86 a ring */ /* 134 08/06 206 86 a ring */
/* 143 08/15 217 8F A ring */ {0x86,0x8F,1,1}, /* 143 08/15 217 8F A ring */ {0x86, 0x8F, 1, 1},
/* 145 09/01 221 91 ae diphthong */ /* 145 09/01 221 91 ae diphthong */
/* 146 09/02 222 92 AE diphthong */ {0x91,0x92,1,1}, /* 146 09/02 222 92 AE diphthong */ {0x91, 0x92, 1, 1},
/* 135 08/07 207 87 c cedilla */ /* 135 08/07 207 87 c cedilla */
/* 128 08/00 200 80 C cedilla */ {0x87,0x80,1,1}, /* 128 08/00 200 80 C cedilla */ {0x87, 0x80, 1, 1},
/* 138 08/10 212 8A e grave */ /* 138 08/10 212 8A e grave */
/* 212 13/04 324 D4 E grave */ {0x8A,0xD4,1,1}, /* 212 13/04 324 D4 E grave */ {0x8A, 0xD4, 1, 1},
/* 130 08/02 202 82 e acute */ /* 130 08/02 202 82 e acute */
/* 144 09/00 220 90 E acute */ {0x82,0x90,1,1}, /* 144 09/00 220 90 E acute */ {0x82, 0x90, 1, 1},
/* 136 08/08 210 88 e circumflex */ /* 136 08/08 210 88 e circumflex */
/* 210 13/02 322 D2 E circumflex */ {0x88,0xD2,1,1}, /* 210 13/02 322 D2 E circumflex */ {0x88, 0xD2, 1, 1},
/* 137 08/09 211 89 e diaeresis */ /* 137 08/09 211 89 e diaeresis */
/* 211 13/03 323 D3 E diaeresis */ {0x89,0xD3,1,1}, /* 211 13/03 323 D3 E diaeresis */ {0x89, 0xD3, 1, 1},
/* 141 08/13 215 8D i grave */ /* 141 08/13 215 8D i grave */
/* 222 13/14 336 DE I grave */ {0x8D,0xDE,1,1}, /* 222 13/14 336 DE I grave */ {0x8D, 0xDE, 1, 1},
/* 161 10/01 241 A1 i acute */ /* 161 10/01 241 A1 i acute */
/* 214 13/06 326 D6 I acute */ {0xA1,0xD6,1,1}, /* 214 13/06 326 D6 I acute */ {0xA1, 0xD6, 1, 1},
/* 140 08/12 214 8C i circumflex */ /* 140 08/12 214 8C i circumflex */
/* 215 13/07 327 D7 I circumflex */ {0x8C,0xD7,1,1}, /* 215 13/07 327 D7 I circumflex */ {0x8C, 0xD7, 1, 1},
/* 139 08/11 213 8B i diaeresis */ /* 139 08/11 213 8B i diaeresis */
/* 216 13/08 330 D8 I diaeresis */ {0x8B,0xD8,1,1}, /* 216 13/08 330 D8 I diaeresis */ {0x8B, 0xD8, 1, 1},
/* 208 13/00 320 D0 Icelandic eth */ /* 208 13/00 320 D0 Icelandic eth */
/* 209 13/01 321 D1 Icelandic Eth */ {0xD0,0xD1,1,1}, /* 209 13/01 321 D1 Icelandic Eth */ {0xD0, 0xD1, 1, 1},
/* 164 10/04 244 A4 n tilde */ /* 164 10/04 244 A4 n tilde */
/* 165 10/05 245 A5 N tilde */ {0xA4,0xA5,1,1}, /* 165 10/05 245 A5 N tilde */ {0xA4, 0xA5, 1, 1},
/* 149 09/05 225 95 o grave */ /* 149 09/05 225 95 o grave */
/* 227 14/03 343 E3 O grave */ {0x95,0xE3,1,1}, /* 227 14/03 343 E3 O grave */ {0x95, 0xE3, 1, 1},
/* 162 10/02 242 A2 o acute */ /* 162 10/02 242 A2 o acute */
/* 224 14/00 340 E0 O acute */ {0xA2,0xE0,1,1}, /* 224 14/00 340 E0 O acute */ {0xA2, 0xE0, 1, 1},
/* 147 09/03 223 93 o circumflex */ /* 147 09/03 223 93 o circumflex */
/* 226 14/02 342 E2 O circumflex */ {0x93,0xE2,1,1}, /* 226 14/02 342 E2 O circumflex */ {0x93, 0xE2, 1, 1},
/* 228 14/04 344 E4 o tilde */ /* 228 14/04 344 E4 o tilde */
/* 229 14/05 345 E5 O tilde */ {0xE4,0xE5,1,1}, /* 229 14/05 345 E5 O tilde */ {0xE4, 0xE5, 1, 1},
/* 148 09/04 224 94 o diaeresis */ /* 148 09/04 224 94 o diaeresis */
/* 153 09/09 231 99 O diaeresis */ {0x94,0x99,1,1}, /* 153 09/09 231 99 O diaeresis */ {0x94, 0x99, 1, 1},
/* 155 09/11 233 9B o slash */ /* 155 09/11 233 9B o slash */
/* 157 09/13 235 9D O slash */ {0x9B,0x9D,1,1}, /* 157 09/13 235 9D O slash */ {0x9B, 0x9D, 1, 1},
/* 151 09/07 227 97 u grave */ /* 151 09/07 227 97 u grave */
/* 235 14/11 353 EB U grave */ {0x97,0xEB,1,1}, /* 235 14/11 353 EB U grave */ {0x97, 0xEB, 1, 1},
/* 163 10/03 243 A3 u acute */ /* 163 10/03 243 A3 u acute */
/* 233 14/09 351 E9 U acute */ {0xA3,0xE9,1,1}, /* 233 14/09 351 E9 U acute */ {0xA3, 0xE9, 1, 1},
/* 150 09/06 226 96 u circumflex */ /* 150 09/06 226 96 u circumflex */
/* 234 14/10 352 EA U circumflex */ {0x96,0xEA,1,1}, /* 234 14/10 352 EA U circumflex */ {0x96, 0xEA, 1, 1},
/* 129 08/01 201 81 u diaeresis */ /* 129 08/01 201 81 u diaeresis */
/* 154 09/10 232 9A U diaeresis */ {0x81,0x9A,1,1}, /* 154 09/10 232 9A U diaeresis */ {0x81, 0x9A, 1, 1},
/* 236 14/12 354 EC y acute */ /* 236 14/12 354 EC y acute */
/* 237 14/13 355 ED Y acute */ {0xEC,0xED,1,1}, /* 237 14/13 355 ED Y acute */ {0xEC, 0xED, 1, 1},
/* 231 14/07 347 E7 Icelandic thorn */ /* 231 14/07 347 E7 Icelandic thorn */
/* 232 14/08 350 E8 Icelandic Thorn */ {0xE7,0xE8,1,1}, /* 232 14/08 350 E8 Icelandic Thorn */ {0xE7, 0xE8, 1, 1},
{0x9C,0,0,0}, /* Pound */ {0x9C, 0, 0, 0}, /* Pound */
{0,0,0,0} {0, 0, 0, 0}
}; };
#else /* KANJI */ #else /* KANJI */
/* lower->upper mapping for IBM Code Page 932 - MS-DOS Japanese SJIS */ /* lower->upper mapping for IBM Code Page 932 - MS-DOS Japanese SJIS */
unsigned char const cp_932[][4] = { unsigned char const cp_932[][4] = {
{0,0,0,0} {0, 0, 0, 0}
}; };
#endif /* KANJI */ #endif /* KANJI */
@ -128,60 +128,69 @@ char *lower_char_map = xx_lower_char_map;
* mapping from lower to upper, but not upper to lower. * mapping from lower to upper, but not upper to lower.
*/ */
static void add_dos_char(int lower, BOOL map_lower_to_upper, static void
int upper, BOOL map_upper_to_lower) add_dos_char (int lower, BOOL map_lower_to_upper, int upper, BOOL map_upper_to_lower)
{ {
lower &= 0xff; lower &= 0xff;
upper &= 0xff; upper &= 0xff;
DEBUGADD( 6, ( "Adding chars 0x%x 0x%x (l->u = %s) (u->l = %s)\n", DEBUGADD (6, ("Adding chars 0x%x 0x%x (l->u = %s) (u->l = %s)\n",
lower, upper, lower, upper,
map_lower_to_upper ? "True" : "False", map_lower_to_upper ? "True" : "False", map_upper_to_lower ? "True" : "False"));
map_upper_to_lower ? "True" : "False" ) ); if (lower)
if (lower) dos_char_map[lower] = 1; dos_char_map[lower] = 1;
if (upper) dos_char_map[upper] = 1; if (upper)
lower_char_map[lower] = (char)lower; /* Define tolower(lower) */ dos_char_map[upper] = 1;
upper_char_map[upper] = (char)upper; /* Define toupper(upper) */ lower_char_map[lower] = (char) lower; /* Define tolower(lower) */
if (lower && upper) { upper_char_map[upper] = (char) upper; /* Define toupper(upper) */
if(map_upper_to_lower) if (lower && upper)
lower_char_map[upper] = (char)lower; {
if(map_lower_to_upper) if (map_upper_to_lower)
upper_char_map[lower] = (char)upper; lower_char_map[upper] = (char) lower;
} if (map_lower_to_upper)
upper_char_map[lower] = (char) upper;
}
} }
/**************************************************************************** /****************************************************************************
initialise the charset arrays initialise the charset arrays
****************************************************************************/ ****************************************************************************/
void charset_initialise(void) void
charset_initialise (void)
{ {
int i; int i;
#ifdef LC_ALL #ifdef LC_ALL
/* include <locale.h> in includes.h if available for OS */ /* include <locale.h> in includes.h if available for OS */
/* we take only standard 7-bit ASCII definitions from ctype */ /* we take only standard 7-bit ASCII definitions from ctype */
setlocale(LC_ALL,"C"); setlocale (LC_ALL, "C");
#endif #endif
for (i= 0;i<=255;i++) { for (i = 0; i <= 255; i++)
dos_char_map[i] = 0; {
} dos_char_map[i] = 0;
}
for (i=0;i<=127;i++) {
if (isalnum(i) || strchr("._^$~!#%&-{}()@'`",(char)i)) for (i = 0; i <= 127; i++)
add_dos_char(i,False,0,False); {
} 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; for (i = 0; i <= 255; i++)
{
/* Some systems have buggy isupper/islower for characters char c = (char) i;
above 127. Best not to rely on them. */ upper_char_map[i] = lower_char_map[i] = c;
if(i < 128) {
if (isupper((int)c)) lower_char_map[i] = tolower(c); /* Some systems have buggy isupper/islower for characters
if (islower((int)c)) upper_char_map[i] = toupper(c); 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]; 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; pstring codepage_file_name;
unsigned char buf[8]; unsigned char buf[8];
FILE *fp = NULL; FILE *fp = NULL;
SMB_OFF_T size; SMB_OFF_T size;
codepage_p cp_p = NULL; codepage_p cp_p = NULL;
SMB_STRUCT_STAT st; 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)) if (strlen (CODEPAGEDIR) + 14 > sizeof (codepage_file_name))
{ {
DEBUG(0,("load_client_codepage: filename too long to load\n")); DEBUG (0, ("load_client_codepage: filename too long to load\n"));
return NULL; return NULL;
} }
pstrcpy(codepage_file_name, CODEPAGEDIR); pstrcpy (codepage_file_name, CODEPAGEDIR);
pstrcat(codepage_file_name, "/"); pstrcat (codepage_file_name, "/");
pstrcat(codepage_file_name, "codepage."); pstrcat (codepage_file_name, "codepage.");
slprintf(&codepage_file_name[strlen(codepage_file_name)], slprintf (&codepage_file_name[strlen (codepage_file_name)],
sizeof(pstring)-(strlen(codepage_file_name)+1), sizeof (pstring) - (strlen (codepage_file_name) + 1), "%03d", client_codepage);
"%03d",
client_codepage);
if(sys_stat(codepage_file_name,&st)!=0) if (sys_stat (codepage_file_name, &st) != 0)
{ {
DEBUG(0,("load_client_codepage: filename %s does not exist.\n", DEBUG (0, ("load_client_codepage: filename %s does not exist.\n", codepage_file_name));
codepage_file_name)); return NULL;
return NULL; }
}
/* Check if it is at least big enough to hold the required /* Check if it is at least big enough to hold the required
data. Should be 2 byte version, 2 byte codepage, 4 byte length, 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 plus zero or more bytes of data. Note that the data cannot be more
than 4 * MAXCODEPAGELINES bytes. than 4 * MAXCODEPAGELINES bytes.
*/ */
size = st.st_size; size = st.st_size;
if( size < CODEPAGE_HEADER_SIZE || size > (CODEPAGE_HEADER_SIZE + 4 * MAXCODEPAGELINES)) if (size < CODEPAGE_HEADER_SIZE || size > (CODEPAGE_HEADER_SIZE + 4 * MAXCODEPAGELINES))
{ {
DEBUG(0,("load_client_codepage: file %s is an incorrect size for a \ DEBUG (0, ("load_client_codepage: file %s is an incorrect size for a \
code page file (size=%d).\n", codepage_file_name, (int)size)); code page file (size=%d).\n", codepage_file_name, (int) size));
return NULL; return NULL;
} }
/* Read the first 8 bytes of the codepage file - check /* Read the first 8 bytes of the codepage file - check
the version number and code page number. All the data the version number and code page number. All the data
is held in little endian format. is held in little endian format.
*/ */
if((fp = sys_fopen( codepage_file_name, "r")) == NULL) if ((fp = sys_fopen (codepage_file_name, "r")) == NULL)
{ {
DEBUG(0,("load_client_codepage: cannot open file %s. Error was %s\n", DEBUG (0, ("load_client_codepage: cannot open file %s. Error was %s\n",
codepage_file_name, unix_error_string (errno))); codepage_file_name, unix_error_string (errno)));
return NULL; return NULL;
} }
if(fread( buf, 1, CODEPAGE_HEADER_SIZE, fp)!=CODEPAGE_HEADER_SIZE) 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", DEBUG (0, ("load_client_codepage: cannot read header from file %s. Error was %s\n",
codepage_file_name, unix_error_string (errno))); codepage_file_name, unix_error_string (errno)));
goto clean_and_exit; goto clean_and_exit;
} }
/* Check the version value */ /* Check the version value */
if(SVAL(buf,CODEPAGE_VERSION_OFFSET) != CODEPAGE_FILE_VERSION_ID) if (SVAL (buf, CODEPAGE_VERSION_OFFSET) != CODEPAGE_FILE_VERSION_ID)
{ {
DEBUG(0,("load_client_codepage: filename %s has incorrect version id. \ DEBUG (0, ("load_client_codepage: filename %s has incorrect version id. \
Needed %hu, got %hu.\n", Needed %hu, got %hu.\n", codepage_file_name, (uint16) CODEPAGE_FILE_VERSION_ID, SVAL (buf, CODEPAGE_VERSION_OFFSET)));
codepage_file_name, (uint16)CODEPAGE_FILE_VERSION_ID, goto clean_and_exit;
SVAL(buf,CODEPAGE_VERSION_OFFSET))); }
goto clean_and_exit;
}
/* Check the codepage matches */ /* Check the codepage matches */
if(SVAL(buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET) != (uint16)client_codepage) if (SVAL (buf, CODEPAGE_CLIENT_CODEPAGE_OFFSET) != (uint16) client_codepage)
{ {
DEBUG(0,("load_client_codepage: filename %s has incorrect codepage. \ DEBUG (0, ("load_client_codepage: filename %s has incorrect codepage. \
Needed %hu, got %hu.\n", Needed %hu, got %hu.\n", codepage_file_name, (uint16) client_codepage, SVAL (buf, CODEPAGE_CLIENT_CODEPAGE_OFFSET)));
codepage_file_name, (uint16)client_codepage, goto clean_and_exit;
SVAL(buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET))); }
goto clean_and_exit;
}
/* Check the length is correct. */ /* Check the length is correct. */
if(IVAL(buf,CODEPAGE_LENGTH_OFFSET) != (size - CODEPAGE_HEADER_SIZE)) if (IVAL (buf, CODEPAGE_LENGTH_OFFSET) != (size - CODEPAGE_HEADER_SIZE))
{ {
DEBUG(0,("load_client_codepage: filename %s has incorrect size headers. \ DEBUG (0, ("load_client_codepage: filename %s has incorrect size headers. \
Needed %u, got %u.\n", codepage_file_name, (uint32)(size - CODEPAGE_HEADER_SIZE), Needed %u, got %u.\n", codepage_file_name, (uint32) (size - CODEPAGE_HEADER_SIZE), IVAL (buf, CODEPAGE_LENGTH_OFFSET)));
IVAL(buf,CODEPAGE_LENGTH_OFFSET))); goto clean_and_exit;
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. */ /* Make sure the size is a multiple of 4. */
if((size % 4 ) != 0) if ((size % 4) != 0)
{ {
DEBUG(0,("load_client_codepage: filename %s has a codepage size not a \ DEBUG (0, ("load_client_codepage: filename %s has a codepage size not a \
multiple of 4.\n", codepage_file_name)); 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. */ /* Allocate space for the code page file and read it all in. */
if((cp_p = (codepage_p)malloc( size + 4 )) == NULL) if ((cp_p = (codepage_p) malloc (size + 4)) == NULL)
{ {
DEBUG(0,("load_client_codepage: malloc fail.\n")); DEBUG (0, ("load_client_codepage: malloc fail.\n"));
goto clean_and_exit; goto clean_and_exit;
} }
if(fread( (char *)cp_p, 1, size, fp)!=size) if (fread ((char *) cp_p, 1, size, fp) != size)
{ {
DEBUG(0,("load_client_codepage: read fail on file %s. Error was %s.\n", DEBUG (0, ("load_client_codepage: read fail on file %s. Error was %s.\n",
codepage_file_name, unix_error_string (errno))); codepage_file_name, unix_error_string (errno)));
goto clean_and_exit; goto clean_and_exit;
} }
/* Ensure array is correctly terminated. */ /* Ensure array is correctly terminated. */
memset(((char *)cp_p) + size, '\0', 4); memset (((char *) cp_p) + size, '\0', 4);
fclose(fp); fclose (fp);
return cp_p; return cp_p;
clean_and_exit: clean_and_exit:
/* pseudo destructor :-) */ /* pseudo destructor :-) */
if(fp != NULL) if (fp != NULL)
fclose(fp); fclose (fp);
if(cp_p) if (cp_p)
free((char *)cp_p); free ((char *) cp_p);
return NULL; return NULL;
} }
/**************************************************************************** /****************************************************************************
initialise the client codepage. initialise the client codepage.
****************************************************************************/ ****************************************************************************/
void codepage_initialise(int client_codepage) void
codepage_initialise (int client_codepage)
{ {
int i; int i;
static codepage_p cp = NULL; static codepage_p cp = NULL;
if(cp != NULL) if (cp != NULL)
{ {
DEBUG(6, DEBUG (6,
("codepage_initialise: called twice - ignoring second client code page = %d\n", ("codepage_initialise: called twice - ignoring second client code page = %d\n",
client_codepage)); client_codepage));
return; 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. * Known client codepages - these can be added to.
*/ */
cp = load_client_codepage( client_codepage ); cp = load_client_codepage (client_codepage);
if(cp == NULL) if (cp == NULL)
{ {
#ifdef KANJI #ifdef KANJI
DEBUG(6,("codepage_initialise: loading dynamic codepage file %s/codepage.%d \ DEBUG (6, ("codepage_initialise: loading dynamic codepage file %s/codepage.%d \
for code page %d failed. Using default client codepage 932\n", for code page %d failed. Using default client codepage 932\n", CODEPAGEDIR, client_codepage, client_codepage));
CODEPAGEDIR, client_codepage, client_codepage)); cp = cp_932;
cp = cp_932; client_codepage = KANJI_CODEPAGE;
client_codepage = KANJI_CODEPAGE;
#else /* KANJI */ #else /* KANJI */
DEBUG(6,("codepage_initialise: loading dynamic codepage file %s/codepage.%d \ DEBUG (6, ("codepage_initialise: loading dynamic codepage file %s/codepage.%d \
for code page %d failed. Using default client codepage 850\n", for code page %d failed. Using default client codepage 850\n", CODEPAGEDIR, client_codepage, client_codepage));
CODEPAGEDIR, client_codepage, client_codepage)); cp = cp_850;
cp = cp_850; client_codepage = MSDOS_LATIN_1_CODEPAGE;
client_codepage = MSDOS_LATIN_1_CODEPAGE;
#endif /* KANJI */ #endif /* KANJI */
} }
/* /*
* Setup the function pointers for the loaded codepage. * Setup the function pointers for the loaded codepage.
*/ */
initialize_multibyte_vectors( client_codepage ); initialize_multibyte_vectors (client_codepage);
if(cp) if (cp)
{ {
for(i = 0; !((cp[i][0] == '\0') && (cp[i][1] == '\0')); i++) 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_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 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 *extra_chars = (char *) strdup (s);
char *t; char *t;
if (!extra_chars) return; if (!extra_chars)
return;
for (t=strtok(extra_chars," \t\r\n"); t; t=strtok(NULL," \t\r\n")) { 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; char c1 = 0, c2 = 0;
if (isdigit((unsigned char)*t) || (*t)=='-') { int i1 = 0, i2 = 0;
sscanf(t,"%i:%i",&i1,&i2); if (isdigit ((unsigned char) *t) || (*t) == '-')
add_dos_char(i1,True,i2,True); {
} else { sscanf (t, "%i:%i", &i1, &i2);
sscanf(t,"%c:%c",&c1,&c2); add_dos_char (i1, True, i2, True);
add_dos_char((unsigned char)c1,True,(unsigned char)c2, 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 You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
@ -84,10 +84,10 @@
* levels higher than DEBUGLEVEL will not be processed. * levels higher than DEBUGLEVEL will not be processed.
*/ */
FILE *dbf = NULL; FILE *dbf = NULL;
pstring debugf = ""; pstring debugf = "";
BOOL append_log = False; BOOL append_log = False;
int DEBUGLEVEL = 1; int DEBUGLEVEL = 1;
/* -------------------------------------------------------------------------- ** /* -------------------------------------------------------------------------- **
@ -108,9 +108,10 @@ int DEBUGLEVEL = 1;
* format_pos - Marks the first free byte of the format_bufr. * format_pos - Marks the first free byte of the format_bufr.
*/ */
static BOOL stdout_logging = False; static BOOL stdout_logging = False;
static pstring format_bufr = { '\0' }; static pstring format_bufr = { '\0' };
static size_t format_pos = 0;
static size_t format_pos = 0;
/* -------------------------------------------------------------------------- ** /* -------------------------------------------------------------------------- **
@ -121,15 +122,16 @@ static size_t format_pos = 0;
* get ready for syslog stuff * get ready for syslog stuff
* ************************************************************************** ** * ************************************************************************** **
*/ */
void setup_logging( const char *pname, BOOL interactive ) void
{ setup_logging (const char *pname, BOOL interactive)
(void) pname; {
if( interactive ) (void) pname;
if (interactive)
{ {
stdout_logging = True; stdout_logging = True;
dbf = stderr; dbf = stderr;
} }
} /* setup_logging */ } /* setup_logging */
/* ************************************************************************** ** /* ************************************************************************** **
* Write an debug message on the debugfile. * Write an debug message on the debugfile.
@ -137,68 +139,70 @@ void setup_logging( const char *pname, BOOL interactive )
* ************************************************************************** ** * ************************************************************************** **
*/ */
#ifdef HAVE_STDARG_H #ifdef HAVE_STDARG_H
int Debug1( const char *format_str, ... ) int
Debug1 (const char *format_str, ...)
{ {
#else #else
int Debug1(va_alist) int
va_dcl Debug1 (va_alist)
{ va_dcl
const char *format_str; {
const char *format_str;
#endif #endif
va_list ap; va_list ap;
int old_errno = errno; int old_errno = errno;
if( stdout_logging ) if (stdout_logging)
{ {
#ifdef HAVE_STDARG_H #ifdef HAVE_STDARG_H
va_start( ap, format_str ); va_start (ap, format_str);
#else #else
va_start( ap ); va_start (ap);
format_str = va_arg( ap, const char * ); format_str = va_arg (ap, const char *);
#endif #endif
(void)vfprintf( dbf, format_str, ap ); (void) vfprintf (dbf, format_str, ap);
va_end( 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
{
errno = old_errno; 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) if (dbf)
{ {
#ifdef HAVE_STDARG_H #ifdef HAVE_STDARG_H
va_start( ap, format_str ); va_start (ap, format_str);
#else #else
va_start( ap ); va_start (ap);
format_str = va_arg( ap, const char * ); format_str = va_arg (ap, const char *);
#endif #endif
(void)vfprintf( dbf, format_str, ap ); (void) vfprintf (dbf, format_str, ap);
va_end( ap ); va_end (ap);
(void)fflush( dbf ); (void) fflush (dbf);
} }
errno = old_errno; errno = old_errno;
return( 0 ); return (0);
} /* Debug1 */ } /* Debug1 */
/* ************************************************************************** ** /* ************************************************************************** **
@ -209,12 +213,13 @@ va_dcl
* *
* ************************************************************************** ** * ************************************************************************** **
*/ */
static void bufr_print( void ) static void
{ bufr_print (void)
format_bufr[format_pos] = '\0'; {
(void)Debug1( "%s", format_bufr ); format_bufr[format_pos] = '\0';
format_pos = 0; (void) Debug1 ("%s", format_bufr);
} /* bufr_print */ format_pos = 0;
} /* bufr_print */
/* ************************************************************************** ** /* ************************************************************************** **
* Format the debug message text. * Format the debug message text.
@ -233,42 +238,42 @@ static void bufr_print( void )
* *
* ************************************************************************** ** * ************************************************************************** **
*/ */
static void format_debug_text( char *msg ) static void
{ format_debug_text (char *msg)
size_t i; {
BOOL timestamp = (!stdout_logging && (lp_timestamp_logs() || size_t i;
!(lp_loaded()))); 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. */ /* Indent two spaces at each new line. */
if(timestamp && 0 == format_pos) if (timestamp && 0 == format_pos)
{ {
format_bufr[0] = format_bufr[1] = ' '; format_bufr[0] = format_bufr[1] = ' ';
format_pos = 2; format_pos = 2;
} }
/* If there's room, copy the character to the format buffer. */ /* If there's room, copy the character to the format buffer. */
if( format_pos < FORMAT_BUFR_MAX ) if (format_pos < FORMAT_BUFR_MAX)
format_bufr[format_pos++] = msg[i]; format_bufr[format_pos++] = msg[i];
/* If a newline is encountered, print & restart. */ /* If a newline is encountered, print & restart. */
if( '\n' == msg[i] ) if ('\n' == msg[i])
bufr_print(); bufr_print ();
/* If the buffer is full dump it out, reset it, and put out a line /* If the buffer is full dump it out, reset it, and put out a line
* continuation indicator. * continuation indicator.
*/ */
if( format_pos >= FORMAT_BUFR_MAX ) if (format_pos >= FORMAT_BUFR_MAX)
{ {
bufr_print(); bufr_print ();
(void)Debug1( " +>\n" ); (void) Debug1 (" +>\n");
} }
} }
/* Just to be safe... */ /* Just to be safe... */
format_bufr[format_pos] = '\0'; format_bufr[format_pos] = '\0';
} /* format_debug_text */ } /* format_debug_text */
/* ************************************************************************** ** /* ************************************************************************** **
* Flush debug output, including the format buffer content. * Flush debug output, including the format buffer content.
@ -278,11 +283,12 @@ static void format_debug_text( char *msg )
* *
* ************************************************************************** ** * ************************************************************************** **
*/ */
void dbgflush( void ) void
{ dbgflush (void)
bufr_print(); {
(void)fflush( dbf ); bufr_print ();
} /* dbgflush */ (void) fflush (dbf);
} /* dbgflush */
/* ************************************************************************** ** /* ************************************************************************** **
* Print a Debug Header. * Print a Debug Header.
@ -306,38 +312,38 @@ void dbgflush( void )
* *
* ************************************************************************** ** * ************************************************************************** **
*/ */
BOOL dbghdr( int level, const char *file, const char *func, int line ) BOOL
{ dbghdr (int level, const char *file, const char *func, int line)
if( format_pos ) {
if (format_pos)
{ {
/* This is a fudge. If there is stuff sitting in the format_bufr, then /* This is a fudge. If there is stuff sitting in the format_bufr, then
* the *right* thing to do is to call * the *right* thing to do is to call
* format_debug_text( "\n" ); * format_debug_text( "\n" );
* to write the remainder, and then proceed with the new header. * to write the remainder, and then proceed with the new header.
* Unfortunately, there are several places in the code at which * Unfortunately, there are several places in the code at which
* the DEBUG() macro is used to build partial lines. That in mind, * the DEBUG() macro is used to build partial lines. That in mind,
* we'll work under the assumption that an incomplete line indicates * we'll work under the assumption that an incomplete line indicates
* that a new header is *not* desired. * 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 ); if (lp_timestamp_logs () || !(lp_loaded ()))
}
/* 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()) )
{ {
/* Print it all out at once to prevent split syslog output. */ /* Print it all out at once to prevent split syslog output. */
(void)Debug1( "[%s, %d] %s:%s(%d)\n", (void) Debug1 ("[%s, %d] %s:%s(%d)\n", timestring (), level, file, func, line);
timestring(), level, file, func, line );
} }
return( True ); return (True);
} /* dbghdr */ } /* dbghdr */
/* ************************************************************************** ** /* ************************************************************************** **
* Add text to the body of the "current" debug message via the format buffer. * 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 #ifdef HAVE_STDARG_H
BOOL dbgtext( const char *format_str, ... ) BOOL
{ dbgtext (const char *format_str, ...)
va_list ap; {
pstring msgbuf; va_list ap;
pstring msgbuf;
va_start( ap, format_str ); va_start (ap, format_str);
vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); vslprintf (msgbuf, sizeof (msgbuf) - 1, format_str, ap);
va_end( ap ); va_end (ap);
format_debug_text( msgbuf ); format_debug_text (msgbuf);
return( True ); return (True);
} /* dbgtext */ } /* dbgtext */
#else #else
BOOL dbgtext( va_alist ) BOOL
va_dcl dbgtext (va_alist)
{ va_dcl
char *format_str; {
va_list ap; char *format_str;
pstring msgbuf; va_list ap;
pstring msgbuf;
va_start( ap ); va_start (ap);
format_str = va_arg( ap, char * ); format_str = va_arg (ap, char *);
vslprintf( msgbuf, sizeof(msgbuf)-1, format_str, ap ); vslprintf (msgbuf, sizeof (msgbuf) - 1, format_str, ap);
va_end( ap ); va_end (ap);
format_debug_text( msgbuf ); format_debug_text (msgbuf);
return( True ); return (True);
} /* dbgtext */ } /* dbgtext */
#endif #endif

Просмотреть файл

@ -22,7 +22,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
@ -34,11 +34,11 @@ struct in_addr loopback_ip;
static struct in_addr default_ip; static struct in_addr default_ip;
static struct in_addr default_bcast; static struct in_addr default_bcast;
static struct in_addr default_nmask; static struct in_addr default_nmask;
static BOOL got_ip=False; static BOOL got_ip = False;
static BOOL got_bcast=False; static BOOL got_bcast = False;
static BOOL got_nmask=False; static BOOL got_nmask = False;
static struct interface *local_interfaces = NULL; static struct interface *local_interfaces = NULL;
struct interface *last_iface; struct interface *last_iface;
@ -47,31 +47,33 @@ struct interface *last_iface;
/**************************************************************************** /****************************************************************************
calculate the default netmask for an address 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. ** Guess a netmask based on the class of the IP address given.
*/ */
switch((ntohl(iad->s_addr) & 0xE0000000)) { switch ((ntohl (iad->s_addr) & 0xE0000000))
case 0x00000000: /* Class A addr */ {
case 0x20000000: case 0x00000000: /* Class A addr */
case 0x40000000: case 0x20000000:
case 0x60000000: case 0x40000000:
inm->s_addr = htonl(0xFF000000); case 0x60000000:
break; inm->s_addr = htonl (0xFF000000);
break;
case 0x80000000: /* Class B addr */
case 0xA0000000: case 0x80000000: /* Class B addr */
inm->s_addr = htonl(0xFFFF0000); case 0xA0000000:
break; inm->s_addr = htonl (0xFFFF0000);
break;
case 0xC0000000: /* Class C addr */
inm->s_addr = htonl(0xFFFFFF00); case 0xC0000000: /* Class C addr */
break; inm->s_addr = htonl (0xFFFFFF00);
break;
default: /* ??? */
inm->s_addr = htonl(0xFFFFFFF0); 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 get the broadcast address for our address
(troyer@saifr00.ateng.az.honeywell.com) (troyer@saifr00.ateng.az.honeywell.com)
****************************************************************************/ ****************************************************************************/
static void get_broadcast(struct in_addr *if_ipaddr, static void
struct in_addr *if_bcast, get_broadcast (struct in_addr *if_ipaddr, struct in_addr *if_bcast, struct in_addr *if_nmask)
struct in_addr *if_nmask) {
{ uint32 nm;
uint32 nm; short onbc;
short onbc; short offbc;
short offbc;
/* get a default netmask and broadcast */ /* get a default netmask and broadcast */
default_netmask(if_nmask, if_ipaddr); default_netmask (if_nmask, if_ipaddr);
get_netmask(if_ipaddr, if_nmask); get_netmask (if_ipaddr, if_nmask);
/* sanity check on the netmask */ /* sanity check on the netmask */
nm = ntohl(if_nmask->s_addr); nm = ntohl (if_nmask->s_addr);
onbc = 0; onbc = 0;
offbc = 0; offbc = 0;
while((onbc + offbc) < 32) { while ((onbc + offbc) < 32)
if(nm & 0x80000000) { {
onbc++; if (nm & 0x80000000)
if(offbc) { {
/* already found an off bit, so mask onbc++;
is wrong */ if (offbc)
onbc = 34; {
} /* already found an off bit, so mask
} else { is wrong */
offbc++; onbc = 34;
} }
nm <<= 1; }
} else
if ((onbc < 8)||(onbc == 34)) { {
DEBUG(0,("Impossible netmask %s - using defaults\n", offbc++;
inet_ntoa(*if_nmask))); }
default_netmask(if_nmask, if_ipaddr); 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 /* 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 all MS operating systems do, we have to comply even if the unix
box is setup differently */ box is setup differently */
if_bcast->s_addr = MKBCADDR(if_ipaddr->s_addr, if_nmask->s_addr); if_bcast->s_addr = MKBCADDR (if_ipaddr->s_addr, if_nmask->s_addr);
DEBUG(4,("Derived broadcast address %s\n", inet_ntoa(*if_bcast))); 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 load a list of network interfaces
****************************************************************************/ ****************************************************************************/
static void interpret_interfaces(char *s, struct interface **interfaces, static void
const char *description) interpret_interfaces (char *s, struct interface **interfaces, const char *description)
{ {
char *ptr; char *ptr;
fstring token; fstring token;
struct interface *iface; struct interface *iface;
struct in_addr ip; struct in_addr ip;
ptr = s; ptr = s;
ipzero = *interpret_addr2("0.0.0.0"); ipzero = *interpret_addr2 ("0.0.0.0");
allones_ip = *interpret_addr2("255.255.255.255"); allones_ip = *interpret_addr2 ("255.255.255.255");
loopback_ip = *interpret_addr2("127.0.0.1"); loopback_ip = *interpret_addr2 ("127.0.0.1");
while (next_token(&ptr,token,NULL,sizeof(token))) { 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 */
{ {
struct interface *i; /* parse it into an IP address/netmasklength pair */
for (i=(*interfaces);i;i=i->next) char *p = strchr (token, '/');
if (ip_equal(ip,i->ip)) break; if (p)
if (i) continue; *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 (*interfaces)
if (!iface) return; 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; iface->next = NULL;
if (!(*interfaces)) { if (got_ip)
(*interfaces) = iface; {
} else { iface->ip = default_ip;
last_iface->next = iface; }
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 */ if (got_nmask)
iface = (struct interface *)malloc(sizeof(*iface)); {
if (!iface) return; 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->next = NULL;
iface->ip = default_ip; (*interfaces) = last_iface = iface;
} else {
get_myname(NULL,&iface->ip);
}
if (got_bcast) { DEBUG (2, ("Added interface ip=%s ", inet_ntoa (iface->ip)));
iface->bcast = default_bcast; DEBUG (2, ("bcast=%s ", inet_ntoa (iface->bcast)));
} else { DEBUG (2, ("nmask=%s\n", inet_ntoa (iface->nmask)));
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)));
} }
/**************************************************************************** /****************************************************************************
load the remote and local interfaces load the remote and local interfaces
****************************************************************************/ ****************************************************************************/
void load_interfaces(void) void
load_interfaces (void)
{ {
/* add the machine's interfaces to local interface structure*/ /* add the machine's interfaces to local interface structure */
interpret_interfaces(lp_interfaces(), &local_interfaces,"interface"); interpret_interfaces (lp_interfaces (), &local_interfaces, "interface");
} }
/**************************************************************************** /****************************************************************************
override the defaults 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) { if (ip)
got_ip = True; {
default_ip = *interpret_addr2(ip); got_ip = True;
} default_ip = *interpret_addr2 (ip);
}
if (bcast) { if (bcast)
got_bcast = True; {
default_bcast = *interpret_addr2(bcast); got_bcast = True;
} default_bcast = *interpret_addr2 (bcast);
}
if (nmask) { if (nmask)
got_nmask = True; {
default_nmask = *interpret_addr2(nmask); got_nmask = True;
} default_nmask = *interpret_addr2 (nmask);
}
} }
/**************************************************************************** /****************************************************************************
check if an IP is one of mine check if an IP is one of mine
**************************************************************************/ **************************************************************************/
BOOL ismyip(struct in_addr ip) BOOL
ismyip (struct in_addr ip)
{ {
struct interface *i; struct interface *i;
for (i=local_interfaces;i;i=i->next) for (i = local_interfaces; i; i = i->next)
if (ip_equal(i->ip,ip)) return True; if (ip_equal (i->ip, ip))
return False; return True;
return False;
} }
/**************************************************************************** /****************************************************************************
check if a packet is from a local (known) net 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; struct interface *i;
for (i=local_interfaces;i;i=i->next) for (i = local_interfaces; i; i = i->next)
if((from.s_addr & i->nmask.s_addr) == (i->ip.s_addr & i->nmask.s_addr)) if ((from.s_addr & i->nmask.s_addr) == (i->ip.s_addr & i->nmask.s_addr))
return True; return True;
return False; return False;
} }
/**************************************************************************** /****************************************************************************
how many interfaces do we have how many interfaces do we have
**************************************************************************/ **************************************************************************/
int iface_count(void) int
iface_count (void)
{ {
int ret = 0; int ret = 0;
struct interface *i; struct interface *i;
for (i=local_interfaces;i;i=i->next) for (i = local_interfaces; i; i = i->next)
ret++; ret++;
return ret; return ret;
} }
/**************************************************************************** /****************************************************************************
True if we have two or more interfaces. 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) if (multi == -1)
multi = (iface_count() > 1 ? True : False); multi = (iface_count () > 1 ? True : False);
return multi; return multi;
} }
/**************************************************************************** /****************************************************************************
return the Nth interface return the Nth interface
**************************************************************************/ **************************************************************************/
struct interface *get_interface(int n) struct interface *
{ get_interface (int n)
struct interface *i; {
struct interface *i;
for (i=local_interfaces;i && n;i=i->next)
n--;
if (i) return i; for (i = local_interfaces; i && n; i = i->next)
return NULL; n--;
if (i)
return i;
return NULL;
} }
/**************************************************************************** /****************************************************************************
return IP of the Nth interface 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; struct interface *i;
for (i=local_interfaces;i && n;i=i->next)
n--;
if (i) return &i->ip; for (i = local_interfaces; i && n; i = i->next)
return NULL; n--;
if (i)
return &i->ip;
return NULL;
} }
/**************************************************************************** /****************************************************************************
Try and find an interface that matches an ip. If we cannot, 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; struct interface *i;
if (zero_ip(ip)) return local_interfaces; if (zero_ip (ip))
return local_interfaces;
for (i=local_interfaces;i;i=i->next) for (i = local_interfaces; i; i = i->next)
if (same_net(i->ip,ip,i->nmask)) return i; 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. the current wins.dat file.
Note that the result is independent of the order of the interfaces Note that the result is independent of the order of the interfaces
**************************************************************************/ **************************************************************************/
unsigned iface_hash(void) unsigned
iface_hash (void)
{ {
unsigned ret = 0; unsigned ret = 0;
struct interface *i; struct interface *i;
for (i=local_interfaces;i;i=i->next) { 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)); unsigned x1 = (unsigned) str_checksum (inet_ntoa (i->ip));
ret ^= (x1 ^ x2); 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 an appropriate interface they return the requested field of the
first known interface. */ 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); struct interface *i = iface_find (ip);
return(i ? &i->bcast : &local_interfaces->bcast); 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); struct interface *i = iface_find (ip);
return(i ? &i->ip : &local_interfaces->ip); return (i ? &i->ip : &local_interfaces->ip);
} }

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -22,36 +22,40 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
/* NOTE: This code makes no attempt to be fast! /* NOTE: This code makes no attempt to be fast!
It assumes that a int is at least 32 bits long It assumes that a int is at least 32 bits long
*/ */
static uint32 A, B, C, D; 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; x &= 0xFFFFFFFF;
return ((x<<s)&0xFFFFFFFF) | (x>>(32-s)); 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) #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) #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 */ /* this applies md4 to 64 byte chunks */
static void mdfour64(uint32 *M) static void
mdfour64 (uint32 * M)
{ {
int j; int j;
uint32 AA, BB, CC, DD; uint32 AA, BB, CC, DD;
uint32 X[16]; uint32 X[16];
for (j=0;j<16;j++) for (j = 0; j < 16; j++)
X[j] = M[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 (A, B, C, D, 0, 3);
ROUND1(C,D,A,B, 2, 11); ROUND1(B,C,D,A, 3, 19); ROUND1 (D, A, B, C, 1, 7);
ROUND1(A,B,C,D, 4, 3); ROUND1(D,A,B,C, 5, 7); ROUND1 (C, D, A, B, 2, 11);
ROUND1(C,D,A,B, 6, 11); ROUND1(B,C,D,A, 7, 19); ROUND1 (B, C, D, A, 3, 19);
ROUND1(A,B,C,D, 8, 3); ROUND1(D,A,B,C, 9, 7); ROUND1 (A, B, C, D, 4, 3);
ROUND1(C,D,A,B, 10, 11); ROUND1(B,C,D,A, 11, 19); ROUND1 (D, A, B, C, 5, 7);
ROUND1(A,B,C,D, 12, 3); ROUND1(D,A,B,C, 13, 7); ROUND1 (C, D, A, B, 6, 11);
ROUND1(C,D,A,B, 14, 11); ROUND1(B,C,D,A, 15, 19); 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 (A, B, C, D, 0, 3);
ROUND2(C,D,A,B, 8, 9); ROUND2(B,C,D,A, 12, 13); ROUND2 (D, A, B, C, 4, 5);
ROUND2(A,B,C,D, 1, 3); ROUND2(D,A,B,C, 5, 5); ROUND2 (C, D, A, B, 8, 9);
ROUND2(C,D,A,B, 9, 9); ROUND2(B,C,D,A, 13, 13); ROUND2 (B, C, D, A, 12, 13);
ROUND2(A,B,C,D, 2, 3); ROUND2(D,A,B,C, 6, 5); ROUND2 (A, B, C, D, 1, 3);
ROUND2(C,D,A,B, 10, 9); ROUND2(B,C,D,A, 14, 13); ROUND2 (D, A, B, C, 5, 5);
ROUND2(A,B,C,D, 3, 3); ROUND2(D,A,B,C, 7, 5); ROUND2 (C, D, A, B, 9, 9);
ROUND2(C,D,A,B, 11, 9); ROUND2(B,C,D,A, 15, 13); 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 (A, B, C, D, 0, 3);
ROUND3(C,D,A,B, 4, 11); ROUND3(B,C,D,A, 12, 15); ROUND3 (D, A, B, C, 8, 9);
ROUND3(A,B,C,D, 2, 3); ROUND3(D,A,B,C, 10, 9); ROUND3 (C, D, A, B, 4, 11);
ROUND3(C,D,A,B, 6, 11); ROUND3(B,C,D,A, 14, 15); ROUND3 (B, C, D, A, 12, 15);
ROUND3(A,B,C,D, 1, 3); ROUND3(D,A,B,C, 9, 9); ROUND3 (A, B, C, D, 2, 3);
ROUND3(C,D,A,B, 5, 11); ROUND3(B,C,D,A, 13, 15); ROUND3 (D, A, B, C, 10, 9);
ROUND3(A,B,C,D, 3, 3); ROUND3(D,A,B,C, 11, 9); ROUND3 (C, D, A, B, 6, 11);
ROUND3(C,D,A,B, 7, 11); ROUND3(B,C,D,A, 15, 15); 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 += AA;
B += BB;
A &= 0xFFFFFFFF; B &= 0xFFFFFFFF; C += CC;
C &= 0xFFFFFFFF; D &= 0xFFFFFFFF; D += DD;
for (j=0;j<16;j++) A &= 0xFFFFFFFF;
X[j] = 0; 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++) for (i = 0; i < 16; i++)
M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) | M[i] = (in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) |
(in[i*4+1]<<8) | (in[i*4+0]<<0); (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[0] = x & 0xFF;
out[1] = (x>>8)&0xFF; out[1] = (x >> 8) & 0xFF;
out[2] = (x>>16)&0xFF; out[2] = (x >> 16) & 0xFF;
out[3] = (x>>24)&0xFF; out[3] = (x >> 24) & 0xFF;
} }
/* produce a md4 message digest from data of length n bytes */ /* 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]; unsigned char buf[128];
uint32 M[16]; uint32 M[16];
uint32 b = n * 8; uint32 b = n * 8;
int i; int i;
A = 0x67452301; A = 0x67452301;
B = 0xefcdab89; B = 0xefcdab89;
C = 0x98badcfe; C = 0x98badcfe;
D = 0x10325476; D = 0x10325476;
while (n > 64) { while (n > 64)
copy64(M, in); {
mdfour64(M); copy64 (M, in);
in += 64; mdfour64 (M);
n -= 64; in += 64;
} n -= 64;
}
for (i=0;i<128;i++) for (i = 0; i < 128; i++)
buf[i] = 0; buf[i] = 0;
memcpy(buf, in, n); memcpy (buf, in, n);
buf[n] = 0x80; 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++) if (n <= 55)
buf[i] = 0; {
copy64(M, buf); 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); for (i = 0; i < 128; i++)
copy4(out+4, B); buf[i] = 0;
copy4(out+8, C); copy64 (M, buf);
copy4(out+12, D);
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 You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/* working out the netmask for an interface is an incredibly non-portable /* 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 code cannot use any of the normal Samba debug stuff or defines.
This is standalone code. This is standalone code.
*/ */
#ifndef AUTOCONF #ifndef AUTOCONF
#include "config.h" #include "config.h"
@ -63,84 +63,89 @@
* Prototype for gcc in fussy mode. * 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 get the netmask address for a local interface
****************************************************************************/ ****************************************************************************/
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask) int
{ get_netmask (struct in_addr *ipaddr, struct in_addr *nmask)
struct ifconf ifc; {
char buff[2048]; struct ifconf ifc;
int fd, i, n; char buff[2048];
struct ifreq *ifr=NULL; 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 #ifdef DEBUG
fprintf(stderr,"socket failed\n"); fprintf (stderr, "socket failed\n");
#endif #endif
return -1; 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;
}
ifr = ifc.ifc_req; ifc.ifc_len = sizeof (buff);
ifc.ifc_buf = buff;
n = ifc.ifc_len / sizeof(struct ifreq); if (ioctl (fd, SIOCGIFCONF, &ifc) != 0)
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"%d interfaces - looking for %s\n", fprintf (stderr, "SIOCGIFCONF failed\n");
n, inet_ntoa(*ipaddr));
#endif #endif
close (fd);
return -1;
}
/* Loop through interfaces, looking for given IP address */ ifr = ifc.ifc_req;
for (i=n-1;i>=0;i--) {
if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) { n = ifc.ifc_len / sizeof (struct ifreq);
#ifdef DEBUG
fprintf(stderr,"SIOCGIFADDR failed\n");
#endif
continue;
}
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"interface %s\n", fprintf (stderr, "%d interfaces - looking for %s\n", n, inet_ntoa (*ipaddr));
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 #endif
close(fd); /* Loop through interfaces, looking for given IP address */
return -1; 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) #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 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 ifreq ifreq;
struct strioctl strioctl; struct strioctl strioctl;
struct ifconf *ifc; struct ifconf *ifc;
char buff[2048]; char buff[2048];
int fd, i, n; int fd, i, n;
struct ifreq *ifr=NULL; struct ifreq *ifr = NULL;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"socket failed\n"); fprintf (stderr, "socket failed\n");
#endif #endif
return -1; 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;
/* Loop through interfaces, looking for given IP address */ ifc = (struct ifconf *) buff;
n = ifc->ifc_len / sizeof(struct ifreq); ifc->ifc_len = BUFSIZ - sizeof (struct ifconf);
strioctl.ic_cmd = SIOCGIFCONF;
for (i = 0; i<n; i++, ifr++) { strioctl.ic_dp = (char *) ifc;
strioctl.ic_len = sizeof (buff);
if (ioctl (fd, I_STR, &strioctl) < 0)
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"interface %s\n", fprintf (stderr, "SIOCGIFCONF failed\n");
inet_ntoa((*(struct sockaddr_in *)&ifr->ifr_addr).sin_addr.s_addr));
#endif #endif
if (ipaddr->s_addr == close (fd);
(*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr) { return -1;
break; }
}
} 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 #ifdef DEBUG
if (i == n) { if (i == n)
fprintf(stderr,"interface not found\n"); {
close(fd); fprintf (stderr, "interface not found\n");
return -1; close (fd);
} return -1;
}
#endif #endif
ifreq = *ifr; 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;
}
close(fd); strioctl.ic_cmd = SIOCGIFNETMASK;
*nmask = ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr; strioctl.ic_dp = (char *) &ifreq;
strioctl.ic_len = sizeof (struct ifreq);
if (ioctl (fd, I_STR, &strioctl) != 0)
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"netmask %s\n", inet_ntoa(*nmask)); fprintf (stderr, "Failed SIOCGIFNETMASK\n");
#endif #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) #elif defined(HAVE_NETMASK_AIX)
#include <stdio.h> #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/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -259,87 +270,93 @@ this should cover most of the rest of systems
* Prototype for gcc in fussy mode. * 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 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]; char buff[2048];
int fd, i; int fd, i;
struct ifconf ifc; struct ifconf ifc;
struct ifreq *ifr=NULL; struct ifreq *ifr = NULL;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"socket failed\n"); fprintf (stderr, "socket failed\n");
#endif #endif
return -1; return -1;
} }
ifc.ifc_len = sizeof(buff); ifc.ifc_len = sizeof (buff);
ifc.ifc_buf = buff; ifc.ifc_buf = buff;
if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { if (ioctl (fd, SIOCGIFCONF, &ifc) != 0)
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"SIOCGIFCONF failed\n"); fprintf (stderr, "SIOCGIFCONF failed\n");
#endif #endif
close(fd); close (fd);
return -1; return -1;
} }
ifr = ifc.ifc_req; ifr = ifc.ifc_req;
/* Loop through interfaces, looking for given IP address */ /* Loop through interfaces, looking for given IP address */
i = ifc.ifc_len; i = ifc.ifc_len;
while (i > 0) { while (i > 0)
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"interface %s\n", fprintf (stderr, "interface %s\n",
inet_ntoa((*(struct sockaddr_in *)&ifr->ifr_addr).sin_addr)); inet_ntoa ((*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr));
#endif #endif
if (ipaddr->s_addr == if (ipaddr->s_addr == (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr)
(*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr) { {
break; break;
} }
i -= ifr->ifr_addr.sa_len + IFNAMSIZ; i -= ifr->ifr_addr.sa_len + IFNAMSIZ;
ifr = (struct ifreq*) ((char*) ifr + ifr->ifr_addr.sa_len + ifr = (struct ifreq *) ((char *) ifr + ifr->ifr_addr.sa_len + IFNAMSIZ);
IFNAMSIZ); }
}
#ifdef DEBUG #ifdef DEBUG
if (i <= 0) { if (i <= 0)
fprintf(stderr,"interface not found\n"); {
close(fd); fprintf (stderr, "interface not found\n");
return -1; close (fd);
} return -1;
}
#endif #endif
if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) { if (ioctl (fd, SIOCGIFNETMASK, ifr) != 0)
{
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr,"SIOCGIFNETMASK failed\n"); fprintf (stderr, "SIOCGIFNETMASK failed\n");
#endif #endif
close(fd); close (fd);
return -1; 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 #ifdef DEBUG
fprintf(stderr,"netmask %s\n", inet_ntoa(*nmask)); fprintf (stderr, "netmask %s\n", inet_ntoa (*nmask));
#endif #endif
return 0; return 0;
} }
#else /* a dummy version */ #else /* a dummy version */
struct in_addr; /* it may not have been declared before */ 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);
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 #endif
@ -347,29 +364,32 @@ int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask);
#ifdef AUTOCONF #ifdef AUTOCONF
/* this is the autoconf driver to test get_netmask() */ /* this is the autoconf driver to test get_netmask() */
main() main ()
{ {
char buf[1024]; char buf[1024];
struct hostent *hp; struct hostent *hp;
struct in_addr ip, nmask; struct in_addr ip, nmask;
if (gethostname(buf, sizeof(buf)-1) != 0) { if (gethostname (buf, sizeof (buf) - 1) != 0)
fprintf(stderr,"gethostname failed\n"); {
exit(1); fprintf (stderr, "gethostname failed\n");
} exit (1);
}
hp = gethostbyname(buf); hp = gethostbyname (buf);
if (!hp) { if (!hp)
fprintf(stderr,"gethostbyname failed\n"); {
exit(1); 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"); fprintf (stderr, "get_netmask failed\n");
exit(1); exit (1);
} }
#endif #endif

Просмотреть файл

@ -22,7 +22,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
@ -32,40 +32,44 @@ extern int DEBUGLEVEL;
/* this is like vsnprintf but the 'n' limit does not include /* this is like vsnprintf but the 'n' limit does not include
the terminating null. So if you have a 1024 byte buffer then the terminating null. So if you have a 1024 byte buffer then
pass 1023 for n */ 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); int ret = vsnprintf (str, n, format, ap);
if (ret > n || ret < 0) { if (ret > n || ret < 0)
str[n] = 0; {
return -1; str[n] = 0;
} return -1;
str[ret] = 0; }
return ret; str[ret] = 0;
return ret;
} }
#ifdef HAVE_STDARG_H #ifdef HAVE_STDARG_H
int slprintf(char *str, int n, const char *format, ...) int
slprintf (char *str, int n, const char *format, ...)
{ {
#else #else
int slprintf(va_alist) int
va_dcl slprintf (va_alist)
va_dcl
{ {
char *str, *format; char *str, *format;
int n; int n;
#endif #endif
va_list ap; va_list ap;
int ret; int ret;
#ifdef HAVE_STDARG_H #ifdef HAVE_STDARG_H
va_start(ap, format); va_start (ap, format);
#else #else
va_start(ap); va_start (ap);
str = va_arg(ap,char *); str = va_arg (ap, char *);
n = va_arg(ap,int); n = va_arg (ap, int);
format = va_arg(ap,char *); format = va_arg (ap, char *);
#endif #endif
ret = vslprintf(str,n,format,ap); ret = vslprintf (str, n, format, ap);
va_end(ap); va_end (ap);
return ret; return ret;
} }

Просмотреть файл

@ -22,7 +22,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
@ -39,9 +39,9 @@ extern int DEBUGLEVEL;
- to allow easier integration of things like the japanese extensions - to allow easier integration of things like the japanese extensions
- to support the philosophy of Samba to expose the features of - to support the philosophy of Samba to expose the features of
the OS within the SMB model. In general whatever file/printer/variable the OS within the SMB model. In general whatever file/printer/variable
expansions/etc make sense to the OS should be acceptable to Samba. 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 return -1 means error
********************************************************************/ ********************************************************************/
#ifndef HAVE_SELECT #ifndef HAVE_SELECT
static int pollfd(int fd) static int
pollfd (int fd)
{ {
int r=0; int r = 0;
#ifdef HAS_RDCHK #ifdef HAS_RDCHK
r = rdchk(fd); r = rdchk (fd);
#elif defined(TCRDCHK) #elif defined(TCRDCHK)
(void)ioctl(fd, TCRDCHK, &r); (void) ioctl (fd, TCRDCHK, &r);
#else #else
(void)ioctl(fd, FIONREAD, &r); (void) ioctl (fd, FIONREAD, &r);
#endif #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; fd_set fds2;
int counter=0; int counter = 0;
int found=0; int found = 0;
FD_ZERO(&fds2); FD_ZERO (&fds2);
while (1) while (1)
{ {
int i; int i;
for (i=0;i<maxfd;i++) { for (i = 0; i < maxfd; i++)
if (FD_ISSET(i,fds) && pollfd(i)>0) { {
found++; if (FD_ISSET (i, fds) && pollfd (i) > 0)
FD_SET(i,&fds2); {
} 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 */ #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 #ifdef USE_POLL
struct pollfd pfd[256]; struct pollfd pfd[256];
int i; int i;
int maxpoll; int maxpoll;
int timeout; int timeout;
int pollrtn; int pollrtn;
maxpoll = 0; maxpoll = 0;
for( i = 0; i < maxfd; i++) { for (i = 0; i < maxfd; i++)
if(FD_ISSET(i,fds)) { {
struct pollfd *pfdp = &pfd[maxpoll++]; if (FD_ISSET (i, fds))
pfdp->fd = i; {
pfdp->events = POLLIN; struct pollfd *pfdp = &pfd[maxpoll++];
pfdp->revents = 0; pfdp->fd = i;
pfdp->events = POLLIN;
pfdp->revents = 0;
}
} }
}
timeout = (tval != NULL) ? (tval->tv_sec * 1000) + (tval->tv_usec/1000) : timeout = (tval != NULL) ? (tval->tv_sec * 1000) + (tval->tv_usec / 1000) : -1;
-1; errno = 0;
errno = 0; do
do { {
pollrtn = poll( &pfd[0], maxpoll, timeout); pollrtn = poll (&pfd[0], maxpoll, timeout);
} while (pollrtn<0 && errno == EINTR); }
while (pollrtn < 0 && errno == EINTR);
FD_ZERO(fds); FD_ZERO (fds);
for( i = 0; i < maxpoll; i++) for (i = 0; i < maxpoll; i++)
if( pfd[i].revents & POLLIN ) if (pfd[i].revents & POLLIN)
FD_SET(pfd[i].fd,fds); FD_SET (pfd[i].fd, fds);
return pollrtn; return pollrtn;
#else /* USE_POLL */ #else /* USE_POLL */
struct timeval t2; struct timeval t2;
int selrtn; int selrtn;
do { do
if (tval) memcpy((void *)&t2,(void *)tval,sizeof(t2)); {
errno = 0; if (tval)
selrtn = select(maxfd,SELECT_CAST fds,NULL,NULL,tval?&t2:NULL); memcpy ((void *) &t2, (void *) tval, sizeof (t2));
} while (selrtn<0 && errno == EINTR); 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 /* USE_POLL */
#endif /* NO_SELECT */ #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. 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. An lstat() wrapper that will deal with 64 bit filesizes.
********************************************************************/ ********************************************************************/
#if 0 #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. 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. 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 */ #endif /* 0 */
/******************************************************************* /*******************************************************************
An open() wrapper that will deal with 64 bit filesizes. 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. 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 #if 0
/******************************************************************* /*******************************************************************
A readdir wrapper that will deal with 64 bit filesizes. 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 system wrapper for getwd
********************************************************************/ ********************************************************************/
char *sys_getwd(char *s) char *
sys_getwd (char *s)
{ {
char *wd; char *wd;
#ifdef HAVE_GETCWD #ifdef HAVE_GETCWD
wd = (char *)getcwd(s, sizeof (pstring)); wd = (char *) getcwd (s, sizeof (pstring));
#else #else
wd = (char *)getwd(s); wd = (char *) getwd (s);
#endif #endif
return wd; return wd;
} }
@ -225,16 +247,18 @@ char *sys_getwd(char *s)
chown isn't used much but OS/2 doesn't have it 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 #ifndef HAVE_CHOWN
static int done; static int done;
if (!done) { if (!done)
DEBUG(1,("WARNING: no chown!\n")); {
done=1; DEBUG (1, ("WARNING: no chown!\n"));
} done = 1;
}
#else #else
return(chown(fname,uid,gid)); return (chown (fname, uid, gid));
#endif #endif
} }
#endif /* 0 */ #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 in the root domain, which can cause dial-on-demand links to come up for no
apparent reason. apparent reason.
****************************************************************************/ ****************************************************************************/
struct hostent *sys_gethostbyname(const char *name) struct hostent *
sys_gethostbyname (const char *name)
{ {
#ifdef REDUCE_ROOT_DNS_LOOKUPS #ifdef REDUCE_ROOT_DNS_LOOKUPS
char query[256], hostname[256]; char query[256], hostname[256];
char *domain; 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, '.')) if (strchr (name, '.'))
return(gethostbyname(name)); return (gethostbyname (name));
/* Get my hostname, which should have domain name /* Get my hostname, which should have domain name
attached. If not, just do the gethostname on the attached. If not, just do the gethostname on the
original string. original string.
*/ */
gethostname(hostname, sizeof(hostname) - 1); gethostname (hostname, sizeof (hostname) - 1);
hostname[sizeof(hostname) - 1] = 0; hostname[sizeof (hostname) - 1] = 0;
if ((domain = strchr(hostname, '.')) == NULL) if ((domain = strchr (hostname, '.')) == NULL)
return(gethostbyname(name)); return (gethostbyname (name));
/* Attach domain name to query and do modified query. /* Attach domain name to query and do modified query.
If names too large, just do gethostname on the If names too large, just do gethostname on the
original string. original string.
*/ */
if((strlen(name) + strlen(domain)) >= sizeof(query)) if ((strlen (name) + strlen (domain)) >= sizeof (query))
return(gethostbyname(name)); return (gethostbyname (name));
slprintf(query, sizeof(query)-1, "%s%s", name, domain); slprintf (query, sizeof (query) - 1, "%s%s", name, domain);
return(gethostbyname(query)); return (gethostbyname (query));
#else /* REDUCE_ROOT_DNS_LOOKUPS */ #else /* REDUCE_ROOT_DNS_LOOKUPS */
return(gethostbyname(name)); return (gethostbyname (name));
#endif /* REDUCE_ROOT_DNS_LOOKUPS */ #endif /* REDUCE_ROOT_DNS_LOOKUPS */
} }
@ -283,15 +308,16 @@ struct hostent *sys_gethostbyname(const char *name)
Wrapper for random(). Wrapper for random().
****************************************************************************/ ****************************************************************************/
#if 0 #if 0
long sys_random(void) long
sys_random (void)
{ {
#if defined(HAVE_RANDOM) #if defined(HAVE_RANDOM)
return (long)random(); return (long) random ();
#elif defined(HAVE_RAND) #elif defined(HAVE_RAND)
return (long)rand(); return (long) rand ();
#else #else
DEBUG(0,("Error - no random function available !\n")); DEBUG (0, ("Error - no random function available !\n"));
exit(1); exit (1);
#endif #endif
} }
@ -299,15 +325,16 @@ long sys_random(void)
Wrapper for srandom(). Wrapper for srandom().
****************************************************************************/ ****************************************************************************/
void sys_srandom(unsigned int seed) void
sys_srandom (unsigned int seed)
{ {
#if defined(HAVE_SRANDOM) #if defined(HAVE_SRANDOM)
srandom(seed); srandom (seed);
#elif defined(HAVE_SRAND) #elif defined(HAVE_SRAND)
srand(seed); srand (seed);
#else #else
DEBUG(0,("Error - no srandom function available !\n")); DEBUG (0, ("Error - no srandom function available !\n"));
exit(1); exit (1);
#endif #endif
} }
#endif /* 0 */ #endif /* 0 */

Просмотреть файл

@ -22,17 +22,17 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
/* /*
This stuff was largely rewritten by Paul Eggert <eggert@twinsun.com> This stuff was largely rewritten by Paul Eggert <eggert@twinsun.com>
in May 1996 in May 1996
*/ */
int serverzone=0; int serverzone = 0;
int extra_time_offset = 0; int extra_time_offset = 0;
extern int DEBUGLEVEL; extern int DEBUGLEVEL;
@ -54,12 +54,13 @@ extern int DEBUGLEVEL;
/******************************************************************* /*******************************************************************
a gettimeofday wrapper a gettimeofday wrapper
********************************************************************/ ********************************************************************/
void GetTimeOfDay(struct timeval *tval) void
GetTimeOfDay (struct timeval *tval)
{ {
#ifdef HAVE_GETTIMEOFDAY_TZ #ifdef HAVE_GETTIMEOFDAY_TZ
gettimeofday(tval,NULL); gettimeofday (tval, NULL);
#else #else
gettimeofday(tval); gettimeofday (tval);
#endif #endif
} }
@ -68,35 +69,36 @@ void GetTimeOfDay(struct timeval *tval)
/******************************************************************* /*******************************************************************
yield the difference between *A and *B, in seconds, ignoring leap seconds 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 ay = a->tm_year + (TM_YEAR_BASE - 1);
int by = b->tm_year + (TM_YEAR_BASE - 1); int by = b->tm_year + (TM_YEAR_BASE - 1);
int intervening_leap_days = int intervening_leap_days = (ay / 4 - by / 4) - (ay / 100 - by / 100) + (ay / 400 - by / 400);
(ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); int years = ay - by;
int years = ay - by; int days = 365 * years + intervening_leap_days + (a->tm_yday - b->tm_yday);
int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); int hours = 24 * days + (a->tm_hour - b->tm_hour);
int hours = 24*days + (a->tm_hour - b->tm_hour); int minutes = 60 * hours + (a->tm_min - b->tm_min);
int minutes = 60*hours + (a->tm_min - b->tm_min); int seconds = 60 * minutes + (a->tm_sec - b->tm_sec);
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 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 = gmtime (&t);
struct tm tm_utc; struct tm tm_utc;
if (!tm) if (!tm)
return 0; return 0;
tm_utc = *tm; tm_utc = *tm;
tm = localtime(&t); tm = localtime (&t);
if (!tm) if (!tm)
return 0; return 0;
return tm_diff(&tm_utc,tm); return tm_diff (&tm_utc, tm);
} }
@ -104,15 +106,17 @@ static int TimeZone(time_t t)
/******************************************************************* /*******************************************************************
init the time differences init the time differences
********************************************************************/ ********************************************************************/
void TimeInit(void) void
TimeInit (void)
{ {
serverzone = TimeZone(time(NULL)); serverzone = TimeZone (time (NULL));
if ((serverzone % 60) != 0) { if ((serverzone % 60) != 0)
DEBUG(1,("WARNING: Your timezone is not a multiple of 1 minute.\n")); {
} 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> 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 struct dst_table
static int table_size = 0; {
int i; time_t start, end;
int zone = 0; 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_WIDTH (365*24*60*60)
#define MAX_DST_SKIP (7*24*60*60) #define MAX_DST_SKIP (7*24*60*60)
for (i=0;i<table_size;i++) for (i = 0; i < table_size; i++)
if (t >= dst_table[i].start && t <= dst_table[i].end) break; if (t >= dst_table[i].start && t <= dst_table[i].end)
break;
if (i<table_size) { if (i < table_size)
zone = dst_table[i].zone; {
} else { zone = dst_table[i].zone;
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
} }
} else
return zone; {
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 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. daylight savings transitions because some local times are ambiguous.
LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions. 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; time_t lt = lte - 60 * extra_time_offset;
int d = TimeZoneFaster(lt); int d = TimeZoneFaster (lt);
time_t t = lt + d; time_t t = lt + d;
/* if overflow occurred, ignore all the adjustments so far */ /* if overflow occurred, ignore all the adjustments so far */
if (((lte < lt) ^ (extra_time_offset < 0)) | ((t < lt) ^ (d < 0))) if (((lte < lt) ^ (extra_time_offset < 0)) | ((t < lt) ^ (d < 0)))
t = lte; t = lte;
/* now t should be close enough to the true UTC to yield the right answer */ /* now t should be close enough to the true UTC to yield the right answer */
return TimeDiff(t); return TimeDiff (t);
} }
/**************************************************************************** /****************************************************************************
try to optimise the localtime call, it can be quite expensive on some machines 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)) #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 serverzone. This is NOT the same as GMT in some cases. This routine
converts this to real GMT. converts this to real GMT.
****************************************************************************/ ****************************************************************************/
time_t nt_time_to_unix(NTTIME *nt) time_t
nt_time_to_unix (NTTIME * nt)
{ {
double d; double d;
time_t ret; time_t ret;
/* The next two lines are a fix needed for the /* The next two lines are a fix needed for the
broken SCO compiler. JRA. */ broken SCO compiler. JRA. */
time_t l_time_min = TIME_T_MIN; time_t l_time_min = TIME_T_MIN;
time_t l_time_max = TIME_T_MAX; 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 = ((double) nt->high) * 4.0 * (double) (1 << 30);
d += (nt->low&0xFFF00000); d += (nt->low & 0xFFF00000);
d *= 1.0e-7; d *= 1.0e-7;
/* now adjust by 369 years to make the secs since 1970 */
d -= TIME_FIXUP_CONSTANT;
if (!(l_time_min <= d && d <= l_time_max)) /* now adjust by 369 years to make the secs since 1970 */
return(0); 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 = (time_t) (d + 0.5);
ret -= serverzone;
ret += LocTimeDiff(ret);
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 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; NTTIME nt;
nt.low = IVAL(p,0); nt.low = IVAL (p, 0);
nt.high = IVAL(p,4); nt.high = IVAL (p, 4);
return nt_time_to_unix(&nt); return nt_time_to_unix (&nt);
} }
/**************************************************************************** /****************************************************************************
put a 8 byte filetime from a time_t put a 8 byte filetime from a time_t
This takes real GMT as input and converts to kludge-GMT 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) if (t == 0)
{ {
nt->low = 0; nt->low = 0;
nt->high = 0; nt->high = 0;
return; return;
} }
/* this converts GMT to kludge-GMT */ /* this converts GMT to kludge-GMT */
t -= LocTimeDiff(t) - serverzone; t -= LocTimeDiff (t) - serverzone;
d = (double)(t); d = (double) (t);
d += TIME_FIXUP_CONSTANT; d += TIME_FIXUP_CONSTANT;
d *= 1.0e7; d *= 1.0e7;
nt->high = (uint32)(d * (1.0/(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)); 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. take an NTTIME structure, containing high / low time. convert to unix time.
lkclXXXX this may need 2 SIVALs not a memcpy. we'll see... 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; NTTIME nt;
unix_to_nt_time(&nt, t); unix_to_nt_time (&nt, t);
SIVAL(p, 0, nt.low); SIVAL (p, 0, nt.low);
SIVAL(p, 4, nt.high); SIVAL (p, 4, nt.high);
} }
/**************************************************************************** /****************************************************************************
check if it's a null mtime 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) if (mtime == (time_t) 0 || mtime == (time_t) 0xFFFFFFFF || mtime == (time_t) - 1)
return(True); return (True);
return(False); return (False);
} }
/******************************************************************* /*******************************************************************
create a 16 bit dos packed date 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; uint16 ret = 0;
ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1); 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)); ret = ((ret & 0xFF) << 8) | (t->tm_mday | (((t->tm_mon + 1) & 0x7) << 5));
return(ret); return (ret);
} }
/******************************************************************* /*******************************************************************
create a 16 bit dos packed time 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; uint16 ret = 0;
ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3)); 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)); ret = ((ret & 0xFF) << 8) | ((t->tm_sec / 2) | ((t->tm_min & 0x7) << 5));
return(ret); return (ret);
} }
/******************************************************************* /*******************************************************************
create a 32 bit dos packed date/time from some parameters create a 32 bit dos packed date/time from some parameters
This takes a GMT time and returns a packed localtime structure 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; struct tm *t;
uint32 ret=0; uint32 ret = 0;
t = LocalTime(&unixdate); t = LocalTime (&unixdate);
if (!t) if (!t)
return 0xFFFFFFFF; return 0xFFFFFFFF;
ret = make_dos_date1(t); ret = make_dos_date1 (t);
ret = ((ret&0xFFFF)<<16) | make_dos_time1(t); ret = ((ret & 0xFFFF) << 16) | make_dos_time1 (t);
return(ret); return (ret);
} }
/******************************************************************* /*******************************************************************
put a dos date into a buffer (time/date format) put a dos date into a buffer (time/date format)
This takes GMT time and puts local time in the buffer 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); uint32 x = make_dos_date (unixdate);
SIVAL(buf,offset,x); SIVAL (buf, offset, x);
} }
/******************************************************************* /*******************************************************************
put a dos date into a buffer (date/time format) put a dos date into a buffer (date/time format)
This takes GMT time and puts local time in the buffer 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); uint32 x = make_dos_date (unixdate);
x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); x = ((x & 0xFFFF) << 16) | ((x & 0xFFFF0000) >> 16);
SIVAL(buf,offset,x); 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 GMT and converts it to LOCAL time before putting it (most SMBs assume
localtime for this sort of date) 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)) if (!null_mtime (unixdate))
unixdate -= TimeDiff(unixdate); unixdate -= TimeDiff (unixdate);
SIVAL(buf,offset,unixdate); SIVAL (buf, offset, unixdate);
} }
/******************************************************************* /*******************************************************************
interpret a 32 bit dos packed date/time to some parameters 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; p0 = date & 0xFF;
p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; p1 = ((date & 0xFF00) >> 8) & 0xFF;
p2 = ((date & 0xFF0000) >> 16) & 0xFF;
p3 = ((date & 0xFF000000) >> 24) & 0xFF;
*second = 2*(p0 & 0x1F); *second = 2 * (p0 & 0x1F);
*minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3); *minute = ((p0 >> 5) & 0xFF) + ((p1 & 0x7) << 3);
*hour = (p1>>3)&0xFF; *hour = (p1 >> 3) & 0xFF;
*day = (p2&0x1F); *day = (p2 & 0x1F);
*month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1; *month = ((p2 >> 5) & 0xFF) + ((p3 & 0x1) << 3) - 1;
*year = ((p3>>1)&0xFF) + 80; *year = ((p3 >> 1) & 0xFF) + 80;
} }
/******************************************************************* /*******************************************************************
create a unix date (int GMT) from a dos date (which is actually in create a unix date (int GMT) from a dos date (which is actually in
localtime) localtime)
********************************************************************/ ********************************************************************/
time_t make_unix_date(void *date_ptr) time_t
make_unix_date (void *date_ptr)
{ {
uint32 dos_date=0; uint32 dos_date = 0;
struct tm t; struct tm t;
time_t ret; time_t ret;
dos_date = IVAL(date_ptr,0); dos_date = IVAL (date_ptr, 0);
if (dos_date == 0) return(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);
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 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); x = IVAL (date_ptr, 0);
x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); x2 = ((x & 0xFFFF) << 16) | ((x & 0xFFFF0000) >> 16);
SIVAL(&x,0,x2); 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 create a unix GMT date from a dos date in 32 bit "unix like" format
these generally arrive as localtimes, with corresponding DST 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); time_t t = (time_t) IVAL (date_ptr, 0);
if (!null_mtime(t)) if (!null_mtime (t))
t += LocTimeDiff(t); t += LocTimeDiff (t);
return(t); return (t);
} }
#if 0 #if 0
/*************************************************************************** /***************************************************************************
return a HTTP/1.0 time string return a HTTP/1.0 time string
***************************************************************************/ ***************************************************************************/
char *http_timestring(time_t t) char *
http_timestring (time_t t)
{ {
static fstring buf; static fstring buf;
struct tm *tm = LocalTime(&t); struct tm *tm = LocalTime (&t);
if (!tm) if (!tm)
slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); slprintf (buf, sizeof (buf) - 1, "%ld seconds since the Epoch", (long) t);
else else
strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); strftime (buf, sizeof (buf) - 1, "%a, %d %b %Y %H:%M:%S %Z", tm);
return buf; return buf;
} }
#endif /*0 */ #endif /*0 */
@ -507,18 +547,22 @@ char *http_timestring(time_t t)
/**************************************************************************** /****************************************************************************
return the date and time as a string return the date and time as a string
****************************************************************************/ ****************************************************************************/
char *timestring(void ) char *
timestring (void)
{ {
static fstring TimeBuf; static fstring TimeBuf;
time_t t = time(NULL); time_t t = time (NULL);
struct tm *tm = LocalTime(&t); struct tm *tm = LocalTime (&t);
if (!tm) { if (!tm)
slprintf(TimeBuf,sizeof(TimeBuf)-1,"%ld seconds since the Epoch",(long)t); {
} else { slprintf (TimeBuf, sizeof (TimeBuf) - 1, "%ld seconds since the Epoch", (long) t);
strftime(TimeBuf,100,"%Y/%m/%d %H:%M:%S",tm); }
} else
return(TimeBuf); {
strftime (TimeBuf, 100, "%Y/%m/%d %H:%M:%S", tm);
}
return (TimeBuf);
} }
/**************************************************************************** /****************************************************************************
@ -526,23 +570,23 @@ char *timestring(void )
structure. 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) if (S_ISDIR (st->st_mode) && fake_dirs)
return (time_t)315493200L; /* 1/1/1980 */ return (time_t) 315493200L; /* 1/1/1980 */
ret = MIN(st->st_ctime, st->st_mtime);
ret1 = MIN(ret, st->st_atime);
if(ret1 != (time_t)0) ret = MIN (st->st_ctime, st->st_mtime);
return ret1; ret1 = MIN (ret, st->st_atime);
/* if (ret1 != (time_t) 0)
* One of ctime, mtime or atime was zero (probably atime). return ret1;
* Just return MIN(ctime, mtime).
*/ /*
return ret; * 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 You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
extern int DEBUGLEVEL; extern int DEBUGLEVEL;
/* internal functions */ /* internal functions */
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 *),
static struct passwd *uname_string_combinations2(char *s, int offset, struct passwd * (*fn) (const char *), int N); int N);
static struct passwd *uname_string_combinations2 (char *s, int offset,
struct passwd *(*fn) (const char *), int N);
/**************************************************************************** /****************************************************************************
get a users home directory. 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); if (!pass)
return(pass->pw_dir); 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 a username from a dos name to a unix name by looking in the username
map. Note that this modifies the name in place. 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. every time Get_Pwnam was called.
Returns True if username was changed, false otherwise. 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 BOOL initialised = False;
static fstring last_from,last_to; static fstring last_from, last_to;
FILE *f; FILE *f;
char *mapfile = lp_username_map(); char *mapfile = lp_username_map ();
char *s; char *s;
pstring buf; pstring buf;
BOOL mapped_user = False; BOOL mapped_user = False;
if (!*user) if (!*user)
return False; return False;
if (!*mapfile) if (!*mapfile)
return False; 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 (!initialised)
{ {
int l = strlen(unixname); *last_from = *last_to = 0;
while (l && isspace(unixname[l-1])) { initialised = True;
unixname[l-1] = 0;
l--;
}
} }
if (strchr(dosname,'*') || user_in_list(user,dosname)) { if (strequal (user, last_to))
DEBUG(3,("Mapped user %s to %s\n",user,unixname)); return False;
mapped_user = True;
fstrcpy(last_from,user); if (strequal (user, last_from))
sscanf(unixname,"%s",user); {
fstrcpy(last_to,user); DEBUG (3, ("Mapped user %s to %s\n", user, last_to));
if(return_if_mapped) { fstrcpy (user, last_to);
fclose(f);
return True; return True;
}
} }
}
fclose(f); 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));
* 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; 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 */ #endif /* 0 */
/**************************************************************************** /****************************************************************************
Get_Pwnam wrapper 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); ret = getpwnam (s);
if (ret) if (ret)
{ {
#ifdef HAVE_GETPWANAM #ifdef HAVE_GETPWANAM
struct passwd_adjunct *pwret; struct passwd_adjunct *pwret;
pwret = getpwanam(s); pwret = getpwanam (s);
if (pwret) if (pwret)
{ {
free(ret->pw_passwd); free (ret->pw_passwd);
ret->pw_passwd = pwret->pwa_passwd; ret->pw_passwd = pwret->pwa_passwd;
} }
#endif #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 a wrapper for getpwnam() that tries with all lower and all upper case
if the initial name fails. Also tried with first letter capitalised 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; fstring user;
int last_char; int last_char;
int usernamelevel = lp_usernamelevel(); int usernamelevel = lp_usernamelevel ();
struct passwd *ret; struct passwd *ret;
if (!a_user || !(*a_user)) if (!a_user || !(*a_user))
return(NULL); return (NULL);
StrnCpy(user,a_user,sizeof(user)-1); StrnCpy (user, a_user, sizeof (user) - 1);
ret = _Get_Pwnam(user); ret = _Get_Pwnam (user);
if (ret) return(ret); if (ret)
return (ret);
strlower(user); strlower (user);
ret = _Get_Pwnam(user); ret = _Get_Pwnam (user);
if (ret) return(ret); if (ret)
return (ret);
strupper(user); strupper (user);
ret = _Get_Pwnam(user); ret = _Get_Pwnam (user);
if (ret) return(ret); if (ret)
return (ret);
/* try with first letter capitalised */ /* try with first letter capitalised */
if (strlen(user) > 1) if (strlen (user) > 1)
strlower(user+1); strlower (user + 1);
ret = _Get_Pwnam(user); ret = _Get_Pwnam (user);
if (ret) return(ret); if (ret)
return (ret);
/* try with last letter capitalised */ /* try with last letter capitalised */
strlower(user); strlower (user);
last_char = strlen(user)-1; last_char = strlen (user) - 1;
user[last_char] = toupper(user[last_char]); user[last_char] = toupper (user[last_char]);
ret = _Get_Pwnam(user); ret = _Get_Pwnam (user);
if (ret) return(ret); if (ret)
return (ret);
/* try all combinations up to usernamelevel */ /* try all combinations up to usernamelevel */
strlower(user); strlower (user);
ret = uname_string_combinations(user, _Get_Pwnam, usernamelevel); ret = uname_string_combinations (user, _Get_Pwnam, usernamelevel);
if (ret) return(ret); if (ret)
return (ret);
return(NULL); return (NULL);
} }
#if 0 #if 0
/**************************************************************************** /****************************************************************************
check if a user is in a netgroup user list 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 #ifdef HAVE_NETGROUP
static char *mydomain = NULL; static char *mydomain = NULL;
if (mydomain == NULL) if (mydomain == NULL)
yp_get_default_domain(&mydomain); yp_get_default_domain (&mydomain);
if(mydomain == NULL) if (mydomain == NULL)
{ {
DEBUG(5,("Unable to get default yp domain\n")); DEBUG (5, ("Unable to get default yp domain\n"));
} }
else else
{ {
DEBUG(5,("looking for user %s of domain %s in netgroup %s\n", DEBUG (5, ("looking for user %s of domain %s in netgroup %s\n", user, mydomain, ngname));
user, mydomain, ngname)); DEBUG (5, ("innetgr is %s\n", innetgr (ngname, NULL, user, mydomain) ? "TRUE" : "FALSE"));
DEBUG(5,("innetgr is %s\n",
innetgr(ngname, NULL, user, mydomain)
? "TRUE" : "FALSE"));
if (innetgr(ngname, NULL, user, mydomain)) if (innetgr (ngname, NULL, user, mydomain))
return (True); return (True);
} }
#endif /* HAVE_NETGROUP */ #endif /* HAVE_NETGROUP */
return False; return False;
} }
/**************************************************************************** /****************************************************************************
check if a user is in a UNIX user list 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 #ifdef HAVE_GETGRNAM
struct group *gptr; struct group *gptr;
char **member; char **member;
struct passwd *pass = Get_Pwnam(user,False); struct passwd *pass = Get_Pwnam (user, False);
if (pass) 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 (strequal(*member,user)) gptr = getgrgid (pass->pw_gid);
return(True); if (gptr && strequal (gptr->gr_name, gname))
member++; 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 */ #endif /* HAVE_GETGRNAM */
return False; return False;
} }
/**************************************************************************** /****************************************************************************
check if a user is in a user list - can check combinations of UNIX check if a user is in a user list - can check combinations of UNIX
and netgroup lists. and netgroup lists.
****************************************************************************/ ****************************************************************************/
BOOL user_in_list(char *user,char *list) BOOL
user_in_list (char *user, char *list)
{ {
pstring tok; pstring tok;
char *p=list; char *p = list;
while (next_token(&p,tok,LIST_SEP, sizeof(tok))) while (next_token (&p, tok, LIST_SEP, sizeof (tok)))
{ {
/* /*
* Check raw username. * Check raw username.
*/ */
if (strequal(user,tok)) if (strequal (user, tok))
return(True); return (True);
/* /*
* Now check to see if any combination * Now check to see if any combination
* of UNIX and netgroups has been specified. * of UNIX and netgroups has been specified.
*/ */
if(*tok == '@') if (*tok == '@')
{ {
/* /*
* Old behaviour. Check netgroup list * Old behaviour. Check netgroup list
* followed by UNIX list. * followed by UNIX list.
*/ */
if(user_in_netgroup_list(user,&tok[1])) if (user_in_netgroup_list (user, &tok[1]))
return True; return True;
if(user_in_group_list(user,&tok[1])) if (user_in_group_list (user, &tok[1]))
return True; 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 == '+') return (False);
{
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);
} }
#endif /* 0 */ #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) offset is the first char to try and change (start with 0)
it assumes the string starts lowercased 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 len = strlen (s);
int i; int i;
struct passwd *ret; struct passwd *ret;
#ifdef PASSWORD_LENGTH #ifdef PASSWORD_LENGTH
len = MIN(len,PASSWORD_LENGTH); len = MIN (len, PASSWORD_LENGTH);
#endif #endif
if (N <= 0 || offset >= len) if (N <= 0 || offset >= len)
return(fn(s)); return (fn (s));
for (i=offset;i<(len-(N-1));i++) for (i = offset; i < (len - (N - 1)); i++)
{ {
char c = s[i]; char c = s[i];
if (!islower(c)) continue; if (!islower (c))
s[i] = toupper(c); continue;
ret = uname_string_combinations2(s,i+1,fn,N-1); s[i] = toupper (c);
if(ret) return(ret); ret = uname_string_combinations2 (s, i + 1, fn, N - 1);
s[i] = c; 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) offset is the first char to try and change (start with 0)
it assumes the string starts lowercased 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; int n;
struct passwd *ret; struct passwd *ret;
for (n=1;n<=N;n++) for (n = 1; n <= N; n++)
{ {
ret = uname_string_combinations2(s,0,fn,n); ret = uname_string_combinations2 (s, 0, fn, n);
if(ret) return(ret); if (ret)
} return (ret);
return(NULL); }
return (NULL);
} }

Просмотреть файл

@ -33,9 +33,10 @@ static int gotalarm;
Signal function to tell us we timed out. 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. 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; SMB_STRUCT_FLOCK lock;
int ret; int ret;
gotalarm = 0; gotalarm = 0;
CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig); CatchSignal (SIGALRM, SIGNAL_CAST gotalarm_sig);
lock.l_type = type; lock.l_type = type;
lock.l_whence = SEEK_SET; lock.l_whence = SEEK_SET;
lock.l_start = 0; lock.l_start = 0;
lock.l_len = 1; lock.l_len = 1;
lock.l_pid = 0; lock.l_pid = 0;
alarm(waitsecs); alarm (waitsecs);
ret = fcntl(fd, SMB_F_SETLKW, &lock); ret = fcntl (fd, SMB_F_SETLKW, &lock);
alarm(0); alarm (0);
CatchSignal(SIGALRM, SIGNAL_CAST SIG_DFL); CatchSignal (SIGALRM, SIGNAL_CAST SIG_DFL);
if (gotalarm) { if (gotalarm)
DEBUG(0, ("do_file_lock: failed to %s file.\n", {
type == F_UNLCK ? "unlock" : "lock")); DEBUG (0, ("do_file_lock: failed to %s file.\n", type == F_UNLCK ? "unlock" : "lock"));
return False; return False;
} }
return (ret == 0); return (ret == 0);
} }
/*************************************************************** /***************************************************************
Lock an fd. Abandon after waitsecs seconds. 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) if (fd < 0)
return False; return False;
(*plock_depth)++; (*plock_depth)++;
if ((*plock_depth) == 0) if ((*plock_depth) == 0)
{ {
if (!do_file_lock(fd, secs, type)) { if (!do_file_lock (fd, secs, type))
DEBUG(10,("file_lock: locking file failed, error = %s.\n", {
unix_error_string (errno))); DEBUG (10, ("file_lock: locking file failed, error = %s.\n",
return False; unix_error_string (errno)));
return False;
}
} }
}
return True; return True;
} }
/*************************************************************** /***************************************************************
Unlock an fd. Abandon after waitsecs seconds. 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) if (*plock_depth == 1)
ret = do_file_lock(fd, 5, F_UNLCK); ret = do_file_lock (fd, 5, F_UNLCK);
(*plock_depth)--; (*plock_depth)--;
if(!ret) if (!ret)
DEBUG(10,("file_unlock: unlocking file failed, error = %s.\n", DEBUG (10, ("file_unlock: unlocking file failed, error = %s.\n",
unix_error_string (errno))); unix_error_string (errno)));
return ret; return ret;
} }
/*************************************************************** /***************************************************************
@ -118,52 +123,54 @@ BOOL file_unlock(int fd, int *plock_depth)
update to be set = True if modification is required. update to be set = True if modification is required.
****************************************************************/ ****************************************************************/
void *startfilepwent(char *pfile, char *s_readbuf, int bufsize, void *
int *file_lock_depth, BOOL update) startfilepwent (char *pfile, char *s_readbuf, int bufsize, int *file_lock_depth, BOOL update)
{ {
FILE *fp = NULL; FILE *fp = NULL;
if (!*pfile) if (!*pfile)
{ {
DEBUG(0, ("startfilepwent: No file set\n")); DEBUG (0, ("startfilepwent: No file set\n"));
return (NULL); return (NULL);
} }
DEBUG(10, ("startfilepwent: opening file %s\n", pfile)); 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) { if (fp == NULL)
DEBUG(0, ("startfilepwent: unable to open file %s\n", pfile)); {
return NULL; DEBUG (0, ("startfilepwent: unable to open file %s\n", pfile));
} return NULL;
}
/* Set a buffer to do more efficient reads */ /* Set a buffer to do more efficient reads */
setvbuf(fp, s_readbuf, _IOFBF, bufsize); setvbuf (fp, s_readbuf, _IOFBF, bufsize);
if (!file_lock(fileno(fp), (update ? F_WRLCK : F_RDLCK), 5, file_lock_depth)) if (!file_lock (fileno (fp), (update ? F_WRLCK : F_RDLCK), 5, file_lock_depth))
{ {
DEBUG(0, ("startfilepwent: unable to lock file %s\n", pfile)); DEBUG (0, ("startfilepwent: unable to lock file %s\n", pfile));
fclose(fp); fclose (fp);
return NULL; return NULL;
} }
/* Make sure it is only rw by the owner */ /* Make sure it is only rw by the owner */
chmod(pfile, 0600); chmod (pfile, 0600);
/* We have a lock on the file. */ /* We have a lock on the file. */
return (void *)fp; return (void *) fp;
} }
/*************************************************************** /***************************************************************
End enumeration of the file. 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); file_unlock (fileno (fp), file_lock_depth);
fclose(fp); fclose (fp);
DEBUG(7, ("endfilepwent: closed file.\n")); 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. Return the current position in the file list as an SMB_BIG_UINT.
This must be treated as an opaque token. 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. Set the current position in the file list from an SMB_BIG_UINT.
This must be treated as an opaque token. 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:". line is of format "xxxx:xxxxxx:xxxxx:".
lines with "#" at the front are ignored. 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. */ /* Static buffers we will return. */
FILE *fp = (FILE *)vp; FILE *fp = (FILE *) vp;
unsigned char c; unsigned char c;
unsigned char *p; unsigned char *p;
size_t linebuf_len; size_t linebuf_len;
if (fp == NULL) if (fp == NULL)
{ {
DEBUG(0,("getfileline: Bad file pointer.\n")); DEBUG (0, ("getfileline: Bad file pointer.\n"));
return -1; return -1;
} }
/* /*
* Scan the file, a line at a time. * Scan the file, a line at a time.
*/ */
while (!feof(fp)) while (!feof (fp))
{ {
linebuf[0] = '\0'; linebuf[0] = '\0';
fgets(linebuf, linebuf_size, fp); fgets (linebuf, linebuf_size, fp);
if (ferror(fp)) if (ferror (fp))
{ {
return -1; return -1;
} }
/* /*
* Check if the string is terminated with a newline - if not * Check if the string is terminated with a newline - if not
* then we must keep reading and discard until we get one. * then we must keep reading and discard until we get one.
*/ */
linebuf_len = strlen(linebuf); linebuf_len = strlen (linebuf);
if (linebuf[linebuf_len - 1] != '\n') if (linebuf[linebuf_len - 1] != '\n')
{ {
c = '\0'; c = '\0';
while (!ferror(fp) && !feof(fp)) while (!ferror (fp) && !feof (fp))
{ {
c = fgetc(fp); c = fgetc (fp);
if (c == '\n') if (c == '\n')
{ {
break; break;
} }
} }
} }
else else
{ {
linebuf[linebuf_len - 1] = '\0'; linebuf[linebuf_len - 1] = '\0';
} }
#ifdef DEBUG_PASSWORD #ifdef DEBUG_PASSWORD
DEBUG(100, ("getfileline: got line |%s|\n", linebuf)); DEBUG (100, ("getfileline: got line |%s|\n", linebuf));
#endif #endif
if ((linebuf[0] == 0) && feof(fp)) if ((linebuf[0] == 0) && feof (fp))
{ {
DEBUG(4, ("getfileline: end of file reached\n")); DEBUG (4, ("getfileline: end of file reached\n"));
return 0; return 0;
} }
if (linebuf[0] == '#' || linebuf[0] == '\0') if (linebuf[0] == '#' || linebuf[0] == '\0')
{ {
DEBUG(6, ("getfileline: skipping comment or blank line\n")); DEBUG (6, ("getfileline: skipping comment or blank line\n"));
continue; continue;
} }
p = (unsigned char *) strchr(linebuf, ':'); p = (unsigned char *) strchr (linebuf, ':');
if (p == NULL) if (p == NULL)
{ {
DEBUG(0, ("getfileline: malformed line entry (no :)\n")); DEBUG (0, ("getfileline: malformed line entry (no :)\n"));
continue; continue;
} }
return linebuf_len; return linebuf_len;
} }
return -1; return -1;
} }
#endif /* 0 */ #endif /* 0 */
/**************************************************************************** /****************************************************************************
read a line from a file with possible \ continuation chars. read a line from a file with possible \ continuation chars.
Blanks at the start or end of a line are stripped. Blanks at the start or end of a line are stripped.
The string will be allocated if s2 is NULL 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; char *s = s2;
int len = 0; int len = 0;
int c; int c;
BOOL start_of_line = True; BOOL start_of_line = True;
if (feof(f)) if (feof (f))
return(NULL); return (NULL);
if (!s2) if (!s2)
{ {
maxlen = MIN(maxlen,8); maxlen = MIN (maxlen, 8);
s = (char *)Realloc(s,maxlen); 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); c = getc (f);
switch (c) switch (c)
{ {
case '\r': case '\r':
break; break;
case '\n': case '\n':
while (len > 0 && s[len-1] == ' ') while (len > 0 && s[len - 1] == ' ')
{ {
s[--len] = 0; s[--len] = 0;
} }
if (len > 0 && s[len-1] == '\\') if (len > 0 && s[len - 1] == '\\')
{ {
s[--len] = 0; s[--len] = 0;
start_of_line = True; start_of_line = True;
break; break;
} }
return(s); return (s);
case EOF: case EOF:
if (len <= 0 && !s2) if (len <= 0 && !s2)
free(s); free (s);
return(len>0?s:NULL); return (len > 0 ? s : NULL);
case ' ': case ' ':
if (start_of_line) if (start_of_line)
break; break;
default: default:
start_of_line = False; start_of_line = False;
s[len++] = c; s[len++] = c;
s[len] = 0; s[len] = 0;
} }
if (!s2 && len > maxlen-3) if (!s2 && len > maxlen - 3)
{ {
maxlen *= 2; maxlen *= 2;
s = (char *)Realloc(s,maxlen); s = (char *) Realloc (s, maxlen);
if (!s) return(NULL); if (!s)
} return (NULL);
}
} }
return(s); return (s);
} }

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -22,7 +22,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
@ -36,54 +36,68 @@ const BOOL global_in_nmbd = False;
/**************************************************************************** /****************************************************************************
interpret a node status response 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); int numnames = CVAL (p, 0);
DEBUG(1,("received %d names\n",numnames)); DEBUG (1, ("received %d names\n", numnames));
if (rname) *rname = 0; if (rname)
if (master) *master = 0; *rname = 0;
if (master)
*master = 0;
p += 1; p += 1;
while (numnames--) while (numnames--)
{ {
char qname[17]; char qname[17];
int type; int type;
fstring flags; fstring flags;
int i; int i;
*flags = 0; *flags = 0;
StrnCpy(qname,p,15); StrnCpy (qname, p, 15);
type = CVAL(p,15); type = CVAL (p, 15);
p += 16; p += 16;
fstrcat(flags, (p[0] & 0x80) ? "<GROUP> " : " "); fstrcat (flags, (p[0] & 0x80) ? "<GROUP> " : " ");
if ((p[0] & 0x60) == 0x00) fstrcat(flags,"B "); if ((p[0] & 0x60) == 0x00)
if ((p[0] & 0x60) == 0x20) fstrcat(flags,"P "); fstrcat (flags, "B ");
if ((p[0] & 0x60) == 0x40) fstrcat(flags,"M "); if ((p[0] & 0x60) == 0x20)
if ((p[0] & 0x60) == 0x60) fstrcat(flags,"H "); fstrcat (flags, "P ");
if (p[0] & 0x10) fstrcat(flags,"<DEREGISTERING> "); if ((p[0] & 0x60) == 0x40)
if (p[0] & 0x08) fstrcat(flags,"<CONFLICT> "); fstrcat (flags, "M ");
if (p[0] & 0x04) fstrcat(flags,"<ACTIVE> "); if ((p[0] & 0x60) == 0x60)
if (p[0] & 0x02) fstrcat(flags,"<PERMANENT> "); 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) { if (master && !*master && type == 0x1d)
StrnCpy(master,qname,15); {
trim_string(master,NULL," "); StrnCpy (master, qname, 15);
} trim_string (master, NULL, " ");
}
if (rname && !*rname && type == 0x20 && !(p[0]&0x80)) { if (rname && !*rname && type == 0x20 && !(p[0] & 0x80))
StrnCpy(rname,qname,15); {
trim_string(rname,NULL," "); StrnCpy (rname, qname, 15);
} trim_string (rname, NULL, " ");
}
for (i = strlen( qname) ; --i >= 0 ; ) {
if (!isprint((int)qname[i])) qname[i] = '.'; for (i = strlen (qname); --i >= 0;)
} {
DEBUG(1,("\t%-15s <%02x> - %s\n",qname,type,flags)); if (!isprint ((int) qname[i]))
p+=2; 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", DEBUG (1, ("num_good_sends=%d num_good_receives=%d\n", IVAL (p, 20), IVAL (p, 24)));
IVAL(p,20),IVAL(p,24)));
} }
#endif /* 0 */ #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 returns an array of IP addresses or NULL if none
*count will be set to the number of addresses returned *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 *
struct in_addr to_ip, int *count, void (*fn)(struct packet_struct *)) 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; BOOL found = False;
int i, retries = 3; int i, retries = 3;
int retry_time = bcast?250:2000; int retry_time = bcast ? 250 : 2000;
struct timeval tval; struct timeval tval;
struct packet_struct p; struct packet_struct p;
struct packet_struct *p2; struct packet_struct *p2;
struct nmb_packet *nmb = &p.packet.nmb; struct nmb_packet *nmb = &p.packet.nmb;
static int name_trn_id = 0; static int name_trn_id = 0;
struct in_addr *ip_list = NULL; struct in_addr *ip_list = NULL;
memset((char *)&p,'\0',sizeof(p)); memset ((char *) &p, '\0', sizeof (p));
(*count) = 0; (*count) = 0;
if (!name_trn_id) name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + if (!name_trn_id)
((unsigned)getpid()%(unsigned)100); name_trn_id = ((unsigned) time (NULL) % (unsigned) 0x7FFF) +
name_trn_id = (name_trn_id+1) % (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.name_trn_id = name_trn_id;
nmb->header.opcode = 0; nmb->header.opcode = 0;
nmb->header.response = False; nmb->header.response = False;
nmb->header.nm_flags.bcast = bcast; nmb->header.nm_flags.bcast = bcast;
nmb->header.nm_flags.recursion_available = False; nmb->header.nm_flags.recursion_available = False;
nmb->header.nm_flags.recursion_desired = recurse; nmb->header.nm_flags.recursion_desired = recurse;
nmb->header.nm_flags.trunc = False; nmb->header.nm_flags.trunc = False;
nmb->header.nm_flags.authoritative = False; nmb->header.nm_flags.authoritative = False;
nmb->header.rcode = 0; nmb->header.rcode = 0;
nmb->header.qdcount = 1; nmb->header.qdcount = 1;
nmb->header.ancount = 0; nmb->header.ancount = 0;
nmb->header.nscount = 0; nmb->header.nscount = 0;
nmb->header.arcount = 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_type = 0x20;
nmb->question.question_class = 0x1; nmb->question.question_class = 0x1;
p.ip = to_ip; p.ip = to_ip;
p.port = NMB_PORT; p.port = NMB_PORT;
p.fd = fd; p.fd = fd;
p.timestamp = time(NULL); p.timestamp = time (NULL);
p.packet_type = NMB_PACKET; p.packet_type = NMB_PACKET;
GetTimeOfDay(&tval); GetTimeOfDay (&tval);
if (!send_packet(&p)) 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))
return NULL; return NULL;
GetTimeOfDay(&tval);
retries--;
}
if ((p2=receive_packet(fd,NMB_PACKET,90))) retries--;
{
struct nmb_packet *nmb2 = &p2->packet.nmb;
debug_nmb_packet(p2);
if (nmb->header.name_trn_id != nmb2->header.name_trn_id || while (1)
!nmb2->header.response) {
{ struct timeval tval2;
/* GetTimeOfDay (&tval2);
* Its not for us - maybe deal with it later if (TvalDiff (&tval, &tval2) > retry_time)
* (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]); if (!retries)
DEBUG(fn?3:2,("%s ",inet_ntoa(ip_list[(*count)]))); break;
(*count)++; if (!found && !send_packet (&p))
return NULL;
GetTimeOfDay (&tval);
retries--;
} }
DEBUG(fn?3:2,(")\n"));
}
found=True; if ((p2 = receive_packet (fd, NMB_PACKET, 90)))
retries=0; {
free_packet(p2); struct nmb_packet *nmb2 = &p2->packet.nmb;
if (fn) debug_nmb_packet (p2);
break;
/* if (nmb->header.name_trn_id != nmb2->header.name_trn_id || !nmb2->header.response)
* If we're doing a unicast lookup we only {
* expect one reply. Don't wait the full 2 /*
* seconds if we got one. JRA. * Its not for us - maybe deal with it later
*/ * (put it on the queue?).
if(!bcast && found) */
break; 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. Start parsing the lmhosts file.
*********************************************************/ *********************************************************/
FILE *startlmhosts(const char *fname) FILE *
startlmhosts (const char *fname)
{ {
FILE *fp = sys_fopen(fname,"r"); FILE *fp = sys_fopen (fname, "r");
if (!fp) { if (!fp)
DEBUG(4,("startlmhosts: Cannot open lmhosts file %s. Error was %s\n", {
fname, unix_error_string (errno))); DEBUG (4, ("startlmhosts: Cannot open lmhosts file %s. Error was %s\n",
return NULL; fname, unix_error_string (errno)));
} return NULL;
return fp; }
return fp;
} }
/******************************************************** /********************************************************
Parse the next line in the lmhosts file. 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)) { 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)
{ {
DEBUG(0,("getlmhostsent: Ill formed hosts line [%s]\n",line)); pstring ip, flags, extra;
continue; 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) return False;
{
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;
} }
/******************************************************** /********************************************************
Finish parsing the lmhosts file. Finish parsing the lmhosts file.
*********************************************************/ *********************************************************/
void endlmhosts(FILE *fp) void
endlmhosts (FILE * fp)
{ {
fclose(fp); fclose (fp);
} }
/******************************************************** /********************************************************
resolve via "bcast" method 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; int sock, i;
/*
* "bcast" means do a broadcast lookup on all the local interfaces.
*/
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, DEBUG (3, ("resolve_name: Attempting broadcast lookup for name %s<0x%x>\n", name, name_type));
interpret_addr(lp_socket_address()), True );
if (sock != -1) { sock = open_socket_in (SOCK_DGRAM, 0, 3, interpret_addr (lp_socket_address ()), True);
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; 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 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; int sock;
struct in_addr wins_ip; struct in_addr wins_ip;
BOOL wins_ismyip; BOOL wins_ismyip;
/* /*
* "wins" means do a unicast lookup to the WINS server. * "wins" means do a unicast lookup to the WINS server.
* Ignore if there is no WINS server specified or if the * Ignore if there is no WINS server specified or if the
* WINS server is one of our interfaces (if we're being * WINS server is one of our interfaces (if we're being
* called from within nmbd - we can't do this call as we * called from within nmbd - we can't do this call as we
* would then block). * 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()) { if (!*lp_wins_server ())
DEBUG(3,("resolve_name: WINS server resolution selected and no WINS server present.\n")); {
return False; DEBUG (3, ("resolve_name: WINS server resolution selected and no WINS server present.\n"));
} return False;
}
wins_ip = *interpret_addr2(lp_wins_server()); wins_ip = *interpret_addr2 (lp_wins_server ());
wins_ismyip = ismyip(wins_ip); wins_ismyip = ismyip (wins_ip);
if((wins_ismyip && !global_in_nmbd) || !wins_ismyip) { if ((wins_ismyip && !global_in_nmbd) || !wins_ismyip)
sock = open_socket_in( SOCK_DGRAM, 0, 3, {
interpret_addr(lp_socket_address()), True ); 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);
}
}
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 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. * "lmhosts" means parse the local lmhosts file.
*/ */
FILE *fp;
pstring lmhost_name;
int name_type2;
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 ); DEBUG (3, ("resolve_name: Attempting lmhosts lookup for name %s<0x%x>\n", name, name_type));
if(fp) {
while (getlmhostsent(fp, lmhost_name, &name_type2, return_ip)) { fp = startlmhosts (LMHOSTSFILE);
if (strequal(name, lmhost_name) && if (fp)
((name_type2 == -1) || (name_type == name_type2)) {
) { while (getlmhostsent (fp, lmhost_name, &name_type2, return_ip))
endlmhosts(fp); {
return True; if (strequal (name, lmhost_name) && ((name_type2 == -1) || (name_type == name_type2)))
} {
} endlmhosts (fp);
endlmhosts(fp); return True;
} }
return False; }
endlmhosts (fp);
}
return False;
} }
/******************************************************** /********************************************************
resolve via "hosts" method 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. * "host" means do a localhost, or dns lookup.
*/ */
struct hostent *hp; struct hostent *hp;
DEBUG(3,("resolve_name: Attempting host lookup for name %s<0x20>\n", name)); DEBUG (3, ("resolve_name: Attempting host lookup for name %s<0x20>\n", name));
if (((hp = Get_Hostbyname(name)) != NULL) && (hp->h_addr != NULL)) { if (((hp = Get_Hostbyname (name)) != NULL) && (hp->h_addr != NULL))
putip((char *)return_ip,(char *)hp->h_addr); {
return True; putip ((char *) return_ip, (char *) hp->h_addr);
} return True;
return False; }
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 or NetBIOS name. This uses the name switch in the
smb.conf to determine the order of name resolution. 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; int i;
BOOL pure_address = True; BOOL pure_address = True;
pstring name_resolve_list; pstring name_resolve_list;
fstring tok; fstring tok;
char *ptr; char *ptr;
if (strcmp(name,"0.0.0.0") == 0) { if (strcmp (name, "0.0.0.0") == 0)
return_ip->s_addr = 0; {
return True; return_ip->s_addr = 0;
} return True;
if (strcmp(name,"255.255.255.255") == 0) { }
return_ip->s_addr = 0xFFFFFFFF; if (strcmp (name, "255.255.255.255") == 0)
return True; {
} 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;
}
pstrcpy(name_resolve_list, lp_name_resolve_order()); for (i = 0; pure_address && name[i]; i++)
if (name_resolve_list == NULL || *name_resolve_list == '\0') if (!(isdigit ((int) name[i]) || name[i] == '.'))
pstrcpy(name_resolve_list, "host"); pure_address = False;
ptr = name_resolve_list;
while (next_token(&ptr, tok, LIST_SEP, sizeof(tok))) { /* if it's in the form of an IP address then get the lib to interpret it */
if((strequal(tok, "host") || strequal(tok, "hosts"))) { if (pure_address)
if (name_type == 0x20 && resolve_hosts(name, return_ip)) { {
return True; return_ip->s_addr = inet_addr (name);
} 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; 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 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 */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -22,7 +22,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
@ -32,23 +32,25 @@ extern int DEBUGLEVEL;
/**************************************************************************** /****************************************************************************
initialises a password structure 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->password, '\0', sizeof (pwd->password));
memset((char *)pwd->smb_lm_pwd, '\0', sizeof(pwd->smb_lm_pwd)); 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_nt_pwd, '\0', sizeof (pwd->smb_nt_pwd));
memset((char *)pwd->smb_lm_owf, '\0', sizeof(pwd->smb_lm_owf)); 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->smb_nt_owf, '\0', sizeof (pwd->smb_nt_owf));
pwd->null_pwd = True; /* safest option... */ pwd->null_pwd = True; /* safest option... */
pwd->cleartext = False; pwd->cleartext = False;
pwd->crypted = False; pwd->crypted = False;
} }
/**************************************************************************** /****************************************************************************
de-obfuscates a password de-obfuscates a password
****************************************************************************/ ****************************************************************************/
static void pwd_deobfuscate(struct pwd_info *pwd) static void
pwd_deobfuscate (struct pwd_info *pwd)
{ {
(void) pwd; (void) pwd;
} }
@ -56,7 +58,8 @@ static void pwd_deobfuscate(struct pwd_info *pwd)
/**************************************************************************** /****************************************************************************
obfuscates a password obfuscates a password
****************************************************************************/ ****************************************************************************/
static void pwd_obfuscate(struct pwd_info *pwd) static void
pwd_obfuscate (struct pwd_info *pwd)
{ {
(void) pwd; (void) pwd;
} }
@ -64,7 +67,8 @@ static void pwd_obfuscate(struct pwd_info *pwd)
/**************************************************************************** /****************************************************************************
sets the obfuscation key info 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) pwd;
(void) int_key; (void) int_key;
@ -75,185 +79,194 @@ void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key)
/**************************************************************************** /****************************************************************************
reads a password 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 */ /* grab a password */
char *user_pass; 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) if (user_pass == NULL || user_pass[0] == 0)
{ {
pwd_set_nullpwd(pwd); pwd_set_nullpwd (pwd);
} }
else if (do_encrypt) else if (do_encrypt)
{ {
pwd_make_lm_nt_16(pwd, user_pass); pwd_make_lm_nt_16 (pwd, user_pass);
} }
else else
{ {
pwd_set_cleartext(pwd, user_pass); pwd_set_cleartext (pwd, user_pass);
} }
} }
#endif #endif
/**************************************************************************** /****************************************************************************
stores a cleartext password 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->cleartext = False;
pwd->null_pwd = True; pwd->null_pwd = True;
pwd->crypted = False; pwd->crypted = False;
} }
/**************************************************************************** /****************************************************************************
stores a cleartext password 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); pwd_init (pwd);
fstrcpy(pwd->password, clr); fstrcpy (pwd->password, clr);
pwd->cleartext = True; pwd->cleartext = True;
pwd->null_pwd = False; pwd->null_pwd = False;
pwd->crypted = False; pwd->crypted = False;
pwd_obfuscate(pwd); pwd_obfuscate (pwd);
} }
/**************************************************************************** /****************************************************************************
gets a cleartext password 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); pwd_deobfuscate (pwd);
if (pwd->cleartext) if (pwd->cleartext)
{ {
fstrcpy(clr, pwd->password); fstrcpy (clr, pwd->password);
} }
else else
{ {
clr[0] = 0; clr[0] = 0;
} }
pwd_obfuscate(pwd); pwd_obfuscate (pwd);
} }
/**************************************************************************** /****************************************************************************
stores lm and nt hashed passwords 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) if (lm_pwd)
{ {
memcpy(pwd->smb_lm_pwd, lm_pwd, 16); memcpy (pwd->smb_lm_pwd, lm_pwd, 16);
} }
else else
{ {
memset((char *)pwd->smb_lm_pwd, '\0', 16); memset ((char *) pwd->smb_lm_pwd, '\0', 16);
} }
if (nt_pwd) if (nt_pwd)
{ {
memcpy(pwd->smb_nt_pwd, nt_pwd, 16); memcpy (pwd->smb_nt_pwd, nt_pwd, 16);
} }
else else
{ {
memset((char *)pwd->smb_nt_pwd, '\0', 16); memset ((char *) pwd->smb_nt_pwd, '\0', 16);
} }
pwd->null_pwd = False; pwd->null_pwd = False;
pwd->cleartext = False; pwd->cleartext = False;
pwd->crypted = False; pwd->crypted = False;
pwd_obfuscate(pwd); pwd_obfuscate (pwd);
} }
/**************************************************************************** /****************************************************************************
gets lm and nt hashed passwords 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); pwd_deobfuscate (pwd);
if (lm_pwd != NULL) if (lm_pwd != NULL)
{ {
memcpy(lm_pwd, pwd->smb_lm_pwd, 16); memcpy (lm_pwd, pwd->smb_lm_pwd, 16);
} }
if (nt_pwd != NULL) if (nt_pwd != NULL)
{ {
memcpy(nt_pwd, pwd->smb_nt_pwd, 16); memcpy (nt_pwd, pwd->smb_nt_pwd, 16);
} }
pwd_obfuscate(pwd); pwd_obfuscate (pwd);
} }
/**************************************************************************** /****************************************************************************
makes lm and nt hashed passwords 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); nt_lm_owf_gen (clr, pwd->smb_nt_pwd, pwd->smb_lm_pwd);
pwd->null_pwd = False; pwd->null_pwd = False;
pwd->cleartext = False; pwd->cleartext = False;
pwd->crypted = False; pwd->crypted = False;
pwd_obfuscate(pwd); pwd_obfuscate (pwd);
} }
/**************************************************************************** /****************************************************************************
makes lm and nt OWF crypts 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 #ifdef DEBUG_PASSWORD
DEBUG(100,("client cryptkey: ")); DEBUG (100, ("client cryptkey: "));
dump_data(100, (char *)cryptkey, 8); dump_data (100, (char *) cryptkey, 8);
#endif #endif
SMBOWFencrypt(pwd->smb_nt_pwd, cryptkey, pwd->smb_nt_owf); SMBOWFencrypt (pwd->smb_nt_pwd, cryptkey, pwd->smb_nt_owf);
#ifdef DEBUG_PASSWORD #ifdef DEBUG_PASSWORD
DEBUG(100,("nt_owf_passwd: ")); DEBUG (100, ("nt_owf_passwd: "));
dump_data(100, (char *)pwd->smb_nt_owf, sizeof(pwd->smb_nt_owf)); dump_data (100, (char *) pwd->smb_nt_owf, sizeof (pwd->smb_nt_owf));
DEBUG(100,("nt_sess_pwd: ")); DEBUG (100, ("nt_sess_pwd: "));
dump_data(100, (char *)pwd->smb_nt_pwd, sizeof(pwd->smb_nt_pwd)); dump_data (100, (char *) pwd->smb_nt_pwd, sizeof (pwd->smb_nt_pwd));
#endif #endif
SMBOWFencrypt(pwd->smb_lm_pwd, cryptkey, pwd->smb_lm_owf); SMBOWFencrypt (pwd->smb_lm_pwd, cryptkey, pwd->smb_lm_owf);
#ifdef DEBUG_PASSWORD #ifdef DEBUG_PASSWORD
DEBUG(100,("lm_owf_passwd: ")); DEBUG (100, ("lm_owf_passwd: "));
dump_data(100, (char *)pwd->smb_lm_owf, sizeof(pwd->smb_lm_owf)); dump_data (100, (char *) pwd->smb_lm_owf, sizeof (pwd->smb_lm_owf));
DEBUG(100,("lm_sess_pwd: ")); DEBUG (100, ("lm_sess_pwd: "));
dump_data(100, (char *)pwd->smb_lm_pwd, sizeof(pwd->smb_lm_pwd)); dump_data (100, (char *) pwd->smb_lm_pwd, sizeof (pwd->smb_lm_pwd));
#endif #endif
pwd->crypted = True; pwd->crypted = True;
pwd_obfuscate(pwd); pwd_obfuscate (pwd);
} }
/**************************************************************************** /****************************************************************************
gets lm and nt crypts 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); pwd_deobfuscate (pwd);
if (lm_owf != NULL) if (lm_owf != NULL)
{ {
memcpy(lm_owf, pwd->smb_lm_owf, 24); memcpy (lm_owf, pwd->smb_lm_owf, 24);
} }
if (nt_owf != NULL) if (nt_owf != NULL)
{ {
memcpy(nt_owf, pwd->smb_nt_owf, 24); memcpy (nt_owf, pwd->smb_nt_owf, 24);
} }
pwd_obfuscate(pwd); pwd_obfuscate (pwd);
} }

Просмотреть файл

@ -24,7 +24,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
@ -48,356 +48,386 @@
about the applicability of ITAR regulations to this code then you about the applicability of ITAR regulations to this code then you
should confirm it for yourself (and maybe let me know if you come should confirm it for yourself (and maybe let me know if you come
up with a different answer to the one above) up with a different answer to the one above)
*/ */
#undef uchar #undef uchar
#define uchar const unsigned char #define uchar const unsigned char
static uchar perm1[56] = {57, 49, 41, 33, 25, 17, 9, static uchar perm1[56] = { 57, 49, 41, 33, 25, 17, 9,
1, 58, 50, 42, 34, 26, 18, 1, 58, 50, 42, 34, 26, 18,
10, 2, 59, 51, 43, 35, 27, 10, 2, 59, 51, 43, 35, 27,
19, 11, 3, 60, 52, 44, 36, 19, 11, 3, 60, 52, 44, 36,
63, 55, 47, 39, 31, 23, 15, 63, 55, 47, 39, 31, 23, 15,
7, 62, 54, 46, 38, 30, 22, 7, 62, 54, 46, 38, 30, 22,
14, 6, 61, 53, 45, 37, 29, 14, 6, 61, 53, 45, 37, 29,
21, 13, 5, 28, 20, 12, 4}; 21, 13, 5, 28, 20, 12, 4
};
static uchar perm2[48] = {14, 17, 11, 24, 1, 5, static uchar perm2[48] = { 14, 17, 11, 24, 1, 5,
3, 28, 15, 6, 21, 10, 3, 28, 15, 6, 21, 10,
23, 19, 12, 4, 26, 8, 23, 19, 12, 4, 26, 8,
16, 7, 27, 20, 13, 2, 16, 7, 27, 20, 13, 2,
41, 52, 31, 37, 47, 55, 41, 52, 31, 37, 47, 55,
30, 40, 51, 45, 33, 48, 30, 40, 51, 45, 33, 48,
44, 49, 39, 56, 34, 53, 44, 49, 39, 56, 34, 53,
46, 42, 50, 36, 29, 32}; 46, 42, 50, 36, 29, 32
};
static uchar perm3[64] = {58, 50, 42, 34, 26, 18, 10, 2, static uchar perm3[64] = { 58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4, 60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6, 62, 54, 46, 38, 30, 22, 14, 6,
64, 56, 48, 40, 32, 24, 16, 8, 64, 56, 48, 40, 32, 24, 16, 8,
57, 49, 41, 33, 25, 17, 9, 1, 57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3, 59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5, 61, 53, 45, 37, 29, 21, 13, 5,
63, 55, 47, 39, 31, 23, 15, 7}; 63, 55, 47, 39, 31, 23, 15, 7
};
static uchar perm4[48] = { 32, 1, 2, 3, 4, 5, static uchar perm4[48] = { 32, 1, 2, 3, 4, 5,
4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9,
8, 9, 10, 11, 12, 13, 8, 9, 10, 11, 12, 13,
12, 13, 14, 15, 16, 17, 12, 13, 14, 15, 16, 17,
16, 17, 18, 19, 20, 21, 16, 17, 18, 19, 20, 21,
20, 21, 22, 23, 24, 25, 20, 21, 22, 23, 24, 25,
24, 25, 26, 27, 28, 29, 24, 25, 26, 27, 28, 29,
28, 29, 30, 31, 32, 1}; 28, 29, 30, 31, 32, 1
};
static uchar perm5[32] = { 16, 7, 20, 21, static uchar perm5[32] = { 16, 7, 20, 21,
29, 12, 28, 17, 29, 12, 28, 17,
1, 15, 23, 26, 1, 15, 23, 26,
5, 18, 31, 10, 5, 18, 31, 10,
2, 8, 24, 14, 2, 8, 24, 14,
32, 27, 3, 9, 32, 27, 3, 9,
19, 13, 30, 6, 19, 13, 30, 6,
22, 11, 4, 25}; 22, 11, 4, 25
};
static uchar perm6[64] ={ 40, 8, 48, 16, 56, 24, 64, 32, static uchar perm6[64] = { 40, 8, 48, 16, 56, 24, 64, 32,
39, 7, 47, 15, 55, 23, 63, 31, 39, 7, 47, 15, 55, 23, 63, 31,
38, 6, 46, 14, 54, 22, 62, 30, 38, 6, 46, 14, 54, 22, 62, 30,
37, 5, 45, 13, 53, 21, 61, 29, 37, 5, 45, 13, 53, 21, 61, 29,
36, 4, 44, 12, 52, 20, 60, 28, 36, 4, 44, 12, 52, 20, 60, 28,
35, 3, 43, 11, 51, 19, 59, 27, 35, 3, 43, 11, 51, 19, 59, 27,
34, 2, 42, 10, 50, 18, 58, 26, 34, 2, 42, 10, 50, 18, 58, 26,
33, 1, 41, 9, 49, 17, 57, 25}; 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] = { static uchar sbox[8][4][16] = {
{{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7}, {{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}, {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}, {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, 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}, {{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}, {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}, {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}}, {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}, {{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, 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}, {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}}, {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}, {{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}, {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}, {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}}, {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}, {{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}, {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}, {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}}, {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}, {{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}, {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}, {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, 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}, {{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}, {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}, {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}}, {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}, {{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}, {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}, {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}}}; {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; int i;
for (i=0;i<n;i++) for (i = 0; i < n; i++)
out[i] = in[p[i]-1]; 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]; char out[64];
int i; int i;
for (i=0;i<n;i++) for (i = 0; i < n; i++)
out[i] = d[(i+count)%n]; out[i] = d[(i + count) % n];
for (i=0;i<n;i++) for (i = 0; i < n; i++)
d[i] = out[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--) while (l1--)
*out++ = *in1++; *out++ = *in1++;
while (l2--) while (l2--)
*out++ = *in2++; *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; int i;
for (i=0;i<n;i++) for (i = 0; i < n; i++)
out[i] = in1[i] ^ in2[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; int i, j, k;
char pk1[56]; char pk1[56];
char c[28]; char c[28];
char d[28]; char d[28];
char cd[56]; char cd[56];
char ki[16][48]; char ki[16][48];
char pd1[64]; char pd1[64];
char l[32], r[32]; char l[32], r[32];
char rl[64]; char rl[64];
permute(pk1, key, perm1, 56); permute (pk1, key, perm1, 56);
for (i=0;i<28;i++) for (i = 0; i < 28; i++)
c[i] = pk1[i]; c[i] = pk1[i];
for (i=0;i<28;i++) for (i = 0; i < 28; i++)
d[i] = pk1[i+28]; d[i] = pk1[i + 28];
for (i=0;i<16;i++) { for (i = 0; i < 16; i++)
lshift(c, sc[i], 28); {
lshift(d, sc[i], 28); lshift (c, sc[i], 28);
lshift (d, sc[i], 28);
concat(cd, c, d, 28, 28); concat (cd, c, d, 28, 28);
permute(ki[i], cd, perm2, 48); permute (ki[i], cd, perm2, 48);
} }
permute(pd1, in, perm3, 64); permute (pd1, in, perm3, 64);
for (j=0;j<32;j++) { for (j = 0; j < 32; j++)
l[j] = pd1[j]; {
r[j] = pd1[j+32]; l[j] = pd1[j];
} r[j] = pd1[j + 32];
}
for (i=0;i<16;i++) { for (i = 0; i < 16; i++)
char er[48]; {
char erk[48]; char er[48];
char b[8][6]; char erk[48];
char cb[32]; char b[8][6];
char pcb[32]; char cb[32];
char r2[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 (j = 0; j < 8; j++)
for (k=0;k<6;k++) for (k = 0; k < 6; k++)
b[j][k] = erk[j*6 + k]; b[j][k] = erk[j * 6 + k];
for (j=0;j<8;j++) { for (j = 0; j < 8; j++)
int m, n; {
m = (b[j][0]<<1) | b[j][5]; 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++) for (k = 0; k < 4; k++)
b[j][k] = (sbox[j][m][n] & (1<<(3-k)))?1:0; b[j][k] = (sbox[j][m][n] & (1 << (3 - k))) ? 1 : 0;
} }
for (j=0;j<8;j++) for (j = 0; j < 8; j++)
for (k=0;k<4;k++) for (k = 0; k < 4; k++)
cb[j*4+k] = b[j][k]; cb[j * 4 + k] = b[j][k];
permute(pcb, cb, perm5, 32); permute (pcb, cb, perm5, 32);
xor(r2, l, pcb, 32); xor (r2, l, pcb, 32);
for (j=0;j<32;j++) for (j = 0; j < 32; j++)
l[j] = r[j]; l[j] = r[j];
for (j=0;j<32;j++) for (j = 0; j < 32; j++)
r[j] = r2[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[0] = str[0] >> 1;
key[1] = ((str[0]&0x01)<<6) | (str[1]>>2); key[1] = ((str[0] & 0x01) << 6) | (str[1] >> 2);
key[2] = ((str[1]&0x03)<<5) | (str[2]>>3); key[2] = ((str[1] & 0x03) << 5) | (str[2] >> 3);
key[3] = ((str[2]&0x07)<<4) | (str[3]>>4); key[3] = ((str[2] & 0x07) << 4) | (str[3] >> 4);
key[4] = ((str[3]&0x0F)<<3) | (str[4]>>5); key[4] = ((str[3] & 0x0F) << 3) | (str[4] >> 5);
key[5] = ((str[4]&0x1F)<<2) | (str[5]>>6); key[5] = ((str[4] & 0x1F) << 2) | (str[5] >> 6);
key[6] = ((str[5]&0x3F)<<1) | (str[6]>>7); key[6] = ((str[5] & 0x3F) << 1) | (str[6] >> 7);
key[7] = str[6]&0x7F; key[7] = str[6] & 0x7F;
for (i=0;i<8;i++) { for (i = 0; i < 8; i++)
key[i] = (key[i]<<1); {
} 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; int i;
char outb[64]; char outb[64];
char inb[64]; char inb[64];
char keyb[64]; char keyb[64];
unsigned char key2[8]; unsigned char key2[8];
str_to_key(key, key2); str_to_key (key, key2);
for (i=0;i<64;i++) { 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; inb[i] = (in[i / 8] & (1 << (7 - (i % 8)))) ? 1 : 0;
outb[i] = 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++) { for (i = 0; i < 8; i++)
out[i] = 0; {
} out[i] = 0;
}
for (i=0;i<64;i++) { for (i = 0; i < 64; i++)
if (outb[i]) {
out[i/8] |= (1<<(7-(i%8))); 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}; unsigned char sp8[8] = { 0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 };
smbhash(p16, sp8, p14, 1); smbhash (p16, sp8, p14, 1);
smbhash(p16+8, sp8, p14+7, 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, c8, p21, 1);
smbhash(p24+8, c8, p21+7, 1); smbhash (p24 + 8, c8, p21 + 7, 1);
smbhash(p24+16, c8, p21+14, 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, in, p14, 0);
smbhash(out+8, in+8, p14+7, 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, in, p14, 1);
smbhash(out+8, in+8, p14+7, 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 (buf, in, key, 1);
smbhash(out, buf, key+9, 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]; unsigned char buf[8];
static unsigned char key2[8]; static unsigned char key2[8];
smbhash(buf, in, key, 1); smbhash (buf, in, key, 1);
key2[0] = key[7]; key2[0] = key[7];
smbhash(out, buf, key2, 1); 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); smbhash (out, in, key, forw);
key2[0] = key[7]; key2[0] = key[7];
smbhash(out + 8, in + 8, key2, forw); 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 s_box[256];
unsigned char index_i = 0; unsigned char index_i = 0;
unsigned char index_j = 0; unsigned char index_j = 0;
unsigned char j = 0; unsigned char j = 0;
int ind; int ind;
for (ind = 0; ind < 256; ind++) for (ind = 0; ind < 256; ind++)
{ {
s_box[ind] = (unsigned char)ind; s_box[ind] = (unsigned char) ind;
} }
for( ind = 0; ind < 256; ind++) for (ind = 0; ind < 256; ind++)
{ {
unsigned char tc; unsigned char tc;
j += (s_box[ind] + key[ind%16]); j += (s_box[ind] + key[ind % 16]);
tc = s_box[ind]; tc = s_box[ind];
s_box[ind] = s_box[j]; s_box[ind] = s_box[j];
s_box[j] = tc; s_box[j] = tc;
} }
for( ind = 0; ind < (val ? 516 : 16); ind++) for (ind = 0; ind < (val ? 516 : 16); ind++)
{ {
unsigned char tc; unsigned char tc;
unsigned char t; unsigned char t;
index_i++; index_i++;
index_j += s_box[index_i]; index_j += s_box[index_i];
tc = s_box[index_i]; tc = s_box[index_i];
s_box[index_i] = s_box[index_j]; s_box[index_i] = s_box[index_j];
s_box[index_j] = tc; s_box[index_j] = tc;
t = s_box[index_i] + s_box[index_j]; t = s_box[index_i] + s_box[index_j];
data[ind] = data[ind] ^ s_box[t]; data[ind] = data[ind] ^ s_box[t];
} }
} }

Просмотреть файл

@ -24,7 +24,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "includes.h" #include "includes.h"
@ -36,34 +36,36 @@ extern int DEBUGLEVEL;
This implements the X/Open SMB password encryption This implements the X/Open SMB password encryption
It takes a password, a 8 byte "crypt key" and puts 24 bytes of It takes a password, a 8 byte "crypt key" and puts 24 bytes of
encrypted password into p24 */ 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 (p21, '\0', 21);
memset(p14,'\0',14); memset (p14, '\0', 14);
StrnCpy((char *)p14,(char *)passwd,14); StrnCpy ((char *) p14, (char *) passwd, 14);
strupper((char *)p14); strupper ((char *) p14);
E_P16(p14, p21); E_P16 (p14, p21);
SMBOWFencrypt(p21, c8, p24); SMBOWFencrypt (p21, c8, p24);
#ifdef DEBUG_PASSWORD #ifdef DEBUG_PASSWORD
DEBUG(100,("SMBencrypt: lm#, challenge, response\n")); DEBUG (100, ("SMBencrypt: lm#, challenge, response\n"));
dump_data(100, (char *)p21, 16); dump_data (100, (char *) p21, 16);
dump_data(100, (char *)c8, 8); dump_data (100, (char *) c8, 8);
dump_data(100, (char *)p24, 24); dump_data (100, (char *) p24, 24);
#endif #endif
} }
/* Routines for Windows NT MD4 Hash functions. */ /* Routines for Windows NT MD4 Hash functions. */
static int _my_wcslen(int16 *str) static int
_my_wcslen (int16 * str)
{ {
int len = 0; int len = 0;
while(*str++ != 0) while (*str++ != 0)
len++; len++;
return len; return len;
} }
/* /*
@ -72,126 +74,133 @@ static int _my_wcslen(int16 *str)
* this must be in intel (little-endian) * this must be in intel (little-endian)
* format. * format.
*/ */
static int _my_mbstowcs(int16 *dst, uchar *src, int len) static int
_my_mbstowcs (int16 * dst, uchar * src, int len)
{ {
int i; int i;
int16 val; int16 val;
for(i = 0; i < len; i++) { for (i = 0; i < len; i++)
val = *src; {
SSVAL(dst,0,val); val = *src;
dst++; SSVAL (dst, 0, val);
src++; dst++;
if(val == 0) src++;
break; if (val == 0)
} break;
return i; }
return i;
} }
/* /*
* Creates the MD4 Hash of the users password in NT UNICODE. * 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 */ /* 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); memset (passwd, '\0', 130);
safe_strcpy( passwd, pwd, sizeof(passwd)-1); safe_strcpy (passwd, pwd, sizeof (passwd) - 1);
/* Calculate the MD4 hash (NT compatible) of the password */ /* Calculate the MD4 hash (NT compatible) of the password */
memset(nt_p16, '\0', 16); memset (nt_p16, '\0', 16);
E_md4hash((uchar *)passwd, nt_p16); E_md4hash ((uchar *) passwd, nt_p16);
#ifdef DEBUG_PASSWORD #ifdef DEBUG_PASSWORD
DEBUG(100,("nt_lm_owf_gen: pwd, nt#\n")); DEBUG (100, ("nt_lm_owf_gen: pwd, nt#\n"));
dump_data(120, passwd, strlen(passwd)); dump_data (120, passwd, strlen (passwd));
dump_data(100, (char *)nt_p16, 16); dump_data (100, (char *) nt_p16, 16);
#endif #endif
/* Mangle the passwords into Lanman format */ /* Mangle the passwords into Lanman format */
passwd[14] = '\0'; passwd[14] = '\0';
strupper(passwd); strupper (passwd);
/* Calculate the SMB (lanman) hash functions of the password */ /* Calculate the SMB (lanman) hash functions of the password */
memset(p16, '\0', 16); memset (p16, '\0', 16);
E_P16((uchar *) passwd, (uchar *)p16); E_P16 ((uchar *) passwd, (uchar *) p16);
#ifdef DEBUG_PASSWORD #ifdef DEBUG_PASSWORD
DEBUG(100,("nt_lm_owf_gen: pwd, lm#\n")); DEBUG (100, ("nt_lm_owf_gen: pwd, lm#\n"));
dump_data(120, passwd, strlen(passwd)); dump_data (120, passwd, strlen (passwd));
dump_data(100, (char *)p16, 16); dump_data (100, (char *) p16, 16);
#endif #endif
/* clear out local copy of user's password (just being paranoid). */ /* clear out local copy of user's password (just being paranoid). */
memset(passwd, '\0', sizeof(passwd)); memset (passwd, '\0', sizeof (passwd));
} }
/* Does the des encryption from the NT or LM MD4 hash. */ /* 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]; uchar p21[21];
memset(p21,'\0',21); memset (p21, '\0', 21);
memcpy(p21, passwd, 16); memcpy (p21, passwd, 16);
E_P24(p21, c8, p24); E_P24 (p21, c8, p24);
} }
/* Does the des encryption from the FIRST 8 BYTES of the NT or LM MD4 hash. */ /* 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]; uchar p21[21];
memset(p21,'\0',21);
memcpy(p21, passwd, 8);
memset(p21 + 8, 0xbd, 8);
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 #ifdef DEBUG_PASSWORD
DEBUG(100,("NTLMSSPOWFencrypt: p21, c8, p24\n")); DEBUG (100, ("NTLMSSPOWFencrypt: p21, c8, p24\n"));
dump_data(100, (char *)p21, 21); dump_data (100, (char *) p21, 21);
dump_data(100, (char *)ntlmchalresp, 8); dump_data (100, (char *) ntlmchalresp, 8);
dump_data(100, (char *)p24, 24); dump_data (100, (char *) p24, 24);
#endif #endif
} }
/* Does the NT MD4 hash then des encryption. */ /* 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]; uchar p21[21];
memset(p21,'\0',21); memset (p21, '\0', 21);
E_md4hash(passwd, p21); E_md4hash (passwd, p21);
SMBOWFencrypt(p21, c8, p24); SMBOWFencrypt (p21, c8, p24);
#ifdef DEBUG_PASSWORD #ifdef DEBUG_PASSWORD
DEBUG(100,("SMBNTencrypt: nt#, challenge, response\n")); DEBUG (100, ("SMBNTencrypt: nt#, challenge, response\n"));
dump_data(100, (char *)p21, 16); dump_data (100, (char *) p21, 16);
dump_data(100, (char *)c8, 8); dump_data (100, (char *) c8, 8);
dump_data(100, (char *)p24, 24); dump_data (100, (char *) p24, 24);
#endif #endif
} }

Просмотреть файл

@ -21,7 +21,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define NO_SYSLOG #define NO_SYSLOG
@ -34,153 +34,170 @@ extern int DEBUGLEVEL;
typedef struct typedef struct
{ {
const char *name; const char *name;
int code; int code;
const char *message; const char *message;
} err_code_struct; } err_code_struct;
/* Dos Error Messages */ /* Dos Error Messages */
static err_code_struct const dos_msgs[] = { static err_code_struct const dos_msgs[] = {
{"ERRbadfunc",1,"Invalid function."}, {"ERRbadfunc", 1, "Invalid function."},
{"ERRbadfile",2,"File not found."}, {"ERRbadfile", 2, "File not found."},
{"ERRbadpath",3,"Directory invalid."}, {"ERRbadpath", 3, "Directory invalid."},
{"ERRnofids",4,"No file descriptors available"}, {"ERRnofids", 4, "No file descriptors available"},
{"ERRnoaccess",5,"Access denied."}, {"ERRnoaccess", 5, "Access denied."},
{"ERRbadfid",6,"Invalid file handle."}, {"ERRbadfid", 6, "Invalid file handle."},
{"ERRbadmcb",7,"Memory control blocks destroyed."}, {"ERRbadmcb", 7, "Memory control blocks destroyed."},
{"ERRnomem",8,"Insufficient server memory to perform the requested function."}, {"ERRnomem", 8, "Insufficient server memory to perform the requested function."},
{"ERRbadmem",9,"Invalid memory block address."}, {"ERRbadmem", 9, "Invalid memory block address."},
{"ERRbadenv",10,"Invalid environment."}, {"ERRbadenv", 10, "Invalid environment."},
{"ERRbadformat",11,"Invalid format."}, {"ERRbadformat", 11, "Invalid format."},
{"ERRbadaccess",12,"Invalid open mode."}, {"ERRbadaccess", 12, "Invalid open mode."},
{"ERRbaddata",13,"Invalid data."}, {"ERRbaddata", 13, "Invalid data."},
{"ERR",14,"reserved."}, {"ERR", 14, "reserved."},
{"ERRbaddrive",15,"Invalid drive specified."}, {"ERRbaddrive", 15, "Invalid drive specified."},
{"ERRremcd",16,"A Delete Directory request attempted to remove the server's current directory."}, {"ERRremcd", 16,
{"ERRdiffdevice",17,"Not same device."}, "A Delete Directory request attempted to remove the server's current directory."},
{"ERRnofiles",18,"A File Search command can find no more files matching the specified criteria."}, {"ERRdiffdevice", 17, "Not same device."},
{"ERRbadshare",32,"The sharing mode specified for an Open conflicts with existing FIDs on the file."}, {"ERRnofiles", 18,
{"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."}, "A File Search command can find no more files matching the specified criteria."},
{"ERRunsup", 50, "The operation is unsupported"}, {"ERRbadshare", 32,
{"ERRnosuchshare", 67, "You specified an invalid share name"}, "The sharing mode specified for an Open conflicts with existing FIDs on the file."},
{"ERRfilexists",80,"The file named in a Create Directory, Make New File or Link request already exists."}, {"ERRlock", 33,
{"ERRbadpipe",230,"Pipe invalid."}, "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."},
{"ERRpipebusy",231,"All instances of the requested pipe are busy."}, {"ERRunsup", 50, "The operation is unsupported"},
{"ERRpipeclosing",232,"Pipe close in progress."}, {"ERRnosuchshare", 67, "You specified an invalid share name"},
{"ERRnotconnected",233,"No process on other end of pipe."}, {"ERRfilexists", 80,
{"ERRmoredata",234,"There is more data to be returned."}, "The file named in a Create Directory, Make New File or Link request already exists."},
{"ERRinvgroup",2455,"Invalid workgroup (try the -W option)"}, {"ERRbadpipe", 230, "Pipe invalid."},
{NULL,-1,NULL}}; {"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 */ /* Server Error Messages */
static err_code_struct const server_msgs[] = { static err_code_struct const server_msgs[] = {
{"ERRerror",1,"Non-specific error code."}, {"ERRerror", 1, "Non-specific error code."},
{"ERRbadpw",2,"Bad password - name/password pair in a Tree Connect or Session Setup are invalid."}, {"ERRbadpw", 2,
{"ERRbadtype",3,"reserved."}, "Bad password - name/password pair in a Tree Connect or Session Setup are invalid."},
{"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."}, {"ERRbadtype", 3, "reserved."},
{"ERRinvnid",5,"The tree ID (TID) specified in a command was invalid."}, {"ERRaccess", 4,
{"ERRinvnetname",6,"Invalid network name in tree connect."}, "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."},
{"ERRinvdevice",7,"Invalid device - printer request made to non-printer connection or non-printer request made to printer connection."}, {"ERRinvnid", 5, "The tree ID (TID) specified in a command was invalid."},
{"ERRqfull",49,"Print queue full (files) -- returned by open print file."}, {"ERRinvnetname", 6, "Invalid network name in tree connect."},
{"ERRqtoobig",50,"Print queue full -- no space."}, {"ERRinvdevice", 7,
{"ERRqeof",51,"EOF on print queue dump."}, "Invalid device - printer request made to non-printer connection or non-printer request made to printer connection."},
{"ERRinvpfid",52,"Invalid print file FID."}, {"ERRqfull", 49, "Print queue full (files) -- returned by open print file."},
{"ERRsmbcmd",64,"The server did not recognize the command received."}, {"ERRqtoobig", 50, "Print queue full -- no space."},
{"ERRsrverror",65,"The server encountered an internal error, e.g., system file unavailable."}, {"ERRqeof", 51, "EOF on print queue dump."},
{"ERRfilespecs",67,"The file handle (FID) and pathname parameters contained an invalid combination of values."}, {"ERRinvpfid", 52, "Invalid print file FID."},
{"ERRreserved",68,"reserved."}, {"ERRsmbcmd", 64, "The server did not recognize the command received."},
{"ERRbadpermits",69,"The access permissions specified for a file or directory are not a valid combination. The server cannot set the requested attribute."}, {"ERRsrverror", 65, "The server encountered an internal error, e.g., system file unavailable."},
{"ERRreserved",70,"reserved."}, {"ERRfilespecs", 67,
{"ERRsetattrmode",71,"The attribute mode in the Set File Attribute request is invalid."}, "The file handle (FID) and pathname parameters contained an invalid combination of values."},
{"ERRpaused",81,"Server is paused."}, {"ERRreserved", 68, "reserved."},
{"ERRmsgoff",82,"Not receiving messages."}, {"ERRbadpermits", 69,
{"ERRnoroom",83,"No room to buffer message."}, "The access permissions specified for a file or directory are not a valid combination. The server cannot set the requested attribute."},
{"ERRrmuns",87,"Too many remote user names."}, {"ERRreserved", 70, "reserved."},
{"ERRtimeout",88,"Operation timed out."}, {"ERRsetattrmode", 71, "The attribute mode in the Set File Attribute request is invalid."},
{"ERRnoresource",89,"No resources currently available for request."}, {"ERRpaused", 81, "Server is paused."},
{"ERRtoomanyuids",90,"Too many UIDs active on this session."}, {"ERRmsgoff", 82, "Not receiving messages."},
{"ERRbaduid",91,"The UID is not known as a valid ID on this session."}, {"ERRnoroom", 83, "No room to buffer message."},
{"ERRusempx",250,"Temp unable to support Raw, use MPX mode."}, {"ERRrmuns", 87, "Too many remote user names."},
{"ERRusestd",251,"Temp unable to support Raw, use standard read/write."}, {"ERRtimeout", 88, "Operation timed out."},
{"ERRcontmpx",252,"Continue in MPX mode."}, {"ERRnoresource", 89, "No resources currently available for request."},
{"ERRreserved",253,"reserved."}, {"ERRtoomanyuids", 90, "Too many UIDs active on this session."},
{"ERRreserved",254,"reserved."}, {"ERRbaduid", 91, "The UID is not known as a valid ID on this session."},
{"ERRnosupport",0xFFFF,"Function not supported."}, {"ERRusempx", 250, "Temp unable to support Raw, use MPX mode."},
{NULL,-1,NULL}}; {"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 */ /* Hard Error Messages */
static err_code_struct const hard_msgs[] = { static err_code_struct const hard_msgs[] = {
{"ERRnowrite",19,"Attempt to write on write-protected diskette."}, {"ERRnowrite", 19, "Attempt to write on write-protected diskette."},
{"ERRbadunit",20,"Unknown unit."}, {"ERRbadunit", 20, "Unknown unit."},
{"ERRnotready",21,"Drive not ready."}, {"ERRnotready", 21, "Drive not ready."},
{"ERRbadcmd",22,"Unknown command."}, {"ERRbadcmd", 22, "Unknown command."},
{"ERRdata",23,"Data error (CRC)."}, {"ERRdata", 23, "Data error (CRC)."},
{"ERRbadreq",24,"Bad request structure length."}, {"ERRbadreq", 24, "Bad request structure length."},
{"ERRseek",25 ,"Seek error."}, {"ERRseek", 25, "Seek error."},
{"ERRbadmedia",26,"Unknown media type."}, {"ERRbadmedia", 26, "Unknown media type."},
{"ERRbadsector",27,"Sector not found."}, {"ERRbadsector", 27, "Sector not found."},
{"ERRnopaper",28,"Printer out of paper."}, {"ERRnopaper", 28, "Printer out of paper."},
{"ERRwrite",29,"Write fault."}, {"ERRwrite", 29, "Write fault."},
{"ERRread",30,"Read fault."}, {"ERRread", 30, "Read fault."},
{"ERRgeneral",31,"General failure."}, {"ERRgeneral", 31, "General failure."},
{"ERRbadshare",32,"An open conflicts with an existing open."}, {"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."}, {"ERRlock", 33,
{"ERRwrongdisk",34,"The wrong disk was found in a drive."}, "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."},
{"ERRFCBUnavail",35,"No FCBs are available to process request."}, {"ERRwrongdisk", 34, "The wrong disk was found in a drive."},
{"ERRsharebufexc",36,"A sharing buffer has been exceeded."}, {"ERRFCBUnavail", 35, "No FCBs are available to process request."},
{NULL,-1,NULL}}; {"ERRsharebufexc", 36, "A sharing buffer has been exceeded."},
{NULL, -1, NULL}
};
struct struct
{ {
int code; int code;
const char *class; const char *class;
err_code_struct const *err_msgs; err_code_struct const *err_msgs;
} const err_classes [] = { } const err_classes[] = {
{0,"SUCCESS",NULL}, {0, "SUCCESS", NULL},
{0x01,"ERRDOS",dos_msgs}, {0x01, "ERRDOS", dos_msgs},
{0x02,"ERRSRV",server_msgs}, {0x02, "ERRSRV", server_msgs},
{0x03,"ERRHRD",hard_msgs}, {0x03, "ERRHRD", hard_msgs},
{0x04,"ERRXOS",NULL}, {0x04, "ERRXOS", NULL},
{0xE1,"ERRRMX1",NULL}, {0xE1, "ERRRMX1", NULL},
{0xE2,"ERRRMX2",NULL}, {0xE2, "ERRRMX2", NULL},
{0xE3,"ERRRMX3",NULL}, {0xE3, "ERRRMX3", NULL},
{0xFF,"ERRCMD",NULL}, {0xFF, "ERRCMD", NULL},
{-1,NULL,NULL}}; {-1, NULL, NULL}
};
/**************************************************************************** /****************************************************************************
return a SMB error string from a SMB buffer return a SMB error string from a SMB buffer
****************************************************************************/ ****************************************************************************/
char *smb_errstr(char *inbuf) char *
smb_errstr (char *inbuf)
{ {
static pstring ret; static pstring ret;
int class = CVAL(inbuf,smb_rcls); int class = CVAL (inbuf, smb_rcls);
int num = SVAL(inbuf,smb_err); int num = SVAL (inbuf, smb_err);
int i,j; int i, j;
for (i=0;err_classes[i].class;i++) for (i = 0; err_classes[i].class; i++)
if (err_classes[i].code == class) if (err_classes[i].code == class)
{ {
if (err_classes[i].err_msgs) if (err_classes[i].err_msgs)
{ {
const err_code_struct *err = err_classes[i].err_msgs; const err_code_struct *err = err_classes[i].err_msgs;
for (j=0;err[j].name;j++) for (j = 0; err[j].name; j++)
if (num == err[j].code) if (num == err[j].code)
{ {
if (DEBUGLEVEL > 0) if (DEBUGLEVEL > 0)
slprintf(ret, sizeof(ret) - 1, "%s - %s (%s)",err_classes[i].class, slprintf (ret, sizeof (ret) - 1, "%s - %s (%s)", err_classes[i].class,
err[j].name,err[j].message); err[j].name, err[j].message);
else else
slprintf(ret, sizeof(ret) - 1, "%s - %s",err_classes[i].class,err[j].name); slprintf (ret, sizeof (ret) - 1, "%s - %s", err_classes[i].class,
return ret; err[j].name);
} return ret;
} }
}
slprintf(ret, sizeof(ret) - 1, "%s - %d",err_classes[i].class,num); slprintf (ret, sizeof (ret) - 1, "%s - %d", err_classes[i].class, num);
return ret; return ret;
} }
slprintf(ret, sizeof(ret) - 1, "Error: Unknown error (%d,%d)",class,num); slprintf (ret, sizeof (ret) - 1, "Error: Unknown error (%d,%d)", class, num);
return(ret); return (ret);
} }

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -8,22 +8,22 @@
* This module Copyright (C) 1997-1998 by the University of Minnesota * 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 The Midnight Commander is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as 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, published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version. or (at your option) any later version.
The Midnight Commander is distributed in the hope that it will be useful, The Midnight Commander is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. 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; extern int DEBUGLEVEL;
static char *bufr = NULL; static char *bufr = NULL;
static int bSize = 0; static int bSize = 0;
/* -------------------------------------------------------------------------- ** /* -------------------------------------------------------------------------- **
* Functions... * Functions...
*/ */
static int EatWhitespace( FILE *InFile ) static int
EatWhitespace (FILE * InFile)
/* ------------------------------------------------------------------------ ** /* ------------------------------------------------------------------------ **
* Scan past whitespace (see ctype(3C)) and return the first non-whitespace * Scan past whitespace (see ctype(3C)) and return the first non-whitespace
* character, or newline, or EOF. * 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 ) ) for (c = getc (InFile); isspace (c) && ('\n' != c); c = getc (InFile))
; ;
return( c ); return (c);
} /* EatWhitespace */ } /* EatWhitespace */
static int EatComment( FILE *InFile ) static int
EatComment (FILE * InFile)
/* ------------------------------------------------------------------------ ** /* ------------------------------------------------------------------------ **
* Scan to the end of a comment. * 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 ) ) for (c = getc (InFile); ('\n' != c) && (EOF != c) && (c > 0); c = getc (InFile))
; ;
return( c ); return (c);
} /* EatComment */ } /* 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 * Scan backards within a string to discover if the last non-whitespace
* character is a line-continuation character ('\\'). * character is a line-continuation character ('\\').
@ -177,16 +180,17 @@ static int Continuation( char *line, int pos )
* *
* ------------------------------------------------------------------------ ** * ------------------------------------------------------------------------ **
*/ */
{ {
pos--; pos--;
while( (pos >= 0) && isspace(line[pos]) ) while ((pos >= 0) && isspace (line[pos]))
pos--; pos--;
return( ((pos >= 0) && ('\\' == line[pos])) ? pos : -1 ); return (((pos >= 0) && ('\\' == line[pos])) ? pos : -1);
} /* Continuation */ } /* 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(). * 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 c;
int i; int i;
int end; int end;
const char *func = "params.c:Section() -"; const char *func = "params.c:Section() -";
i = 0; /* <i> is the offset of the next free byte in bufr[] and */ 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 */ end = 0; /* <end> is the current "end of string" offset. In most */
/* cases these will be the same, but if the last */ /* cases these will be the same, but if the last */
/* character written to bufr[] is a space, then <end> */ /* character written to bufr[] is a space, then <end> */
/* will be one less than <i>. */ /* will be one less than <i>. */
c = EatWhitespace( InFile ); /* We've already got the '['. Scan */ c = EatWhitespace (InFile); /* We've already got the '['. Scan */
/* past initial white space. */ /* 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. */ /* Check that the buffer is big enough for the next character. */
if( i > (bSize - 2) ) if (i > (bSize - 2))
{
bSize += BUFR_INC;
bufr = Realloc( bufr, bSize );
if( NULL == bufr )
{ {
DEBUG(0, ("%s Memory re-allocation failure.", func) ); bSize += BUFR_INC;
return( False ); bufr = Realloc (bufr, bSize);
if (NULL == bufr)
{
DEBUG (0, ("%s Memory re-allocation failure.", func));
return (False);
}
} }
}
/* Handle a single character. */ /* Handle a single character. */
switch( c ) switch (c)
{ {
case ']': /* Found the closing bracket. */ case ']': /* Found the closing bracket. */
bufr[end] = '\0'; bufr[end] = '\0';
if( 0 == end ) /* Don't allow an empty name. */ if (0 == end) /* Don't allow an empty name. */
{ {
DEBUG(0, ("%s Empty section name in configuration file.\n", func )); DEBUG (0, ("%s Empty section name in configuration file.\n", func));
return( False ); return (False);
} }
if( !sfunc( bufr ) ) /* Got a valid name. Deal with it. */ if (!sfunc (bufr)) /* Got a valid name. Deal with it. */
return( False ); return (False);
(void)EatComment( InFile ); /* Finish off the line. */ (void) EatComment (InFile); /* Finish off the line. */
return( True ); return (True);
case '\n': /* Got newline before closing ']'. */ case '\n': /* Got newline before closing ']'. */
i = Continuation( bufr, i ); /* Check for line continuation. */ i = Continuation (bufr, i); /* Check for line continuation. */
if( i < 0 ) if (i < 0)
{ {
bufr[end] = '\0'; bufr[end] = '\0';
DEBUG(0, ("%s Badly formed line in configuration file: %s\n", DEBUG (0, ("%s Badly formed line in configuration file: %s\n", func, bufr));
func, bufr )); return (False);
return( False ); }
} end = ((i > 0) && (' ' == bufr[i - 1])) ? (i - 1) : (i);
end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); c = getc (InFile); /* Continue with next line. */
c = getc( InFile ); /* Continue with next line. */ break;
break;
default: /* All else are a valid name chars. */ default: /* All else are a valid name chars. */
if( isspace( c ) ) /* One space per whitespace region. */ if (isspace (c)) /* One space per whitespace region. */
{ {
bufr[end] = ' '; bufr[end] = ' ';
i = end + 1; i = end + 1;
c = EatWhitespace( InFile ); c = EatWhitespace (InFile);
} }
else /* All others copy verbatim. */ else /* All others copy verbatim. */
{ {
bufr[i++] = c; bufr[i++] = c;
end = i; end = i;
c = getc( InFile ); c = getc (InFile);
} }
} }
} }
/* We arrive here if we've met the EOF before the closing bracket. */ /* 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 )); DEBUG (0, ("%s Unexpected EOF in the configuration file: %s\n", func, bufr));
return( False ); return (False);
} /* Section */ } /* 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(). * 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 i = 0; /* Position within bufr. */
int end = 0; /* bufr[end] is current end-of-string. */ int end = 0; /* bufr[end] is current end-of-string. */
int vstart = 0; /* Starting position of the parameter value. */ int vstart = 0; /* Starting position of the parameter value. */
const char *func = "params.c:Parameter() -"; const char *func = "params.c:Parameter() -";
/* Read the parameter name. */ /* Read the parameter name. */
while( 0 == vstart ) /* Loop until we've found the start of the value. */ while (0 == vstart) /* Loop until we've found the start of the value. */
{ {
if( i > (bSize - 2) ) /* Ensure there's space for next char. */ if (i > (bSize - 2)) /* Ensure there's space for next char. */
{
bSize += BUFR_INC;
bufr = Realloc( bufr, bSize );
if( NULL == bufr )
{ {
DEBUG(0, ("%s Memory re-allocation failure.", func) ); bSize += BUFR_INC;
return( False ); bufr = Realloc (bufr, bSize);
if (NULL == bufr)
{
DEBUG (0, ("%s Memory re-allocation failure.", func));
return (False);
}
} }
}
switch( c ) switch (c)
{ {
case '=': /* Equal sign marks end of param name. */ case '=': /* Equal sign marks end of param name. */
if( 0 == end ) /* Don't allow an empty name. */ if (0 == end) /* Don't allow an empty name. */
{ {
DEBUG(0, ("%s Invalid parameter name in config. file.\n", func )); DEBUG (0, ("%s Invalid parameter name in config. file.\n", func));
return( False ); return (False);
} }
bufr[end++] = '\0'; /* Mark end of string & advance. */ bufr[end++] = '\0'; /* Mark end of string & advance. */
i = end; /* New string starts here. */ i = end; /* New string starts here. */
vstart = end; /* New string is parameter value. */ vstart = end; /* New string is parameter value. */
bufr[i] = '\0'; /* New string is nul, for now. */ bufr[i] = '\0'; /* New string is nul, for now. */
break; break;
case '\n': /* Find continuation char, else error. */ case '\n': /* Find continuation char, else error. */
i = Continuation( bufr, i ); i = Continuation (bufr, i);
if( i < 0 ) if (i < 0)
{ {
bufr[end] = '\0'; bufr[end] = '\0';
DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", DEBUG (1, ("%s Ignoring badly formed line in configuration file: %s\n",
func, bufr )); func, bufr));
return( True ); return (True);
} }
end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); end = ((i > 0) && (' ' == bufr[i - 1])) ? (i - 1) : (i);
c = getc( InFile ); /* Read past eoln. */ c = getc (InFile); /* Read past eoln. */
break; break;
case '\0': /* Shouldn't have EOF within param name. */ case '\0': /* Shouldn't have EOF within param name. */
case EOF: case EOF:
bufr[i] = '\0'; bufr[i] = '\0';
DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, bufr )); DEBUG (1, ("%s Unexpected end-of-file at: %s\n", func, bufr));
return( True ); return (True);
default: default:
if( isspace( c ) ) /* One ' ' per whitespace region. */ if (isspace (c)) /* One ' ' per whitespace region. */
{ {
bufr[end] = ' '; bufr[end] = ' ';
i = end + 1; i = end + 1;
c = EatWhitespace( InFile ); c = EatWhitespace (InFile);
} }
else /* All others verbatim. */ else /* All others verbatim. */
{ {
bufr[i++] = c; bufr[i++] = c;
end = i; end = i;
c = getc( InFile ); c = getc (InFile);
} }
} }
} }
/* Now parse the value. */ /* Now parse the value. */
c = EatWhitespace( InFile ); /* Again, trim leading whitespace. */ c = EatWhitespace (InFile); /* Again, trim leading whitespace. */
while( (EOF !=c) && (c > 0) ) while ((EOF != c) && (c > 0))
{ {
if( i > (bSize - 2) ) /* Make sure there's enough room. */ if (i > (bSize - 2)) /* Make sure there's enough room. */
{
bSize += BUFR_INC;
bufr = Realloc( bufr, bSize );
if( NULL == bufr )
{ {
DEBUG(0, ("%s Memory re-allocation failure.", func) ); bSize += BUFR_INC;
return( False ); bufr = Realloc (bufr, bSize);
if (NULL == bufr)
{
DEBUG (0, ("%s Memory re-allocation failure.", func));
return (False);
}
} }
}
switch( c ) switch (c)
{ {
case '\r': /* Explicitly remove '\r' because the older */ case '\r': /* Explicitly remove '\r' because the older */
c = getc( InFile ); /* version called fgets_slash() which also */ c = getc (InFile); /* version called fgets_slash() which also */
break; /* removes them. */ break; /* removes them. */
case '\n': /* Marks end of value unless there's a '\'. */ case '\n': /* Marks end of value unless there's a '\'. */
i = Continuation( bufr, i ); i = Continuation (bufr, i);
if( i < 0 ) if (i < 0)
c = 0; c = 0;
else else
{ {
for( end = i; (end >= 0) && isspace(bufr[end]); end-- ) for (end = i; (end >= 0) && isspace (bufr[end]); end--)
; ;
c = getc( InFile ); c = getc (InFile);
} }
break; break;
default: /* All others verbatim. Note that spaces do */ default: /* All others verbatim. Note that spaces do */
bufr[i++] = c; /* not advance <end>. This allows trimming */ bufr[i++] = c; /* not advance <end>. This allows trimming */
if( !isspace( c ) ) /* of whitespace at the end of the line. */ if (!isspace (c)) /* of whitespace at the end of the line. */
end = i; end = i;
c = getc( InFile ); c = getc (InFile);
break; break;
} }
} }
bufr[end] = '\0'; /* End of value. */ bufr[end] = '\0'; /* End of value. */
return( pfunc( bufr, &bufr[vstart] ) ); /* Pass name & value to pfunc(). */ return (pfunc (bufr, &bufr[vstart])); /* Pass name & value to pfunc(). */
} /* Parameter */ } /* Parameter */
static BOOL Parse( FILE *InFile, static BOOL
BOOL (*sfunc)(const char *), Parse (FILE * InFile, BOOL (*sfunc) (const char *), BOOL (*pfunc) (const char *, const char *))
BOOL (*pfunc)(const char *, const char *) )
/* ------------------------------------------------------------------------ ** /* ------------------------------------------------------------------------ **
* Scan & parse the input. * Scan & parse the input.
* *
@ -444,44 +447,45 @@ static BOOL Parse( FILE *InFile,
* *
* ------------------------------------------------------------------------ ** * ------------------------------------------------------------------------ **
*/ */
{ {
int c; int c;
c = EatWhitespace( InFile ); c = EatWhitespace (InFile);
while( (EOF != c) && (c > 0) ) while ((EOF != c) && (c > 0))
{ {
switch( c ) switch (c)
{ {
case '\n': /* Blank line. */ case '\n': /* Blank line. */
c = EatWhitespace( InFile ); c = EatWhitespace (InFile);
break; break;
case ';': /* Comment line. */ case ';': /* Comment line. */
case '#': case '#':
c = EatComment( InFile ); c = EatComment (InFile);
break; break;
case '[': /* Section Header. */ case '[': /* Section Header. */
if( !Section( InFile, sfunc ) ) if (!Section (InFile, sfunc))
return( False ); return (False);
c = EatWhitespace( InFile ); c = EatWhitespace (InFile);
break; break;
case '\\': /* Bogus backslash. */ case '\\': /* Bogus backslash. */
c = EatWhitespace( InFile ); c = EatWhitespace (InFile);
break; break;
default: /* Parameter line. */ default: /* Parameter line. */
if( !Parameter( InFile, pfunc, c ) ) if (!Parameter (InFile, pfunc, c))
return( False ); return (False);
c = EatWhitespace( InFile ); c = EatWhitespace (InFile);
break; break;
} }
} }
return( True ); return (True);
} /* Parse */ } /* Parse */
static FILE *OpenConfFile( const char *FileName ) static FILE *
OpenConfFile (const char *FileName)
/* ------------------------------------------------------------------------ ** /* ------------------------------------------------------------------------ **
* Open a configuration file. * Open a configuration file.
* *
@ -492,32 +496,32 @@ static FILE *OpenConfFile( const char *FileName )
* *
* ------------------------------------------------------------------------ ** * ------------------------------------------------------------------------ **
*/ */
{ {
FILE *OpenedFile; FILE *OpenedFile;
const char *func = "params.c:OpenConfFile() -"; const char *func = "params.c:OpenConfFile() -";
extern BOOL in_client; extern BOOL in_client;
int lvl = in_client?1:0; 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) ); DEBUG (lvl, ("%s No configuration filename specified.\n", func));
return( NULL ); return (NULL);
} }
OpenedFile = sys_fopen( FileName, "r" ); OpenedFile = sys_fopen (FileName, "r");
if( NULL == OpenedFile ) if (NULL == OpenedFile)
{ {
DEBUG( lvl, DEBUG (lvl,
("%s Unable to open configuration file \"%s\":\n\t%s\n", ("%s Unable to open configuration file \"%s\":\n\t%s\n",
func, FileName, unix_error_string (errno)) ); func, FileName, unix_error_string (errno)));
} }
return( OpenedFile ); return (OpenedFile);
} /* OpenConfFile */ } /* OpenConfFile */
BOOL pm_process( const char *FileName, BOOL
BOOL (*sfunc)(const char *), pm_process (const char *FileName,
BOOL (*pfunc)(const char *, const char *) ) BOOL (*sfunc) (const char *), BOOL (*pfunc) (const char *, const char *))
/* ------------------------------------------------------------------------ ** /* ------------------------------------------------------------------------ **
* Process the named parameter file. * Process the named parameter file.
* *
@ -531,46 +535,46 @@ BOOL pm_process( const char *FileName,
* *
* ------------------------------------------------------------------------ ** * ------------------------------------------------------------------------ **
*/ */
{ {
int result; int result;
FILE *InFile; FILE *InFile;
const char *func = "params.c:pm_process() -"; const char *func = "params.c:pm_process() -";
InFile = OpenConfFile( FileName ); /* Open the config file. */ InFile = OpenConfFile (FileName); /* Open the config file. */
if( NULL == InFile ) if (NULL == InFile)
return( False ); 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 */ if (NULL != bufr) /* If we already have a buffer */
result = Parse( InFile, sfunc, pfunc ); /* (recursive call), then just */ result = Parse (InFile, sfunc, pfunc); /* (recursive call), then just */
/* use it. */ /* use it. */
else /* If we don't have a buffer */ else /* If we don't have a buffer */
{ /* allocate one, then parse, */ { /* allocate one, then parse, */
bSize = BUFR_INC; /* then free. */ bSize = BUFR_INC; /* then free. */
bufr = (char *)malloc( bSize ); bufr = (char *) malloc (bSize);
if( NULL == bufr ) if (NULL == bufr)
{ {
DEBUG(0,("%s memory allocation failure.\n", func)); DEBUG (0, ("%s memory allocation failure.\n", func));
fclose(InFile); fclose (InFile);
return( False ); return (False);
} }
result = Parse( InFile, sfunc, pfunc ); result = Parse (InFile, sfunc, pfunc);
free( bufr ); free (bufr);
bufr = NULL; bufr = NULL;
bSize = 0; 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)); DEBUG (0, ("%s Failed. Error returned from params.c:parse().\n", func));
return( False ); return (False);
} }
return( True ); /* Generic success. */ return (True); /* Generic success. */
} /* pm_process */ } /* pm_process */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

Просмотреть файл

@ -11,7 +11,7 @@
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
void init_tarfs(void); void init_tarfs (void);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/

Просмотреть файл

@ -11,7 +11,7 @@
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
void init_undelfs(void); void init_undelfs (void);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/

Просмотреть файл

@ -344,7 +344,7 @@ mcview_load_next_prev (mcview_t * view, int direction)
view->dir_count = dir_count; view->dir_count = dir_count;
view->dir_idx = dir_idx; view->dir_idx = dir_idx;
view->dpy_bbar_dirty = FALSE; /* FIXME */ view->dpy_bbar_dirty = FALSE; /* FIXME */
view->dirty++; view->dirty++;
} }

Просмотреть файл

@ -59,7 +59,7 @@
/*** file scope macro definitions ****************************************************************/ /*** 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 ****************************************************************/ /*** 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, /* Shows {file} or the output of {command} in the internal viewer,
* starting in line {start_line}. * starting in line {start_line}.
*/ */
extern gboolean mcview_viewer (const char *command, const vfs_path_t * file_vpath, extern gboolean mcview_viewer (const char *command, const vfs_path_t * file_vpath, int start_line);
int start_line);
extern gboolean mcview_load (struct mcview_struct *, const char *, const char *, int); extern gboolean mcview_load (struct mcview_struct *, const char *, const char *, int);