mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-11 05:49:18 +03:00
Merge branch '2846_cleanup' into 4.8.1-stable
* 2846_cleanup: Clarify cvs dependency. Indent files. (mcview_moveto_eol): comparison of unsigned expression < 0 fixup. Try fix of compile warnings about assigned but unused variables Code cleanup: removed unused variables amd removed unnedeed code. Fix of f13 key handling. Ticket #2538: mcviewer: unused result of str_term_width1(). src/filemanager/mountlist.c: apply mc code indentation policy. Sync with gnulib 06b335ade65c8fe60fee8b9e18b670bb54ed924a: Minor optimization and type accuracy of some editor functions. Fix of mult-byte characters and tabulation printing. Menubar: ignore GPM_UP event. Accuracy use of arguments of dlg_move and widget_move macros. Ticket #2846: code cleanup before 4.8.1.4 release.
This commit is contained in:
commit
232f8c458a
@ -19,7 +19,7 @@ Build requirements for GNU Midnight Commander
|
||||
- pcre (if glib < 2.14)
|
||||
- slang or ncurses
|
||||
- gettext
|
||||
- cvs
|
||||
- cvs (for gettext < 0.18 or if gettext >= 0.18 is built with --with-cvs)
|
||||
|
||||
|
||||
Installation instructions for GNU Midnight Commander
|
||||
|
@ -99,7 +99,6 @@ static void
|
||||
load_codepages_list_from_file (GPtrArray ** list, const char *fname)
|
||||
{
|
||||
FILE *f;
|
||||
guint i;
|
||||
char buf[BUF_MEDIUM];
|
||||
char *default_codepage = NULL;
|
||||
|
||||
@ -107,7 +106,7 @@ load_codepages_list_from_file (GPtrArray ** list, const char *fname)
|
||||
if (f == NULL)
|
||||
return;
|
||||
|
||||
for (i = 0; fgets (buf, sizeof buf, f) != NULL;)
|
||||
while (fgets (buf, sizeof buf, f) != NULL)
|
||||
{
|
||||
/* split string into id and cpname */
|
||||
char *p = buf;
|
||||
@ -141,6 +140,8 @@ load_codepages_list_from_file (GPtrArray ** list, const char *fname)
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
/* whether id is already present in list */
|
||||
/* if yes, overwrite description */
|
||||
for (i = 0; i < (*list)->len; i++)
|
||||
|
@ -25,7 +25,8 @@ GTree *mc_event_get_event_group_by_name (const gchar * event_group_name, gboolea
|
||||
GPtrArray *mc_event_get_event_by_name (GTree * event_group, const gchar * event_name,
|
||||
gboolean create_new, GError ** mcerror);
|
||||
mc_event_callback_t *mc_event_is_callback_in_array (GPtrArray * callbacks,
|
||||
mc_event_callback_func_t event_callback, gpointer event_init_data);
|
||||
mc_event_callback_func_t event_callback,
|
||||
gpointer event_init_data);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_EVENT_INTERNAL_H */
|
||||
|
@ -319,7 +319,6 @@ str_8bit_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
goto finally;
|
||||
memset (actual, ' ', width - length - ident);
|
||||
actual += width - length - ident;
|
||||
remain -= width - length - ident;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -393,7 +392,6 @@ str_8bit_term_trim (const char *text, int width)
|
||||
{
|
||||
memset (actual, '.', width);
|
||||
actual += width;
|
||||
remain -= width;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -260,7 +260,6 @@ str_ascii_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
goto finally;
|
||||
memset (actual, ' ', width - length - ident);
|
||||
actual += width - length - ident;
|
||||
remain -= width - length - ident;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -340,7 +339,6 @@ str_ascii_term_trim (const char *text, int width)
|
||||
{
|
||||
memset (actual, '.', width);
|
||||
actual += width;
|
||||
remain -= width;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -208,9 +208,8 @@ mc_util_write_backup_content (const char *from_file_name, const char *to_file_na
|
||||
if (fwrite ((const void *) contents, 1, length, backup_fd) != length)
|
||||
ret1 = FALSE;
|
||||
{
|
||||
int ret2;
|
||||
ret2 = fflush (backup_fd);
|
||||
ret2 = fclose (backup_fd);
|
||||
(void) fflush (backup_fd);
|
||||
(void) fclose (backup_fd);
|
||||
}
|
||||
g_free (contents);
|
||||
return ret1;
|
||||
|
@ -1523,10 +1523,8 @@ vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char ter
|
||||
{
|
||||
if (logfile)
|
||||
{
|
||||
size_t ret1;
|
||||
int ret2;
|
||||
ret1 = fwrite (&c, 1, 1, logfile);
|
||||
ret2 = fflush (logfile);
|
||||
(void) fwrite (&c, 1, 1, logfile);
|
||||
(void) fflush (logfile);
|
||||
}
|
||||
if (c == '\n')
|
||||
return 1;
|
||||
|
@ -104,13 +104,11 @@ mc_def_getlocalcopy (const vfs_path_t * filename_vpath)
|
||||
fdin = -1;
|
||||
if (i == -1)
|
||||
goto fail;
|
||||
|
||||
i = close (fdout);
|
||||
fdout = -1;
|
||||
if (i == -1)
|
||||
{
|
||||
fdout = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (mc_stat (filename_vpath, &mystat) != -1)
|
||||
mc_chmod (tmp_vpath, mystat.st_mode);
|
||||
|
@ -24,7 +24,7 @@
|
||||
#define B_HELP 3
|
||||
#define B_USER 100
|
||||
|
||||
#define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
|
||||
#define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + (_y), ((Dlg_head *)(h))->x + (_x))
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
|
@ -108,14 +108,12 @@ draw_history_button (WInput * in)
|
||||
c = in->history->next ? (in->history->prev ? '|' : 'v') : '^';
|
||||
widget_move (&in->widget, 0, in->field_width - HISTORY_BUTTON_WIDTH);
|
||||
tty_setcolor (disabled ? DISABLED_COLOR : in->color[WINPUTC_HISTORY]);
|
||||
|
||||
#ifdef LARGE_HISTORY_BUTTON
|
||||
{
|
||||
Dlg_head *h;
|
||||
h = in->widget.owner;
|
||||
tty_print_string ("[ ]");
|
||||
widget_move (&in->widget, 0, in->field_width - HISTORY_BUTTON_WIDTH + 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
tty_print_char (c);
|
||||
}
|
||||
|
||||
@ -1115,8 +1113,6 @@ input_handle_char (WInput * in, int key)
|
||||
cb_ret_t v;
|
||||
unsigned long command;
|
||||
|
||||
v = MSG_NOT_HANDLED;
|
||||
|
||||
if (quote != 0)
|
||||
{
|
||||
input_free_completions (in);
|
||||
|
@ -123,9 +123,13 @@ listbox_draw (WListbox * l, gboolean focused)
|
||||
const Dlg_head *h = l->widget.owner;
|
||||
const gboolean disabled = (((Widget *) l)->options & W_DISABLED) != 0;
|
||||
const int normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL];
|
||||
int selc =
|
||||
disabled ? DISABLED_COLOR : focused ? h->
|
||||
color[DLG_COLOR_HOT_FOCUS] : h->color[DLG_COLOR_FOCUS];
|
||||
/* *INDENT-OFF* */
|
||||
int selc = disabled
|
||||
? DISABLED_COLOR
|
||||
: focused
|
||||
? h->color[DLG_COLOR_HOT_FOCUS]
|
||||
: h->color[DLG_COLOR_FOCUS];
|
||||
/* *INDENT-ON* */
|
||||
|
||||
GList *le;
|
||||
int pos;
|
||||
|
@ -2,9 +2,12 @@
|
||||
Pulldown menu code
|
||||
|
||||
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2007, 2009, 2011
|
||||
2007, 2009, 2011, 2012
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Written by:
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2012
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
The Midnight Commander is free software: you can redistribute it
|
||||
@ -602,6 +605,9 @@ menubar_event (Gpm_Event * event, void *data)
|
||||
if (!menubar->is_active && ((event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)) != 0))
|
||||
return MOU_NORMAL;
|
||||
|
||||
if (event->y == 1 && (event->type & GPM_UP) != 0)
|
||||
return MOU_NORMAL;
|
||||
|
||||
if (!menubar->is_dropped)
|
||||
{
|
||||
menubar->previous_widget = dlg_get_current_widget_id (menubar->widget.owner);
|
||||
@ -613,9 +619,6 @@ menubar_event (Gpm_Event * event, void *data)
|
||||
/* Mouse operations on the menubar */
|
||||
if (event->y == 1 || !was_active)
|
||||
{
|
||||
if ((event->type & GPM_UP) != 0)
|
||||
return MOU_NORMAL;
|
||||
|
||||
/* wheel events on menubar */
|
||||
if (event->buttons & GPM_B_UP)
|
||||
menubar_left (menubar);
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + _y, ((Widget *)(w))->x + _x)
|
||||
#define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + (_y), ((Widget *)(w))->x + (_x))
|
||||
/* Sets/clear the specified flag in the options field */
|
||||
#define widget_option(w,f,i) \
|
||||
w.options = ((i) ? ((w).options | (f)) : ((w).options & (~(f))))
|
||||
|
@ -88,7 +88,9 @@ static gboolean parse_mc_v_argument (const gchar * option_name, const gchar * va
|
||||
|
||||
static GOptionContext *context;
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
static gboolean mc_args__nouse_subshell = FALSE;
|
||||
#endif /* HAVE_SUBSHELL_SUPPORT */
|
||||
static gboolean mc_args__show_datadirs = FALSE;
|
||||
static gboolean mc_args__show_datadirs_extended = FALSE;
|
||||
static gboolean mc_args__show_configure_opts = FALSE;
|
||||
@ -609,9 +611,11 @@ mc_setup_by_args (int argc, char **argv, GError ** error)
|
||||
smbfs_set_debug (mc_args__debug_level);
|
||||
#endif /* ENABLE_VFS_SMB */
|
||||
|
||||
#if defined ENABLE_VFS_FTP || defined ENABLE_VFS_FTP
|
||||
if (mc_args__netfs_logfile != NULL)
|
||||
{
|
||||
vfs_path_t *vpath;
|
||||
|
||||
#ifdef ENABLE_VFS_FTP
|
||||
vpath = vfs_path_from_str ("ftp://");
|
||||
mc_setctl (vpath, VFS_SETCTL_LOGFILE, (void *) mc_args__netfs_logfile);
|
||||
@ -623,6 +627,7 @@ mc_setup_by_args (int argc, char **argv, GError ** error)
|
||||
vfs_path_free (vpath);
|
||||
#endif /* ENABLE_VFS_SMB */
|
||||
}
|
||||
#endif /* ENABLE_VFS_FTP || ENABLE_VFS_SMB */
|
||||
|
||||
base = x_basename (argv[0]);
|
||||
tmp = (argc > 0) ? argv[1] : NULL;
|
||||
|
@ -200,7 +200,7 @@ background_attention (int fd, void *closure)
|
||||
/* void *routine; */
|
||||
int argc, i, result, status;
|
||||
char *data[MAXCALLARGS];
|
||||
ssize_t bytes, ret;
|
||||
ssize_t bytes;
|
||||
struct TaskList *p;
|
||||
int to_child_fd = -1;
|
||||
enum ReturnType type;
|
||||
@ -330,9 +330,9 @@ background_attention (int fd, void *closure)
|
||||
}
|
||||
|
||||
/* Send the result code and the value for shared variables */
|
||||
ret = write (to_child_fd, &result, sizeof (int));
|
||||
(void) write (to_child_fd, &result, sizeof (int));
|
||||
if (have_ctx && to_child_fd != -1)
|
||||
ret = write (to_child_fd, ctx, sizeof (FileOpContext));
|
||||
(void) write (to_child_fd, ctx, sizeof (FileOpContext));
|
||||
}
|
||||
else if (type == Return_String)
|
||||
{
|
||||
@ -365,15 +365,15 @@ background_attention (int fd, void *closure)
|
||||
if (resstr)
|
||||
{
|
||||
len = strlen (resstr);
|
||||
ret = write (to_child_fd, &len, sizeof (len));
|
||||
(void) write (to_child_fd, &len, sizeof (len));
|
||||
if (len != 0)
|
||||
ret = write (to_child_fd, resstr, len);
|
||||
(void) write (to_child_fd, resstr, len);
|
||||
g_free (resstr);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = 0;
|
||||
ret = write (to_child_fd, &len, sizeof (len));
|
||||
(void) write (to_child_fd, &len, sizeof (len));
|
||||
}
|
||||
}
|
||||
for (i = 0; i < argc; i++)
|
||||
@ -398,17 +398,16 @@ static void
|
||||
parent_call_header (void *routine, int argc, enum ReturnType type, FileOpContext * ctx)
|
||||
{
|
||||
int have_ctx;
|
||||
ssize_t ret;
|
||||
|
||||
have_ctx = (ctx != NULL);
|
||||
|
||||
ret = write (parent_fd, &routine, sizeof (routine));
|
||||
ret = write (parent_fd, &argc, sizeof (int));
|
||||
ret = write (parent_fd, &type, sizeof (type));
|
||||
ret = write (parent_fd, &have_ctx, sizeof (have_ctx));
|
||||
(void) write (parent_fd, &routine, sizeof (routine));
|
||||
(void) write (parent_fd, &argc, sizeof (int));
|
||||
(void) write (parent_fd, &type, sizeof (type));
|
||||
(void) write (parent_fd, &have_ctx, sizeof (have_ctx));
|
||||
|
||||
if (have_ctx)
|
||||
ret = write (parent_fd, ctx, sizeof (FileOpContext));
|
||||
(void) write (parent_fd, ctx, sizeof (FileOpContext));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -417,7 +416,6 @@ static int
|
||||
parent_va_call (void *routine, gpointer data, int argc, va_list ap)
|
||||
{
|
||||
int i;
|
||||
ssize_t ret;
|
||||
struct FileOpContext *ctx = (struct FileOpContext *) data;
|
||||
|
||||
parent_call_header (routine, argc, Return_Integer, ctx);
|
||||
@ -428,13 +426,13 @@ parent_va_call (void *routine, gpointer data, int argc, va_list ap)
|
||||
|
||||
len = va_arg (ap, int);
|
||||
value = va_arg (ap, void *);
|
||||
ret = write (parent_fd, &len, sizeof (int));
|
||||
ret = write (parent_fd, value, len);
|
||||
(void) write (parent_fd, &len, sizeof (int));
|
||||
(void) write (parent_fd, value, len);
|
||||
}
|
||||
|
||||
ret = read (from_parent_fd, &i, sizeof (int));
|
||||
(void) read (from_parent_fd, &i, sizeof (int));
|
||||
if (ctx)
|
||||
ret = read (from_parent_fd, ctx, sizeof (FileOpContext));
|
||||
(void) read (from_parent_fd, ctx, sizeof (FileOpContext));
|
||||
|
||||
return i;
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ clipboard_file_to_ext_clip (const gchar * event_group_name, const gchar * event_
|
||||
gpointer init_data, gpointer data)
|
||||
{
|
||||
char *tmp, *cmd;
|
||||
int res = 0;
|
||||
const char *d = getenv ("DISPLAY");
|
||||
|
||||
(void) event_group_name;
|
||||
@ -81,7 +80,7 @@ clipboard_file_to_ext_clip (const gchar * event_group_name, const gchar * event_
|
||||
cmd = g_strconcat (clipboard_store_path, " ", tmp, " 2>/dev/null", (char *) NULL);
|
||||
|
||||
if (cmd != NULL)
|
||||
res = my_system (EXECUTE_AS_SHELL, shell, cmd);
|
||||
(void) my_system (EXECUTE_AS_SHELL, shell, cmd);
|
||||
|
||||
g_free (cmd);
|
||||
g_free (tmp);
|
||||
@ -127,7 +126,6 @@ clipboard_text_to_file (const gchar * event_group_name, const gchar * event_name
|
||||
{
|
||||
int file;
|
||||
vfs_path_t *fname_vpath = NULL;
|
||||
ssize_t ret;
|
||||
size_t str_len;
|
||||
const char *text = (const char *) data;
|
||||
|
||||
@ -147,7 +145,7 @@ clipboard_text_to_file (const gchar * event_group_name, const gchar * event_name
|
||||
return TRUE;
|
||||
|
||||
str_len = strlen (text);
|
||||
ret = mc_write (file, (char *) text, str_len);
|
||||
(void) mc_write (file, (char *) text, str_len);
|
||||
mc_close (file);
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -90,7 +90,6 @@ show_console_contents_linux (int starty, unsigned char begin_line, unsigned char
|
||||
unsigned char message = 0;
|
||||
unsigned short bytes = 0;
|
||||
int i;
|
||||
ssize_t ret;
|
||||
|
||||
/* Is tty console? */
|
||||
if (mc_global.tty.console_flag == '\0')
|
||||
@ -105,29 +104,29 @@ show_console_contents_linux (int starty, unsigned char begin_line, unsigned char
|
||||
|
||||
/* Send command to the console handler */
|
||||
message = CONSOLE_CONTENTS;
|
||||
ret = write (pipefd1[1], &message, 1);
|
||||
(void) write (pipefd1[1], &message, 1);
|
||||
/* Check for outdated cons.saver */
|
||||
ret = read (pipefd2[0], &message, 1);
|
||||
(void) read (pipefd2[0], &message, 1);
|
||||
if (message != CONSOLE_CONTENTS)
|
||||
return;
|
||||
|
||||
/* Send the range of lines that we want */
|
||||
ret = write (pipefd1[1], &begin_line, 1);
|
||||
ret = write (pipefd1[1], &end_line, 1);
|
||||
(void) write (pipefd1[1], &begin_line, 1);
|
||||
(void) write (pipefd1[1], &end_line, 1);
|
||||
/* Read the corresponding number of bytes */
|
||||
ret = read (pipefd2[0], &bytes, 2);
|
||||
(void) read (pipefd2[0], &bytes, 2);
|
||||
|
||||
/* Read the bytes and output them */
|
||||
for (i = 0; i < bytes; i++)
|
||||
{
|
||||
if ((i % COLS) == 0)
|
||||
tty_gotoyx (starty + (i / COLS), 0);
|
||||
ret = read (pipefd2[0], &message, 1);
|
||||
(void) read (pipefd2[0], &message, 1);
|
||||
tty_print_char (message);
|
||||
}
|
||||
|
||||
/* Read the value of the mc_global.tty.console_flag */
|
||||
ret = read (pipefd2[0], &message, 1);
|
||||
(void) read (pipefd2[0], &message, 1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -240,10 +239,9 @@ handle_console_linux (console_action_t action)
|
||||
if (action == CONSOLE_DONE || mc_global.tty.console_flag == '\0')
|
||||
{
|
||||
/* We are done -> Let's clean up */
|
||||
pid_t ret;
|
||||
close (pipefd1[1]);
|
||||
close (pipefd2[0]);
|
||||
ret = waitpid (cons_saver_pid, &status, 0);
|
||||
(void) waitpid (cons_saver_pid, &status, 0);
|
||||
mc_global.tty.console_flag = '\0';
|
||||
}
|
||||
break;
|
||||
@ -382,9 +380,10 @@ console_save (void)
|
||||
|
||||
for (i = 0; i < screen_shot.xsize * screen_shot.ysize; i++)
|
||||
{
|
||||
screen_shot.buf[i] =
|
||||
(screen_shot.buf[i] & 0xff00) | (unsigned char) revmap.
|
||||
scrmap[screen_shot.buf[i] & 0xff];
|
||||
/* *INDENT-OFF* */
|
||||
screen_shot.buf[i] = (screen_shot.buf[i] & 0xff00)
|
||||
| (unsigned char) revmap.scrmap[screen_shot.buf[i] & 0xff];
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,8 +143,7 @@ send_contents (char *buffer, unsigned int columns, unsigned int rows)
|
||||
static void __attribute__ ((noreturn)) die (void)
|
||||
{
|
||||
unsigned char zero = 0;
|
||||
ssize_t ret;
|
||||
ret = write (1, &zero, 1);
|
||||
(void) write (1, &zero, 1);
|
||||
exit (3);
|
||||
}
|
||||
|
||||
|
@ -632,31 +632,22 @@ dview_get_utf (char *str, int *char_width, gboolean * result)
|
||||
if (str == NULL)
|
||||
{
|
||||
*result = FALSE;
|
||||
width = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
|
||||
if (res < 0)
|
||||
{
|
||||
ch = *str;
|
||||
width = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = res;
|
||||
/* Calculate UTF-8 char width */
|
||||
next_ch = g_utf8_next_char (str);
|
||||
if (next_ch)
|
||||
{
|
||||
if (next_ch != NULL)
|
||||
width = next_ch - str;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = 0;
|
||||
width = 0;
|
||||
}
|
||||
}
|
||||
*char_width = width;
|
||||
return ch;
|
||||
@ -2197,7 +2188,6 @@ static void
|
||||
do_merge_hunk (WDiff * dview)
|
||||
{
|
||||
int from1, to1, from2, to2;
|
||||
int res;
|
||||
int hunk;
|
||||
|
||||
hunk = get_current_hunk (dview, &from1, &to1, &from2, &to2);
|
||||
@ -2244,7 +2234,7 @@ do_merge_hunk (WDiff * dview)
|
||||
}
|
||||
fflush (merge_file);
|
||||
fclose (merge_file);
|
||||
res = rewrite_backup_content (merge_file_name_vpath, dview->file[0]);
|
||||
rewrite_backup_content (merge_file_name_vpath, dview->file[0]);
|
||||
mc_unlink (merge_file_name_vpath);
|
||||
vfs_path_free (merge_file_name_vpath);
|
||||
}
|
||||
@ -2377,7 +2367,7 @@ dview_init (WDiff * dview, const char *args, const char *file1, const char *file
|
||||
static void
|
||||
dview_reread (WDiff * dview)
|
||||
{
|
||||
int ndiff = dview->ndiff;
|
||||
int ndiff;
|
||||
|
||||
destroy_hdiff (dview);
|
||||
if (dview->a[0] != NULL)
|
||||
@ -2984,7 +2974,7 @@ dview_ok_to_exit (WDiff * dview)
|
||||
break;
|
||||
case 1: /* No */
|
||||
if (mc_util_restore_from_backup_if_possible (dview->file[0], "~~~"))
|
||||
res = mc_util_unlink_backup_if_possible (dview->file[0], "~~~");
|
||||
mc_util_unlink_backup_if_possible (dview->file[0], "~~~");
|
||||
/* fall through */
|
||||
default:
|
||||
res = TRUE;
|
||||
|
@ -7,8 +7,9 @@ noinst_LTLIBRARIES =
|
||||
endif
|
||||
|
||||
libedit_la_SOURCES = \
|
||||
bookmark.c edit.c editcmd.c editwidget.c editdraw.c editkeys.c \
|
||||
editmenu.c editoptions.c edit-impl.h edit.h edit-widget.h \
|
||||
bookmark.c edit.c editcmd.c editwidget.c editwidget.h \
|
||||
editdraw.c editkeys.c \
|
||||
editmenu.c editoptions.c edit-impl.h edit.h \
|
||||
syntax.c wordproc.c \
|
||||
choosesyntax.c etags.c etags.h editcmd_dialogs.c editcmd_dialogs.h
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include "lib/global.h"
|
||||
#include "lib/util.h" /* MAX_SAVED_BOOKMARKS */
|
||||
|
||||
#include "edit-widget.h"
|
||||
#include "editwidget.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include "lib/widget.h" /* Listbox */
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h"
|
||||
#include "editwidget.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
|
@ -204,7 +204,7 @@ long edit_eol (WEdit * edit, long current);
|
||||
void edit_update_curs_row (WEdit * edit);
|
||||
void edit_update_curs_col (WEdit * edit);
|
||||
void edit_find_bracket (WEdit * edit);
|
||||
int edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line);
|
||||
gboolean edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line);
|
||||
void edit_set_codeset (WEdit * edit);
|
||||
|
||||
void edit_block_copy_cmd (WEdit * edit);
|
||||
@ -226,12 +226,11 @@ int edit_save_confirm_cmd (WEdit * edit);
|
||||
int edit_save_as_cmd (WEdit * edit);
|
||||
WEdit *edit_init (WEdit * edit, int y, int x, int lines, int cols,
|
||||
const vfs_path_t * filename_vpath, long line);
|
||||
int edit_clean (WEdit * edit);
|
||||
gboolean edit_clean (WEdit * edit);
|
||||
gboolean edit_ok_to_exit (WEdit * edit);
|
||||
int edit_renew (WEdit * edit);
|
||||
int edit_new_cmd (WEdit * edit);
|
||||
int edit_reload (WEdit * edit, const vfs_path_t * filename_vpath);
|
||||
int edit_load_cmd (WEdit * edit, edit_current_file_t what);
|
||||
gboolean edit_renew (WEdit * edit);
|
||||
gboolean edit_new_cmd (WEdit * edit);
|
||||
gboolean edit_load_cmd (WEdit * edit, edit_current_file_t what);
|
||||
void edit_mark_cmd (WEdit * edit, int unmark);
|
||||
void edit_mark_current_word_cmd (WEdit * edit);
|
||||
void edit_mark_current_line_cmd (WEdit * edit);
|
||||
@ -250,8 +249,8 @@ void edit_insert_over (WEdit * edit);
|
||||
int edit_insert_column_of_text_from_file (WEdit * edit, int file,
|
||||
long *start_pos, long *end_pos, int *col1, int *col2);
|
||||
long edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath);
|
||||
int edit_load_back_cmd (WEdit * edit);
|
||||
int edit_load_forward_cmd (WEdit * edit);
|
||||
gboolean edit_load_back_cmd (WEdit * edit);
|
||||
gboolean edit_load_forward_cmd (WEdit * edit);
|
||||
void edit_block_process_cmd (WEdit * edit, int macro_number);
|
||||
void edit_refresh_cmd (WEdit * edit);
|
||||
void edit_date_cmd (WEdit * edit);
|
||||
@ -314,4 +313,17 @@ void edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_inserti
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
/**
|
||||
* Load a new file into the editor. If it fails, preserve the old file.
|
||||
* To do it, allocate a new widget, initialize it and, if the new file
|
||||
* was loaded, copy the data to the old widget.
|
||||
*
|
||||
* @returns TRUE on success, FALSE on failure.
|
||||
*/
|
||||
static inline gboolean
|
||||
edit_reload (WEdit * edit, const vfs_path_t * filename_vpath)
|
||||
{
|
||||
return edit_reload_line (edit, filename_vpath, 0);
|
||||
}
|
||||
|
||||
#endif /* MC__EDIT_IMPL_H */
|
||||
|
@ -2,12 +2,13 @@
|
||||
Editor low level data handling and cursor fundamentals.
|
||||
|
||||
Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
|
||||
2007, 2008, 2009, 2010, 2011
|
||||
2007, 2008, 2009, 2010, 2011, 2012
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Written by:
|
||||
Paul Sheer 1996, 1997
|
||||
Ilia Maslakov <il.smind@gmail.com> 2009, 2010, 2011
|
||||
Andrew Borodin <aborodin@vmail.ru> 2012.
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -69,7 +70,7 @@
|
||||
#include "src/keybind-defaults.h"
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h"
|
||||
#include "editwidget.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
@ -242,17 +243,19 @@ edit_init_buffers (WEdit * edit)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Load file OR text into buffers. Set cursor to the beginning of file.
|
||||
* @returns 1 on error.
|
||||
*
|
||||
* @returns FALSE on error.
|
||||
*/
|
||||
|
||||
static int
|
||||
static gboolean
|
||||
edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath)
|
||||
{
|
||||
long buf, buf2;
|
||||
int file = -1;
|
||||
int ret = 1;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
edit->curs2 = edit->last_byte;
|
||||
buf2 = edit->curs2 >> S_EDIT_BUF_SIZE;
|
||||
@ -267,7 +270,7 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath)
|
||||
g_free (filename);
|
||||
edit_error_dialog (_("Error"), errmsg);
|
||||
g_free (errmsg);
|
||||
return 1;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!edit->buffers2[buf2])
|
||||
@ -288,11 +291,11 @@ edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath)
|
||||
if (mc_read (file, (char *) edit->buffers2[buf], EDIT_BUF_SIZE) < 0)
|
||||
break;
|
||||
}
|
||||
ret = 0;
|
||||
ret = TRUE;
|
||||
}
|
||||
while (0);
|
||||
while (FALSE);
|
||||
|
||||
if (ret != 0)
|
||||
if (!ret)
|
||||
{
|
||||
gchar *errmsg, *filename;
|
||||
|
||||
@ -370,9 +373,16 @@ edit_insert_stream (WEdit * edit, FILE * f)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Open file and create it if necessary. Return 0 for success, 1 for error. */
|
||||
/**
|
||||
* Open file and create it if necessary.
|
||||
*
|
||||
* @param edit editor object
|
||||
* @param filename_vpath file name
|
||||
* @param st buffer for store stat info
|
||||
* @returns TRUE for success, FALSE for error.
|
||||
*/
|
||||
|
||||
static int
|
||||
static gboolean
|
||||
check_file_access (WEdit * edit, const vfs_path_t * filename_vpath, struct stat *st)
|
||||
{
|
||||
int file;
|
||||
@ -396,12 +406,10 @@ check_file_access (WEdit * edit, const vfs_path_t * filename_vpath, struct stat
|
||||
g_free (filename);
|
||||
goto cleanup;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* New file, delete it if it's not modified or saved */
|
||||
edit->delete_file = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check what we have opened */
|
||||
if (mc_fstat (file, st) < 0)
|
||||
@ -448,55 +456,55 @@ check_file_access (WEdit * edit, const vfs_path_t * filename_vpath, struct stat
|
||||
{
|
||||
edit_error_dialog (_("Error"), errmsg);
|
||||
g_free (errmsg);
|
||||
return 1;
|
||||
return FALSE;
|
||||
}
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Open the file and load it into the buffers, either directly or using
|
||||
* a filter. Return 0 on success, 1 on error.
|
||||
* a filter. Return TRUE on success, FALSE on error.
|
||||
*
|
||||
* Fast loading (edit_load_file_fast) is used when the file size is
|
||||
* known. In this case the data is read into the buffers by blocks.
|
||||
* If the file size is not known, the data is loaded byte by byte in
|
||||
* edit_insert_file.
|
||||
*
|
||||
* @param edit editor object
|
||||
* @return TRUE if file was successfully opened and loaded to buffers, FALSE otherwise
|
||||
*/
|
||||
|
||||
static int
|
||||
static gboolean
|
||||
edit_load_file (WEdit * edit)
|
||||
{
|
||||
int fast_load = 1;
|
||||
gboolean fast_load = TRUE;
|
||||
|
||||
/* Cannot do fast load if a filter is used */
|
||||
if (edit_find_filter (edit->filename_vpath) >= 0)
|
||||
fast_load = 0;
|
||||
|
||||
fast_load = FALSE;
|
||||
|
||||
/*
|
||||
* FIXME: line end translation should disable fast loading as well
|
||||
* Consider doing fseek() to the end and ftell() for the real size.
|
||||
*/
|
||||
|
||||
if (edit->filename_vpath != NULL)
|
||||
{
|
||||
|
||||
/*
|
||||
* VFS may report file size incorrectly, and slow load is not a big
|
||||
* deal considering overhead in VFS.
|
||||
*/
|
||||
if (!vfs_file_is_local (edit->filename_vpath))
|
||||
fast_load = 0;
|
||||
fast_load = FALSE;
|
||||
|
||||
/* If we are dealing with a real file, check that it exists */
|
||||
if (check_file_access (edit, edit->filename_vpath, &edit->stat1))
|
||||
return 1;
|
||||
if (!check_file_access (edit, edit->filename_vpath, &edit->stat1))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* nothing to load */
|
||||
fast_load = 0;
|
||||
fast_load = FALSE;
|
||||
}
|
||||
|
||||
edit_init_buffers (edit);
|
||||
@ -518,13 +526,13 @@ edit_load_file (WEdit * edit)
|
||||
if (edit_insert_file (edit, edit->filename_vpath) < 0)
|
||||
{
|
||||
edit_clean (edit);
|
||||
return 1;
|
||||
return FALSE;
|
||||
}
|
||||
edit->undo_stack_disable = 0;
|
||||
}
|
||||
}
|
||||
edit->lb = LB_ASIS;
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -2283,7 +2291,7 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
|
||||
edit->converter = str_cnv_from_term;
|
||||
edit_set_codeset (edit);
|
||||
|
||||
if (edit_load_file (edit))
|
||||
if (!edit_load_file (edit))
|
||||
{
|
||||
/* edit_load_file already gives an error message */
|
||||
if (to_free)
|
||||
@ -2316,15 +2324,15 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Clear the edit struct, freeing everything in it. Return 1 on success */
|
||||
|
||||
int
|
||||
/** Clear the edit struct, freeing everything in it. Return TRUE on success */
|
||||
gboolean
|
||||
edit_clean (WEdit * edit)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
if (!edit)
|
||||
return 0;
|
||||
if (edit == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* a stale lock, remove it */
|
||||
if (edit->locked)
|
||||
@ -2360,13 +2368,13 @@ edit_clean (WEdit * edit)
|
||||
|
||||
edit_purge_widget (edit);
|
||||
|
||||
return 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** returns 1 on success */
|
||||
|
||||
int
|
||||
/** returns TRUE on success */
|
||||
gboolean
|
||||
edit_renew (WEdit * edit)
|
||||
{
|
||||
int y = edit->widget.y;
|
||||
@ -2379,44 +2387,15 @@ edit_renew (WEdit * edit)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Load a new file into the editor. If it fails, preserve the old file.
|
||||
* To do it, allocate a new widget, initialize it and, if the new file
|
||||
* was loaded, copy the data to the old widget.
|
||||
* Return 1 on success, 0 on failure.
|
||||
*/
|
||||
|
||||
int
|
||||
edit_reload (WEdit * edit, const vfs_path_t * filename_vpath)
|
||||
{
|
||||
WEdit *e;
|
||||
int y = edit->widget.y;
|
||||
int x = edit->widget.x;
|
||||
int lines = edit->widget.lines;
|
||||
int columns = edit->widget.cols;
|
||||
|
||||
e = g_malloc0 (sizeof (WEdit));
|
||||
e->widget = edit->widget;
|
||||
if (edit_init (e, y, x, lines, columns, filename_vpath, 0) == NULL)
|
||||
{
|
||||
g_free (e);
|
||||
return 0;
|
||||
}
|
||||
edit_clean (edit);
|
||||
memcpy (edit, e, sizeof (WEdit));
|
||||
g_free (e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Load a new file into the editor and set line. If it fails, preserve the old file.
|
||||
* To do it, allocate a new widget, initialize it and, if the new file
|
||||
* was loaded, copy the data to the old widget.
|
||||
* Return 1 on success, 0 on failure.
|
||||
*
|
||||
* @returns TRUE on success, FALSE on failure.
|
||||
*/
|
||||
|
||||
int
|
||||
gboolean
|
||||
edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line)
|
||||
{
|
||||
WEdit *e;
|
||||
@ -2427,15 +2406,18 @@ edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line)
|
||||
|
||||
e = g_malloc0 (sizeof (WEdit));
|
||||
e->widget = edit->widget;
|
||||
|
||||
if (edit_init (e, y, x, lines, columns, filename_vpath, line) == NULL)
|
||||
{
|
||||
g_free (e);
|
||||
return 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
edit_clean (edit);
|
||||
memcpy (edit, e, sizeof (WEdit));
|
||||
g_free (e);
|
||||
return 1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -61,7 +61,7 @@ extern int show_right_margin;
|
||||
void edit_stack_init (void);
|
||||
void edit_stack_free (void);
|
||||
|
||||
int edit_file (const vfs_path_t * _file_vpath, int line);
|
||||
gboolean edit_file (const vfs_path_t * _file_vpath, int line);
|
||||
|
||||
char *edit_get_file_name (const WEdit * edit);
|
||||
int edit_get_curs_col (const WEdit * edit);
|
||||
|
@ -2,11 +2,12 @@
|
||||
Editor high level editing commands
|
||||
|
||||
Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
|
||||
2007, 2011
|
||||
2007, 2011, 2012
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Written by:
|
||||
Paul Sheer, 1996, 1997
|
||||
Andrew Borodin <aborodin@vmail.ru> 2012
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -75,7 +76,7 @@
|
||||
#include "src/filemanager/layout.h" /* mc_refresh() */
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h"
|
||||
#include "editwidget.h"
|
||||
#include "editcmd_dialogs.h"
|
||||
#include "etags.h"
|
||||
|
||||
@ -489,18 +490,24 @@ edit_save_cmd (WEdit * edit)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** returns 1 on error */
|
||||
/**
|
||||
* Load file content
|
||||
*
|
||||
* @param edit widget object
|
||||
* @param exp_vpath vfs file path
|
||||
* @return TRUE if file content was successfully loaded, FALSE otherwise
|
||||
*/
|
||||
|
||||
static int
|
||||
static gboolean
|
||||
edit_load_file_from_filename (WEdit * edit, const vfs_path_t * exp_vpath)
|
||||
{
|
||||
int prev_locked = edit->locked;
|
||||
vfs_path_t *prev_filename;
|
||||
int ret = 0;
|
||||
gboolean ret = TRUE;
|
||||
|
||||
prev_filename = vfs_path_clone (edit->filename_vpath);
|
||||
if (!edit_reload (edit, exp_vpath))
|
||||
ret = 1;
|
||||
ret = FALSE;
|
||||
else if (prev_locked)
|
||||
unlock_file (prev_filename);
|
||||
|
||||
@ -648,7 +655,7 @@ edit_block_delete (WEdit * edit)
|
||||
{
|
||||
long count;
|
||||
long start_mark, end_mark;
|
||||
int curs_pos, line_width;
|
||||
int curs_pos;
|
||||
long curs_line, c1, c2;
|
||||
|
||||
if (eval_marks (edit, &start_mark, &end_mark))
|
||||
@ -676,9 +683,6 @@ edit_block_delete (WEdit * edit)
|
||||
|
||||
curs_line = edit->curs_line;
|
||||
|
||||
/* calculate line width and cursor position before cut */
|
||||
line_width = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0,
|
||||
edit_eol (edit, edit->curs1));
|
||||
curs_pos = edit->curs_col + edit->over_col;
|
||||
|
||||
/* move cursor to start of selection */
|
||||
@ -689,12 +693,14 @@ edit_block_delete (WEdit * edit)
|
||||
{
|
||||
if (edit->column_highlight)
|
||||
{
|
||||
int line_width;
|
||||
|
||||
if (edit->mark2 < 0)
|
||||
edit_mark_cmd (edit, 0);
|
||||
edit_delete_column_of_text (edit);
|
||||
/* move cursor to the saved position */
|
||||
edit_move_to_line (edit, curs_line);
|
||||
/* calculate line width after cut */
|
||||
/* calculate line width and cursor position before cut */
|
||||
line_width = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0,
|
||||
edit_eol (edit, edit->curs1));
|
||||
if (option_cursor_beyond_eol && curs_pos > line_width)
|
||||
@ -2069,23 +2075,21 @@ edit_save_confirm_cmd (WEdit * edit)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** returns 1 on success */
|
||||
|
||||
int
|
||||
/* returns TRUE on success */
|
||||
gboolean
|
||||
edit_new_cmd (WEdit * edit)
|
||||
{
|
||||
if (edit->modified)
|
||||
{
|
||||
if (edit_query_dialog2
|
||||
(_("Warning"),
|
||||
_
|
||||
("Current text was modified without a file save.\nContinue discards these changes"),
|
||||
_("C&ontinue"), _("&Cancel")))
|
||||
if (edit->modified
|
||||
&& edit_query_dialog2 (_("Warning"),
|
||||
_("Current text was modified without a file save.\n"
|
||||
"Continue discards these changes"),
|
||||
_("C&ontinue"), _("&Cancel")) == 1)
|
||||
{
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
return 0;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
|
||||
return edit_renew (edit); /* if this gives an error, something has really screwed up */
|
||||
@ -2093,17 +2097,19 @@ edit_new_cmd (WEdit * edit)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
gboolean
|
||||
edit_load_cmd (WEdit * edit, edit_current_file_t what)
|
||||
{
|
||||
gboolean ret = TRUE;
|
||||
|
||||
if (edit->modified
|
||||
&& (edit_query_dialog2
|
||||
(_("Warning"),
|
||||
&& edit_query_dialog2 (_("Warning"),
|
||||
_("Current text was modified without a file save.\n"
|
||||
"Continue discards these changes"), _("C&ontinue"), _("&Cancel")) == 1))
|
||||
"Continue discards these changes"), _("C&ontinue"),
|
||||
_("&Cancel")) == 1)
|
||||
{
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
switch (what)
|
||||
@ -2117,19 +2123,17 @@ edit_load_cmd (WEdit * edit, edit_current_file_t what)
|
||||
MC_HISTORY_EDIT_LOAD, filename);
|
||||
g_free (filename);
|
||||
|
||||
if (exp != NULL)
|
||||
{
|
||||
if (*exp != '\0')
|
||||
if (exp != NULL && *exp != '\0')
|
||||
{
|
||||
vfs_path_t *exp_vpath;
|
||||
|
||||
exp_vpath = vfs_path_from_str (exp);
|
||||
edit_load_file_from_filename (edit, exp_vpath);
|
||||
ret = edit_load_file_from_filename (edit, exp_vpath);
|
||||
vfs_path_free (exp_vpath);
|
||||
}
|
||||
|
||||
g_free (exp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EDIT_FILE_SYNTAX:
|
||||
@ -2145,7 +2149,7 @@ edit_load_cmd (WEdit * edit, edit_current_file_t what)
|
||||
}
|
||||
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -3021,8 +3025,8 @@ edit_save_block_cmd (WEdit * edit)
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** returns TRUE on success */
|
||||
|
||||
/** returns TRUE on success */
|
||||
gboolean
|
||||
edit_insert_file_cmd (WEdit * edit)
|
||||
{
|
||||
@ -3358,78 +3362,57 @@ edit_begin_end_repeat_cmd (WEdit * edit)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
gboolean
|
||||
edit_load_forward_cmd (WEdit * edit)
|
||||
{
|
||||
if (edit->modified)
|
||||
{
|
||||
if (edit_query_dialog2
|
||||
(_("Warning"),
|
||||
_("Current text was modified without a file save\n"
|
||||
"Continue discards these changes"), _("C&ontinue"), _("&Cancel")))
|
||||
if (edit->modified
|
||||
&& edit_query_dialog2 (_("Warning"),
|
||||
_("Current text was modified without a file save.\n"
|
||||
"Continue discards these changes"), _("C&ontinue"),
|
||||
_("&Cancel")) == 1)
|
||||
{
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO)
|
||||
{
|
||||
|
||||
if (edit_stack_iterator + 1 >= MAX_HISTORY_MOVETO)
|
||||
return FALSE;
|
||||
|
||||
if (edit_history_moveto[edit_stack_iterator + 1].line < 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
edit_stack_iterator++;
|
||||
if (edit_history_moveto[edit_stack_iterator].filename_vpath)
|
||||
{
|
||||
edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename_vpath,
|
||||
if (edit_history_moveto[edit_stack_iterator].filename_vpath != NULL)
|
||||
return edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename_vpath,
|
||||
edit_history_moveto[edit_stack_iterator].line);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
gboolean
|
||||
edit_load_back_cmd (WEdit * edit)
|
||||
{
|
||||
if (edit->modified)
|
||||
{
|
||||
if (edit_query_dialog2
|
||||
(_("Warning"),
|
||||
_("Current text was modified without a file save\n"
|
||||
"Continue discards these changes"), _("C&ontinue"), _("&Cancel")))
|
||||
if (edit->modified
|
||||
&& edit_query_dialog2 (_("Warning"),
|
||||
_("Current text was modified without a file save.\n"
|
||||
"Continue discards these changes"), _("C&ontinue"),
|
||||
_("&Cancel")) == 1)
|
||||
{
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (edit_stack_iterator > 0)
|
||||
{
|
||||
|
||||
if (edit_stack_iterator < 0)
|
||||
return FALSE;
|
||||
|
||||
edit_stack_iterator--;
|
||||
if (edit_history_moveto[edit_stack_iterator].filename_vpath)
|
||||
{
|
||||
edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename_vpath,
|
||||
if (edit_history_moveto[edit_stack_iterator].filename_vpath != NULL)
|
||||
return edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename_vpath,
|
||||
edit_history_moveto[edit_stack_iterator].line);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include "src/main.h"
|
||||
#include "src/history.h"
|
||||
|
||||
#include "src/editor/edit-widget.h"
|
||||
#include "src/editor/editwidget.h"
|
||||
#include "src/editor/etags.h"
|
||||
#include "src/editor/editcmd_dialogs.h"
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
||||
#include "src/main.h" /* macro_index */
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h"
|
||||
#include "editwidget.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
@ -246,17 +246,15 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
|
||||
}
|
||||
|
||||
edit_move (x1, y);
|
||||
p = line;
|
||||
i = 1;
|
||||
while (p->ch)
|
||||
for (p = line; p->ch != 0; p++)
|
||||
{
|
||||
int style;
|
||||
unsigned int textchar;
|
||||
int color;
|
||||
|
||||
if (cols_to_skip)
|
||||
if (cols_to_skip != 0)
|
||||
{
|
||||
p++;
|
||||
cols_to_skip--;
|
||||
continue;
|
||||
}
|
||||
@ -279,41 +277,23 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
|
||||
tty_setcolor (EDITOR_MARKED_COLOR);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
if (color != EDITOR_NORMAL_COLOR)
|
||||
{
|
||||
textchar = ' ';
|
||||
tty_lowlevel_setcolor (color);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
tty_setcolor (EDITOR_WHITESPACE_COLOR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (style & MOD_BOLD)
|
||||
{
|
||||
else if (style & MOD_BOLD)
|
||||
tty_setcolor (EDITOR_BOLD_COLOR);
|
||||
}
|
||||
else if (style & MOD_MARKED)
|
||||
{
|
||||
tty_setcolor (EDITOR_MARKED_COLOR);
|
||||
}
|
||||
else
|
||||
{
|
||||
tty_lowlevel_setcolor (color);
|
||||
}
|
||||
}
|
||||
|
||||
if (show_right_margin)
|
||||
{
|
||||
if (i > option_word_wrap_line_length + edit->start_col)
|
||||
tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
|
||||
i++;
|
||||
}
|
||||
|
||||
tty_print_anychar (textchar);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,6 +335,7 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co
|
||||
edit_get_syntax_color (edit, b - 1, &color);
|
||||
q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
|
||||
start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;
|
||||
|
||||
if (option_line_state)
|
||||
{
|
||||
cur_line = edit->start_line + row;
|
||||
@ -390,6 +371,9 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co
|
||||
while (col <= end_col - edit->start_col)
|
||||
{
|
||||
int cw = 1;
|
||||
int tab_over = 0;
|
||||
gboolean wide_width_char = FALSE;
|
||||
gboolean control_char = FALSE;
|
||||
|
||||
p->ch = 0;
|
||||
p->style = 0;
|
||||
@ -439,6 +423,9 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co
|
||||
break;
|
||||
case '\t':
|
||||
i = TAB_SIZE - ((int) col % TAB_SIZE);
|
||||
tab_over = (end_col - edit->start_col) - (col + i - 1);
|
||||
if (tab_over < 0)
|
||||
i += tab_over;
|
||||
col += i;
|
||||
if (tty_use_colors () &&
|
||||
((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws))
|
||||
@ -524,6 +511,14 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co
|
||||
{
|
||||
c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_unichar_iswide (c))
|
||||
{
|
||||
wide_width_char = TRUE;
|
||||
col++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (edit->utf8)
|
||||
c = convert_from_utf_to_current_c (c, edit->converter);
|
||||
@ -541,6 +536,7 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co
|
||||
p->style = abn_style;
|
||||
p++;
|
||||
col += 2;
|
||||
control_char = TRUE;
|
||||
break;
|
||||
}
|
||||
if (c == 127)
|
||||
@ -552,6 +548,7 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co
|
||||
p->style = abn_style;
|
||||
p++;
|
||||
col += 2;
|
||||
control_char = TRUE;
|
||||
break;
|
||||
}
|
||||
if (!edit->utf8)
|
||||
@ -592,6 +589,20 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co
|
||||
{
|
||||
q += cw - 1;
|
||||
}
|
||||
|
||||
if (col > (end_col - edit->start_col + 1))
|
||||
{
|
||||
if (wide_width_char)
|
||||
{
|
||||
p--;
|
||||
break;
|
||||
}
|
||||
if (control_char)
|
||||
{
|
||||
p -= 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -600,7 +611,7 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co
|
||||
start_col_real = start_col = 0;
|
||||
}
|
||||
|
||||
p->ch = '\0';
|
||||
p->ch = 0;
|
||||
|
||||
print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@
|
||||
#endif
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h" /* WEdit */
|
||||
#include "editwidget.h" /* WEdit */
|
||||
#include "editcmd_dialogs.h"
|
||||
|
||||
#include "src/keybind-defaults.h" /* keybind_lookup_keymap_command() */
|
||||
|
@ -51,7 +51,7 @@
|
||||
#include "src/keybind-defaults.h"
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h"
|
||||
#include "editwidget.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include "lib/global.h"
|
||||
#include "lib/widget.h"
|
||||
|
||||
#include "edit-widget.h"
|
||||
#include "editwidget.h"
|
||||
#include "edit-impl.h"
|
||||
#include "src/setup.h" /* option_tab_spacing */
|
||||
|
||||
|
@ -57,7 +57,7 @@
|
||||
#include "src/main.h" /* home_dir */
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h"
|
||||
#include "editwidget.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
@ -359,7 +359,7 @@ edit_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
gboolean
|
||||
edit_file (const vfs_path_t * _file_vpath, int line)
|
||||
{
|
||||
static gboolean made_directory = FALSE;
|
||||
@ -387,7 +387,7 @@ edit_file (const vfs_path_t * _file_vpath, int line)
|
||||
wedit = edit_init (NULL, 1, 0, LINES - 2, COLS, _file_vpath, line);
|
||||
|
||||
if (wedit == NULL)
|
||||
return 0;
|
||||
return FALSE;
|
||||
|
||||
/* Create a new dialog and add it widgets to it */
|
||||
edit_dlg =
|
||||
@ -414,7 +414,7 @@ edit_file (const vfs_path_t * _file_vpath, int line)
|
||||
if (edit_dlg->state == DLG_CLOSED)
|
||||
destroy_dlg (edit_dlg);
|
||||
|
||||
return 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -60,7 +60,7 @@
|
||||
#include "lib/widget.h" /* message() */
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h"
|
||||
#include "editwidget.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
|
@ -50,7 +50,7 @@
|
||||
#include "src/setup.h" /* option_tab_spacing */
|
||||
|
||||
#include "edit-impl.h"
|
||||
#include "edit-widget.h"
|
||||
#include "editwidget.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
|
@ -258,15 +258,13 @@ do_chown (uid_t u, gid_t g)
|
||||
static void
|
||||
apply_chowns (uid_t u, gid_t g)
|
||||
{
|
||||
char *fname;
|
||||
|
||||
need_update = end_chown = 1;
|
||||
do_chown (u, g);
|
||||
|
||||
do
|
||||
{
|
||||
fname = next_file ();
|
||||
|
||||
next_file ();
|
||||
do_chown (u, g);
|
||||
}
|
||||
while (current_panel->marked);
|
||||
|
@ -273,7 +273,7 @@ select_unselect_cmd (const char *title, const char *history_name, gboolean do_se
|
||||
if (quick_dialog (&quick_dlg) == B_CANCEL)
|
||||
return;
|
||||
|
||||
if (!reg_exp)
|
||||
if (reg_exp == NULL)
|
||||
return;
|
||||
if (!*reg_exp)
|
||||
{
|
||||
|
@ -83,7 +83,8 @@ WInput *cmdline;
|
||||
static char *
|
||||
examine_cd (const char *_path)
|
||||
{
|
||||
typedef enum { copy_sym, subst_var } state_t;
|
||||
typedef enum
|
||||
{ copy_sym, subst_var } state_t;
|
||||
|
||||
state_t state = copy_sym;
|
||||
char *q;
|
||||
|
@ -113,9 +113,7 @@ statfs (char const *filename, struct fs_info *buf)
|
||||
errno = (device == B_ENTRY_NOT_FOUND ? ENOENT
|
||||
: device == B_BAD_VALUE ? EINVAL
|
||||
: device == B_NAME_TOO_LONG ? ENAMETOOLONG
|
||||
: device == B_NO_MEMORY ? ENOMEM
|
||||
: device == B_FILE_ERROR ? EIO
|
||||
: 0);
|
||||
: device == B_NO_MEMORY ? ENOMEM : device == B_FILE_ERROR ? EIO : 0);
|
||||
return -1;
|
||||
}
|
||||
/* If successful, buf->dev will be == device. */
|
||||
|
@ -1693,10 +1693,9 @@ do_find (const char *start_dir, ssize_t start_dir_len, const char *ignore_dirs,
|
||||
/* absolute path */
|
||||
if (start_dir_len < 0)
|
||||
{
|
||||
int ret;
|
||||
vfs_path_free (current_panel->cwd_vpath);
|
||||
current_panel->cwd_vpath = vfs_path_from_str (PATH_SEP_STR);
|
||||
ret = chdir (PATH_SEP_STR);
|
||||
chdir (PATH_SEP_STR);
|
||||
}
|
||||
panelize_save_panel (current_panel);
|
||||
}
|
||||
|
@ -628,10 +628,7 @@ create_panels (void)
|
||||
|
||||
/* 3. Create active panel */
|
||||
if (current_dir == NULL)
|
||||
{
|
||||
current_dir = vfs_path_to_str (original_dir);
|
||||
mc_chdir (original_dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
vfs_path_t *vpath;
|
||||
|
@ -1233,7 +1233,9 @@ safe_read (int fd, void *buf, size_t count)
|
||||
INT_MAX bytes fails with errno == EINVAL. See
|
||||
<http://lists.gnu.org/archive/html/bug-gnu-utils/2002-04/msg00010.html>.
|
||||
When decreasing COUNT, keep it block-aligned. */
|
||||
/* *INDENT-OFF* */
|
||||
enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 };
|
||||
/* *INDENT-ON* */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@ -1517,7 +1519,9 @@ my_statfs (struct my_statfs *myfs_stats, const char *path)
|
||||
myfs_stats->typename = entry->me_type;
|
||||
myfs_stats->mpoint = entry->me_mountdir;
|
||||
myfs_stats->device = entry->me_devname;
|
||||
myfs_stats->avail = ((uintmax_t) (getuid () ? fs_use.fsu_bavail : fs_use.fsu_bfree) * fs_use.fsu_blocksize) >> 10;
|
||||
myfs_stats->avail =
|
||||
((uintmax_t) (getuid ()? fs_use.fsu_bavail : fs_use.fsu_bfree) *
|
||||
fs_use.fsu_blocksize) >> 10;
|
||||
myfs_stats->total = ((uintmax_t) fs_use.fsu_blocks * fs_use.fsu_blocksize) >> 10;
|
||||
myfs_stats->nfree = (uintmax_t) fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = (uintmax_t) fs_use.fsu_files;
|
||||
|
@ -2876,6 +2876,8 @@ subshell_chdir (const vfs_path_t * vpath)
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
if (mc_global.tty.use_subshell && vfs_current_is_local ())
|
||||
do_subshell_chdir (vpath, FALSE, TRUE);
|
||||
#else /* HAVE_SUBSHELL_SUPPORT */
|
||||
(void) vpath;
|
||||
#endif /* HAVE_SUBSHELL_SUPPORT */
|
||||
}
|
||||
|
||||
@ -3956,7 +3958,7 @@ panel_new_with_dir (const char *panel_name, const char *wpath)
|
||||
vfs_path_t *vpath;
|
||||
|
||||
vpath = vfs_path_from_str (curdir);
|
||||
err = mc_chdir (vpath);
|
||||
mc_chdir (vpath);
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
g_free (curdir);
|
||||
|
@ -387,9 +387,8 @@ do_external_panelize (char *command)
|
||||
current_panel->count = next_free;
|
||||
if (list->list[0].fname[0] == PATH_SEP)
|
||||
{
|
||||
int ret;
|
||||
panel_set_cwd (current_panel, PATH_SEP_STR);
|
||||
ret = chdir (PATH_SEP_STR);
|
||||
chdir (PATH_SEP_STR);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -736,7 +736,6 @@ static void
|
||||
tree_rescan (void *data)
|
||||
{
|
||||
WTree *tree = data;
|
||||
int ret;
|
||||
vfs_path_t *old_vpath;
|
||||
|
||||
old_vpath = vfs_path_clone (vfs_get_raw_current_dir ());
|
||||
@ -746,7 +745,7 @@ tree_rescan (void *data)
|
||||
if (tree->selected_ptr != NULL && mc_chdir (tree->selected_ptr->name) == 0)
|
||||
{
|
||||
tree_store_rescan (tree->selected_ptr->name);
|
||||
ret = mc_chdir (old_vpath);
|
||||
mc_chdir (old_vpath);
|
||||
}
|
||||
vfs_path_free (old_vpath);
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ tree_store_add_entry (const vfs_path_t * name)
|
||||
abort ();
|
||||
|
||||
/* Search for the correct place */
|
||||
while (current && (flag = pathcmp (current->name, name)) < 0)
|
||||
while (current != NULL && (flag = pathcmp (current->name, name)) < 0)
|
||||
{
|
||||
old = current;
|
||||
current = current->next;
|
||||
@ -430,6 +430,7 @@ tree_store_add_entry (const vfs_path_t * name)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (old != NULL)
|
||||
old->next = new;
|
||||
new->prev = old;
|
||||
}
|
||||
@ -440,7 +441,7 @@ tree_store_add_entry (const vfs_path_t * name)
|
||||
{
|
||||
/* Insert in to the middle of the list */
|
||||
new->prev = old;
|
||||
if (old)
|
||||
if (old != NULL)
|
||||
{
|
||||
/* Yes, in the middle */
|
||||
new->next = old->next;
|
||||
|
@ -93,7 +93,6 @@ static const global_keymap_ini_t default_main_keymap[] = {
|
||||
{"Delete", "f8"},
|
||||
{"Menu", "f9"},
|
||||
{"Quit", "f10"},
|
||||
{"ViewFile", "f13"},
|
||||
{"MenuLastSelected", "f19"},
|
||||
{"QuitQuiet", "f20"},
|
||||
{"History", "alt-h"},
|
||||
|
@ -373,7 +373,8 @@ learn_save (void)
|
||||
|
||||
esc_str = strutils_escape (learnkeys[i].sequence, -1, ";\\", TRUE);
|
||||
|
||||
mc_config_set_string_raw_value (mc_main_config, section, key_name_conv_tab[i].name, esc_str);
|
||||
mc_config_set_string_raw_value (mc_main_config, section, key_name_conv_tab[i].name,
|
||||
esc_str);
|
||||
|
||||
g_free (esc_str);
|
||||
}
|
||||
|
@ -603,10 +603,8 @@ main (int argc, char *argv[])
|
||||
S_IRUSR | S_IWUSR);
|
||||
if (last_wd_fd != -1)
|
||||
{
|
||||
ssize_t ret1;
|
||||
int ret2;
|
||||
ret1 = write (last_wd_fd, last_wd_string, strlen (last_wd_string));
|
||||
ret2 = close (last_wd_fd);
|
||||
(void) write (last_wd_fd, last_wd_string, strlen (last_wd_string));
|
||||
(void) close (last_wd_fd);
|
||||
}
|
||||
}
|
||||
g_free (last_wd_string);
|
||||
|
@ -252,10 +252,7 @@ init_subshell_child (const char *pty_name)
|
||||
|
||||
/* It simplifies things to change to our home directory here, */
|
||||
/* and the user's startup file may do a `cd' command anyway */
|
||||
{
|
||||
int ret;
|
||||
ret = chdir (mc_config_get_home_dir ()); /* FIXME? What about when we re-run the subshell? */
|
||||
}
|
||||
chdir (mc_config_get_home_dir ()); /* FIXME? What about when we re-run the subshell? */
|
||||
|
||||
/* Set MC_SID to prevent running one mc from another */
|
||||
mc_sid = getsid (0);
|
||||
|
@ -251,9 +251,8 @@ fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, c
|
||||
|
||||
if (logfile)
|
||||
{
|
||||
size_t ret;
|
||||
ret = fwrite (str, strlen (str), 1, logfile);
|
||||
ret = fflush (logfile);
|
||||
(void) fwrite (str, strlen (str), 1, logfile);
|
||||
(void) fflush (logfile);
|
||||
}
|
||||
|
||||
tty_enable_interrupt_key ();
|
||||
@ -330,13 +329,13 @@ fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
res = dup2 (fileset1[0], 0);
|
||||
(void) dup2 (fileset1[0], 0);
|
||||
close (fileset1[0]);
|
||||
close (fileset1[1]);
|
||||
res = dup2 (fileset2[1], 1);
|
||||
(void) dup2 (fileset2[1], 1);
|
||||
close (2);
|
||||
/* stderr to /dev/null */
|
||||
res = open ("/dev/null", O_WRONLY);
|
||||
(void) open ("/dev/null", O_WRONLY);
|
||||
close (fileset2[0]);
|
||||
close (fileset2[1]);
|
||||
execvp (path, const_cast (char **, argv));
|
||||
@ -710,18 +709,24 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
|
||||
char *temp;
|
||||
char *data_start = buffer + 1;
|
||||
char *filename = data_start;
|
||||
char *linkname = data_start;
|
||||
char *filename_bound = filename + strlen (filename);
|
||||
char *linkname_bound = filename_bound;
|
||||
char *filename_bound;
|
||||
|
||||
filename_bound = filename + strlen (filename);
|
||||
|
||||
if (!strcmp (data_start, "\".\"") || !strcmp (data_start, "\"..\""))
|
||||
break; /* We'll do "." and ".." ourselves */
|
||||
|
||||
if (S_ISLNK (ST.st_mode))
|
||||
{
|
||||
char *linkname;
|
||||
char *linkname_bound;
|
||||
/* we expect: "escaped-name" -> "escaped-name"
|
||||
// -> cannot occur in filenames,
|
||||
// because it will be escaped to -\> */
|
||||
|
||||
|
||||
linkname_bound = filename_bound;
|
||||
|
||||
if (*filename == '"')
|
||||
++filename;
|
||||
|
||||
|
@ -477,8 +477,7 @@ ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply,
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t ret;
|
||||
ret = fwrite (cmdstr, cmdlen, 1, MEDATA->logfile);
|
||||
(void) fwrite (cmdstr, cmdlen, 1, MEDATA->logfile);
|
||||
}
|
||||
|
||||
fflush (MEDATA->logfile);
|
||||
@ -2488,7 +2487,8 @@ ftpfs_netrc_lookup (const char *host, char **login, char **pass)
|
||||
}
|
||||
|
||||
/* Ignore unsafe passwords */
|
||||
if (strcmp (*login, "anonymous") && strcmp (*login, "ftp")
|
||||
if (*login != NULL &&
|
||||
strcmp (*login, "anonymous") != 0 && strcmp (*login, "ftp") != 0
|
||||
&& ftpfs_netrc_bad_mode (netrcname))
|
||||
{
|
||||
need_break = 1;
|
||||
|
@ -190,8 +190,11 @@ sfs_vfmake (const vfs_path_t * vpath, vfs_path_t * cache_vpath)
|
||||
COPY_CHAR;
|
||||
continue;
|
||||
}
|
||||
if (ptr != NULL)
|
||||
{
|
||||
COPY_STRING (ptr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*s_iter == '%')
|
||||
|
@ -54,7 +54,8 @@ struct pwd_info
|
||||
uchar smb_nt_owf[24];
|
||||
};
|
||||
|
||||
struct cli_state {
|
||||
struct cli_state
|
||||
{
|
||||
int port;
|
||||
int fd;
|
||||
uint16 cnum;
|
||||
|
@ -19,9 +19,11 @@
|
||||
Types of reply packet.
|
||||
**********************************************************/
|
||||
|
||||
enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
|
||||
enum netbios_reply_type_code
|
||||
{ NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
|
||||
NMB_REL, NMB_WAIT_ACK, NMB_MULTIHOMED_REG,
|
||||
WINS_REG, WINS_QUERY };
|
||||
WINS_REG, WINS_QUERY
|
||||
};
|
||||
|
||||
/* From rfc1002, 4.2.1.2 */
|
||||
/* Question types. */
|
||||
@ -123,10 +125,14 @@ enum netbios_reply_type_code { NMB_QUERY, NMB_STATUS, NMB_REG, NMB_REG_REFRESH,
|
||||
*
|
||||
*/
|
||||
|
||||
enum name_source {LMHOSTS_NAME, REGISTER_NAME, SELF_NAME, DNS_NAME,
|
||||
DNSFAIL_NAME, PERMANENT_NAME, WINS_PROXY_NAME};
|
||||
enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3};
|
||||
enum packet_type {NMB_PACKET, DGRAM_PACKET};
|
||||
enum name_source
|
||||
{ LMHOSTS_NAME, REGISTER_NAME, SELF_NAME, DNS_NAME,
|
||||
DNSFAIL_NAME, PERMANENT_NAME, WINS_PROXY_NAME
|
||||
};
|
||||
enum node_type
|
||||
{ B_NODE = 0, P_NODE = 1, M_NODE = 2, NBDD_NODE = 3 };
|
||||
enum packet_type
|
||||
{ NMB_PACKET, DGRAM_PACKET };
|
||||
|
||||
enum master_state
|
||||
{
|
||||
@ -231,7 +237,8 @@ typedef void (*userdata_free_fn)(struct userdata_struct *);
|
||||
|
||||
/* Structure to define any userdata passed around. */
|
||||
|
||||
struct userdata_struct {
|
||||
struct userdata_struct
|
||||
{
|
||||
userdata_copy_fn copy_fn;
|
||||
userdata_free_fn free_fn;
|
||||
unsigned int userdata_len;
|
||||
@ -247,8 +254,7 @@ typedef void (*response_function)(struct subnet_record *, struct response_record
|
||||
struct packet_struct *);
|
||||
|
||||
/* typedef to define the function called when this response record times out. */
|
||||
typedef void (*timeout_response_function)(struct subnet_record *,
|
||||
struct response_record *);
|
||||
typedef void (*timeout_response_function) (struct subnet_record *, struct response_record *);
|
||||
|
||||
/* typedef to define the function called when the request that caused this
|
||||
response record to be created is successful. */
|
||||
@ -263,49 +269,34 @@ typedef void (*fail_function)(struct subnet_record *, struct response_record *,
|
||||
|
||||
typedef void (*register_name_success_function) (struct subnet_record *,
|
||||
struct userdata_struct *,
|
||||
struct nmb_name *,
|
||||
uint16,
|
||||
int,
|
||||
struct in_addr);
|
||||
struct nmb_name *, uint16, int, struct in_addr);
|
||||
typedef void (*register_name_fail_function) (struct subnet_record *,
|
||||
struct response_record *,
|
||||
struct nmb_name *);
|
||||
struct response_record *, struct nmb_name *);
|
||||
|
||||
typedef void (*release_name_success_function) (struct subnet_record *,
|
||||
struct userdata_struct *,
|
||||
struct nmb_name *,
|
||||
struct in_addr);
|
||||
struct nmb_name *, struct in_addr);
|
||||
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 *,
|
||||
struct userdata_struct *,
|
||||
struct nmb_name *,
|
||||
uint16,
|
||||
int,
|
||||
struct in_addr);
|
||||
struct nmb_name *, uint16, int, struct in_addr);
|
||||
typedef void (*refresh_name_fail_function) (struct subnet_record *,
|
||||
struct response_record *,
|
||||
struct nmb_name *);
|
||||
struct response_record *, struct nmb_name *);
|
||||
|
||||
typedef void (*query_name_success_function) (struct subnet_record *,
|
||||
struct userdata_struct *,
|
||||
struct nmb_name *,
|
||||
struct in_addr,
|
||||
struct res_rec *answers);
|
||||
struct in_addr, struct res_rec * answers);
|
||||
|
||||
typedef void (*query_name_fail_function) (struct subnet_record *,
|
||||
struct response_record *,
|
||||
struct nmb_name *,
|
||||
int);
|
||||
struct response_record *, struct nmb_name *, int);
|
||||
|
||||
typedef void (*node_status_success_function) (struct subnet_record *,
|
||||
struct userdata_struct *,
|
||||
struct res_rec *,
|
||||
struct in_addr);
|
||||
typedef void (*node_status_fail_function)( struct subnet_record *,
|
||||
struct response_record *);
|
||||
struct res_rec *, struct in_addr);
|
||||
typedef void (*node_status_fail_function) (struct subnet_record *, struct response_record *);
|
||||
|
||||
/* Initiated name queries are recorded in this list to track any responses. */
|
||||
|
||||
@ -346,7 +337,8 @@ struct response_record
|
||||
netbios names.
|
||||
*/
|
||||
|
||||
enum subnet_type {
|
||||
enum subnet_type
|
||||
{
|
||||
NORMAL_SUBNET = 0, /* Subnet listed in interfaces list. */
|
||||
UNICAST_SUBNET = 1, /* Subnet for unicast packets. */
|
||||
REMOTE_BROADCAST_SUBNET = 2, /* Subnet for remote broadcasts. */
|
||||
@ -354,7 +346,8 @@ enum subnet_type {
|
||||
};
|
||||
|
||||
/* A resource record. */
|
||||
struct res_rec {
|
||||
struct res_rec
|
||||
{
|
||||
struct nmb_name rr_name;
|
||||
int rr_type;
|
||||
int rr_class;
|
||||
@ -366,11 +359,13 @@ struct res_rec {
|
||||
/* An nmb packet. */
|
||||
struct nmb_packet
|
||||
{
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
int name_trn_id;
|
||||
int opcode;
|
||||
BOOL response;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
BOOL bcast;
|
||||
BOOL recursion_available;
|
||||
BOOL recursion_desired;
|
||||
@ -384,7 +379,8 @@ struct nmb_packet
|
||||
int arcount;
|
||||
} header;
|
||||
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
struct nmb_name question_name;
|
||||
int question_type;
|
||||
int question_class;
|
||||
@ -398,10 +394,13 @@ struct nmb_packet
|
||||
|
||||
/* A datagram - this normally contains SMB data in the data[] array. */
|
||||
|
||||
struct dgram_packet {
|
||||
struct {
|
||||
struct dgram_packet
|
||||
{
|
||||
struct
|
||||
{
|
||||
int msg_type;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
enum node_type node_type;
|
||||
BOOL first;
|
||||
BOOL more;
|
||||
@ -431,7 +430,8 @@ struct packet_struct
|
||||
int fd;
|
||||
time_t timestamp;
|
||||
enum packet_type packet_type;
|
||||
union {
|
||||
union
|
||||
{
|
||||
struct nmb_packet nmb;
|
||||
struct dgram_packet dgram;
|
||||
} packet;
|
||||
@ -501,5 +501,6 @@ extern struct subnet_record *remote_broadcast_subnet;
|
||||
#define NEXT_SUBNET_INCLUDING_UNICAST(x) (get_next_subnet_maybe_unicast((x)))
|
||||
|
||||
/* To be removed. */
|
||||
enum state_type { TEST };
|
||||
enum state_type
|
||||
{ TEST };
|
||||
#endif /* _NAMESERV_H_ */
|
||||
|
@ -174,8 +174,7 @@ int set_maxfiles(int requested_max);
|
||||
BOOL do_file_lock (int fd, int waitsecs, int type);
|
||||
BOOL file_lock (int fd, int type, int secs, int *plock_depth);
|
||||
BOOL file_unlock (int fd, int *plock_depth);
|
||||
void *startfilepwent(char *pfile, char *s_readbuf, int bufsize,
|
||||
int *file_lock_depth, BOOL update);
|
||||
void *startfilepwent (char *pfile, char *s_readbuf, int bufsize, int *file_lock_depth, BOOL update);
|
||||
void endfilepwent (void *vp, int *file_lock_depth);
|
||||
SMB_BIG_UINT getfilepwpos (void *vp);
|
||||
BOOL setfilepwpos (void *vp, SMB_BIG_UINT tok);
|
||||
@ -247,22 +246,18 @@ BOOL cli_api_pipe(struct cli_state *cli, char *pipe_name, int pipe_name_len,
|
||||
uint16 * setup, uint32 setup_count, uint32 max_setup_count,
|
||||
char *params, uint32 param_count, uint32 max_param_count,
|
||||
char *data, uint32 data_count, uint32 max_data_count,
|
||||
char **rparam, uint32 *rparam_count,
|
||||
char **rdata, uint32 *rdata_count);
|
||||
char **rparam, uint32 * rparam_count, char **rdata, uint32 * rdata_count);
|
||||
BOOL cli_api (struct cli_state *cli,
|
||||
char *param, int prcnt, int mprcnt,
|
||||
char *data, int drcnt, int mdrcnt,
|
||||
char **rparam, int *rprcnt,
|
||||
char **rdata, int *rdrcnt);
|
||||
char **rparam, int *rprcnt, char **rdata, int *rdrcnt);
|
||||
BOOL cli_NetWkstaUserLogon (struct cli_state *cli, char *user, char *workstation);
|
||||
int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void * state);
|
||||
int cli_RNetShareEnum (struct cli_state *cli,
|
||||
void (*fn) (const char *, uint32, const char *, void *), void *state);
|
||||
BOOL cli_NetServerEnum (struct cli_state *cli, char *workgroup, uint32 stype,
|
||||
void (*fn) (const char *, uint32, const char *, void *), void *state);
|
||||
BOOL cli_session_setup(struct cli_state *cli,
|
||||
char *user,
|
||||
char *pass, int passlen,
|
||||
char *ntpass, int ntpasslen,
|
||||
char *workgroup);
|
||||
BOOL cli_session_setup (struct cli_state *cli, char *user, char *pass, int passlen, char *ntpass,
|
||||
int ntpasslen, char *workgroup);
|
||||
BOOL cli_ulogoff (struct cli_state *cli);
|
||||
BOOL cli_send_tconX (struct cli_state *cli,
|
||||
const char *share, const char *dev, const char *pass, int passlen);
|
||||
@ -278,23 +273,18 @@ BOOL cli_lock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int ti
|
||||
BOOL cli_unlock (struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout);
|
||||
size_t cli_read (struct cli_state *cli, int fnum, char *buf, off_t offset, size_t size);
|
||||
ssize_t cli_write (struct cli_state *cli,
|
||||
int fnum, uint16 write_mode,
|
||||
const char *buf, off_t offset, size_t size);
|
||||
ssize_t cli_smbwrite(struct cli_state *cli,
|
||||
int fnum, const char *buf, off_t offset, size_t size);
|
||||
int fnum, uint16 write_mode, const char *buf, off_t offset, size_t size);
|
||||
ssize_t cli_smbwrite (struct cli_state *cli, int fnum, const char *buf, off_t offset, size_t size);
|
||||
BOOL cli_getattrE (struct cli_state *cli, int fd,
|
||||
uint16 *attr, size_t *size,
|
||||
time_t *c_time, time_t *a_time, time_t *m_time);
|
||||
BOOL cli_getatr(struct cli_state *cli, char *fname,
|
||||
uint16 *attr, size_t *size, time_t *t);
|
||||
uint16 * attr, size_t * size, time_t * c_time, time_t * a_time, time_t * m_time);
|
||||
BOOL cli_getatr (struct cli_state *cli, char *fname, uint16 * attr, size_t * size, time_t * t);
|
||||
BOOL cli_setatr (struct cli_state *cli, char *fname, uint16 attr, time_t t);
|
||||
BOOL cli_qpathinfo (struct cli_state *cli, const char *fname,
|
||||
time_t * c_time, time_t * a_time, time_t * m_time,
|
||||
size_t * size, uint16 * mode);
|
||||
BOOL cli_qpathinfo2 (struct cli_state *cli, const char *fname,
|
||||
time_t * c_time, time_t * a_time, time_t * m_time,
|
||||
time_t *w_time, size_t *size, uint16 *mode,
|
||||
SMB_INO_T *ino);
|
||||
time_t * w_time, size_t * size, uint16 * mode, SMB_INO_T * ino);
|
||||
BOOL cli_qfileinfo (struct cli_state *cli, int fnum,
|
||||
uint16 * mode, size_t * size,
|
||||
time_t * c_time, time_t * a_time, time_t * m_time,
|
||||
@ -302,8 +292,7 @@ BOOL cli_qfileinfo(struct cli_state *cli, int fnum,
|
||||
int cli_list (struct cli_state *cli, const char *Mask, uint16 attribute,
|
||||
void (*fn) (file_info *, const char *, void *), void *state);
|
||||
BOOL cli_negprot (struct cli_state *cli);
|
||||
BOOL cli_session_request(struct cli_state *cli,
|
||||
struct nmb_name *calling, struct nmb_name *called);
|
||||
BOOL cli_session_request (struct cli_state *cli, struct nmb_name *calling, struct nmb_name *called);
|
||||
BOOL cli_connect (struct cli_state *cli, const char *host, struct in_addr *ip);
|
||||
struct cli_state *cli_initialise (struct cli_state *cli);
|
||||
void cli_shutdown (struct cli_state *cli);
|
||||
@ -314,11 +303,9 @@ BOOL cli_reestablish_connection(struct cli_state *cli);
|
||||
BOOL cli_establish_connection (struct cli_state *cli,
|
||||
char *dest_host, struct in_addr *dest_ip,
|
||||
struct nmb_name *calling, struct nmb_name *called,
|
||||
char *service, char *service_type,
|
||||
BOOL do_shutdown, BOOL do_tcon);
|
||||
char *service, char *service_type, BOOL do_shutdown, BOOL do_tcon);
|
||||
BOOL cli_chkpath (struct cli_state *cli, char *path);
|
||||
BOOL cli_message_start(struct cli_state *cli, char *host, char *username,
|
||||
int *grp);
|
||||
BOOL cli_message_start (struct cli_state *cli, char *host, char *username, int *grp);
|
||||
BOOL cli_message_text (struct cli_state *cli, char *msg, int len, int grp);
|
||||
BOOL cli_message_end (struct cli_state *cli, int grp);
|
||||
BOOL cli_dskattr (struct cli_state *cli, int *bsize, int *total, int *avail);
|
||||
@ -615,6 +602,5 @@ BOOL lp_kernel_oplocks(void);
|
||||
/* The following definitions come from param/params.c */
|
||||
|
||||
BOOL pm_process (const char *FileName,
|
||||
BOOL (*sfunc)(const char *),
|
||||
BOOL (*pfunc)(const char *, const char *) );
|
||||
BOOL (*sfunc) (const char *), BOOL (*pfunc) (const char *, const char *));
|
||||
#endif /* _PROTO_H_ */
|
||||
|
@ -51,7 +51,8 @@ typedef int BOOL;
|
||||
arguemnts to DEBUG() right. We have got them wrong too often in the
|
||||
past */
|
||||
#ifdef HAVE_STDARG_H
|
||||
int Debug1( const char *, ... )
|
||||
int
|
||||
Debug1 (const char *, ...)
|
||||
#ifdef __GNUC__
|
||||
__attribute__ ((format (printf, 1, 2)))
|
||||
#endif
|
||||
@ -532,7 +533,8 @@ typedef struct
|
||||
time_t status_time;
|
||||
} dir_status_struct;
|
||||
|
||||
struct uid_cache {
|
||||
struct uid_cache
|
||||
{
|
||||
int entries;
|
||||
uid_t list[UID_CACHE_SIZE];
|
||||
};
|
||||
@ -655,7 +657,8 @@ typedef struct
|
||||
} user_struct;
|
||||
|
||||
|
||||
enum {LPQ_QUEUED,LPQ_PAUSED,LPQ_SPOOLING,LPQ_PRINTING};
|
||||
enum
|
||||
{ LPQ_QUEUED, LPQ_PAUSED, LPQ_SPOOLING, LPQ_PRINTING };
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -668,7 +671,8 @@ typedef struct
|
||||
char file[100];
|
||||
} print_queue_struct;
|
||||
|
||||
enum {LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR};
|
||||
enum
|
||||
{ LPSTAT_OK, LPSTAT_STOPPED, LPSTAT_ERROR };
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -709,21 +713,24 @@ typedef struct
|
||||
|
||||
/* each implementation of the share mode code needs
|
||||
to support the following operations */
|
||||
struct share_ops {
|
||||
struct share_ops
|
||||
{
|
||||
BOOL (*stop_mgmt) (void);
|
||||
BOOL (*lock_entry) (connection_struct *, SMB_DEV_T, SMB_INO_T, int *);
|
||||
BOOL (*unlock_entry) (connection_struct *, SMB_DEV_T, SMB_INO_T, int);
|
||||
int (*get_entries) (connection_struct *, int, SMB_DEV_T, SMB_INO_T, share_mode_entry **);
|
||||
void (*del_entry) (int, files_struct *);
|
||||
BOOL (*set_entry) (int, files_struct *, uint16, uint16);
|
||||
BOOL (*mod_entry)(int, files_struct *, void (*)(share_mode_entry *, SMB_DEV_T, SMB_INO_T, void *), void *);
|
||||
BOOL (*mod_entry) (int, files_struct *,
|
||||
void (*)(share_mode_entry *, SMB_DEV_T, SMB_INO_T, void *), void *);
|
||||
int (*forall) (void (*)(share_mode_entry *, char *));
|
||||
void (*status) (FILE *);
|
||||
};
|
||||
|
||||
/* each implementation of the shared memory code needs
|
||||
to support the following operations */
|
||||
struct shmem_ops {
|
||||
struct shmem_ops
|
||||
{
|
||||
BOOL (*shm_close) (void);
|
||||
int (*shm_alloc) (int);
|
||||
BOOL (*shm_free) (int);
|
||||
@ -741,7 +748,8 @@ struct shmem_ops {
|
||||
* to support the following operations.
|
||||
*/
|
||||
|
||||
struct passdb_ops {
|
||||
struct passdb_ops
|
||||
{
|
||||
/*
|
||||
* Password database ops.
|
||||
*/
|
||||
@ -793,7 +801,8 @@ struct passdb_ops {
|
||||
/*
|
||||
* password checking functions
|
||||
*/
|
||||
struct smb_passwd *(*smb_password_chal )(char *username, char lm_pass[24], char nt_pass[24], char chal[8]);
|
||||
struct smb_passwd *(*smb_password_chal) (char *username, char lm_pass[24], char nt_pass[24],
|
||||
char chal[8]);
|
||||
struct smb_passwd *(*smb_password_check) (char *username, char lm_hash[16], char nt_hash[16]);
|
||||
struct passwd *(*unix_password_check) (char *username, char *pass, int pass_len);
|
||||
#endif
|
||||
@ -815,7 +824,8 @@ struct connect_record
|
||||
};
|
||||
|
||||
/* This is used by smbclient to send it to a smbfs mount point */
|
||||
struct connection_options {
|
||||
struct connection_options
|
||||
{
|
||||
int protocol;
|
||||
/* Connection-Options */
|
||||
uint32 max_xmit;
|
||||
@ -845,7 +855,8 @@ typedef enum
|
||||
P_LOCAL, P_GLOBAL, P_SEPARATOR, P_NONE
|
||||
} parm_class;
|
||||
|
||||
struct enum_list {
|
||||
struct enum_list
|
||||
{
|
||||
int value;
|
||||
const char *name;
|
||||
};
|
||||
@ -859,7 +870,8 @@ struct parm_struct
|
||||
BOOL (*special) (const char *, char **);
|
||||
const struct enum_list *enum_list;
|
||||
unsigned flags;
|
||||
union {
|
||||
union
|
||||
{
|
||||
BOOL bvalue;
|
||||
int ivalue;
|
||||
char *svalue;
|
||||
@ -867,7 +879,8 @@ struct parm_struct
|
||||
} def;
|
||||
};
|
||||
|
||||
struct bitmap {
|
||||
struct bitmap
|
||||
{
|
||||
uint32 *b;
|
||||
int n;
|
||||
};
|
||||
@ -1323,7 +1336,8 @@ struct bitmap {
|
||||
#define ERRCMD 0xFF /* Command was not in the "SMB" format. */
|
||||
|
||||
#ifdef HAVE_STDARG_H
|
||||
int slprintf(char *str, int n, const char *format, ...)
|
||||
int
|
||||
slprintf (char *str, int n, const char *format, ...)
|
||||
#ifdef __GNUC__
|
||||
__attribute__ ((format (printf, 3, 4)))
|
||||
#endif
|
||||
@ -1474,24 +1488,33 @@ extern int dcelogin_atmost_once;
|
||||
|
||||
/* protocol types. It assumes that higher protocols include lower protocols
|
||||
as subsets */
|
||||
enum protocol_types {PROTOCOL_NONE,PROTOCOL_CORE,PROTOCOL_COREPLUS,PROTOCOL_LANMAN1,PROTOCOL_LANMAN2,PROTOCOL_NT1};
|
||||
enum protocol_types
|
||||
{ PROTOCOL_NONE, PROTOCOL_CORE, PROTOCOL_COREPLUS, PROTOCOL_LANMAN1, PROTOCOL_LANMAN2,
|
||||
PROTOCOL_NT1
|
||||
};
|
||||
|
||||
/* security levels */
|
||||
enum security_types {SEC_SHARE,SEC_USER,SEC_SERVER,SEC_DOMAIN};
|
||||
enum security_types
|
||||
{ SEC_SHARE, SEC_USER, SEC_SERVER, SEC_DOMAIN };
|
||||
|
||||
/* printing types */
|
||||
enum printing_types {PRINT_BSD,PRINT_SYSV,PRINT_AIX,PRINT_HPUX,
|
||||
PRINT_QNX,PRINT_PLP,PRINT_LPRNG,PRINT_SOFTQ};
|
||||
enum printing_types
|
||||
{ PRINT_BSD, PRINT_SYSV, PRINT_AIX, PRINT_HPUX,
|
||||
PRINT_QNX, PRINT_PLP, PRINT_LPRNG, PRINT_SOFTQ
|
||||
};
|
||||
|
||||
/* Remote architectures we know about. */
|
||||
enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA};
|
||||
enum remote_arch_types
|
||||
{ RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_SAMBA };
|
||||
|
||||
/* case handling */
|
||||
enum case_handling {CASE_LOWER,CASE_UPPER};
|
||||
enum case_handling
|
||||
{ CASE_LOWER, CASE_UPPER };
|
||||
|
||||
#ifdef WITH_SSL
|
||||
/* SSL version options */
|
||||
enum ssl_version_enum {SMB_SSL_V2,SMB_SSL_V3,SMB_SSL_V23,SMB_SSL_TLS1};
|
||||
enum ssl_version_enum
|
||||
{ SMB_SSL_V2, SMB_SSL_V3, SMB_SSL_V23, SMB_SSL_TLS1 };
|
||||
#endif /* WITH_SSL */
|
||||
|
||||
/* Macros to get at offsets within smb_lkrng and smb_unlkrng
|
||||
@ -1677,7 +1700,8 @@ extern int unix_ERR_code;
|
||||
#define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0])) >= (n))
|
||||
|
||||
/* A netbios name structure. */
|
||||
struct nmb_name {
|
||||
struct nmb_name
|
||||
{
|
||||
char name[17];
|
||||
char scope[64];
|
||||
unsigned int name_type;
|
||||
|
@ -243,6 +243,3 @@ Byte offset Type name description
|
||||
#define TYPE_VIRTUAL 0x40
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -35,20 +35,28 @@ static BOOL mapsinited = 0;
|
||||
static char unix2dos[256];
|
||||
static char dos2unix[256];
|
||||
|
||||
static void initmaps(void) {
|
||||
static void
|
||||
initmaps (void)
|
||||
{
|
||||
int k;
|
||||
|
||||
for (k = 0; k < 256; k++) unix2dos[k] = k;
|
||||
for (k = 0; k < 256; k++) dos2unix[k] = k;
|
||||
for (k = 0; k < 256; k++)
|
||||
unix2dos[k] = k;
|
||||
for (k = 0; k < 256; k++)
|
||||
dos2unix[k] = k;
|
||||
|
||||
mapsinited = True;
|
||||
}
|
||||
|
||||
static void update_map(const char * str) {
|
||||
static void
|
||||
update_map (const char *str)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
for (p = str; *p; p++) {
|
||||
if (p[1]) {
|
||||
for (p = str; *p; p++)
|
||||
{
|
||||
if (p[1])
|
||||
{
|
||||
unix2dos[(unsigned char) *p] = p[1];
|
||||
dos2unix[(unsigned char) p[1]] = *p;
|
||||
p++;
|
||||
@ -56,10 +64,13 @@ static void update_map(const char * str) {
|
||||
}
|
||||
}
|
||||
|
||||
static void init_iso8859_1(void) {
|
||||
static void
|
||||
init_iso8859_1 (void)
|
||||
{
|
||||
|
||||
int i;
|
||||
if (!mapsinited) initmaps();
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
/* Do not map undefined characters to some accidental code */
|
||||
for (i = 128; i < 256; i++)
|
||||
@ -86,10 +97,13 @@ update_map("\370\233\371\227\372\243\373\226\374\201\375\354\376\347\377\230");
|
||||
|
||||
/* Init for eastern european languages. */
|
||||
|
||||
static void init_iso8859_2(void) {
|
||||
static void
|
||||
init_iso8859_2 (void)
|
||||
{
|
||||
|
||||
int i;
|
||||
if (!mapsinited) initmaps();
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
/* Do not map undefined characters to some accidental code */
|
||||
for (i = 128; i < 256; i++)
|
||||
@ -123,10 +137,12 @@ update_map("\370\375\371\205\372\243\373\373\374\201\375\354\376\356\377\372");
|
||||
|
||||
/* Added by Max Khon <max@iclub.nsu.ru> */
|
||||
|
||||
static void init_iso8859_5(void)
|
||||
static void
|
||||
init_iso8859_5 (void)
|
||||
{
|
||||
int i;
|
||||
if (!mapsinited) initmaps();
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
/* Do not map undefined characters to some accidental code */
|
||||
for (i = 128; i < 256; i++)
|
||||
@ -150,9 +166,11 @@ update_map("\360\374\240\377");
|
||||
|
||||
/* Init for russian language (koi8) */
|
||||
|
||||
static void init_koi8_r(void)
|
||||
static void
|
||||
init_koi8_r (void)
|
||||
{
|
||||
if (!mapsinited) initmaps();
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
/* There aren't undefined characters between 128 and 255 */
|
||||
|
||||
@ -178,17 +196,23 @@ update_map("\370\234\371\233\372\207\373\230\374\235\375\231\376\227\377\232");
|
||||
/*
|
||||
* Convert unix to dos
|
||||
*/
|
||||
char *unix2dos_format(char *str,BOOL overwrite)
|
||||
char *
|
||||
unix2dos_format (char *str, BOOL overwrite)
|
||||
{
|
||||
char *p;
|
||||
char *dp;
|
||||
|
||||
if (!mapsinited) initmaps();
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
if (overwrite) {
|
||||
for (p = str; *p; p++) *p = unix2dos[(unsigned char)*p];
|
||||
if (overwrite)
|
||||
{
|
||||
for (p = str; *p; p++)
|
||||
*p = unix2dos[(unsigned char) *p];
|
||||
return str;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
for (p = str, dp = cvtbuf; *p && dp < &(cvtbuf[sizeof (cvtbuf) - 1]); p++, dp++)
|
||||
*dp = unix2dos[(unsigned char) *p];
|
||||
*dp = 0;
|
||||
@ -199,17 +223,23 @@ char *unix2dos_format(char *str,BOOL overwrite)
|
||||
/*
|
||||
* Convert dos to unix
|
||||
*/
|
||||
char *dos2unix_format(char *str, BOOL overwrite)
|
||||
char *
|
||||
dos2unix_format (char *str, BOOL overwrite)
|
||||
{
|
||||
char *p;
|
||||
char *dp;
|
||||
|
||||
if (!mapsinited) initmaps();
|
||||
if (!mapsinited)
|
||||
initmaps ();
|
||||
|
||||
if (overwrite) {
|
||||
for (p = str; *p; p++) *p = dos2unix[(unsigned char)*p];
|
||||
if (overwrite)
|
||||
{
|
||||
for (p = str; *p; p++)
|
||||
*p = dos2unix[(unsigned char) *p];
|
||||
return str;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
for (p = str, dp = cvtbuf; *p && dp < &(cvtbuf[sizeof (cvtbuf) - 1]); p++, dp++)
|
||||
*dp = dos2unix[(unsigned char) *p];
|
||||
*dp = 0;
|
||||
@ -221,17 +251,27 @@ char *dos2unix_format(char *str, BOOL overwrite)
|
||||
/*
|
||||
* 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")) {
|
||||
}
|
||||
else if (strequal (str, "iso8859-2"))
|
||||
{
|
||||
init_iso8859_2 ();
|
||||
} else if (strequal (str, "iso8859-5")) {
|
||||
}
|
||||
else if (strequal (str, "iso8859-5"))
|
||||
{
|
||||
init_iso8859_5 ();
|
||||
} else if (strequal (str, "koi8-r")) {
|
||||
}
|
||||
else if (strequal (str, "koi8-r"))
|
||||
{
|
||||
init_koi8_r ();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG (0, ("unrecognized character set %s\n", str));
|
||||
}
|
||||
}
|
||||
|
@ -128,20 +128,22 @@ char *lower_char_map = xx_lower_char_map;
|
||||
* mapping from lower to upper, but not upper to lower.
|
||||
*/
|
||||
|
||||
static void add_dos_char(int lower, BOOL map_lower_to_upper,
|
||||
int upper, BOOL map_upper_to_lower)
|
||||
static void
|
||||
add_dos_char (int lower, BOOL map_lower_to_upper, int upper, BOOL map_upper_to_lower)
|
||||
{
|
||||
lower &= 0xff;
|
||||
upper &= 0xff;
|
||||
DEBUGADD (6, ("Adding chars 0x%x 0x%x (l->u = %s) (u->l = %s)\n",
|
||||
lower, upper,
|
||||
map_lower_to_upper ? "True" : "False",
|
||||
map_upper_to_lower ? "True" : "False" ) );
|
||||
if (lower) dos_char_map[lower] = 1;
|
||||
if (upper) dos_char_map[upper] = 1;
|
||||
map_lower_to_upper ? "True" : "False", map_upper_to_lower ? "True" : "False"));
|
||||
if (lower)
|
||||
dos_char_map[lower] = 1;
|
||||
if (upper)
|
||||
dos_char_map[upper] = 1;
|
||||
lower_char_map[lower] = (char) lower; /* Define tolower(lower) */
|
||||
upper_char_map[upper] = (char) upper; /* Define toupper(upper) */
|
||||
if (lower && upper) {
|
||||
if (lower && upper)
|
||||
{
|
||||
if (map_upper_to_lower)
|
||||
lower_char_map[upper] = (char) lower;
|
||||
if (map_lower_to_upper)
|
||||
@ -152,7 +154,8 @@ static void add_dos_char(int lower, BOOL map_lower_to_upper,
|
||||
/****************************************************************************
|
||||
initialise the charset arrays
|
||||
****************************************************************************/
|
||||
void charset_initialise(void)
|
||||
void
|
||||
charset_initialise (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -162,24 +165,30 @@ void charset_initialise(void)
|
||||
setlocale (LC_ALL, "C");
|
||||
#endif
|
||||
|
||||
for (i= 0;i<=255;i++) {
|
||||
for (i = 0; i <= 255; i++)
|
||||
{
|
||||
dos_char_map[i] = 0;
|
||||
}
|
||||
|
||||
for (i=0;i<=127;i++) {
|
||||
for (i = 0; i <= 127; i++)
|
||||
{
|
||||
if (isalnum (i) || strchr ("._^$~!#%&-{}()@'`", (char) i))
|
||||
add_dos_char (i, False, 0, False);
|
||||
}
|
||||
|
||||
for (i=0; i<=255; i++) {
|
||||
for (i = 0; i <= 255; i++)
|
||||
{
|
||||
char c = (char) i;
|
||||
upper_char_map[i] = lower_char_map[i] = c;
|
||||
|
||||
/* Some systems have buggy isupper/islower for characters
|
||||
above 127. Best not to rely on them. */
|
||||
if(i < 128) {
|
||||
if (isupper((int)c)) lower_char_map[i] = tolower(c);
|
||||
if (islower((int)c)) upper_char_map[i] = toupper(c);
|
||||
if (i < 128)
|
||||
{
|
||||
if (isupper ((int) c))
|
||||
lower_char_map[i] = tolower (c);
|
||||
if (islower ((int) c))
|
||||
upper_char_map[i] = toupper (c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -190,7 +199,8 @@ load the client codepage.
|
||||
|
||||
typedef const unsigned char (*codepage_p)[4];
|
||||
|
||||
static codepage_p load_client_codepage( int client_codepage )
|
||||
static codepage_p
|
||||
load_client_codepage (int client_codepage)
|
||||
{
|
||||
pstring codepage_file_name;
|
||||
unsigned char buf[8];
|
||||
@ -211,14 +221,11 @@ static codepage_p load_client_codepage( int client_codepage )
|
||||
pstrcat (codepage_file_name, "/");
|
||||
pstrcat (codepage_file_name, "codepage.");
|
||||
slprintf (&codepage_file_name[strlen (codepage_file_name)],
|
||||
sizeof(pstring)-(strlen(codepage_file_name)+1),
|
||||
"%03d",
|
||||
client_codepage);
|
||||
sizeof (pstring) - (strlen (codepage_file_name) + 1), "%03d", client_codepage);
|
||||
|
||||
if (sys_stat (codepage_file_name, &st) != 0)
|
||||
{
|
||||
DEBUG(0,("load_client_codepage: filename %s does not exist.\n",
|
||||
codepage_file_name));
|
||||
DEBUG (0, ("load_client_codepage: filename %s does not exist.\n", codepage_file_name));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -259,9 +266,7 @@ code page file (size=%d).\n", codepage_file_name, (int)size));
|
||||
if (SVAL (buf, CODEPAGE_VERSION_OFFSET) != CODEPAGE_FILE_VERSION_ID)
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: filename %s has incorrect version id. \
|
||||
Needed %hu, got %hu.\n",
|
||||
codepage_file_name, (uint16)CODEPAGE_FILE_VERSION_ID,
|
||||
SVAL(buf,CODEPAGE_VERSION_OFFSET)));
|
||||
Needed %hu, got %hu.\n", codepage_file_name, (uint16) CODEPAGE_FILE_VERSION_ID, SVAL (buf, CODEPAGE_VERSION_OFFSET)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
|
||||
@ -269,9 +274,7 @@ Needed %hu, got %hu.\n",
|
||||
if (SVAL (buf, CODEPAGE_CLIENT_CODEPAGE_OFFSET) != (uint16) client_codepage)
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: filename %s has incorrect codepage. \
|
||||
Needed %hu, got %hu.\n",
|
||||
codepage_file_name, (uint16)client_codepage,
|
||||
SVAL(buf,CODEPAGE_CLIENT_CODEPAGE_OFFSET)));
|
||||
Needed %hu, got %hu.\n", codepage_file_name, (uint16) client_codepage, SVAL (buf, CODEPAGE_CLIENT_CODEPAGE_OFFSET)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
|
||||
@ -279,8 +282,7 @@ Needed %hu, got %hu.\n",
|
||||
if (IVAL (buf, CODEPAGE_LENGTH_OFFSET) != (size - CODEPAGE_HEADER_SIZE))
|
||||
{
|
||||
DEBUG (0, ("load_client_codepage: filename %s has incorrect size headers. \
|
||||
Needed %u, got %u.\n", codepage_file_name, (uint32)(size - CODEPAGE_HEADER_SIZE),
|
||||
IVAL(buf,CODEPAGE_LENGTH_OFFSET)));
|
||||
Needed %u, got %u.\n", codepage_file_name, (uint32) (size - CODEPAGE_HEADER_SIZE), IVAL (buf, CODEPAGE_LENGTH_OFFSET)));
|
||||
goto clean_and_exit;
|
||||
}
|
||||
|
||||
@ -328,7 +330,8 @@ clean_and_exit:
|
||||
/****************************************************************************
|
||||
initialise the client codepage.
|
||||
****************************************************************************/
|
||||
void codepage_initialise(int client_codepage)
|
||||
void
|
||||
codepage_initialise (int client_codepage)
|
||||
{
|
||||
int i;
|
||||
static codepage_p cp = NULL;
|
||||
@ -352,14 +355,12 @@ void codepage_initialise(int client_codepage)
|
||||
{
|
||||
#ifdef KANJI
|
||||
DEBUG (6, ("codepage_initialise: loading dynamic codepage file %s/codepage.%d \
|
||||
for code page %d failed. Using default client codepage 932\n",
|
||||
CODEPAGEDIR, client_codepage, client_codepage));
|
||||
for code page %d failed. Using default client codepage 932\n", CODEPAGEDIR, client_codepage, client_codepage));
|
||||
cp = cp_932;
|
||||
client_codepage = KANJI_CODEPAGE;
|
||||
#else /* KANJI */
|
||||
DEBUG (6, ("codepage_initialise: loading dynamic codepage file %s/codepage.%d \
|
||||
for code page %d failed. Using default client codepage 850\n",
|
||||
CODEPAGEDIR, client_codepage, client_codepage));
|
||||
for code page %d failed. Using default client codepage 850\n", CODEPAGEDIR, client_codepage, client_codepage));
|
||||
cp = cp_850;
|
||||
client_codepage = MSDOS_LATIN_1_CODEPAGE;
|
||||
#endif /* KANJI */
|
||||
@ -380,19 +381,25 @@ for code page %d failed. Using default client codepage 850\n",
|
||||
/*******************************************************************
|
||||
add characters depending on a string passed by the user
|
||||
********************************************************************/
|
||||
void add_char_string(const char *s)
|
||||
void
|
||||
add_char_string (const char *s)
|
||||
{
|
||||
char *extra_chars = (char *) strdup (s);
|
||||
char *t;
|
||||
if (!extra_chars) return;
|
||||
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;
|
||||
if (isdigit((unsigned char)*t) || (*t)=='-') {
|
||||
if (isdigit ((unsigned char) *t) || (*t) == '-')
|
||||
{
|
||||
sscanf (t, "%i:%i", &i1, &i2);
|
||||
add_dos_char (i1, True, i2, True);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
sscanf (t, "%c:%c", &c1, &c2);
|
||||
add_dos_char ((unsigned char) c1, True, (unsigned char) c2, True);
|
||||
}
|
||||
|
@ -110,6 +110,7 @@ int DEBUGLEVEL = 1;
|
||||
|
||||
static BOOL stdout_logging = False;
|
||||
static pstring format_bufr = { '\0' };
|
||||
|
||||
static size_t format_pos = 0;
|
||||
|
||||
|
||||
@ -121,7 +122,8 @@ static size_t format_pos = 0;
|
||||
* 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)
|
||||
@ -137,10 +139,12 @@ void setup_logging( const char *pname, BOOL interactive )
|
||||
* ************************************************************************** **
|
||||
*/
|
||||
#ifdef HAVE_STDARG_H
|
||||
int Debug1( const char *format_str, ... )
|
||||
int
|
||||
Debug1 (const char *format_str, ...)
|
||||
{
|
||||
#else
|
||||
int Debug1(va_alist)
|
||||
int
|
||||
Debug1 (va_alist)
|
||||
va_dcl
|
||||
{
|
||||
const char *format_str;
|
||||
@ -209,7 +213,8 @@ va_dcl
|
||||
*
|
||||
* ************************************************************************** **
|
||||
*/
|
||||
static void bufr_print( void )
|
||||
static void
|
||||
bufr_print (void)
|
||||
{
|
||||
format_bufr[format_pos] = '\0';
|
||||
(void) Debug1 ("%s", format_bufr);
|
||||
@ -233,11 +238,11 @@ 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() ||
|
||||
!(lp_loaded())));
|
||||
BOOL timestamp = (!stdout_logging && (lp_timestamp_logs () || !(lp_loaded ())));
|
||||
|
||||
for (i = 0; msg[i]; i++)
|
||||
{
|
||||
@ -278,7 +283,8 @@ static void format_debug_text( char *msg )
|
||||
*
|
||||
* ************************************************************************** **
|
||||
*/
|
||||
void dbgflush( void )
|
||||
void
|
||||
dbgflush (void)
|
||||
{
|
||||
bufr_print ();
|
||||
(void) fflush (dbf);
|
||||
@ -306,7 +312,8 @@ 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)
|
||||
{
|
||||
@ -332,8 +339,7 @@ BOOL dbghdr( int level, const char *file, const char *func, int line )
|
||||
if (lp_timestamp_logs () || !(lp_loaded ()))
|
||||
{
|
||||
/* Print it all out at once to prevent split syslog output. */
|
||||
(void)Debug1( "[%s, %d] %s:%s(%d)\n",
|
||||
timestring(), level, file, func, line );
|
||||
(void) Debug1 ("[%s, %d] %s:%s(%d)\n", timestring (), level, file, func, line);
|
||||
}
|
||||
|
||||
return (True);
|
||||
@ -353,7 +359,8 @@ BOOL dbghdr( int level, const char *file, const char *func, int line )
|
||||
* ************************************************************************** **
|
||||
*/
|
||||
#ifdef HAVE_STDARG_H
|
||||
BOOL dbgtext( const char *format_str, ... )
|
||||
BOOL
|
||||
dbgtext (const char *format_str, ...)
|
||||
{
|
||||
va_list ap;
|
||||
pstring msgbuf;
|
||||
@ -368,7 +375,8 @@ BOOL dbghdr( int level, const char *file, const char *func, int line )
|
||||
} /* dbgtext */
|
||||
|
||||
#else
|
||||
BOOL dbgtext( va_alist )
|
||||
BOOL
|
||||
dbgtext (va_alist)
|
||||
va_dcl
|
||||
{
|
||||
char *format_str;
|
||||
|
@ -47,12 +47,14 @@ struct interface *last_iface;
|
||||
/****************************************************************************
|
||||
calculate the default netmask for an address
|
||||
****************************************************************************/
|
||||
static void default_netmask(struct in_addr *inm, struct in_addr *iad)
|
||||
static void
|
||||
default_netmask (struct in_addr *inm, struct in_addr *iad)
|
||||
{
|
||||
/*
|
||||
** Guess a netmask based on the class of the IP address given.
|
||||
*/
|
||||
switch((ntohl(iad->s_addr) & 0xE0000000)) {
|
||||
switch ((ntohl (iad->s_addr) & 0xE0000000))
|
||||
{
|
||||
case 0x00000000: /* Class A addr */
|
||||
case 0x20000000:
|
||||
case 0x40000000:
|
||||
@ -79,9 +81,8 @@ static void default_netmask(struct in_addr *inm, struct in_addr *iad)
|
||||
get the broadcast address for our address
|
||||
(troyer@saifr00.ateng.az.honeywell.com)
|
||||
****************************************************************************/
|
||||
static void get_broadcast(struct in_addr *if_ipaddr,
|
||||
struct in_addr *if_bcast,
|
||||
struct in_addr *if_nmask)
|
||||
static void
|
||||
get_broadcast (struct in_addr *if_ipaddr, struct in_addr *if_bcast, struct in_addr *if_nmask)
|
||||
{
|
||||
uint32 nm;
|
||||
short onbc;
|
||||
@ -96,22 +97,27 @@ static void get_broadcast(struct in_addr *if_ipaddr,
|
||||
nm = ntohl (if_nmask->s_addr);
|
||||
onbc = 0;
|
||||
offbc = 0;
|
||||
while((onbc + offbc) < 32) {
|
||||
if(nm & 0x80000000) {
|
||||
while ((onbc + offbc) < 32)
|
||||
{
|
||||
if (nm & 0x80000000)
|
||||
{
|
||||
onbc++;
|
||||
if(offbc) {
|
||||
if (offbc)
|
||||
{
|
||||
/* already found an off bit, so mask
|
||||
is wrong */
|
||||
onbc = 34;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
offbc++;
|
||||
}
|
||||
nm <<= 1;
|
||||
}
|
||||
if ((onbc < 8)||(onbc == 34)) {
|
||||
DEBUG(0,("Impossible netmask %s - using defaults\n",
|
||||
inet_ntoa(*if_nmask)));
|
||||
if ((onbc < 8) || (onbc == 34))
|
||||
{
|
||||
DEBUG (0, ("Impossible netmask %s - using defaults\n", inet_ntoa (*if_nmask)));
|
||||
default_netmask (if_nmask, if_ipaddr);
|
||||
}
|
||||
|
||||
@ -128,8 +134,8 @@ static void get_broadcast(struct in_addr *if_ipaddr,
|
||||
/****************************************************************************
|
||||
load a list of network interfaces
|
||||
****************************************************************************/
|
||||
static void interpret_interfaces(char *s, struct interface **interfaces,
|
||||
const char *description)
|
||||
static void
|
||||
interpret_interfaces (char *s, struct interface **interfaces, const char *description)
|
||||
{
|
||||
char *ptr;
|
||||
fstring token;
|
||||
@ -141,10 +147,12 @@ static void interpret_interfaces(char *s, struct interface **interfaces,
|
||||
allones_ip = *interpret_addr2 ("255.255.255.255");
|
||||
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;
|
||||
if (p)
|
||||
*p++ = 0;
|
||||
|
||||
ip = *interpret_addr2 (token);
|
||||
|
||||
@ -152,29 +160,38 @@ static void interpret_interfaces(char *s, struct interface **interfaces,
|
||||
{
|
||||
struct interface *i;
|
||||
for (i = (*interfaces); i; i = i->next)
|
||||
if (ip_equal(ip,i->ip)) break;
|
||||
if (i) continue;
|
||||
if (ip_equal (ip, i->ip))
|
||||
break;
|
||||
if (i)
|
||||
continue;
|
||||
}
|
||||
|
||||
iface = (struct interface *) malloc (sizeof (*iface));
|
||||
if (!iface) return;
|
||||
if (!iface)
|
||||
return;
|
||||
|
||||
iface->ip = ip;
|
||||
|
||||
if (p) {
|
||||
if (p)
|
||||
{
|
||||
if (strlen (p) > 2)
|
||||
iface->nmask = *interpret_addr2 (p);
|
||||
else
|
||||
iface->nmask.s_addr = htonl (((ALLONES >> atoi (p)) ^ ALLONES));
|
||||
} else {
|
||||
}
|
||||
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)) {
|
||||
if (!(*interfaces))
|
||||
{
|
||||
(*interfaces) = iface;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
last_iface->next = iface;
|
||||
}
|
||||
last_iface = iface;
|
||||
@ -183,32 +200,42 @@ static void interpret_interfaces(char *s, struct interface **interfaces,
|
||||
DEBUG (2, ("nmask=%s\n", inet_ntoa (iface->nmask)));
|
||||
}
|
||||
|
||||
if (*interfaces) return;
|
||||
if (*interfaces)
|
||||
return;
|
||||
|
||||
/* setup a default interface */
|
||||
iface = (struct interface *) malloc (sizeof (*iface));
|
||||
if (!iface) return;
|
||||
if (!iface)
|
||||
return;
|
||||
|
||||
iface->next = NULL;
|
||||
|
||||
if (got_ip) {
|
||||
if (got_ip)
|
||||
{
|
||||
iface->ip = default_ip;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
get_myname (NULL, &iface->ip);
|
||||
}
|
||||
|
||||
if (got_bcast) {
|
||||
if (got_bcast)
|
||||
{
|
||||
iface->bcast = default_bcast;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
get_broadcast (&iface->ip, &iface->bcast, &iface->nmask);
|
||||
}
|
||||
|
||||
if (got_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)) {
|
||||
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)));
|
||||
}
|
||||
|
||||
@ -224,7 +251,8 @@ static void interpret_interfaces(char *s, struct interface **interfaces,
|
||||
/****************************************************************************
|
||||
load the remote and local interfaces
|
||||
****************************************************************************/
|
||||
void load_interfaces(void)
|
||||
void
|
||||
load_interfaces (void)
|
||||
{
|
||||
/* add the machine's interfaces to local interface structure */
|
||||
interpret_interfaces (lp_interfaces (), &local_interfaces, "interface");
|
||||
@ -234,19 +262,23 @@ void load_interfaces(void)
|
||||
/****************************************************************************
|
||||
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);
|
||||
}
|
||||
|
||||
if (bcast) {
|
||||
if (bcast)
|
||||
{
|
||||
got_bcast = True;
|
||||
default_bcast = *interpret_addr2 (bcast);
|
||||
}
|
||||
|
||||
if (nmask) {
|
||||
if (nmask)
|
||||
{
|
||||
got_nmask = True;
|
||||
default_nmask = *interpret_addr2 (nmask);
|
||||
}
|
||||
@ -256,18 +288,21 @@ void iface_set_default(char *ip,char *bcast,char *nmask)
|
||||
/****************************************************************************
|
||||
check if an IP is one of mine
|
||||
**************************************************************************/
|
||||
BOOL ismyip(struct in_addr ip)
|
||||
BOOL
|
||||
ismyip (struct in_addr ip)
|
||||
{
|
||||
struct interface *i;
|
||||
for (i = local_interfaces; i; i = i->next)
|
||||
if (ip_equal(i->ip,ip)) return True;
|
||||
if (ip_equal (i->ip, ip))
|
||||
return True;
|
||||
return False;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
check if a packet is from a local (known) net
|
||||
**************************************************************************/
|
||||
BOOL is_local_net(struct in_addr from)
|
||||
BOOL
|
||||
is_local_net (struct in_addr from)
|
||||
{
|
||||
struct interface *i;
|
||||
for (i = local_interfaces; i; i = i->next)
|
||||
@ -279,7 +314,8 @@ BOOL is_local_net(struct in_addr from)
|
||||
/****************************************************************************
|
||||
how many interfaces do we have
|
||||
**************************************************************************/
|
||||
int iface_count(void)
|
||||
int
|
||||
iface_count (void)
|
||||
{
|
||||
int ret = 0;
|
||||
struct interface *i;
|
||||
@ -292,7 +328,8 @@ int iface_count(void)
|
||||
/****************************************************************************
|
||||
True if we have two or more interfaces.
|
||||
**************************************************************************/
|
||||
BOOL we_are_multihomed(void)
|
||||
BOOL
|
||||
we_are_multihomed (void)
|
||||
{
|
||||
static int multi = -1;
|
||||
|
||||
@ -305,41 +342,48 @@ BOOL we_are_multihomed(void)
|
||||
/****************************************************************************
|
||||
return the Nth interface
|
||||
**************************************************************************/
|
||||
struct interface *get_interface(int n)
|
||||
struct interface *
|
||||
get_interface (int n)
|
||||
{
|
||||
struct interface *i;
|
||||
|
||||
for (i = local_interfaces; i && n; i = i->next)
|
||||
n--;
|
||||
|
||||
if (i) return i;
|
||||
if (i)
|
||||
return i;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
return IP of the Nth interface
|
||||
**************************************************************************/
|
||||
struct in_addr *iface_n_ip(int n)
|
||||
struct in_addr *
|
||||
iface_n_ip (int n)
|
||||
{
|
||||
struct interface *i;
|
||||
|
||||
for (i = local_interfaces; i && n; i = i->next)
|
||||
n--;
|
||||
|
||||
if (i) return &i->ip;
|
||||
if (i)
|
||||
return &i->ip;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Try and find an interface that matches an ip. If we cannot, return NULL
|
||||
**************************************************************************/
|
||||
static struct interface *iface_find(struct in_addr ip)
|
||||
static struct interface *
|
||||
iface_find (struct in_addr ip)
|
||||
{
|
||||
struct interface *i;
|
||||
if (zero_ip(ip)) return local_interfaces;
|
||||
if (zero_ip (ip))
|
||||
return local_interfaces;
|
||||
|
||||
for (i = local_interfaces; i; i = i->next)
|
||||
if (same_net(i->ip,ip,i->nmask)) return i;
|
||||
if (same_net (i->ip, ip, i->nmask))
|
||||
return i;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -351,12 +395,14 @@ used to detect a change in interfaces to tell us whether to discard
|
||||
the current wins.dat file.
|
||||
Note that the result is independent of the order of the interfaces
|
||||
**************************************************************************/
|
||||
unsigned iface_hash(void)
|
||||
unsigned
|
||||
iface_hash (void)
|
||||
{
|
||||
unsigned ret = 0;
|
||||
struct interface *i;
|
||||
|
||||
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));
|
||||
ret ^= (x1 ^ x2);
|
||||
@ -371,17 +417,16 @@ unsigned iface_hash(void)
|
||||
an appropriate interface they return the requested field of the
|
||||
first known interface. */
|
||||
|
||||
struct in_addr *iface_bcast(struct in_addr ip)
|
||||
struct in_addr *
|
||||
iface_bcast (struct in_addr ip)
|
||||
{
|
||||
struct interface *i = iface_find (ip);
|
||||
return (i ? &i->bcast : &local_interfaces->bcast);
|
||||
}
|
||||
|
||||
struct in_addr *iface_ip(struct in_addr ip)
|
||||
struct in_addr *
|
||||
iface_ip (struct in_addr ip)
|
||||
{
|
||||
struct interface *i = iface_find (ip);
|
||||
return (i ? &i->ip : &local_interfaces->ip);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -33,22 +33,26 @@
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static uint32 H(uint32 X, uint32 Y, uint32 Z)
|
||||
static uint32
|
||||
H (uint32 X, uint32 Y, uint32 Z)
|
||||
{
|
||||
return X ^ Y ^ Z;
|
||||
}
|
||||
|
||||
static uint32 lshift(uint32 x, int s)
|
||||
static uint32
|
||||
lshift (uint32 x, int s)
|
||||
{
|
||||
x &= 0xFFFFFFFF;
|
||||
return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
|
||||
@ -59,7 +63,8 @@ static uint32 lshift(uint32 x, int s)
|
||||
#define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + (uint32)0x6ED9EBA1,s)
|
||||
|
||||
/* this applies md4 to 64 byte chunks */
|
||||
static void mdfour64(uint32 *M)
|
||||
static void
|
||||
mdfour64 (uint32 * M)
|
||||
{
|
||||
int j;
|
||||
uint32 AA, BB, CC, DD;
|
||||
@ -68,45 +73,78 @@ static void mdfour64(uint32 *M)
|
||||
for (j = 0; j < 16; j++)
|
||||
X[j] = M[j];
|
||||
|
||||
AA = A; BB = B; CC = C; DD = D;
|
||||
AA = A;
|
||||
BB = B;
|
||||
CC = C;
|
||||
DD = D;
|
||||
|
||||
ROUND1(A,B,C,D, 0, 3); ROUND1(D,A,B,C, 1, 7);
|
||||
ROUND1(C,D,A,B, 2, 11); ROUND1(B,C,D,A, 3, 19);
|
||||
ROUND1(A,B,C,D, 4, 3); ROUND1(D,A,B,C, 5, 7);
|
||||
ROUND1(C,D,A,B, 6, 11); ROUND1(B,C,D,A, 7, 19);
|
||||
ROUND1(A,B,C,D, 8, 3); ROUND1(D,A,B,C, 9, 7);
|
||||
ROUND1(C,D,A,B, 10, 11); ROUND1(B,C,D,A, 11, 19);
|
||||
ROUND1(A,B,C,D, 12, 3); ROUND1(D,A,B,C, 13, 7);
|
||||
ROUND1(C,D,A,B, 14, 11); ROUND1(B,C,D,A, 15, 19);
|
||||
ROUND1 (A, B, C, D, 0, 3);
|
||||
ROUND1 (D, A, B, C, 1, 7);
|
||||
ROUND1 (C, D, A, B, 2, 11);
|
||||
ROUND1 (B, C, D, A, 3, 19);
|
||||
ROUND1 (A, B, C, D, 4, 3);
|
||||
ROUND1 (D, A, B, C, 5, 7);
|
||||
ROUND1 (C, D, A, B, 6, 11);
|
||||
ROUND1 (B, C, D, A, 7, 19);
|
||||
ROUND1 (A, B, C, D, 8, 3);
|
||||
ROUND1 (D, A, B, C, 9, 7);
|
||||
ROUND1 (C, D, A, B, 10, 11);
|
||||
ROUND1 (B, C, D, A, 11, 19);
|
||||
ROUND1 (A, B, C, D, 12, 3);
|
||||
ROUND1 (D, A, B, C, 13, 7);
|
||||
ROUND1 (C, D, A, B, 14, 11);
|
||||
ROUND1 (B, C, D, A, 15, 19);
|
||||
|
||||
ROUND2(A,B,C,D, 0, 3); ROUND2(D,A,B,C, 4, 5);
|
||||
ROUND2(C,D,A,B, 8, 9); ROUND2(B,C,D,A, 12, 13);
|
||||
ROUND2(A,B,C,D, 1, 3); ROUND2(D,A,B,C, 5, 5);
|
||||
ROUND2(C,D,A,B, 9, 9); ROUND2(B,C,D,A, 13, 13);
|
||||
ROUND2(A,B,C,D, 2, 3); ROUND2(D,A,B,C, 6, 5);
|
||||
ROUND2(C,D,A,B, 10, 9); ROUND2(B,C,D,A, 14, 13);
|
||||
ROUND2(A,B,C,D, 3, 3); ROUND2(D,A,B,C, 7, 5);
|
||||
ROUND2(C,D,A,B, 11, 9); ROUND2(B,C,D,A, 15, 13);
|
||||
ROUND2 (A, B, C, D, 0, 3);
|
||||
ROUND2 (D, A, B, C, 4, 5);
|
||||
ROUND2 (C, D, A, B, 8, 9);
|
||||
ROUND2 (B, C, D, A, 12, 13);
|
||||
ROUND2 (A, B, C, D, 1, 3);
|
||||
ROUND2 (D, A, B, C, 5, 5);
|
||||
ROUND2 (C, D, A, B, 9, 9);
|
||||
ROUND2 (B, C, D, A, 13, 13);
|
||||
ROUND2 (A, B, C, D, 2, 3);
|
||||
ROUND2 (D, A, B, C, 6, 5);
|
||||
ROUND2 (C, D, A, B, 10, 9);
|
||||
ROUND2 (B, C, D, A, 14, 13);
|
||||
ROUND2 (A, B, C, D, 3, 3);
|
||||
ROUND2 (D, A, B, C, 7, 5);
|
||||
ROUND2 (C, D, A, B, 11, 9);
|
||||
ROUND2 (B, C, D, A, 15, 13);
|
||||
|
||||
ROUND3(A,B,C,D, 0, 3); ROUND3(D,A,B,C, 8, 9);
|
||||
ROUND3(C,D,A,B, 4, 11); ROUND3(B,C,D,A, 12, 15);
|
||||
ROUND3(A,B,C,D, 2, 3); ROUND3(D,A,B,C, 10, 9);
|
||||
ROUND3(C,D,A,B, 6, 11); ROUND3(B,C,D,A, 14, 15);
|
||||
ROUND3(A,B,C,D, 1, 3); ROUND3(D,A,B,C, 9, 9);
|
||||
ROUND3(C,D,A,B, 5, 11); ROUND3(B,C,D,A, 13, 15);
|
||||
ROUND3(A,B,C,D, 3, 3); ROUND3(D,A,B,C, 11, 9);
|
||||
ROUND3(C,D,A,B, 7, 11); ROUND3(B,C,D,A, 15, 15);
|
||||
ROUND3 (A, B, C, D, 0, 3);
|
||||
ROUND3 (D, A, B, C, 8, 9);
|
||||
ROUND3 (C, D, A, B, 4, 11);
|
||||
ROUND3 (B, C, D, A, 12, 15);
|
||||
ROUND3 (A, B, C, D, 2, 3);
|
||||
ROUND3 (D, A, B, C, 10, 9);
|
||||
ROUND3 (C, D, A, B, 6, 11);
|
||||
ROUND3 (B, C, D, A, 14, 15);
|
||||
ROUND3 (A, B, C, D, 1, 3);
|
||||
ROUND3 (D, A, B, C, 9, 9);
|
||||
ROUND3 (C, D, A, B, 5, 11);
|
||||
ROUND3 (B, C, D, A, 13, 15);
|
||||
ROUND3 (A, B, C, D, 3, 3);
|
||||
ROUND3 (D, A, B, C, 11, 9);
|
||||
ROUND3 (C, D, A, B, 7, 11);
|
||||
ROUND3 (B, C, D, A, 15, 15);
|
||||
|
||||
A += AA; B += BB; C += CC; D += DD;
|
||||
A += AA;
|
||||
B += BB;
|
||||
C += CC;
|
||||
D += DD;
|
||||
|
||||
A &= 0xFFFFFFFF; B &= 0xFFFFFFFF;
|
||||
C &= 0xFFFFFFFF; D &= 0xFFFFFFFF;
|
||||
A &= 0xFFFFFFFF;
|
||||
B &= 0xFFFFFFFF;
|
||||
C &= 0xFFFFFFFF;
|
||||
D &= 0xFFFFFFFF;
|
||||
|
||||
for (j = 0; j < 16; j++)
|
||||
X[j] = 0;
|
||||
}
|
||||
|
||||
static void copy64(uint32 *M, unsigned char *in)
|
||||
static void
|
||||
copy64 (uint32 * M, unsigned char *in)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -115,7 +153,8 @@ static void copy64(uint32 *M, unsigned char *in)
|
||||
(in[i * 4 + 1] << 8) | (in[i * 4 + 0] << 0);
|
||||
}
|
||||
|
||||
static void copy4(unsigned char *out,uint32 x)
|
||||
static void
|
||||
copy4 (unsigned char *out, uint32 x)
|
||||
{
|
||||
out[0] = x & 0xFF;
|
||||
out[1] = (x >> 8) & 0xFF;
|
||||
@ -124,7 +163,8 @@ static void copy4(unsigned char *out,uint32 x)
|
||||
}
|
||||
|
||||
/* produce a md4 message digest from data of length n bytes */
|
||||
void mdfour(unsigned char *out, unsigned char *in, int n)
|
||||
void
|
||||
mdfour (unsigned char *out, unsigned char *in, int n)
|
||||
{
|
||||
unsigned char buf[128];
|
||||
uint32 M[16];
|
||||
@ -136,7 +176,8 @@ void mdfour(unsigned char *out, unsigned char *in, int n)
|
||||
C = 0x98badcfe;
|
||||
D = 0x10325476;
|
||||
|
||||
while (n > 64) {
|
||||
while (n > 64)
|
||||
{
|
||||
copy64 (M, in);
|
||||
mdfour64 (M);
|
||||
in += 64;
|
||||
@ -148,11 +189,14 @@ void mdfour(unsigned char *out, unsigned char *in, int n)
|
||||
memcpy (buf, in, n);
|
||||
buf[n] = 0x80;
|
||||
|
||||
if (n <= 55) {
|
||||
if (n <= 55)
|
||||
{
|
||||
copy4 (buf + 56, b);
|
||||
copy64 (M, buf);
|
||||
mdfour64 (M);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
copy4 (buf + 120, b);
|
||||
copy64 (M, buf);
|
||||
mdfour64 (M);
|
||||
@ -171,5 +215,3 @@ void mdfour(unsigned char *out, unsigned char *in, int n)
|
||||
|
||||
A = B = C = D = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -68,14 +68,16 @@ int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask);
|
||||
/****************************************************************************
|
||||
get the netmask address for a local interface
|
||||
****************************************************************************/
|
||||
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
int
|
||||
get_netmask (struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
{
|
||||
struct ifconf ifc;
|
||||
char buff[2048];
|
||||
int fd, i, n;
|
||||
struct ifreq *ifr = NULL;
|
||||
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "socket failed\n");
|
||||
#endif
|
||||
@ -84,7 +86,8 @@ int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
|
||||
ifc.ifc_len = sizeof (buff);
|
||||
ifc.ifc_buf = buff;
|
||||
if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) {
|
||||
if (ioctl (fd, SIOCGIFCONF, &ifc) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "SIOCGIFCONF failed\n");
|
||||
#endif
|
||||
@ -97,13 +100,14 @@ int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
n = ifc.ifc_len / sizeof (struct ifreq);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"%d interfaces - looking for %s\n",
|
||||
n, inet_ntoa(*ipaddr));
|
||||
fprintf (stderr, "%d interfaces - looking for %s\n", n, inet_ntoa (*ipaddr));
|
||||
#endif
|
||||
|
||||
/* Loop through interfaces, looking for given IP address */
|
||||
for (i=n-1;i>=0;i--) {
|
||||
if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) {
|
||||
for (i = n - 1; i >= 0; i--)
|
||||
{
|
||||
if (ioctl (fd, SIOCGIFADDR, &ifr[i]) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "SIOCGIFADDR failed\n");
|
||||
#endif
|
||||
@ -114,12 +118,13 @@ int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
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) {
|
||||
if (ipaddr->s_addr != (*(struct sockaddr_in *) &ifr[i].ifr_addr).sin_addr.s_addr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) {
|
||||
if (ioctl (fd, SIOCGIFNETMASK, &ifr[i]) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "SIOCGIFNETMASK failed\n");
|
||||
#endif
|
||||
@ -165,7 +170,8 @@ int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
/****************************************************************************
|
||||
this should cover most of the rest of systems
|
||||
****************************************************************************/
|
||||
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
int
|
||||
get_netmask (struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
{
|
||||
struct ifreq ifreq;
|
||||
struct strioctl strioctl;
|
||||
@ -174,7 +180,8 @@ this should cover most of the rest of systems
|
||||
int fd, i, n;
|
||||
struct ifreq *ifr = NULL;
|
||||
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "socket failed\n");
|
||||
#endif
|
||||
@ -186,7 +193,8 @@ this should cover most of the rest of systems
|
||||
strioctl.ic_cmd = SIOCGIFCONF;
|
||||
strioctl.ic_dp = (char *) ifc;
|
||||
strioctl.ic_len = sizeof (buff);
|
||||
if (ioctl(fd, I_STR, &strioctl) < 0) {
|
||||
if (ioctl (fd, I_STR, &strioctl) < 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "SIOCGIFCONF failed\n");
|
||||
#endif
|
||||
@ -199,19 +207,21 @@ this should cover most of the rest of systems
|
||||
/* Loop through interfaces, looking for given IP address */
|
||||
n = ifc->ifc_len / sizeof (struct ifreq);
|
||||
|
||||
for (i = 0; i<n; i++, ifr++) {
|
||||
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) {
|
||||
if (ipaddr->s_addr == (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (i == n) {
|
||||
if (i == n)
|
||||
{
|
||||
fprintf (stderr, "interface not found\n");
|
||||
close (fd);
|
||||
return -1;
|
||||
@ -223,7 +233,8 @@ this should cover most of the rest of systems
|
||||
strioctl.ic_cmd = SIOCGIFNETMASK;
|
||||
strioctl.ic_dp = (char *) &ifreq;
|
||||
strioctl.ic_len = sizeof (struct ifreq);
|
||||
if (ioctl(fd, I_STR, &strioctl) != 0) {
|
||||
if (ioctl (fd, I_STR, &strioctl) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "Failed SIOCGIFNETMASK\n");
|
||||
#endif
|
||||
@ -265,14 +276,16 @@ int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask);
|
||||
this one is for AIX
|
||||
****************************************************************************/
|
||||
|
||||
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
int
|
||||
get_netmask (struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
{
|
||||
char buff[2048];
|
||||
int fd, i;
|
||||
struct ifconf ifc;
|
||||
struct ifreq *ifr = NULL;
|
||||
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "socket failed\n");
|
||||
#endif
|
||||
@ -283,7 +296,8 @@ this one is for AIX
|
||||
ifc.ifc_len = sizeof (buff);
|
||||
ifc.ifc_buf = buff;
|
||||
|
||||
if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) {
|
||||
if (ioctl (fd, SIOCGIFCONF, &ifc) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "SIOCGIFCONF failed\n");
|
||||
#endif
|
||||
@ -294,30 +308,32 @@ this one is for AIX
|
||||
ifr = ifc.ifc_req;
|
||||
/* Loop through interfaces, looking for given IP address */
|
||||
i = ifc.ifc_len;
|
||||
while (i > 0) {
|
||||
while (i > 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "interface %s\n",
|
||||
inet_ntoa ((*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr));
|
||||
#endif
|
||||
if (ipaddr->s_addr ==
|
||||
(*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr) {
|
||||
if (ipaddr->s_addr == (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr.s_addr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
i -= ifr->ifr_addr.sa_len + IFNAMSIZ;
|
||||
ifr = (struct ifreq*) ((char*) ifr + ifr->ifr_addr.sa_len +
|
||||
IFNAMSIZ);
|
||||
ifr = (struct ifreq *) ((char *) ifr + ifr->ifr_addr.sa_len + IFNAMSIZ);
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
if (i <= 0) {
|
||||
if (i <= 0)
|
||||
{
|
||||
fprintf (stderr, "interface not found\n");
|
||||
close (fd);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) {
|
||||
if (ioctl (fd, SIOCGIFNETMASK, ifr) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "SIOCGIFNETMASK failed\n");
|
||||
#endif
|
||||
@ -337,7 +353,8 @@ this one is for AIX
|
||||
#else /* a dummy version */
|
||||
struct in_addr; /* it may not have been declared before */
|
||||
int get_netmask (struct in_addr *ipaddr, struct in_addr *nmask);
|
||||
int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
int
|
||||
get_netmask (struct in_addr *ipaddr, struct in_addr *nmask)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -353,21 +370,24 @@ int get_netmask(struct in_addr *ipaddr, struct in_addr *nmask);
|
||||
struct hostent *hp;
|
||||
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);
|
||||
}
|
||||
|
||||
hp = gethostbyname (buf);
|
||||
|
||||
if (!hp) {
|
||||
if (!hp)
|
||||
{
|
||||
fprintf (stderr, "gethostbyname failed\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
memcpy ((char *) &ip, (char *) hp->h_addr, hp->h_length);
|
||||
|
||||
if (get_netmask(&ip, &nmask) == 0) exit(0);
|
||||
if (get_netmask (&ip, &nmask) == 0)
|
||||
exit (0);
|
||||
|
||||
fprintf (stderr, "get_netmask failed\n");
|
||||
exit (1);
|
||||
|
@ -32,10 +32,12 @@ extern int DEBUGLEVEL;
|
||||
/* this is like vsnprintf but the 'n' limit does not include
|
||||
the terminating null. So if you have a 1024 byte buffer then
|
||||
pass 1023 for n */
|
||||
int vslprintf(char *str, int n, const char *format, va_list ap)
|
||||
int
|
||||
vslprintf (char *str, int n, const char *format, va_list ap)
|
||||
{
|
||||
int ret = vsnprintf (str, n, format, ap);
|
||||
if (ret > n || ret < 0) {
|
||||
if (ret > n || ret < 0)
|
||||
{
|
||||
str[n] = 0;
|
||||
return -1;
|
||||
}
|
||||
@ -44,10 +46,12 @@ int vslprintf(char *str, int n, const char *format, va_list ap)
|
||||
}
|
||||
|
||||
#ifdef HAVE_STDARG_H
|
||||
int slprintf(char *str, int n, const char *format, ...)
|
||||
int
|
||||
slprintf (char *str, int n, const char *format, ...)
|
||||
{
|
||||
#else
|
||||
int slprintf(va_alist)
|
||||
int
|
||||
slprintf (va_alist)
|
||||
va_dcl
|
||||
{
|
||||
char *str, *format;
|
||||
|
@ -50,7 +50,8 @@ return if some data has arrived on one of the file descriptors
|
||||
return -1 means error
|
||||
********************************************************************/
|
||||
#ifndef HAVE_SELECT
|
||||
static int pollfd(int fd)
|
||||
static int
|
||||
pollfd (int fd)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
@ -65,7 +66,8 @@ static int pollfd(int fd)
|
||||
return (r);
|
||||
}
|
||||
|
||||
int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
|
||||
int
|
||||
sys_select (int maxfd, fd_set * fds, struct timeval *tval)
|
||||
{
|
||||
fd_set fds2;
|
||||
int counter = 0;
|
||||
@ -76,26 +78,31 @@ int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
|
||||
while (1)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<maxfd;i++) {
|
||||
if (FD_ISSET(i,fds) && pollfd(i)>0) {
|
||||
for (i = 0; i < maxfd; i++)
|
||||
{
|
||||
if (FD_ISSET (i, fds) && pollfd (i) > 0)
|
||||
{
|
||||
found++;
|
||||
FD_SET (i, &fds2);
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
if (found)
|
||||
{
|
||||
memcpy ((void *) fds, (void *) &fds2, sizeof (fds2));
|
||||
return (found);
|
||||
}
|
||||
|
||||
if (tval && tval->tv_sec < counter) return(0);
|
||||
if (tval && tval->tv_sec < counter)
|
||||
return (0);
|
||||
sleep (1);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
#else /* !NO_SELECT */
|
||||
int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
|
||||
int
|
||||
sys_select (int maxfd, fd_set * fds, struct timeval *tval)
|
||||
{
|
||||
#ifdef USE_POLL
|
||||
struct pollfd pfd[256];
|
||||
@ -105,8 +112,10 @@ int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
|
||||
int pollrtn;
|
||||
|
||||
maxpoll = 0;
|
||||
for( i = 0; i < maxfd; i++) {
|
||||
if(FD_ISSET(i,fds)) {
|
||||
for (i = 0; i < maxfd; i++)
|
||||
{
|
||||
if (FD_ISSET (i, fds))
|
||||
{
|
||||
struct pollfd *pfdp = &pfd[maxpoll++];
|
||||
pfdp->fd = i;
|
||||
pfdp->events = POLLIN;
|
||||
@ -114,12 +123,13 @@ int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
|
||||
}
|
||||
}
|
||||
|
||||
timeout = (tval != NULL) ? (tval->tv_sec * 1000) + (tval->tv_usec/1000) :
|
||||
-1;
|
||||
timeout = (tval != NULL) ? (tval->tv_sec * 1000) + (tval->tv_usec / 1000) : -1;
|
||||
errno = 0;
|
||||
do {
|
||||
do
|
||||
{
|
||||
pollrtn = poll (&pfd[0], maxpoll, timeout);
|
||||
} while (pollrtn<0 && errno == EINTR);
|
||||
}
|
||||
while (pollrtn < 0 && errno == EINTR);
|
||||
|
||||
FD_ZERO (fds);
|
||||
|
||||
@ -133,11 +143,14 @@ int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
|
||||
struct timeval t2;
|
||||
int selrtn;
|
||||
|
||||
do {
|
||||
if (tval) memcpy((void *)&t2,(void *)tval,sizeof(t2));
|
||||
do
|
||||
{
|
||||
if (tval)
|
||||
memcpy ((void *) &t2, (void *) tval, sizeof (t2));
|
||||
errno = 0;
|
||||
selrtn = select (maxfd, SELECT_CAST fds, NULL, NULL, tval ? &t2 : NULL);
|
||||
} while (selrtn<0 && errno == EINTR);
|
||||
}
|
||||
while (selrtn < 0 && errno == EINTR);
|
||||
|
||||
return (selrtn);
|
||||
}
|
||||
@ -148,7 +161,8 @@ int sys_select(int maxfd, fd_set *fds,struct timeval *tval)
|
||||
A stat() wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
|
||||
int sys_stat(const char *fname,SMB_STRUCT_STAT *sbuf)
|
||||
int
|
||||
sys_stat (const char *fname, SMB_STRUCT_STAT * sbuf)
|
||||
{
|
||||
return stat (fname, sbuf);
|
||||
}
|
||||
@ -157,7 +171,8 @@ int sys_stat(const char *fname,SMB_STRUCT_STAT *sbuf)
|
||||
An lstat() wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
#if 0
|
||||
int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf)
|
||||
int
|
||||
sys_lstat (const char *fname, SMB_STRUCT_STAT * sbuf)
|
||||
{
|
||||
return lstat (fname, sbuf);
|
||||
}
|
||||
@ -166,7 +181,8 @@ int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf)
|
||||
An fseek() wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
|
||||
int sys_fseek(FILE *fp, SMB_OFF_T offset, int whence)
|
||||
int
|
||||
sys_fseek (FILE * fp, SMB_OFF_T offset, int whence)
|
||||
{
|
||||
return fseek (fp, offset, whence);
|
||||
}
|
||||
@ -175,7 +191,8 @@ int sys_fseek(FILE *fp, SMB_OFF_T offset, int whence)
|
||||
An ftell() wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
|
||||
SMB_OFF_T sys_ftell(FILE *fp)
|
||||
SMB_OFF_T
|
||||
sys_ftell (FILE * fp)
|
||||
{
|
||||
return (SMB_OFF_T) ftell (fp);
|
||||
}
|
||||
@ -184,7 +201,8 @@ SMB_OFF_T sys_ftell(FILE *fp)
|
||||
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);
|
||||
}
|
||||
@ -193,16 +211,19 @@ int sys_open(const char *path, int oflag, mode_t mode)
|
||||
An fopen() wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
|
||||
FILE *sys_fopen(const char *path, const char *type)
|
||||
FILE *
|
||||
sys_fopen (const char *path, const char *type)
|
||||
{
|
||||
return fopen (path, type);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*******************************************************************
|
||||
A readdir wrapper that will deal with 64 bit filesizes.
|
||||
********************************************************************/
|
||||
|
||||
SMB_STRUCT_DIRENT *sys_readdir(DIR *dirp)
|
||||
SMB_STRUCT_DIRENT *
|
||||
sys_readdir (DIR * dirp)
|
||||
{
|
||||
return readdir (dirp);
|
||||
}
|
||||
@ -210,7 +231,8 @@ SMB_STRUCT_DIRENT *sys_readdir(DIR *dirp)
|
||||
/*******************************************************************
|
||||
system wrapper for getwd
|
||||
********************************************************************/
|
||||
char *sys_getwd(char *s)
|
||||
char *
|
||||
sys_getwd (char *s)
|
||||
{
|
||||
char *wd;
|
||||
#ifdef HAVE_GETCWD
|
||||
@ -225,11 +247,13 @@ char *sys_getwd(char *s)
|
||||
chown isn't used much but OS/2 doesn't have it
|
||||
********************************************************************/
|
||||
|
||||
int sys_chown(const char *fname,uid_t uid,gid_t gid)
|
||||
int
|
||||
sys_chown (const char *fname, uid_t uid, gid_t gid)
|
||||
{
|
||||
#ifndef HAVE_CHOWN
|
||||
static int done;
|
||||
if (!done) {
|
||||
if (!done)
|
||||
{
|
||||
DEBUG (1, ("WARNING: no chown!\n"));
|
||||
done = 1;
|
||||
}
|
||||
@ -243,7 +267,8 @@ A wrapper for gethostbyname() that tries avoids looking up hostnames
|
||||
in the root domain, which can cause dial-on-demand links to come up for no
|
||||
apparent reason.
|
||||
****************************************************************************/
|
||||
struct hostent *sys_gethostbyname(const char *name)
|
||||
struct hostent *
|
||||
sys_gethostbyname (const char *name)
|
||||
{
|
||||
#ifdef REDUCE_ROOT_DNS_LOOKUPS
|
||||
char query[256], hostname[256];
|
||||
@ -283,7 +308,8 @@ struct hostent *sys_gethostbyname(const char *name)
|
||||
Wrapper for random().
|
||||
****************************************************************************/
|
||||
#if 0
|
||||
long sys_random(void)
|
||||
long
|
||||
sys_random (void)
|
||||
{
|
||||
#if defined(HAVE_RANDOM)
|
||||
return (long) random ();
|
||||
@ -299,7 +325,8 @@ long sys_random(void)
|
||||
Wrapper for srandom().
|
||||
****************************************************************************/
|
||||
|
||||
void sys_srandom(unsigned int seed)
|
||||
void
|
||||
sys_srandom (unsigned int seed)
|
||||
{
|
||||
#if defined(HAVE_SRANDOM)
|
||||
srandom (seed);
|
||||
|
@ -54,7 +54,8 @@ extern int DEBUGLEVEL;
|
||||
/*******************************************************************
|
||||
a gettimeofday wrapper
|
||||
********************************************************************/
|
||||
void GetTimeOfDay(struct timeval *tval)
|
||||
void
|
||||
GetTimeOfDay (struct timeval *tval)
|
||||
{
|
||||
#ifdef HAVE_GETTIMEOFDAY_TZ
|
||||
gettimeofday (tval, NULL);
|
||||
@ -68,12 +69,12 @@ void GetTimeOfDay(struct timeval *tval)
|
||||
/*******************************************************************
|
||||
yield the difference between *A and *B, in seconds, ignoring leap seconds
|
||||
********************************************************************/
|
||||
static int tm_diff(struct tm *a, struct tm *b)
|
||||
static int
|
||||
tm_diff (struct tm *a, struct tm *b)
|
||||
{
|
||||
int ay = a->tm_year + (TM_YEAR_BASE - 1);
|
||||
int by = b->tm_year + (TM_YEAR_BASE - 1);
|
||||
int intervening_leap_days =
|
||||
(ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400);
|
||||
int intervening_leap_days = (ay / 4 - by / 4) - (ay / 100 - by / 100) + (ay / 400 - by / 400);
|
||||
int years = ay - by;
|
||||
int days = 365 * years + intervening_leap_days + (a->tm_yday - b->tm_yday);
|
||||
int hours = 24 * days + (a->tm_hour - b->tm_hour);
|
||||
@ -86,7 +87,8 @@ static int tm_diff(struct tm *a, struct tm *b)
|
||||
/*******************************************************************
|
||||
return the UTC offset in seconds west of UTC, or 0 if it cannot be determined
|
||||
******************************************************************/
|
||||
static int TimeZone(time_t t)
|
||||
static int
|
||||
TimeZone (time_t t)
|
||||
{
|
||||
struct tm *tm = gmtime (&t);
|
||||
struct tm tm_utc;
|
||||
@ -104,11 +106,13 @@ static int TimeZone(time_t t)
|
||||
/*******************************************************************
|
||||
init the time differences
|
||||
********************************************************************/
|
||||
void TimeInit(void)
|
||||
void
|
||||
TimeInit (void)
|
||||
{
|
||||
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"));
|
||||
}
|
||||
|
||||
@ -124,33 +128,45 @@ call of this function. This saves a LOT of time on many unixes.
|
||||
|
||||
Updated by Paul Eggert <eggert@twinsun.com>
|
||||
********************************************************************/
|
||||
static int TimeZoneFaster(time_t t)
|
||||
static int
|
||||
TimeZoneFaster (time_t t)
|
||||
{
|
||||
static struct dst_table {time_t start,end; int zone;} *dst_table = NULL;
|
||||
static struct dst_table
|
||||
{
|
||||
time_t start, end;
|
||||
int zone;
|
||||
} *dst_table = NULL;
|
||||
static int table_size = 0;
|
||||
int i;
|
||||
int zone = 0;
|
||||
|
||||
if (t == 0) t = time(NULL);
|
||||
if (t == 0)
|
||||
t = time (NULL);
|
||||
|
||||
/* Tunis has a 8 day DST region, we need to be careful ... */
|
||||
#define MAX_DST_WIDTH (365*24*60*60)
|
||||
#define MAX_DST_SKIP (7*24*60*60)
|
||||
|
||||
for (i = 0; i < table_size; i++)
|
||||
if (t >= dst_table[i].start && t <= dst_table[i].end) break;
|
||||
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 {
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t low, high;
|
||||
|
||||
zone = TimeZone (t);
|
||||
dst_table = (struct dst_table *)Realloc(dst_table,
|
||||
sizeof(dst_table[0])*(i+1));
|
||||
if (!dst_table) {
|
||||
dst_table = (struct dst_table *) Realloc (dst_table, sizeof (dst_table[0]) * (i + 1));
|
||||
if (!dst_table)
|
||||
{
|
||||
table_size = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
table_size++;
|
||||
|
||||
dst_table[i].zone = zone;
|
||||
@ -166,7 +182,8 @@ static int TimeZoneFaster(time_t t)
|
||||
high = TIME_T_MAX;
|
||||
|
||||
/* widen the new entry using two bisection searches */
|
||||
while (low+60*60 < dst_table[i].start) {
|
||||
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
|
||||
@ -177,7 +194,8 @@ static int TimeZoneFaster(time_t t)
|
||||
low = t;
|
||||
}
|
||||
|
||||
while (high-60*60 > dst_table[i].end) {
|
||||
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
|
||||
@ -188,10 +206,8 @@ static int TimeZoneFaster(time_t t)
|
||||
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));
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -201,7 +217,8 @@ static int TimeZoneFaster(time_t t)
|
||||
/****************************************************************************
|
||||
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;
|
||||
}
|
||||
@ -214,7 +231,8 @@ int TimeDiff(time_t t)
|
||||
daylight savings transitions because some local times are ambiguous.
|
||||
LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions.
|
||||
+**************************************************************************/
|
||||
static int LocTimeDiff(time_t lte)
|
||||
static int
|
||||
LocTimeDiff (time_t lte)
|
||||
{
|
||||
time_t lt = lte - 60 * extra_time_offset;
|
||||
int d = TimeZoneFaster (lt);
|
||||
@ -232,7 +250,8 @@ static int LocTimeDiff(time_t lte)
|
||||
/****************************************************************************
|
||||
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;
|
||||
|
||||
@ -252,7 +271,8 @@ its the GMT you get by taking a localtime and adding the
|
||||
serverzone. This is NOT the same as GMT in some cases. This routine
|
||||
converts this to real GMT.
|
||||
****************************************************************************/
|
||||
time_t nt_time_to_unix(NTTIME *nt)
|
||||
time_t
|
||||
nt_time_to_unix (NTTIME * nt)
|
||||
{
|
||||
double d;
|
||||
time_t ret;
|
||||
@ -261,7 +281,8 @@ time_t nt_time_to_unix(NTTIME *nt)
|
||||
time_t l_time_min = TIME_T_MIN;
|
||||
time_t l_time_max = TIME_T_MAX;
|
||||
|
||||
if (nt->high == 0) return(0);
|
||||
if (nt->high == 0)
|
||||
return (0);
|
||||
|
||||
d = ((double) nt->high) * 4.0 * (double) (1 << 30);
|
||||
d += (nt->low & 0xFFF00000);
|
||||
@ -287,7 +308,8 @@ time_t nt_time_to_unix(NTTIME *nt)
|
||||
/****************************************************************************
|
||||
interprets an nt time into a unix time_t
|
||||
****************************************************************************/
|
||||
time_t interpret_long_date(char *p)
|
||||
time_t
|
||||
interpret_long_date (char *p)
|
||||
{
|
||||
NTTIME nt;
|
||||
nt.low = IVAL (p, 0);
|
||||
@ -299,7 +321,8 @@ time_t interpret_long_date(char *p)
|
||||
put a 8 byte filetime from a time_t
|
||||
This takes real GMT as input and converts to kludge-GMT
|
||||
****************************************************************************/
|
||||
void unix_to_nt_time(NTTIME *nt, time_t t)
|
||||
void
|
||||
unix_to_nt_time (NTTIME * nt, time_t t)
|
||||
{
|
||||
double d;
|
||||
|
||||
@ -326,7 +349,8 @@ void unix_to_nt_time(NTTIME *nt, time_t t)
|
||||
take an NTTIME structure, containing high / low time. convert to unix time.
|
||||
lkclXXXX this may need 2 SIVALs not a memcpy. we'll see...
|
||||
****************************************************************************/
|
||||
void put_long_date(char *p,time_t t)
|
||||
void
|
||||
put_long_date (char *p, time_t t)
|
||||
{
|
||||
NTTIME nt;
|
||||
unix_to_nt_time (&nt, t);
|
||||
@ -337,7 +361,8 @@ void put_long_date(char *p,time_t t)
|
||||
/****************************************************************************
|
||||
check if it's a null mtime
|
||||
****************************************************************************/
|
||||
BOOL null_mtime(time_t mtime)
|
||||
BOOL
|
||||
null_mtime (time_t mtime)
|
||||
{
|
||||
if (mtime == (time_t) 0 || mtime == (time_t) 0xFFFFFFFF || mtime == (time_t) - 1)
|
||||
return (True);
|
||||
@ -347,7 +372,8 @@ BOOL null_mtime(time_t mtime)
|
||||
/*******************************************************************
|
||||
create a 16 bit dos packed date
|
||||
********************************************************************/
|
||||
static uint16 make_dos_date1(struct tm *t)
|
||||
static uint16
|
||||
make_dos_date1 (struct tm *t)
|
||||
{
|
||||
uint16 ret = 0;
|
||||
ret = (((unsigned) (t->tm_mon + 1)) >> 3) | ((t->tm_year - 80) << 1);
|
||||
@ -358,7 +384,8 @@ static uint16 make_dos_date1(struct tm *t)
|
||||
/*******************************************************************
|
||||
create a 16 bit dos packed time
|
||||
********************************************************************/
|
||||
static uint16 make_dos_time1(struct tm *t)
|
||||
static uint16
|
||||
make_dos_time1 (struct tm *t)
|
||||
{
|
||||
uint16 ret = 0;
|
||||
ret = ((((unsigned) t->tm_min >> 3) & 0x7) | (((unsigned) t->tm_hour) << 3));
|
||||
@ -370,7 +397,8 @@ static uint16 make_dos_time1(struct tm *t)
|
||||
create a 32 bit dos packed date/time from some parameters
|
||||
This takes a GMT time and returns a packed localtime structure
|
||||
********************************************************************/
|
||||
static uint32 make_dos_date(time_t unixdate)
|
||||
static uint32
|
||||
make_dos_date (time_t unixdate)
|
||||
{
|
||||
struct tm *t;
|
||||
uint32 ret = 0;
|
||||
@ -389,7 +417,8 @@ static uint32 make_dos_date(time_t unixdate)
|
||||
put a dos date into a buffer (time/date format)
|
||||
This takes GMT time and puts local time in the buffer
|
||||
********************************************************************/
|
||||
void put_dos_date(char *buf,int offset,time_t unixdate)
|
||||
void
|
||||
put_dos_date (char *buf, int offset, time_t unixdate)
|
||||
{
|
||||
uint32 x = make_dos_date (unixdate);
|
||||
SIVAL (buf, offset, x);
|
||||
@ -399,7 +428,8 @@ void put_dos_date(char *buf,int offset,time_t unixdate)
|
||||
put a dos date into a buffer (date/time format)
|
||||
This takes GMT time and puts local time in the buffer
|
||||
********************************************************************/
|
||||
void put_dos_date2(char *buf,int offset,time_t unixdate)
|
||||
void
|
||||
put_dos_date2 (char *buf, int offset, time_t unixdate)
|
||||
{
|
||||
uint32 x = make_dos_date (unixdate);
|
||||
x = ((x & 0xFFFF) << 16) | ((x & 0xFFFF0000) >> 16);
|
||||
@ -411,7 +441,8 @@ put a dos 32 bit "unix like" date into a buffer. This routine takes
|
||||
GMT and converts it to LOCAL time before putting it (most SMBs assume
|
||||
localtime for this sort of date)
|
||||
********************************************************************/
|
||||
void put_dos_date3(char *buf,int offset,time_t unixdate)
|
||||
void
|
||||
put_dos_date3 (char *buf, int offset, time_t unixdate)
|
||||
{
|
||||
if (!null_mtime (unixdate))
|
||||
unixdate -= TimeDiff (unixdate);
|
||||
@ -421,12 +452,16 @@ void put_dos_date3(char *buf,int offset,time_t unixdate)
|
||||
/*******************************************************************
|
||||
interpret a 32 bit dos packed date/time to some parameters
|
||||
********************************************************************/
|
||||
static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second)
|
||||
static void
|
||||
interpret_dos_date (uint32 date, int *year, int *month, int *day, int *hour, int *minute,
|
||||
int *second)
|
||||
{
|
||||
uint32 p0, p1, p2, p3;
|
||||
|
||||
p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF;
|
||||
p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF;
|
||||
p0 = date & 0xFF;
|
||||
p1 = ((date & 0xFF00) >> 8) & 0xFF;
|
||||
p2 = ((date & 0xFF0000) >> 16) & 0xFF;
|
||||
p3 = ((date & 0xFF000000) >> 24) & 0xFF;
|
||||
|
||||
*second = 2 * (p0 & 0x1F);
|
||||
*minute = ((p0 >> 5) & 0xFF) + ((p1 & 0x7) << 3);
|
||||
@ -440,7 +475,8 @@ static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *ho
|
||||
create a unix date (int GMT) from a dos date (which is actually in
|
||||
localtime)
|
||||
********************************************************************/
|
||||
time_t make_unix_date(void *date_ptr)
|
||||
time_t
|
||||
make_unix_date (void *date_ptr)
|
||||
{
|
||||
uint32 dos_date = 0;
|
||||
struct tm t;
|
||||
@ -448,7 +484,8 @@ time_t make_unix_date(void *date_ptr)
|
||||
|
||||
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);
|
||||
@ -463,7 +500,8 @@ time_t make_unix_date(void *date_ptr)
|
||||
/*******************************************************************
|
||||
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;
|
||||
|
||||
@ -478,7 +516,8 @@ time_t make_unix_date2(void *date_ptr)
|
||||
create a unix GMT date from a dos date in 32 bit "unix like" format
|
||||
these generally arrive as localtimes, with corresponding DST
|
||||
******************************************************************/
|
||||
time_t make_unix_date3(void *date_ptr)
|
||||
time_t
|
||||
make_unix_date3 (void *date_ptr)
|
||||
{
|
||||
time_t t = (time_t) IVAL (date_ptr, 0);
|
||||
if (!null_mtime (t))
|
||||
@ -490,7 +529,8 @@ time_t make_unix_date3(void *date_ptr)
|
||||
/***************************************************************************
|
||||
return a HTTP/1.0 time string
|
||||
***************************************************************************/
|
||||
char *http_timestring(time_t t)
|
||||
char *
|
||||
http_timestring (time_t t)
|
||||
{
|
||||
static fstring buf;
|
||||
struct tm *tm = LocalTime (&t);
|
||||
@ -507,15 +547,19 @@ char *http_timestring(time_t t)
|
||||
/****************************************************************************
|
||||
return the date and time as a string
|
||||
****************************************************************************/
|
||||
char *timestring(void )
|
||||
char *
|
||||
timestring (void)
|
||||
{
|
||||
static fstring TimeBuf;
|
||||
time_t t = time (NULL);
|
||||
struct tm *tm = LocalTime (&t);
|
||||
|
||||
if (!tm) {
|
||||
if (!tm)
|
||||
{
|
||||
slprintf (TimeBuf, sizeof (TimeBuf) - 1, "%ld seconds since the Epoch", (long) t);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
strftime (TimeBuf, 100, "%Y/%m/%d %H:%M:%S", tm);
|
||||
}
|
||||
return (TimeBuf);
|
||||
@ -526,7 +570,8 @@ char *timestring(void )
|
||||
structure.
|
||||
****************************************************************************/
|
||||
|
||||
time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs)
|
||||
time_t
|
||||
get_create_time (SMB_STRUCT_STAT * st, BOOL fake_dirs)
|
||||
{
|
||||
time_t ret, ret1;
|
||||
|
||||
@ -545,4 +590,3 @@ time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs)
|
||||
*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -28,19 +28,23 @@
|
||||
extern int DEBUGLEVEL;
|
||||
|
||||
/* internal functions */
|
||||
static struct passwd *uname_string_combinations(char *s, struct passwd * (*fn) (const char *), int N);
|
||||
static struct passwd *uname_string_combinations2(char *s, int offset, struct passwd * (*fn) (const char *), int N);
|
||||
static struct passwd *uname_string_combinations (char *s, struct passwd *(*fn) (const char *),
|
||||
int N);
|
||||
static struct passwd *uname_string_combinations2 (char *s, int offset,
|
||||
struct passwd *(*fn) (const char *), int N);
|
||||
|
||||
/****************************************************************************
|
||||
get a users home directory.
|
||||
****************************************************************************/
|
||||
const char *get_home_dir(char *user)
|
||||
const char *
|
||||
get_home_dir (char *user)
|
||||
{
|
||||
struct passwd *pass;
|
||||
|
||||
pass = Get_Pwnam (user);
|
||||
|
||||
if (!pass) return(NULL);
|
||||
if (!pass)
|
||||
return (NULL);
|
||||
return (pass->pw_dir);
|
||||
}
|
||||
|
||||
@ -56,7 +60,8 @@ function. Previously, the map_username was being called
|
||||
every time Get_Pwnam was called.
|
||||
Returns True if username was changed, false otherwise.
|
||||
********************************************************************/
|
||||
BOOL map_username(const char *user)
|
||||
BOOL
|
||||
map_username (const char *user)
|
||||
{
|
||||
static BOOL initialised = False;
|
||||
static fstring last_from, last_to;
|
||||
@ -72,7 +77,8 @@ BOOL map_username(const char *user)
|
||||
if (!*mapfile)
|
||||
return False;
|
||||
|
||||
if (!initialised) {
|
||||
if (!initialised)
|
||||
{
|
||||
*last_from = *last_to = 0;
|
||||
initialised = True;
|
||||
}
|
||||
@ -80,21 +86,24 @@ BOOL map_username(const char *user)
|
||||
if (strequal (user, last_to))
|
||||
return False;
|
||||
|
||||
if (strequal(user,last_from)) {
|
||||
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) {
|
||||
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) {
|
||||
while ((s = fgets_slash (buf, sizeof (buf), f)) != NULL)
|
||||
{
|
||||
char *unixname = s;
|
||||
char *dosname = strchr (unixname, '=');
|
||||
BOOL return_if_mapped = False;
|
||||
@ -106,7 +115,8 @@ BOOL map_username(const char *user)
|
||||
|
||||
while (isspace (*unixname))
|
||||
unixname++;
|
||||
if ('!' == *unixname) {
|
||||
if ('!' == *unixname)
|
||||
{
|
||||
return_if_mapped = True;
|
||||
unixname++;
|
||||
while (*unixname && isspace (*unixname))
|
||||
@ -118,19 +128,22 @@ BOOL map_username(const char *user)
|
||||
|
||||
{
|
||||
int l = strlen (unixname);
|
||||
while (l && isspace(unixname[l-1])) {
|
||||
while (l && isspace (unixname[l - 1]))
|
||||
{
|
||||
unixname[l - 1] = 0;
|
||||
l--;
|
||||
}
|
||||
}
|
||||
|
||||
if (strchr(dosname,'*') || user_in_list(user,dosname)) {
|
||||
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) {
|
||||
if (return_if_mapped)
|
||||
{
|
||||
fclose (f);
|
||||
return True;
|
||||
}
|
||||
@ -153,7 +166,8 @@ BOOL map_username(const char *user)
|
||||
/****************************************************************************
|
||||
Get_Pwnam wrapper
|
||||
****************************************************************************/
|
||||
static struct passwd *_Get_Pwnam(const char *s)
|
||||
static struct passwd *
|
||||
_Get_Pwnam (const char *s)
|
||||
{
|
||||
struct passwd *ret;
|
||||
|
||||
@ -180,7 +194,8 @@ static struct passwd *_Get_Pwnam(const char *s)
|
||||
a wrapper for getpwnam() that tries with all lower and all upper case
|
||||
if the initial name fails. Also tried with first letter capitalised
|
||||
****************************************************************************/
|
||||
struct passwd *Get_Pwnam(const char *a_user)
|
||||
struct passwd *
|
||||
Get_Pwnam (const char *a_user)
|
||||
{
|
||||
fstring user;
|
||||
int last_char;
|
||||
@ -194,33 +209,39 @@ struct passwd *Get_Pwnam(const char *a_user)
|
||||
StrnCpy (user, a_user, sizeof (user) - 1);
|
||||
|
||||
ret = _Get_Pwnam (user);
|
||||
if (ret) return(ret);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
strlower (user);
|
||||
ret = _Get_Pwnam (user);
|
||||
if (ret) return(ret);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
strupper (user);
|
||||
ret = _Get_Pwnam (user);
|
||||
if (ret) return(ret);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
/* try with first letter capitalised */
|
||||
if (strlen (user) > 1)
|
||||
strlower (user + 1);
|
||||
ret = _Get_Pwnam (user);
|
||||
if (ret) return(ret);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
/* try with last letter capitalised */
|
||||
strlower (user);
|
||||
last_char = strlen (user) - 1;
|
||||
user[last_char] = toupper (user[last_char]);
|
||||
ret = _Get_Pwnam (user);
|
||||
if (ret) return(ret);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
/* try all combinations up to usernamelevel */
|
||||
strlower (user);
|
||||
ret = uname_string_combinations (user, _Get_Pwnam, usernamelevel);
|
||||
if (ret) return(ret);
|
||||
if (ret)
|
||||
return (ret);
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
@ -229,7 +250,8 @@ struct passwd *Get_Pwnam(const char *a_user)
|
||||
/****************************************************************************
|
||||
check if a user is in a netgroup user list
|
||||
****************************************************************************/
|
||||
static BOOL user_in_netgroup_list(char *user,char *ngname)
|
||||
static BOOL
|
||||
user_in_netgroup_list (char *user, char *ngname)
|
||||
{
|
||||
#ifdef HAVE_NETGROUP
|
||||
static char *mydomain = NULL;
|
||||
@ -242,11 +264,8 @@ static BOOL user_in_netgroup_list(char *user,char *ngname)
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG(5,("looking for user %s of domain %s in netgroup %s\n",
|
||||
user, mydomain, ngname));
|
||||
DEBUG(5,("innetgr is %s\n",
|
||||
innetgr(ngname, NULL, user, mydomain)
|
||||
? "TRUE" : "FALSE"));
|
||||
DEBUG (5, ("looking for user %s of domain %s in netgroup %s\n", user, mydomain, ngname));
|
||||
DEBUG (5, ("innetgr is %s\n", innetgr (ngname, NULL, user, mydomain) ? "TRUE" : "FALSE"));
|
||||
|
||||
if (innetgr (ngname, NULL, user, mydomain))
|
||||
return (True);
|
||||
@ -258,7 +277,8 @@ static BOOL user_in_netgroup_list(char *user,char *ngname)
|
||||
/****************************************************************************
|
||||
check if a user is in a UNIX user list
|
||||
****************************************************************************/
|
||||
static BOOL user_in_group_list(char *user,char *gname)
|
||||
static BOOL
|
||||
user_in_group_list (char *user, char *gname)
|
||||
{
|
||||
#ifdef HAVE_GETGRNAM
|
||||
struct group *gptr;
|
||||
@ -292,7 +312,8 @@ static BOOL user_in_group_list(char *user,char *gname)
|
||||
check if a user is in a user list - can check combinations of UNIX
|
||||
and netgroup lists.
|
||||
****************************************************************************/
|
||||
BOOL user_in_list(char *user,char *list)
|
||||
BOOL
|
||||
user_in_list (char *user, char *list)
|
||||
{
|
||||
pstring tok;
|
||||
char *p = list;
|
||||
@ -376,7 +397,8 @@ try all combinations with N uppercase letters.
|
||||
offset is the first char to try and change (start with 0)
|
||||
it assumes the string starts lowercased
|
||||
****************************************************************************/
|
||||
static struct passwd *uname_string_combinations2(char *s,int offset,struct passwd *(*fn)(const char *),int N)
|
||||
static struct passwd *
|
||||
uname_string_combinations2 (char *s, int offset, struct passwd *(*fn) (const char *), int N)
|
||||
{
|
||||
int len = strlen (s);
|
||||
int i;
|
||||
@ -394,10 +416,12 @@ static struct passwd *uname_string_combinations2(char *s,int offset,struct passw
|
||||
|
||||
{
|
||||
char c = s[i];
|
||||
if (!islower(c)) continue;
|
||||
if (!islower (c))
|
||||
continue;
|
||||
s[i] = toupper (c);
|
||||
ret = uname_string_combinations2 (s, i + 1, fn, N - 1);
|
||||
if(ret) return(ret);
|
||||
if (ret)
|
||||
return (ret);
|
||||
s[i] = c;
|
||||
}
|
||||
return (NULL);
|
||||
@ -410,7 +434,8 @@ try all combinations with up to N uppercase letters.
|
||||
offset is the first char to try and change (start with 0)
|
||||
it assumes the string starts lowercased
|
||||
****************************************************************************/
|
||||
static struct passwd * uname_string_combinations(char *s,struct passwd * (*fn)(const char *),int N)
|
||||
static struct passwd *
|
||||
uname_string_combinations (char *s, struct passwd *(*fn) (const char *), int N)
|
||||
{
|
||||
int n;
|
||||
struct passwd *ret;
|
||||
@ -418,7 +443,8 @@ static struct passwd * uname_string_combinations(char *s,struct passwd * (*fn)(c
|
||||
for (n = 1; n <= N; n++)
|
||||
{
|
||||
ret = uname_string_combinations2 (s, 0, fn, n);
|
||||
if(ret) return(ret);
|
||||
if (ret)
|
||||
return (ret);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ static int gotalarm;
|
||||
Signal function to tell us we timed out.
|
||||
****************************************************************/
|
||||
|
||||
static void gotalarm_sig(void)
|
||||
static void
|
||||
gotalarm_sig (void)
|
||||
{
|
||||
gotalarm = 1;
|
||||
}
|
||||
@ -43,7 +44,8 @@ static void gotalarm_sig(void)
|
||||
seconds.
|
||||
****************************************************************/
|
||||
|
||||
BOOL do_file_lock(int fd, int waitsecs, int type)
|
||||
BOOL
|
||||
do_file_lock (int fd, int waitsecs, int type)
|
||||
{
|
||||
SMB_STRUCT_FLOCK lock;
|
||||
int ret;
|
||||
@ -62,9 +64,9 @@ BOOL do_file_lock(int fd, int waitsecs, int type)
|
||||
alarm (0);
|
||||
CatchSignal (SIGALRM, SIGNAL_CAST SIG_DFL);
|
||||
|
||||
if (gotalarm) {
|
||||
DEBUG(0, ("do_file_lock: failed to %s file.\n",
|
||||
type == F_UNLCK ? "unlock" : "lock"));
|
||||
if (gotalarm)
|
||||
{
|
||||
DEBUG (0, ("do_file_lock: failed to %s file.\n", type == F_UNLCK ? "unlock" : "lock"));
|
||||
return False;
|
||||
}
|
||||
|
||||
@ -75,7 +77,8 @@ BOOL do_file_lock(int fd, int waitsecs, int type)
|
||||
Lock an fd. Abandon after waitsecs seconds.
|
||||
****************************************************************/
|
||||
|
||||
BOOL file_lock(int fd, int type, int secs, int *plock_depth)
|
||||
BOOL
|
||||
file_lock (int fd, int type, int secs, int *plock_depth)
|
||||
{
|
||||
if (fd < 0)
|
||||
return False;
|
||||
@ -84,7 +87,8 @@ BOOL file_lock(int fd, int type, int secs, int *plock_depth)
|
||||
|
||||
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)));
|
||||
return False;
|
||||
@ -98,7 +102,8 @@ BOOL file_lock(int fd, int type, int secs, int *plock_depth)
|
||||
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;
|
||||
|
||||
@ -118,8 +123,8 @@ BOOL file_unlock(int fd, int *plock_depth)
|
||||
update to be set = True if modification is required.
|
||||
****************************************************************/
|
||||
|
||||
void *startfilepwent(char *pfile, char *s_readbuf, int bufsize,
|
||||
int *file_lock_depth, BOOL update)
|
||||
void *
|
||||
startfilepwent (char *pfile, char *s_readbuf, int bufsize, int *file_lock_depth, BOOL update)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
|
||||
@ -132,7 +137,8 @@ void *startfilepwent(char *pfile, char *s_readbuf, int bufsize,
|
||||
|
||||
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;
|
||||
}
|
||||
@ -157,7 +163,8 @@ void *startfilepwent(char *pfile, char *s_readbuf, int bufsize,
|
||||
/***************************************************************
|
||||
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;
|
||||
|
||||
@ -171,7 +178,8 @@ void endfilepwent(void *vp, int *file_lock_depth)
|
||||
Return the current position in the file list as an SMB_BIG_UINT.
|
||||
This must be treated as an opaque token.
|
||||
*************************************************************************/
|
||||
SMB_BIG_UINT getfilepwpos(void *vp)
|
||||
SMB_BIG_UINT
|
||||
getfilepwpos (void *vp)
|
||||
{
|
||||
return (SMB_BIG_UINT) sys_ftell ((FILE *) vp);
|
||||
}
|
||||
@ -180,7 +188,8 @@ SMB_BIG_UINT getfilepwpos(void *vp)
|
||||
Set the current position in the file list from an SMB_BIG_UINT.
|
||||
This must be treated as an opaque token.
|
||||
*************************************************************************/
|
||||
BOOL setfilepwpos(void *vp, SMB_BIG_UINT tok)
|
||||
BOOL
|
||||
setfilepwpos (void *vp, SMB_BIG_UINT tok)
|
||||
{
|
||||
return !sys_fseek ((FILE *) vp, (SMB_OFF_T) tok, SEEK_SET);
|
||||
}
|
||||
@ -190,7 +199,8 @@ BOOL setfilepwpos(void *vp, SMB_BIG_UINT tok)
|
||||
line is of format "xxxx:xxxxxx:xxxxx:".
|
||||
lines with "#" at the front are ignored.
|
||||
*************************************************************************/
|
||||
int getfileline(void *vp, char *linebuf, int linebuf_size)
|
||||
int
|
||||
getfileline (void *vp, char *linebuf, int linebuf_size)
|
||||
{
|
||||
/* Static buffers we will return. */
|
||||
FILE *fp = (FILE *) vp;
|
||||
@ -272,7 +282,8 @@ read a line from a file with possible \ continuation chars.
|
||||
Blanks at the start or end of a line are stripped.
|
||||
The string will be allocated if s2 is NULL
|
||||
****************************************************************************/
|
||||
char *fgets_slash(char *s2,int maxlen,FILE *f)
|
||||
char *
|
||||
fgets_slash (char *s2, int maxlen, FILE * f)
|
||||
{
|
||||
char *s = s2;
|
||||
int len = 0;
|
||||
@ -288,7 +299,8 @@ char *fgets_slash(char *s2,int maxlen,FILE *f)
|
||||
s = (char *) Realloc (s, maxlen);
|
||||
}
|
||||
|
||||
if (!s || maxlen < 2) return(NULL);
|
||||
if (!s || maxlen < 2)
|
||||
return (NULL);
|
||||
|
||||
*s = 0;
|
||||
|
||||
@ -327,9 +339,9 @@ char *fgets_slash(char *s2,int maxlen,FILE *f)
|
||||
{
|
||||
maxlen *= 2;
|
||||
s = (char *) Realloc (s, maxlen);
|
||||
if (!s) return(NULL);
|
||||
if (!s)
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
return (s);
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,8 @@ int smb_read_error = 0;
|
||||
/****************************************************************************
|
||||
determine if a file descriptor is in fact a socket
|
||||
****************************************************************************/
|
||||
BOOL is_a_socket(int fd)
|
||||
BOOL
|
||||
is_a_socket (int fd)
|
||||
{
|
||||
int v;
|
||||
unsigned int l;
|
||||
@ -64,7 +65,8 @@ BOOL is_a_socket(int fd)
|
||||
}
|
||||
|
||||
|
||||
enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON};
|
||||
enum SOCK_OPT_TYPES
|
||||
{ OPT_BOOL, OPT_INT, OPT_ON };
|
||||
|
||||
static const struct
|
||||
{
|
||||
@ -73,45 +75,60 @@ static const struct
|
||||
int option;
|
||||
int value;
|
||||
int opttype;
|
||||
} socket_options[] = {
|
||||
{"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, 0, OPT_BOOL},
|
||||
{"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, 0, OPT_BOOL},
|
||||
{"SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, 0, OPT_BOOL},
|
||||
} socket_options[] =
|
||||
{
|
||||
{
|
||||
"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, 0, OPT_BOOL},
|
||||
{
|
||||
"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, 0, OPT_BOOL},
|
||||
{
|
||||
"SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, 0, OPT_BOOL},
|
||||
#ifdef TCP_NODELAY
|
||||
{"TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, 0, OPT_BOOL},
|
||||
{
|
||||
"TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, 0, OPT_BOOL},
|
||||
#endif
|
||||
#ifdef IPTOS_LOWDELAY
|
||||
{"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON},
|
||||
{
|
||||
"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON},
|
||||
#endif
|
||||
#ifdef IPTOS_THROUGHPUT
|
||||
{"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON},
|
||||
{
|
||||
"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON},
|
||||
#endif
|
||||
#ifdef SO_SNDBUF
|
||||
{"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT},
|
||||
{
|
||||
"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT},
|
||||
#endif
|
||||
#ifdef SO_RCVBUF
|
||||
{"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT},
|
||||
{
|
||||
"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT},
|
||||
#endif
|
||||
#ifdef SO_SNDLOWAT
|
||||
{"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT},
|
||||
{
|
||||
"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT},
|
||||
#endif
|
||||
#ifdef SO_RCVLOWAT
|
||||
{"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT},
|
||||
{
|
||||
"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT},
|
||||
#endif
|
||||
#ifdef SO_SNDTIMEO
|
||||
{"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT},
|
||||
{
|
||||
"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT},
|
||||
#endif
|
||||
#ifdef SO_RCVTIMEO
|
||||
{"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT},
|
||||
{
|
||||
"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT},
|
||||
#endif
|
||||
{NULL,0,0,0,0}};
|
||||
{
|
||||
NULL, 0, 0, 0, 0}};
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
set user socket options
|
||||
****************************************************************************/
|
||||
void set_socket_options(int fd, char *options)
|
||||
void
|
||||
set_socket_options (int fd, char *options)
|
||||
{
|
||||
fstring tok;
|
||||
|
||||
@ -169,7 +186,8 @@ void set_socket_options(int fd, char *options)
|
||||
/****************************************************************************
|
||||
close the socket communication
|
||||
****************************************************************************/
|
||||
void close_sockets(void )
|
||||
void
|
||||
close_sockets (void)
|
||||
{
|
||||
#ifdef WITH_SSL
|
||||
sslutil_disconnect (Client);
|
||||
@ -184,7 +202,8 @@ void close_sockets(void )
|
||||
/****************************************************************************
|
||||
write to a socket
|
||||
****************************************************************************/
|
||||
ssize_t write_socket(int fd,char *buf,size_t len)
|
||||
ssize_t
|
||||
write_socket (int fd, char *buf, size_t len)
|
||||
{
|
||||
ssize_t ret = 0;
|
||||
|
||||
@ -204,7 +223,8 @@ ssize_t write_socket(int fd,char *buf,size_t len)
|
||||
/****************************************************************************
|
||||
read from a socket
|
||||
****************************************************************************/
|
||||
ssize_t read_udp_socket(int fd,char *buf,size_t len)
|
||||
ssize_t
|
||||
read_udp_socket (int fd, char *buf, size_t len)
|
||||
{
|
||||
ssize_t ret;
|
||||
struct sockaddr_in sock;
|
||||
@ -214,7 +234,8 @@ ssize_t read_udp_socket(int fd,char *buf,size_t len)
|
||||
memset ((char *) &sock, '\0', socklen);
|
||||
memset ((char *) &lastip, '\0', sizeof (lastip));
|
||||
ret = (ssize_t) recvfrom (fd, buf, len, 0, (struct sockaddr *) &sock, &socklen);
|
||||
if (ret <= 0) {
|
||||
if (ret <= 0)
|
||||
{
|
||||
DEBUG (2, ("read socket failed. ERRNO=%s\n", unix_error_string (errno)));
|
||||
return (0);
|
||||
}
|
||||
@ -236,7 +257,8 @@ maxcount = number to be read.
|
||||
time_out = timeout in milliseconds
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t read_with_timeout(int fd,char *buf,size_t mincnt,size_t maxcnt,unsigned int time_out)
|
||||
ssize_t
|
||||
read_with_timeout (int fd, char *buf, size_t mincnt, size_t maxcnt, unsigned int time_out)
|
||||
{
|
||||
fd_set fds;
|
||||
int selrtn;
|
||||
@ -245,32 +267,41 @@ ssize_t read_with_timeout(int fd,char *buf,size_t mincnt,size_t maxcnt,unsigned
|
||||
struct timeval timeout;
|
||||
|
||||
/* just checking .... */
|
||||
if (maxcnt <= 0) return(0);
|
||||
if (maxcnt <= 0)
|
||||
return (0);
|
||||
|
||||
smb_read_error = 0;
|
||||
|
||||
/* Blocking read */
|
||||
if (time_out <= 0) {
|
||||
if (mincnt == 0) mincnt = maxcnt;
|
||||
if (time_out <= 0)
|
||||
{
|
||||
if (mincnt == 0)
|
||||
mincnt = maxcnt;
|
||||
|
||||
while (nread < mincnt) {
|
||||
while (nread < mincnt)
|
||||
{
|
||||
#ifdef WITH_SSL
|
||||
if(fd == sslFd){
|
||||
if (fd == sslFd)
|
||||
{
|
||||
readret = SSL_read (ssl, buf + nread, maxcnt - nread);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
readret = read (fd, buf + nread, maxcnt - nread);
|
||||
}
|
||||
#else /* WITH_SSL */
|
||||
readret = read (fd, buf + nread, maxcnt - nread);
|
||||
#endif /* WITH_SSL */
|
||||
|
||||
if (readret == 0) {
|
||||
if (readret == 0)
|
||||
{
|
||||
DEBUG (5, ("read_with_timeout: blocking read. EOF from client.\n"));
|
||||
smb_read_error = READ_EOF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (readret == -1) {
|
||||
if (readret == -1)
|
||||
{
|
||||
DEBUG (0, ("read_with_timeout: read error = %s.\n", unix_error_string (errno)));
|
||||
smb_read_error = READ_ERROR;
|
||||
return -1;
|
||||
@ -298,40 +329,51 @@ ssize_t read_with_timeout(int fd,char *buf,size_t mincnt,size_t maxcnt,unsigned
|
||||
selrtn = sys_select (fd + 1, &fds, &timeout);
|
||||
|
||||
/* Check if error */
|
||||
if(selrtn == -1) {
|
||||
if (selrtn == -1)
|
||||
{
|
||||
/* something is wrong. Maybe the socket is dead? */
|
||||
DEBUG(0,("read_with_timeout: timeout read. select error = %s.\n", unix_error_string (errno) ));
|
||||
DEBUG (0,
|
||||
("read_with_timeout: timeout read. select error = %s.\n",
|
||||
unix_error_string (errno)));
|
||||
smb_read_error = READ_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Did we timeout ? */
|
||||
if (selrtn == 0) {
|
||||
if (selrtn == 0)
|
||||
{
|
||||
DEBUG (10, ("read_with_timeout: timeout read. select timed out.\n"));
|
||||
smb_read_error = READ_TIMEOUT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef WITH_SSL
|
||||
if(fd == sslFd){
|
||||
if (fd == sslFd)
|
||||
{
|
||||
readret = SSL_read (ssl, buf + nread, maxcnt - nread);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
readret = read (fd, buf + nread, maxcnt - nread);
|
||||
}
|
||||
#else /* WITH_SSL */
|
||||
readret = read (fd, buf + nread, maxcnt - nread);
|
||||
#endif /* WITH_SSL */
|
||||
|
||||
if (readret == 0) {
|
||||
if (readret == 0)
|
||||
{
|
||||
/* we got EOF on the file descriptor */
|
||||
DEBUG (5, ("read_with_timeout: timeout read. EOF from client.\n"));
|
||||
smb_read_error = READ_EOF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (readret == -1) {
|
||||
if (readret == -1)
|
||||
{
|
||||
/* the descriptor is probably dead */
|
||||
DEBUG(0,("read_with_timeout: timeout read. read error = %s.\n", unix_error_string (errno) ));
|
||||
DEBUG (0,
|
||||
("read_with_timeout: timeout read. read error = %s.\n",
|
||||
unix_error_string (errno)));
|
||||
smb_read_error = READ_ERROR;
|
||||
return -1;
|
||||
}
|
||||
@ -347,7 +389,8 @@ ssize_t read_with_timeout(int fd,char *buf,size_t mincnt,size_t maxcnt,unsigned
|
||||
/****************************************************************************
|
||||
send a keepalive packet (rfc1002)
|
||||
****************************************************************************/
|
||||
BOOL send_keepalive(int client)
|
||||
BOOL
|
||||
send_keepalive (int client)
|
||||
{
|
||||
unsigned char buf[4];
|
||||
|
||||
@ -362,7 +405,8 @@ BOOL send_keepalive(int client)
|
||||
/****************************************************************************
|
||||
read data from the client, reading exactly N bytes.
|
||||
****************************************************************************/
|
||||
ssize_t read_data(int fd,char *buffer,size_t N)
|
||||
ssize_t
|
||||
read_data (int fd, char *buffer, size_t N)
|
||||
{
|
||||
ssize_t ret;
|
||||
size_t total = 0;
|
||||
@ -372,9 +416,12 @@ ssize_t read_data(int fd,char *buffer,size_t N)
|
||||
while (total < N)
|
||||
{
|
||||
#ifdef WITH_SSL
|
||||
if(fd == sslFd){
|
||||
if (fd == sslFd)
|
||||
{
|
||||
ret = SSL_read (ssl, buffer + total, N - total);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = read (fd, buffer + total, N - total);
|
||||
}
|
||||
#else /* WITH_SSL */
|
||||
@ -383,13 +430,17 @@ ssize_t read_data(int fd,char *buffer,size_t N)
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
DEBUG(10,("read_data: read of %d returned 0. Error = %s\n", (int)(N - total), unix_error_string (errno) ));
|
||||
DEBUG (10,
|
||||
("read_data: read of %d returned 0. Error = %s\n", (int) (N - total),
|
||||
unix_error_string (errno)));
|
||||
smb_read_error = READ_EOF;
|
||||
return 0;
|
||||
}
|
||||
if (ret == -1)
|
||||
{
|
||||
DEBUG(0,("read_data: read failure for %d. Error = %s\n", (int)(N - total), unix_error_string (errno) ));
|
||||
DEBUG (0,
|
||||
("read_data: read failure for %d. Error = %s\n", (int) (N - total),
|
||||
unix_error_string (errno)));
|
||||
smb_read_error = READ_ERROR;
|
||||
return -1;
|
||||
}
|
||||
@ -402,7 +453,8 @@ ssize_t read_data(int fd,char *buffer,size_t N)
|
||||
/****************************************************************************
|
||||
write data to a fd
|
||||
****************************************************************************/
|
||||
ssize_t write_data(int fd,char *buffer,size_t N)
|
||||
ssize_t
|
||||
write_data (int fd, char *buffer, size_t N)
|
||||
{
|
||||
size_t total = 0;
|
||||
ssize_t ret;
|
||||
@ -410,20 +462,25 @@ ssize_t write_data(int fd,char *buffer,size_t N)
|
||||
while (total < N)
|
||||
{
|
||||
#ifdef WITH_SSL
|
||||
if(fd == sslFd){
|
||||
if (fd == sslFd)
|
||||
{
|
||||
ret = SSL_write (ssl, buffer + total, N - total);
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = write (fd, buffer + total, N - total);
|
||||
}
|
||||
#else /* WITH_SSL */
|
||||
ret = write (fd, buffer + total, N - total);
|
||||
#endif /* WITH_SSL */
|
||||
|
||||
if (ret == -1) {
|
||||
if (ret == -1)
|
||||
{
|
||||
DEBUG (1, ("write_data: write failure. Error = %s\n", unix_error_string (errno)));
|
||||
return -1;
|
||||
}
|
||||
if (ret == 0) return total;
|
||||
if (ret == 0)
|
||||
return total;
|
||||
|
||||
total += ret;
|
||||
}
|
||||
@ -439,7 +496,8 @@ This version of the function will return a length of zero on receiving
|
||||
a keepalive packet.
|
||||
timeout is in milliseconds.
|
||||
****************************************************************************/
|
||||
static ssize_t read_smb_length_return_keepalive(int fd,char *inbuf,unsigned int timeout)
|
||||
static ssize_t
|
||||
read_smb_length_return_keepalive (int fd, char *inbuf, unsigned int timeout)
|
||||
{
|
||||
ssize_t len = 0;
|
||||
int msg_type;
|
||||
@ -466,6 +524,7 @@ static ssize_t read_smb_length_return_keepalive(int fd,char *inbuf,unsigned int
|
||||
|
||||
return (len);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/****************************************************************************
|
||||
read 4 bytes of a smb packet and return the smb length of the packet
|
||||
@ -473,7 +532,8 @@ store the result in the buffer. This version of the function will
|
||||
never return a session keepalive (length of zero).
|
||||
timeout is in milliseconds.
|
||||
****************************************************************************/
|
||||
ssize_t read_smb_length(int fd,char *inbuf,unsigned int timeout)
|
||||
ssize_t
|
||||
read_smb_length (int fd, char *inbuf, unsigned int timeout)
|
||||
{
|
||||
ssize_t len;
|
||||
|
||||
@ -501,7 +561,8 @@ ssize_t read_smb_length(int fd,char *inbuf,unsigned int timeout)
|
||||
This function will return on a
|
||||
receipt of a session keepalive packet.
|
||||
****************************************************************************/
|
||||
BOOL receive_smb(int fd,char *buffer, unsigned int timeout)
|
||||
BOOL
|
||||
receive_smb (int fd, char *buffer, unsigned int timeout)
|
||||
{
|
||||
ssize_t len, ret;
|
||||
|
||||
@ -516,7 +577,8 @@ BOOL receive_smb(int fd,char *buffer, unsigned int timeout)
|
||||
return (False);
|
||||
}
|
||||
|
||||
if (len > BUFFER_SIZE) {
|
||||
if (len > BUFFER_SIZE)
|
||||
{
|
||||
DEBUG (0, ("Invalid packet length! (%d bytes).\n", (int) len));
|
||||
if (len > BUFFER_SIZE + (SAFETY_MARGIN / 2))
|
||||
{
|
||||
@ -524,9 +586,11 @@ BOOL receive_smb(int fd,char *buffer, unsigned int timeout)
|
||||
}
|
||||
}
|
||||
|
||||
if(len > 0) {
|
||||
if (len > 0)
|
||||
{
|
||||
ret = read_data (fd, buffer + 4, len);
|
||||
if (ret != len) {
|
||||
if (ret != len)
|
||||
{
|
||||
smb_read_error = READ_ERROR;
|
||||
return False;
|
||||
}
|
||||
@ -545,7 +609,8 @@ BOOL receive_smb(int fd,char *buffer, unsigned int timeout)
|
||||
should never go into a blocking read.
|
||||
****************************************************************************/
|
||||
|
||||
BOOL client_receive_smb(int fd,char *buffer, unsigned int timeout)
|
||||
BOOL
|
||||
client_receive_smb (int fd, char *buffer, unsigned int timeout)
|
||||
{
|
||||
BOOL ret;
|
||||
|
||||
@ -572,7 +637,8 @@ BOOL client_receive_smb(int fd,char *buffer, unsigned int timeout)
|
||||
send an null session message to a fd
|
||||
****************************************************************************/
|
||||
#if 0
|
||||
BOOL send_null_session_msg(int fd)
|
||||
BOOL
|
||||
send_null_session_msg (int fd)
|
||||
{
|
||||
ssize_t ret;
|
||||
uint32 blank = 0;
|
||||
@ -585,7 +651,9 @@ BOOL send_null_session_msg(int fd)
|
||||
ret = write_socket (fd, buffer + nwritten, len - nwritten);
|
||||
if (ret <= 0)
|
||||
{
|
||||
DEBUG(0,("send_null_session_msg: Error writing %d bytes to client. %d. Exiting\n",(int)len,(int)ret));
|
||||
DEBUG (0,
|
||||
("send_null_session_msg: Error writing %d bytes to client. %d. Exiting\n",
|
||||
(int) len, (int) ret));
|
||||
close_sockets ();
|
||||
exit (1);
|
||||
}
|
||||
@ -599,7 +667,8 @@ BOOL send_null_session_msg(int fd)
|
||||
/****************************************************************************
|
||||
send an smb to a fd
|
||||
****************************************************************************/
|
||||
BOOL send_smb(int fd,char *buffer)
|
||||
BOOL
|
||||
send_smb (int fd, char *buffer)
|
||||
{
|
||||
size_t len;
|
||||
size_t nwritten = 0;
|
||||
@ -626,7 +695,8 @@ BOOL send_smb(int fd,char *buffer)
|
||||
/****************************************************************************
|
||||
send a single packet to a port on another machine
|
||||
****************************************************************************/
|
||||
BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type)
|
||||
BOOL
|
||||
send_one_packet (char *buf, int len, struct in_addr ip, int port, int type)
|
||||
{
|
||||
BOOL ret;
|
||||
int out_fd;
|
||||
@ -668,7 +738,8 @@ BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type)
|
||||
/****************************************************************************
|
||||
open a socket of the specified type, port and address for incoming data
|
||||
****************************************************************************/
|
||||
int open_socket_in(int type, int port, int dlevel,uint32 socket_addr, BOOL rebind)
|
||||
int
|
||||
open_socket_in (int type, int port, int dlevel, uint32 socket_addr, BOOL rebind)
|
||||
{
|
||||
struct hostent *hp;
|
||||
struct sockaddr_in sock;
|
||||
@ -677,7 +748,10 @@ int open_socket_in(int type, int port, int dlevel,uint32 socket_addr, BOOL rebin
|
||||
|
||||
/* get my host name */
|
||||
if (gethostname (host_name, MAXHOSTNAMELEN) == -1)
|
||||
{ DEBUG(0,("gethostname failed\n")); return -1; }
|
||||
{
|
||||
DEBUG (0, ("gethostname failed\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* get host info */
|
||||
if ((hp = Get_Hostbyname (host_name)) == 0)
|
||||
@ -697,7 +771,10 @@ int open_socket_in(int type, int port, int dlevel,uint32 socket_addr, BOOL rebin
|
||||
sock.sin_addr.s_addr = socket_addr;
|
||||
res = socket (hp->h_addrtype, type, 0);
|
||||
if (res == -1)
|
||||
{ DEBUG(0,("socket failed\n")); return -1; }
|
||||
{
|
||||
DEBUG (0, ("socket failed\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
{
|
||||
int val = 1;
|
||||
@ -711,7 +788,8 @@ int open_socket_in(int type, int port, int dlevel,uint32 socket_addr, BOOL rebin
|
||||
/* now we've got a socket - we need to bind it */
|
||||
if (bind (res, (struct sockaddr *) &sock, sizeof (sock)) < 0)
|
||||
{
|
||||
if (port) {
|
||||
if (port)
|
||||
{
|
||||
if (port == SMB_PORT || port == NMB_PORT)
|
||||
DEBUG (dlevel, ("bind failed on port %d socket_addr=%s (%s)\n",
|
||||
port, inet_ntoa (sock.sin_addr), unix_error_string (errno)));
|
||||
@ -735,7 +813,8 @@ int open_socket_in(int type, int port, int dlevel,uint32 socket_addr, BOOL rebin
|
||||
/****************************************************************************
|
||||
create an outgoing socket. timeout is in milliseconds.
|
||||
**************************************************************************/
|
||||
int open_socket_out(int type, struct in_addr *addr, int port ,int timeout)
|
||||
int
|
||||
open_socket_out (int type, struct in_addr *addr, int port, int timeout)
|
||||
{
|
||||
struct sockaddr_in sock_out;
|
||||
int res, ret;
|
||||
@ -745,9 +824,13 @@ int open_socket_out(int type, struct in_addr *addr, int port ,int timeout)
|
||||
/* create a socket to write to */
|
||||
res = socket (PF_INET, type, 0);
|
||||
if (res == -1)
|
||||
{ DEBUG(0,("socket error\n")); return -1; }
|
||||
{
|
||||
DEBUG (0, ("socket error\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (type != SOCK_STREAM) return(res);
|
||||
if (type != SOCK_STREAM)
|
||||
return (res);
|
||||
|
||||
memset ((char *) &sock_out, '\0', sizeof (sock_out));
|
||||
putip ((char *) &sock_out.sin_addr, (char *) addr);
|
||||
@ -765,27 +848,29 @@ connect_again:
|
||||
ret = connect (res, (struct sockaddr *) &sock_out, sizeof (sock_out));
|
||||
|
||||
/* Some systems return EAGAIN when they mean EINPROGRESS */
|
||||
if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
|
||||
errno == EAGAIN) && loops--) {
|
||||
if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY || errno == EAGAIN) && loops--)
|
||||
{
|
||||
msleep (connect_loop);
|
||||
goto connect_again;
|
||||
}
|
||||
|
||||
if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY ||
|
||||
errno == EAGAIN)) {
|
||||
if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY || errno == EAGAIN))
|
||||
{
|
||||
DEBUG (1, ("timeout connecting to %s:%d\n", inet_ntoa (*addr), port));
|
||||
close (res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef EISCONN
|
||||
if (ret < 0 && errno == EISCONN) {
|
||||
if (ret < 0 && errno == EISCONN)
|
||||
{
|
||||
errno = 0;
|
||||
ret = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ret < 0) {
|
||||
if (ret < 0)
|
||||
{
|
||||
DEBUG (1, ("error connecting to %s:%d (%s)\n",
|
||||
inet_ntoa (*addr), port, unix_error_string (errno)));
|
||||
close (res);
|
||||
@ -811,7 +896,8 @@ static BOOL global_client_addr_done = False;
|
||||
/*******************************************************************
|
||||
return the DNS name of the client
|
||||
******************************************************************/
|
||||
char *client_name(int fd)
|
||||
char *
|
||||
client_name (int fd)
|
||||
{
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
|
||||
@ -828,24 +914,28 @@ char *client_name(int fd)
|
||||
|
||||
pstrcpy (name_buf, "UNKNOWN");
|
||||
|
||||
if (fd == -1) {
|
||||
if (fd == -1)
|
||||
{
|
||||
return name_buf;
|
||||
}
|
||||
|
||||
if (getpeername(fd, &sa, &length) < 0) {
|
||||
if (getpeername (fd, &sa, &length) < 0)
|
||||
{
|
||||
DEBUG (0, ("getpeername failed. Error was %s\n", unix_error_string (errno)));
|
||||
return name_buf;
|
||||
}
|
||||
|
||||
/* Look up the remote host name. */
|
||||
if ((hp = gethostbyaddr((char *) &sockin->sin_addr,
|
||||
sizeof(sockin->sin_addr),
|
||||
AF_INET)) == 0) {
|
||||
if ((hp = gethostbyaddr ((char *) &sockin->sin_addr, sizeof (sockin->sin_addr), AF_INET)) == 0)
|
||||
{
|
||||
DEBUG (1, ("Gethostbyaddr failed for %s\n", client_addr (fd)));
|
||||
StrnCpy (name_buf, client_addr (fd), sizeof (name_buf) - 1);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
StrnCpy (name_buf, (char *) hp->h_name, sizeof (name_buf) - 1);
|
||||
if (!matchname(name_buf, sockin->sin_addr)) {
|
||||
if (!matchname (name_buf, sockin->sin_addr))
|
||||
{
|
||||
DEBUG (0, ("Matchname failed on %s %s\n", name_buf, client_addr (fd)));
|
||||
pstrcpy (name_buf, "UNKNOWN");
|
||||
}
|
||||
@ -857,7 +947,8 @@ char *client_name(int fd)
|
||||
/*******************************************************************
|
||||
return the IP addr of the client as a string
|
||||
******************************************************************/
|
||||
char *client_addr(int fd)
|
||||
char *
|
||||
client_addr (int fd)
|
||||
{
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
|
||||
@ -873,11 +964,13 @@ char *client_addr(int fd)
|
||||
|
||||
fstrcpy (addr_buf, "0.0.0.0");
|
||||
|
||||
if (fd == -1) {
|
||||
if (fd == -1)
|
||||
{
|
||||
return addr_buf;
|
||||
}
|
||||
|
||||
if (getpeername(fd, &sa, &length) < 0) {
|
||||
if (getpeername (fd, &sa, &length) < 0)
|
||||
{
|
||||
DEBUG (0, ("getpeername failed. Error was %s\n", unix_error_string (errno)));
|
||||
return addr_buf;
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ extern int DEBUGLEVEL;
|
||||
|
||||
static char *last_ptr = NULL;
|
||||
|
||||
void set_first_token(char *ptr)
|
||||
void
|
||||
set_first_token (char *ptr)
|
||||
{
|
||||
last_ptr = ptr;
|
||||
}
|
||||
@ -41,32 +42,41 @@ void set_first_token(char *ptr)
|
||||
Based on a routine by GJC@VILLAGE.COM.
|
||||
Extensively modified by Andrew.Tridgell@anu.edu.au
|
||||
****************************************************************************/
|
||||
BOOL next_token(char **ptr,char *buff, const char *sep, size_t bufsize)
|
||||
BOOL
|
||||
next_token (char **ptr, char *buff, const char *sep, size_t bufsize)
|
||||
{
|
||||
char *s;
|
||||
BOOL quoted;
|
||||
size_t len = 1;
|
||||
|
||||
if (!ptr) ptr = &last_ptr;
|
||||
if (!ptr) return(False);
|
||||
if (!ptr)
|
||||
ptr = &last_ptr;
|
||||
if (!ptr)
|
||||
return (False);
|
||||
|
||||
s = *ptr;
|
||||
|
||||
/* default to simple separators */
|
||||
if (!sep) sep = " \t\n\r";
|
||||
if (!sep)
|
||||
sep = " \t\n\r";
|
||||
|
||||
/* find the first non sep char */
|
||||
while(*s && strchr(sep,*s)) s++;
|
||||
while (*s && strchr (sep, *s))
|
||||
s++;
|
||||
|
||||
/* nothing left? */
|
||||
if (! *s) return(False);
|
||||
if (!*s)
|
||||
return (False);
|
||||
|
||||
/* copy over the token */
|
||||
for (quoted = False; len < bufsize && *s && (quoted || !strchr (sep, *s)); s++)
|
||||
{
|
||||
if (*s == '\"') {
|
||||
if (*s == '\"')
|
||||
{
|
||||
quoted = !quoted;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
len++;
|
||||
*buff++ = *s;
|
||||
}
|
||||
@ -84,34 +94,45 @@ BOOL next_token(char **ptr,char *buff, const char *sep, size_t bufsize)
|
||||
Convert list of tokens to array; dependent on above routine.
|
||||
Uses last_ptr from above - bit of a hack.
|
||||
****************************************************************************/
|
||||
char **toktocliplist(int *ctok, char *sep)
|
||||
char **
|
||||
toktocliplist (int *ctok, char *sep)
|
||||
{
|
||||
char *s = last_ptr;
|
||||
int ictok = 0;
|
||||
char **ret, **iret;
|
||||
|
||||
if (!sep) sep = " \t\n\r";
|
||||
if (!sep)
|
||||
sep = " \t\n\r";
|
||||
|
||||
while(*s && strchr(sep,*s)) s++;
|
||||
while (*s && strchr (sep, *s))
|
||||
s++;
|
||||
|
||||
/* nothing left? */
|
||||
if (!*s) return(NULL);
|
||||
if (!*s)
|
||||
return (NULL);
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
ictok++;
|
||||
while(*s && (!strchr(sep,*s))) s++;
|
||||
while(*s && strchr(sep,*s)) *s++=0;
|
||||
} while(*s);
|
||||
while (*s && (!strchr (sep, *s)))
|
||||
s++;
|
||||
while (*s && strchr (sep, *s))
|
||||
*s++ = 0;
|
||||
}
|
||||
while (*s);
|
||||
|
||||
*ctok = ictok;
|
||||
s = last_ptr;
|
||||
|
||||
if (!(ret=iret=malloc(ictok*sizeof(char *)))) return NULL;
|
||||
if (!(ret = iret = malloc (ictok * sizeof (char *))))
|
||||
return NULL;
|
||||
|
||||
while(ictok--) {
|
||||
while (ictok--)
|
||||
{
|
||||
*iret++ = s;
|
||||
while (*s++);
|
||||
while(!*s) s++;
|
||||
while (!*s)
|
||||
s++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -121,7 +142,8 @@ char **toktocliplist(int *ctok, char *sep)
|
||||
/*******************************************************************
|
||||
case insensitive string compararison
|
||||
********************************************************************/
|
||||
int StrCaseCmp(const char *s, const char *t)
|
||||
int
|
||||
StrCaseCmp (const char *s, const char *t)
|
||||
{
|
||||
/* compare until we run out of string, either t or s, or find a difference */
|
||||
/* We *must* use toupper rather than tolower here due to the
|
||||
@ -194,7 +216,8 @@ int StrCaseCmp(const char *s, const char *t)
|
||||
/*******************************************************************
|
||||
case insensitive string compararison, length limited
|
||||
********************************************************************/
|
||||
int StrnCaseCmp(const char *s, const char *t, size_t n)
|
||||
int
|
||||
StrnCaseCmp (const char *s, const char *t, size_t n)
|
||||
{
|
||||
/* compare until we run out of string, either t or s, or chars */
|
||||
/* We *must* use toupper rather than tolower here due to the
|
||||
@ -278,10 +301,13 @@ int StrnCaseCmp(const char *s, const char *t, size_t n)
|
||||
/*******************************************************************
|
||||
compare 2 strings
|
||||
********************************************************************/
|
||||
BOOL strequal(const char *s1, const char *s2)
|
||||
BOOL
|
||||
strequal (const char *s1, const char *s2)
|
||||
{
|
||||
if (s1 == s2) return(True);
|
||||
if (!s1 || !s2) return(False);
|
||||
if (s1 == s2)
|
||||
return (True);
|
||||
if (!s1 || !s2)
|
||||
return (False);
|
||||
|
||||
return (StrCaseCmp (s1, s2) == 0);
|
||||
}
|
||||
@ -289,10 +315,13 @@ BOOL strequal(const char *s1, const char *s2)
|
||||
/*******************************************************************
|
||||
compare 2 strings up to and including the nth char.
|
||||
******************************************************************/
|
||||
BOOL strnequal(const char *s1,const char *s2,size_t n)
|
||||
BOOL
|
||||
strnequal (const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
if (s1 == s2) return(True);
|
||||
if (!s1 || !s2 || !n) return(False);
|
||||
if (s1 == s2)
|
||||
return (True);
|
||||
if (!s1 || !s2 || !n)
|
||||
return (False);
|
||||
|
||||
return (StrnCaseCmp (s1, s2, n) == 0);
|
||||
}
|
||||
@ -300,10 +329,13 @@ BOOL strnequal(const char *s1,const char *s2,size_t n)
|
||||
/*******************************************************************
|
||||
compare 2 strings (case sensitive)
|
||||
********************************************************************/
|
||||
BOOL strcsequal(const char *s1,const char *s2)
|
||||
BOOL
|
||||
strcsequal (const char *s1, const char *s2)
|
||||
{
|
||||
if (s1 == s2) return(True);
|
||||
if (!s1 || !s2) return(False);
|
||||
if (s1 == s2)
|
||||
return (True);
|
||||
if (!s1 || !s2)
|
||||
return (False);
|
||||
|
||||
return (strcmp (s1, s2) == 0);
|
||||
}
|
||||
@ -312,7 +344,8 @@ BOOL strcsequal(const char *s1,const char *s2)
|
||||
/*******************************************************************
|
||||
convert a string to lower case
|
||||
********************************************************************/
|
||||
void strlower(char *s)
|
||||
void
|
||||
strlower (char *s)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
@ -365,7 +398,8 @@ void strlower(char *s)
|
||||
/*******************************************************************
|
||||
convert a string to upper case
|
||||
********************************************************************/
|
||||
void strupper(char *s)
|
||||
void
|
||||
strupper (char *s)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
@ -419,7 +453,8 @@ void strupper(char *s)
|
||||
/*******************************************************************
|
||||
convert a string to "normal" form
|
||||
********************************************************************/
|
||||
void strnorm(char *s)
|
||||
void
|
||||
strnorm (char *s)
|
||||
{
|
||||
extern int case_default;
|
||||
if (case_default == CASE_UPPER)
|
||||
@ -431,7 +466,8 @@ void strnorm(char *s)
|
||||
/*******************************************************************
|
||||
check if a string is in "normal" case
|
||||
********************************************************************/
|
||||
BOOL strisnormal(char *s)
|
||||
BOOL
|
||||
strisnormal (char *s)
|
||||
{
|
||||
extern int case_default;
|
||||
if (case_default == CASE_UPPER)
|
||||
@ -444,7 +480,8 @@ BOOL strisnormal(char *s)
|
||||
/****************************************************************************
|
||||
string replace
|
||||
****************************************************************************/
|
||||
void string_replace(char *s,char oldc,char newc)
|
||||
void
|
||||
string_replace (char *s, char oldc, char newc)
|
||||
{
|
||||
size_t skip;
|
||||
while (*s)
|
||||
@ -465,7 +502,8 @@ void string_replace(char *s,char oldc,char newc)
|
||||
/*******************************************************************
|
||||
skip past some strings in a buffer
|
||||
********************************************************************/
|
||||
char *skip_string(char *buf,size_t n)
|
||||
char *
|
||||
skip_string (char *buf, size_t n)
|
||||
{
|
||||
while (n--)
|
||||
buf += strlen (buf) + 1;
|
||||
@ -479,11 +517,13 @@ char *skip_string(char *buf,size_t n)
|
||||
16.oct.98, jdblair@cobaltnet.com.
|
||||
********************************************************************/
|
||||
|
||||
size_t str_charnum(const char *s)
|
||||
size_t
|
||||
str_charnum (const char *s)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
while (*s != '\0') {
|
||||
while (*s != '\0')
|
||||
{
|
||||
int skip = skip_multibyte_char (*s);
|
||||
s += (skip ? skip : 1);
|
||||
len++;
|
||||
@ -495,7 +535,8 @@ size_t str_charnum(const char *s)
|
||||
trim the specified elements off the front and back of a string
|
||||
********************************************************************/
|
||||
|
||||
BOOL trim_string(char *s,const char *front,const char *back)
|
||||
BOOL
|
||||
trim_string (char *s, const char *front, const char *back)
|
||||
{
|
||||
BOOL ret = False;
|
||||
size_t front_len = (front && *front) ? strlen (front) : 0;
|
||||
@ -528,8 +569,7 @@ BOOL trim_string(char *s,const char *front,const char *back)
|
||||
if (!is_multibyte_codepage ())
|
||||
{
|
||||
s_len = strlen (s);
|
||||
while ((s_len >= back_len) &&
|
||||
(strncmp(s + s_len - back_len, back, back_len)==0))
|
||||
while ((s_len >= back_len) && (strncmp (s + s_len - back_len, back, back_len) == 0))
|
||||
{
|
||||
ret = True;
|
||||
s[s_len - back_len] = '\0';
|
||||
@ -591,7 +631,8 @@ BOOL trim_string(char *s,const char *front,const char *back)
|
||||
/****************************************************************************
|
||||
does a string have any uppercase chars in it?
|
||||
****************************************************************************/
|
||||
BOOL strhasupper(const char *s)
|
||||
BOOL
|
||||
strhasupper (const char *s)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
@ -625,7 +666,8 @@ BOOL strhasupper(const char *s)
|
||||
size_t skip = skip_multibyte_char (*s);
|
||||
if (skip != 0)
|
||||
s += skip;
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (isupper (*s))
|
||||
return (True);
|
||||
s++;
|
||||
@ -639,7 +681,8 @@ BOOL strhasupper(const char *s)
|
||||
/****************************************************************************
|
||||
does a string have any lowercase chars in it?
|
||||
****************************************************************************/
|
||||
BOOL strhaslower(const char *s)
|
||||
BOOL
|
||||
strhaslower (const char *s)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
@ -681,7 +724,8 @@ BOOL strhaslower(const char *s)
|
||||
size_t skip = skip_multibyte_char (*s);
|
||||
if (skip != 0)
|
||||
s += skip;
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (islower (*s))
|
||||
return (True);
|
||||
s++;
|
||||
@ -695,7 +739,8 @@ BOOL strhaslower(const char *s)
|
||||
/****************************************************************************
|
||||
find the number of chars in a string
|
||||
****************************************************************************/
|
||||
size_t count_chars(const char *s,char c)
|
||||
size_t
|
||||
count_chars (const char *s, char c)
|
||||
{
|
||||
size_t count = 0;
|
||||
|
||||
@ -732,7 +777,8 @@ size_t count_chars(const char *s,char c)
|
||||
size_t skip = skip_multibyte_char (*s);
|
||||
if (skip != 0)
|
||||
s += skip;
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (*s == c)
|
||||
count++;
|
||||
s++;
|
||||
@ -748,23 +794,27 @@ size_t count_chars(const char *s,char c)
|
||||
safe string copy into a known length string. maxlength does not
|
||||
include the terminating zero.
|
||||
********************************************************************/
|
||||
char *safe_strcpy(char *dest,const char *src, size_t maxlength)
|
||||
char *
|
||||
safe_strcpy (char *dest, const char *src, size_t maxlength)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if (!dest) {
|
||||
if (!dest)
|
||||
{
|
||||
DEBUG (0, ("ERROR: NULL dest in safe_strcpy\n"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!src) {
|
||||
if (!src)
|
||||
{
|
||||
*dest = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
len = strlen (src);
|
||||
|
||||
if (len > maxlength) {
|
||||
if (len > maxlength)
|
||||
{
|
||||
DEBUG (0, ("ERROR: string overflow by %d in safe_strcpy [%.50s]\n",
|
||||
(int) (len - maxlength), src));
|
||||
len = maxlength;
|
||||
@ -779,23 +829,27 @@ char *safe_strcpy(char *dest,const char *src, size_t maxlength)
|
||||
safe string cat into a string. maxlength does not
|
||||
include the terminating zero.
|
||||
********************************************************************/
|
||||
char *safe_strcat(char *dest, const char *src, size_t maxlength)
|
||||
char *
|
||||
safe_strcat (char *dest, const char *src, size_t maxlength)
|
||||
{
|
||||
size_t src_len, dest_len;
|
||||
|
||||
if (!dest) {
|
||||
if (!dest)
|
||||
{
|
||||
DEBUG (0, ("ERROR: NULL dest in safe_strcat\n"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!src) {
|
||||
if (!src)
|
||||
{
|
||||
return dest;
|
||||
}
|
||||
|
||||
src_len = strlen (src);
|
||||
dest_len = strlen (dest);
|
||||
|
||||
if (src_len + dest_len > maxlength) {
|
||||
if (src_len + dest_len > maxlength)
|
||||
{
|
||||
DEBUG (0, ("ERROR: string overflow by %d in safe_strcat [%.50s]\n",
|
||||
(int) (src_len + dest_len - maxlength), src));
|
||||
src_len = maxlength - dest_len;
|
||||
@ -809,15 +863,18 @@ char *safe_strcat(char *dest, const char *src, size_t maxlength)
|
||||
/****************************************************************************
|
||||
this is a safer strcpy(), meant to prevent core dumps when nasty things happen
|
||||
****************************************************************************/
|
||||
char *StrCpy(char *dest,const char *src)
|
||||
char *
|
||||
StrCpy (char *dest, const char *src)
|
||||
{
|
||||
char *d = dest;
|
||||
|
||||
/* I don't want to get lazy with these ... */
|
||||
SMB_ASSERT (dest && src);
|
||||
|
||||
if (!dest) return(NULL);
|
||||
if (!src) {
|
||||
if (!dest)
|
||||
return (NULL);
|
||||
if (!src)
|
||||
{
|
||||
*dest = 0;
|
||||
return (dest);
|
||||
}
|
||||
@ -828,11 +885,14 @@ char *StrCpy(char *dest,const char *src)
|
||||
/****************************************************************************
|
||||
like strncpy but always null terminates. Make sure there is room!
|
||||
****************************************************************************/
|
||||
char *StrnCpy(char *dest,const char *src,size_t n)
|
||||
char *
|
||||
StrnCpy (char *dest, const char *src, size_t n)
|
||||
{
|
||||
char *d = dest;
|
||||
if (!dest) return(NULL);
|
||||
if (!src) {
|
||||
if (!dest)
|
||||
return (NULL);
|
||||
if (!src)
|
||||
{
|
||||
*dest = 0;
|
||||
return (dest);
|
||||
}
|
||||
@ -846,7 +906,8 @@ char *StrnCpy(char *dest,const char *src,size_t n)
|
||||
like strncpy but copies up to the character marker. always null terminates.
|
||||
returns a pointer to the character marker in the source string (src).
|
||||
****************************************************************************/
|
||||
char *strncpyn(char *dest, const char *src,size_t n, char c)
|
||||
char *
|
||||
strncpyn (char *dest, const char *src, size_t n, char c)
|
||||
{
|
||||
char *p;
|
||||
size_t str_len;
|
||||
@ -875,7 +936,8 @@ char *strncpyn(char *dest, const char *src,size_t n, char c)
|
||||
valid examples: "0A5D15"; "0x15, 0x49, 0xa2"; "59\ta9\te3\n"
|
||||
|
||||
**************************************************************/
|
||||
size_t strhex_to_str(char *p, size_t len, const char *strhex)
|
||||
size_t
|
||||
strhex_to_str (char *p, size_t len, const char *strhex)
|
||||
{
|
||||
size_t i;
|
||||
size_t num_chars = 0;
|
||||
@ -919,18 +981,24 @@ size_t strhex_to_str(char *p, size_t len, const char *strhex)
|
||||
/****************************************************************************
|
||||
check if a string is part of a list
|
||||
****************************************************************************/
|
||||
BOOL in_list(char *s,char *list,BOOL casesensitive)
|
||||
BOOL
|
||||
in_list (char *s, char *list, BOOL casesensitive)
|
||||
{
|
||||
pstring tok;
|
||||
char *p = list;
|
||||
|
||||
if (!list) return(False);
|
||||
if (!list)
|
||||
return (False);
|
||||
|
||||
while (next_token(&p,tok,LIST_SEP,sizeof(tok))) {
|
||||
if (casesensitive) {
|
||||
while (next_token (&p, tok, LIST_SEP, sizeof (tok)))
|
||||
{
|
||||
if (casesensitive)
|
||||
{
|
||||
if (strcmp (tok, s) == 0)
|
||||
return (True);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (StrCaseCmp (tok, s) == 0)
|
||||
return (True);
|
||||
}
|
||||
@ -945,7 +1013,8 @@ static char *null_string = NULL;
|
||||
/****************************************************************************
|
||||
set a string value, allocing the space for the string
|
||||
****************************************************************************/
|
||||
BOOL string_init(char **dest,const char *src)
|
||||
BOOL
|
||||
string_init (char **dest, const char *src)
|
||||
{
|
||||
size_t l;
|
||||
if (!src)
|
||||
@ -955,8 +1024,10 @@ BOOL string_init(char **dest,const char *src)
|
||||
|
||||
if (l == 0)
|
||||
{
|
||||
if (!null_string) {
|
||||
if((null_string = (char *)malloc(1)) == NULL) {
|
||||
if (!null_string)
|
||||
{
|
||||
if ((null_string = (char *) malloc (1)) == NULL)
|
||||
{
|
||||
DEBUG (0, ("string_init: malloc fail for null_string.\n"));
|
||||
return False;
|
||||
}
|
||||
@ -967,7 +1038,8 @@ BOOL string_init(char **dest,const char *src)
|
||||
else
|
||||
{
|
||||
(*dest) = (char *) malloc (l + 1);
|
||||
if ((*dest) == NULL) {
|
||||
if ((*dest) == NULL)
|
||||
{
|
||||
DEBUG (0, ("Out of memory in string_init\n"));
|
||||
return False;
|
||||
}
|
||||
@ -980,12 +1052,15 @@ BOOL string_init(char **dest,const char *src)
|
||||
/****************************************************************************
|
||||
free a string value
|
||||
****************************************************************************/
|
||||
void string_free(char **s)
|
||||
void
|
||||
string_free (char **s)
|
||||
{
|
||||
if (!s || !(*s)) return;
|
||||
if (!s || !(*s))
|
||||
return;
|
||||
if (*s == null_string)
|
||||
*s = NULL;
|
||||
if (*s) free(*s);
|
||||
if (*s)
|
||||
free (*s);
|
||||
*s = NULL;
|
||||
}
|
||||
|
||||
@ -993,7 +1068,8 @@ void string_free(char **s)
|
||||
set a string value, allocing the space for the string, and deallocating any
|
||||
existing space
|
||||
****************************************************************************/
|
||||
BOOL string_set(char **dest,const char *src)
|
||||
BOOL
|
||||
string_set (char **dest, const char *src)
|
||||
{
|
||||
string_free (dest);
|
||||
|
||||
@ -1010,23 +1086,29 @@ insert. It may do multiple replacements.
|
||||
|
||||
any of " ; ' or ` in the insert string are replaced with _
|
||||
****************************************************************************/
|
||||
void string_sub(char *s,const char *pattern,const char *insert)
|
||||
void
|
||||
string_sub (char *s, const char *pattern, const char *insert)
|
||||
{
|
||||
char *p;
|
||||
size_t ls, lp, li, i;
|
||||
|
||||
if (!insert || !pattern || !s) return;
|
||||
if (!insert || !pattern || !s)
|
||||
return;
|
||||
|
||||
ls = strlen (s);
|
||||
lp = strlen (pattern);
|
||||
li = strlen (insert);
|
||||
|
||||
if (!*pattern) return;
|
||||
if (!*pattern)
|
||||
return;
|
||||
|
||||
while (lp <= ls && (p = strstr(s,pattern))) {
|
||||
while (lp <= ls && (p = strstr (s, pattern)))
|
||||
{
|
||||
memmove (p + li, p + lp, ls + 1 - (PTR_DIFF (p, s) + lp));
|
||||
for (i=0;i<li;i++) {
|
||||
switch (insert[i]) {
|
||||
for (i = 0; i < li; i++)
|
||||
{
|
||||
switch (insert[i])
|
||||
{
|
||||
case '`':
|
||||
case '"':
|
||||
case '\'':
|
||||
@ -1047,20 +1129,24 @@ void string_sub(char *s,const char *pattern,const char *insert)
|
||||
similar to string_sub() but allows for any character to be substituted.
|
||||
Use with caution!
|
||||
****************************************************************************/
|
||||
void all_string_sub(char *s,const char *pattern,const char *insert)
|
||||
void
|
||||
all_string_sub (char *s, const char *pattern, const char *insert)
|
||||
{
|
||||
char *p;
|
||||
size_t ls, lp, li;
|
||||
|
||||
if (!insert || !pattern || !s) return;
|
||||
if (!insert || !pattern || !s)
|
||||
return;
|
||||
|
||||
ls = strlen (s);
|
||||
lp = strlen (pattern);
|
||||
li = strlen (insert);
|
||||
|
||||
if (!*pattern) return;
|
||||
if (!*pattern)
|
||||
return;
|
||||
|
||||
while (lp <= ls && (p = strstr(s,pattern))) {
|
||||
while (lp <= ls && (p = strstr (s, pattern)))
|
||||
{
|
||||
memmove (p + li, p + lp, ls + 1 - (PTR_DIFF (p, s) + lp));
|
||||
memcpy (p, insert, li);
|
||||
s = p + li;
|
||||
@ -1072,7 +1158,8 @@ void all_string_sub(char *s,const char *pattern,const char *insert)
|
||||
/****************************************************************************
|
||||
splits out the front and back at a separator.
|
||||
****************************************************************************/
|
||||
void split_at_last_component(char *path, char *front, char sep, char *back)
|
||||
void
|
||||
split_at_last_component (char *path, char *front, char sep, char *back)
|
||||
{
|
||||
char *p = strrchr (path, sep);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -36,13 +36,16 @@ const BOOL global_in_nmbd = False;
|
||||
/****************************************************************************
|
||||
interpret a node status response
|
||||
****************************************************************************/
|
||||
static void _interpret_node_status(char *p, char *master,char *rname)
|
||||
static void
|
||||
_interpret_node_status (char *p, char *master, char *rname)
|
||||
{
|
||||
int numnames = CVAL (p, 0);
|
||||
DEBUG (1, ("received %d names\n", numnames));
|
||||
|
||||
if (rname) *rname = 0;
|
||||
if (master) *master = 0;
|
||||
if (rname)
|
||||
*rname = 0;
|
||||
if (master)
|
||||
*master = 0;
|
||||
|
||||
p += 1;
|
||||
while (numnames--)
|
||||
@ -57,33 +60,44 @@ static void _interpret_node_status(char *p, char *master,char *rname)
|
||||
p += 16;
|
||||
|
||||
fstrcat (flags, (p[0] & 0x80) ? "<GROUP> " : " ");
|
||||
if ((p[0] & 0x60) == 0x00) fstrcat(flags,"B ");
|
||||
if ((p[0] & 0x60) == 0x20) fstrcat(flags,"P ");
|
||||
if ((p[0] & 0x60) == 0x40) fstrcat(flags,"M ");
|
||||
if ((p[0] & 0x60) == 0x60) fstrcat(flags,"H ");
|
||||
if (p[0] & 0x10) fstrcat(flags,"<DEREGISTERING> ");
|
||||
if (p[0] & 0x08) fstrcat(flags,"<CONFLICT> ");
|
||||
if (p[0] & 0x04) fstrcat(flags,"<ACTIVE> ");
|
||||
if (p[0] & 0x02) fstrcat(flags,"<PERMANENT> ");
|
||||
if ((p[0] & 0x60) == 0x00)
|
||||
fstrcat (flags, "B ");
|
||||
if ((p[0] & 0x60) == 0x20)
|
||||
fstrcat (flags, "P ");
|
||||
if ((p[0] & 0x60) == 0x40)
|
||||
fstrcat (flags, "M ");
|
||||
if ((p[0] & 0x60) == 0x60)
|
||||
fstrcat (flags, "H ");
|
||||
if (p[0] & 0x10)
|
||||
fstrcat (flags, "<DEREGISTERING> ");
|
||||
if (p[0] & 0x08)
|
||||
fstrcat (flags, "<CONFLICT> ");
|
||||
if (p[0] & 0x04)
|
||||
fstrcat (flags, "<ACTIVE> ");
|
||||
if (p[0] & 0x02)
|
||||
fstrcat (flags, "<PERMANENT> ");
|
||||
|
||||
if (master && !*master && type == 0x1d) {
|
||||
if (master && !*master && type == 0x1d)
|
||||
{
|
||||
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, " ");
|
||||
}
|
||||
|
||||
for (i = strlen( qname) ; --i >= 0 ; ) {
|
||||
if (!isprint((int)qname[i])) qname[i] = '.';
|
||||
for (i = strlen (qname); --i >= 0;)
|
||||
{
|
||||
if (!isprint ((int) qname[i]))
|
||||
qname[i] = '.';
|
||||
}
|
||||
DEBUG (1, ("\t%-15s <%02x> - %s\n", qname, type, flags));
|
||||
p += 2;
|
||||
}
|
||||
DEBUG(1,("num_good_sends=%d num_good_receives=%d\n",
|
||||
IVAL(p,20),IVAL(p,24)));
|
||||
DEBUG (1, ("num_good_sends=%d num_good_receives=%d\n", IVAL (p, 20), IVAL (p, 24)));
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
@ -92,7 +106,8 @@ static void _interpret_node_status(char *p, char *master,char *rname)
|
||||
returns an array of IP addresses or NULL if none
|
||||
*count will be set to the number of addresses returned
|
||||
****************************************************************************/
|
||||
struct in_addr *name_query(int fd,const char *name,int name_type, BOOL bcast,BOOL recurse,
|
||||
struct in_addr *
|
||||
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;
|
||||
@ -108,7 +123,8 @@ struct in_addr *name_query(int fd,const char *name,int name_type, BOOL bcast,BOO
|
||||
memset ((char *) &p, '\0', sizeof (p));
|
||||
(*count) = 0;
|
||||
|
||||
if (!name_trn_id) name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) +
|
||||
if (!name_trn_id)
|
||||
name_trn_id = ((unsigned) time (NULL) % (unsigned) 0x7FFF) +
|
||||
((unsigned) getpid () % (unsigned) 100);
|
||||
name_trn_id = (name_trn_id + 1) % (unsigned) 0x7FFF;
|
||||
|
||||
@ -163,8 +179,7 @@ struct in_addr *name_query(int fd,const char *name,int name_type, BOOL bcast,BOO
|
||||
struct nmb_packet *nmb2 = &p2->packet.nmb;
|
||||
debug_nmb_packet (p2);
|
||||
|
||||
if (nmb->header.name_trn_id != nmb2->header.name_trn_id ||
|
||||
!nmb2->header.response)
|
||||
if (nmb->header.name_trn_id != nmb2->header.name_trn_id || !nmb2->header.response)
|
||||
{
|
||||
/*
|
||||
* Its not for us - maybe deal with it later
|
||||
@ -178,9 +193,7 @@ struct in_addr *name_query(int fd,const char *name,int name_type, BOOL bcast,BOO
|
||||
}
|
||||
|
||||
if (nmb2->header.opcode != 0 ||
|
||||
nmb2->header.nm_flags.bcast ||
|
||||
nmb2->header.rcode ||
|
||||
!nmb2->header.ancount)
|
||||
nmb2->header.nm_flags.bcast || nmb2->header.rcode || !nmb2->header.ancount)
|
||||
{
|
||||
/*
|
||||
* XXXX what do we do with this? Could be a redirect, but
|
||||
@ -228,10 +241,12 @@ struct in_addr *name_query(int fd,const char *name,int name_type, BOOL bcast,BOO
|
||||
Start parsing the lmhosts file.
|
||||
*********************************************************/
|
||||
|
||||
FILE *startlmhosts(const char *fname)
|
||||
FILE *
|
||||
startlmhosts (const char *fname)
|
||||
{
|
||||
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)));
|
||||
return NULL;
|
||||
@ -242,11 +257,13 @@ FILE *startlmhosts(const char *fname)
|
||||
/********************************************************
|
||||
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;
|
||||
|
||||
while(!feof(fp) && !ferror(fp)) {
|
||||
while (!feof (fp) && !ferror (fp))
|
||||
{
|
||||
pstring ip, flags, extra;
|
||||
char *ptr;
|
||||
int count = 0;
|
||||
@ -327,7 +344,8 @@ BOOL getlmhostsent( FILE *fp, pstring name, int *name_type, struct in_addr *ipad
|
||||
Finish parsing the lmhosts file.
|
||||
*********************************************************/
|
||||
|
||||
void endlmhosts(FILE *fp)
|
||||
void
|
||||
endlmhosts (FILE * fp)
|
||||
{
|
||||
fclose (fp);
|
||||
}
|
||||
@ -335,7 +353,8 @@ void endlmhosts(FILE *fp)
|
||||
/********************************************************
|
||||
resolve via "bcast" method
|
||||
*********************************************************/
|
||||
static BOOL resolve_bcast(const char *name, struct in_addr *return_ip, int name_type)
|
||||
static BOOL
|
||||
resolve_bcast (const char *name, struct in_addr *return_ip, int name_type)
|
||||
{
|
||||
int sock, i;
|
||||
|
||||
@ -345,10 +364,10 @@ static BOOL resolve_bcast(const char *name, struct in_addr *return_ip, int name_
|
||||
|
||||
DEBUG (3, ("resolve_name: Attempting broadcast lookup for name %s<0x%x>\n", name, name_type));
|
||||
|
||||
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) {
|
||||
if (sock != -1)
|
||||
{
|
||||
struct in_addr *iplist = NULL;
|
||||
int count;
|
||||
int num_interfaces = iface_count ();
|
||||
@ -358,13 +377,14 @@ static BOOL resolve_bcast(const char *name, struct in_addr *return_ip, int name_
|
||||
* Lookup the name on all the interfaces, return on
|
||||
* the first successful match.
|
||||
*/
|
||||
for( i = 0; i < num_interfaces; i++) {
|
||||
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) {
|
||||
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);
|
||||
@ -382,7 +402,8 @@ static BOOL resolve_bcast(const char *name, struct in_addr *return_ip, int name_
|
||||
/********************************************************
|
||||
resolve via "wins" method
|
||||
*********************************************************/
|
||||
static BOOL resolve_wins(const char *name, struct in_addr *return_ip, int name_type)
|
||||
static BOOL
|
||||
resolve_wins (const char *name, struct in_addr *return_ip, int name_type)
|
||||
{
|
||||
int sock;
|
||||
struct in_addr wins_ip;
|
||||
@ -398,7 +419,8 @@ static BOOL resolve_wins(const char *name, struct in_addr *return_ip, int name_t
|
||||
|
||||
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;
|
||||
}
|
||||
@ -406,16 +428,17 @@ static BOOL resolve_wins(const char *name, struct in_addr *return_ip, int name_t
|
||||
wins_ip = *interpret_addr2 (lp_wins_server ());
|
||||
wins_ismyip = ismyip (wins_ip);
|
||||
|
||||
if((wins_ismyip && !global_in_nmbd) || !wins_ismyip) {
|
||||
sock = open_socket_in( SOCK_DGRAM, 0, 3,
|
||||
interpret_addr(lp_socket_address()), True );
|
||||
if ((wins_ismyip && !global_in_nmbd) || !wins_ismyip)
|
||||
{
|
||||
sock = open_socket_in (SOCK_DGRAM, 0, 3, interpret_addr (lp_socket_address ()), True);
|
||||
|
||||
if (sock != -1) {
|
||||
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) {
|
||||
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);
|
||||
@ -432,7 +455,8 @@ static BOOL resolve_wins(const char *name, struct in_addr *return_ip, int name_t
|
||||
/********************************************************
|
||||
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.
|
||||
@ -445,11 +469,12 @@ static BOOL resolve_lmhosts(const char *name, struct in_addr *return_ip, int nam
|
||||
DEBUG (3, ("resolve_name: Attempting lmhosts lookup for name %s<0x%x>\n", name, name_type));
|
||||
|
||||
fp = startlmhosts (LMHOSTSFILE);
|
||||
if(fp) {
|
||||
while (getlmhostsent(fp, lmhost_name, &name_type2, return_ip)) {
|
||||
if (strequal(name, lmhost_name) &&
|
||||
((name_type2 == -1) || (name_type == name_type2))
|
||||
) {
|
||||
if (fp)
|
||||
{
|
||||
while (getlmhostsent (fp, lmhost_name, &name_type2, return_ip))
|
||||
{
|
||||
if (strequal (name, lmhost_name) && ((name_type2 == -1) || (name_type == name_type2)))
|
||||
{
|
||||
endlmhosts (fp);
|
||||
return True;
|
||||
}
|
||||
@ -463,7 +488,8 @@ static BOOL resolve_lmhosts(const char *name, struct in_addr *return_ip, int nam
|
||||
/********************************************************
|
||||
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.
|
||||
@ -472,7 +498,8 @@ static BOOL resolve_hosts(const char *name, struct in_addr *return_ip)
|
||||
|
||||
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;
|
||||
}
|
||||
@ -486,7 +513,8 @@ static BOOL resolve_hosts(const char *name, struct in_addr *return_ip)
|
||||
or NetBIOS name. This uses the name switch in the
|
||||
smb.conf to determine the order of name resolution.
|
||||
*********************************************************/
|
||||
BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type)
|
||||
BOOL
|
||||
resolve_name (const char *name, struct in_addr * return_ip, int name_type)
|
||||
{
|
||||
int i;
|
||||
BOOL pure_address = True;
|
||||
@ -494,11 +522,13 @@ BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type)
|
||||
fstring tok;
|
||||
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;
|
||||
}
|
||||
if (strcmp(name,"255.255.255.255") == 0) {
|
||||
if (strcmp (name, "255.255.255.255") == 0)
|
||||
{
|
||||
return_ip->s_addr = 0xFFFFFFFF;
|
||||
return True;
|
||||
}
|
||||
@ -508,7 +538,8 @@ BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type)
|
||||
pure_address = False;
|
||||
|
||||
/* if it's in the form of an IP address then get the lib to interpret it */
|
||||
if (pure_address) {
|
||||
if (pure_address)
|
||||
{
|
||||
return_ip->s_addr = inet_addr (name);
|
||||
return True;
|
||||
}
|
||||
@ -518,26 +549,39 @@ BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type)
|
||||
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)) {
|
||||
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)) {
|
||||
}
|
||||
else if (strequal (tok, "lmhosts"))
|
||||
{
|
||||
if (resolve_lmhosts (name, return_ip, name_type))
|
||||
{
|
||||
return True;
|
||||
}
|
||||
} else if(strequal( tok, "wins")) {
|
||||
}
|
||||
else if (strequal (tok, "wins"))
|
||||
{
|
||||
/* don't resolve 1D via WINS */
|
||||
if (name_type != 0x1D &&
|
||||
resolve_wins(name, return_ip, name_type)) {
|
||||
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)) {
|
||||
}
|
||||
else if (strequal (tok, "bcast"))
|
||||
{
|
||||
if (resolve_bcast (name, return_ip, name_type))
|
||||
{
|
||||
return True;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG (0, ("resolve_name: unknown name switch type %s\n", tok));
|
||||
}
|
||||
}
|
||||
@ -550,9 +594,11 @@ BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type)
|
||||
/********************************************************
|
||||
find the IP address of the master browser or DMB for a workgroup
|
||||
*********************************************************/
|
||||
BOOL find_master_ip(char *group, struct in_addr *master_ip)
|
||||
BOOL
|
||||
find_master_ip (char *group, struct in_addr * master_ip)
|
||||
{
|
||||
if (resolve_name(group, master_ip, 0x1D)) return True;
|
||||
if (resolve_name (group, master_ip, 0x1D))
|
||||
return True;
|
||||
|
||||
return resolve_name (group, master_ip, 0x1B);
|
||||
}
|
||||
|
@ -32,7 +32,8 @@ extern int DEBUGLEVEL;
|
||||
int num_good_sends = 0;
|
||||
int num_good_receives = 0;
|
||||
|
||||
static struct opcode_names {
|
||||
static struct opcode_names
|
||||
{
|
||||
const char *nmb_opcode_name;
|
||||
int opcode;
|
||||
} const nmb_header_opcode_names[] = {
|
||||
@ -49,11 +50,13 @@ static struct opcode_names {
|
||||
/****************************************************************************
|
||||
* Lookup a nmb opcode name.
|
||||
****************************************************************************/
|
||||
static const char *lookup_opcode_name( int opcode )
|
||||
static const char *
|
||||
lookup_opcode_name (int opcode)
|
||||
{
|
||||
const struct opcode_names *op_namep = nmb_header_opcode_names;
|
||||
|
||||
while(op_namep->nmb_opcode_name) {
|
||||
while (op_namep->nmb_opcode_name)
|
||||
{
|
||||
if (opcode == op_namep->opcode)
|
||||
return op_namep->nmb_opcode_name;
|
||||
op_namep++;
|
||||
@ -64,16 +67,13 @@ static const char *lookup_opcode_name( int opcode )
|
||||
/****************************************************************************
|
||||
print out a res_rec structure
|
||||
****************************************************************************/
|
||||
static void debug_nmb_res_rec(struct res_rec *res, const char *hdr)
|
||||
static void
|
||||
debug_nmb_res_rec (struct res_rec *res, const char *hdr)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
DEBUGADD (4, (" %s: nmb_name=%s rr_type=%d rr_class=%d ttl=%d\n",
|
||||
hdr,
|
||||
nmb_namestr(&res->rr_name),
|
||||
res->rr_type,
|
||||
res->rr_class,
|
||||
res->ttl ) );
|
||||
hdr, nmb_namestr (&res->rr_name), res->rr_type, res->rr_class, res->ttl));
|
||||
|
||||
if (res->rdlength == 0 || res->rdata == NULL)
|
||||
return;
|
||||
@ -85,9 +85,11 @@ static void debug_nmb_res_rec(struct res_rec *res, const char *hdr)
|
||||
for (j = 0; j < 16; j++)
|
||||
{
|
||||
unsigned char x = res->rdata[i + j];
|
||||
if (x < 32 || x > 127) x = '.';
|
||||
if (x < 32 || x > 127)
|
||||
x = '.';
|
||||
|
||||
if (i+j >= res->rdlength) break;
|
||||
if (i + j >= res->rdlength)
|
||||
break;
|
||||
DEBUGADD (4, ("%c", x));
|
||||
}
|
||||
|
||||
@ -95,7 +97,8 @@ static void debug_nmb_res_rec(struct res_rec *res, const char *hdr)
|
||||
|
||||
for (j = 0; j < 16; j++)
|
||||
{
|
||||
if (i+j >= res->rdlength) break;
|
||||
if (i + j >= res->rdlength)
|
||||
break;
|
||||
DEBUGADD (4, ("%02X", (unsigned char) res->rdata[i + j]));
|
||||
}
|
||||
|
||||
@ -106,7 +109,8 @@ static void debug_nmb_res_rec(struct res_rec *res, const char *hdr)
|
||||
/****************************************************************************
|
||||
process a nmb packet
|
||||
****************************************************************************/
|
||||
void debug_nmb_packet(struct packet_struct *p)
|
||||
void
|
||||
debug_nmb_packet (struct packet_struct *p)
|
||||
{
|
||||
struct nmb_packet *nmb = &p->packet.nmb;
|
||||
|
||||
@ -116,8 +120,7 @@ void debug_nmb_packet(struct packet_struct *p)
|
||||
inet_ntoa (p->ip), p->port,
|
||||
nmb->header.name_trn_id,
|
||||
lookup_opcode_name (nmb->header.opcode),
|
||||
nmb->header.opcode,
|
||||
BOOLSTR(nmb->header.response) );
|
||||
nmb->header.opcode, BOOLSTR (nmb->header.response));
|
||||
dbgtext (" header: flags: bcast=%s rec_avail=%s rec_des=%s trunc=%s auth=%s\n",
|
||||
BOOLSTR (nmb->header.nm_flags.bcast),
|
||||
BOOLSTR (nmb->header.nm_flags.recursion_available),
|
||||
@ -127,17 +130,14 @@ void debug_nmb_packet(struct packet_struct *p)
|
||||
dbgtext (" header: rcode=%d qdcount=%d ancount=%d nscount=%d arcount=%d\n",
|
||||
nmb->header.rcode,
|
||||
nmb->header.qdcount,
|
||||
nmb->header.ancount,
|
||||
nmb->header.nscount,
|
||||
nmb->header.arcount );
|
||||
nmb->header.ancount, nmb->header.nscount, nmb->header.arcount);
|
||||
}
|
||||
|
||||
if (nmb->header.qdcount)
|
||||
{
|
||||
DEBUGADD (4, (" question: q_name=%s q_type=%d q_class=%d\n",
|
||||
nmb_namestr (&nmb->question.question_name),
|
||||
nmb->question.question_type,
|
||||
nmb->question.question_class) );
|
||||
nmb->question.question_type, nmb->question.question_class));
|
||||
}
|
||||
|
||||
if (nmb->answers && nmb->header.ancount)
|
||||
@ -157,16 +157,19 @@ void debug_nmb_packet(struct packet_struct *p)
|
||||
/*******************************************************************
|
||||
handle "compressed" name pointers
|
||||
******************************************************************/
|
||||
static BOOL handle_name_ptrs(unsigned char *ubuf,int *offset,int length,
|
||||
BOOL *got_pointer,int *ret)
|
||||
static BOOL
|
||||
handle_name_ptrs (unsigned char *ubuf, int *offset, int length, BOOL * got_pointer, int *ret)
|
||||
{
|
||||
int loop_count = 0;
|
||||
|
||||
while ((ubuf[*offset] & 0xC0) == 0xC0) {
|
||||
if (!*got_pointer) (*ret) += 2;
|
||||
while ((ubuf[*offset] & 0xC0) == 0xC0)
|
||||
{
|
||||
if (!*got_pointer)
|
||||
(*ret) += 2;
|
||||
(*got_pointer) = True;
|
||||
(*offset) = ((ubuf[*offset] & ~0xC0) << 8) | ubuf[(*offset) + 1];
|
||||
if (loop_count++ == 10 || (*offset) < 0 || (*offset)>(length-2)) {
|
||||
if (loop_count++ == 10 || (*offset) < 0 || (*offset) > (length - 2))
|
||||
{
|
||||
return (False);
|
||||
}
|
||||
}
|
||||
@ -177,7 +180,8 @@ static BOOL handle_name_ptrs(unsigned char *ubuf,int *offset,int length,
|
||||
parse a nmb name from "compressed" format to something readable
|
||||
return the space taken by the name, or 0 if the name is invalid
|
||||
******************************************************************/
|
||||
static int parse_nmb_name(char *inbuf,int offset,int length, struct nmb_name *name)
|
||||
static int
|
||||
parse_nmb_name (char *inbuf, int offset, int length, struct nmb_name *name)
|
||||
{
|
||||
int m, n = 0;
|
||||
unsigned char *ubuf = (unsigned char *) inbuf;
|
||||
@ -204,7 +208,8 @@ static int parse_nmb_name(char *inbuf,int offset,int length, struct nmb_name *na
|
||||
if (!got_pointer)
|
||||
ret += m + 2;
|
||||
offset++;
|
||||
while (m > 0) {
|
||||
while (m > 0)
|
||||
{
|
||||
unsigned char c1, c2;
|
||||
c1 = ubuf[offset++] - 'A';
|
||||
c2 = ubuf[offset++] - 'A';
|
||||
@ -215,7 +220,8 @@ static int parse_nmb_name(char *inbuf,int offset,int length, struct nmb_name *na
|
||||
}
|
||||
name->name[n] = 0;
|
||||
|
||||
if (n==16) {
|
||||
if (n == 16)
|
||||
{
|
||||
/* parse out the name type,
|
||||
its always in the 16th byte of the name */
|
||||
name->name_type = ((unsigned char) name->name[15]) & 0xff;
|
||||
@ -229,7 +235,8 @@ static int parse_nmb_name(char *inbuf,int offset,int length, struct nmb_name *na
|
||||
|
||||
/* now the domain parts (if any) */
|
||||
n = 0;
|
||||
while (ubuf[offset]) {
|
||||
while (ubuf[offset])
|
||||
{
|
||||
/* we can have pointers within the domain part as well */
|
||||
if (!handle_name_ptrs (ubuf, &offset, length, &got_pointer, &ret))
|
||||
return (0);
|
||||
@ -259,18 +266,22 @@ static int parse_nmb_name(char *inbuf,int offset,int length, struct nmb_name *na
|
||||
size. The idea is that it also means that compressed names conform
|
||||
to the doman name system. See RFC1002.
|
||||
******************************************************************/
|
||||
static int put_nmb_name(char *buf,int offset,struct nmb_name *name)
|
||||
static int
|
||||
put_nmb_name (char *buf, int offset, struct nmb_name *name)
|
||||
{
|
||||
int ret, m;
|
||||
fstring buf1;
|
||||
char *p;
|
||||
|
||||
if (strcmp(name->name,"*") == 0) {
|
||||
if (strcmp (name->name, "*") == 0)
|
||||
{
|
||||
/* special case for wildcard name */
|
||||
memset (buf1, '\0', 20);
|
||||
buf1[0] = '*';
|
||||
buf1[15] = name->name_type;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
slprintf (buf1, sizeof (buf1) - 1, "%-15.15s%c", name->name, name->name_type);
|
||||
}
|
||||
|
||||
@ -278,7 +289,8 @@ static int put_nmb_name(char *buf,int offset,struct nmb_name *name)
|
||||
|
||||
ret = 34;
|
||||
|
||||
for (m=0;m<16;m++) {
|
||||
for (m = 0; m < 16; m++)
|
||||
{
|
||||
buf[offset + 1 + 2 * m] = 'A' + ((buf1[m] >> 4) & 0xF);
|
||||
buf[offset + 2 + 2 * m] = 'A' + (buf1[m] & 0xF);
|
||||
}
|
||||
@ -286,13 +298,15 @@ static int put_nmb_name(char *buf,int offset,struct nmb_name *name)
|
||||
|
||||
buf[offset] = 0;
|
||||
|
||||
if (name->scope[0]) {
|
||||
if (name->scope[0])
|
||||
{
|
||||
/* XXXX this scope handling needs testing */
|
||||
ret += strlen (name->scope) + 1;
|
||||
pstrcpy (&buf[offset + 1], name->scope);
|
||||
|
||||
p = &buf[offset + 1];
|
||||
while ((p = strchr(p,'.'))) {
|
||||
while ((p = strchr (p, '.')))
|
||||
{
|
||||
buf[offset] = PTR_DIFF (p, &buf[offset + 1]);
|
||||
offset += (buf[offset] + 1);
|
||||
p = &buf[offset + 1];
|
||||
@ -306,7 +320,8 @@ static int put_nmb_name(char *buf,int offset,struct nmb_name *name)
|
||||
/*******************************************************************
|
||||
useful for debugging messages
|
||||
******************************************************************/
|
||||
char *nmb_namestr(struct nmb_name *n)
|
||||
char *
|
||||
nmb_namestr (struct nmb_name *n)
|
||||
{
|
||||
static int i = 0;
|
||||
static fstring ret[4];
|
||||
@ -324,19 +339,22 @@ char *nmb_namestr(struct nmb_name *n)
|
||||
/*******************************************************************
|
||||
allocate and parse some resource records
|
||||
******************************************************************/
|
||||
static BOOL parse_alloc_res_rec(char *inbuf,int *offset,int length,
|
||||
struct res_rec **recs, int count)
|
||||
static BOOL
|
||||
parse_alloc_res_rec (char *inbuf, int *offset, int length, struct res_rec **recs, int count)
|
||||
{
|
||||
int i;
|
||||
*recs = (struct res_rec *) malloc (sizeof (**recs) * count);
|
||||
if (!*recs) return(False);
|
||||
if (!*recs)
|
||||
return (False);
|
||||
|
||||
memset ((char *) *recs, '\0', sizeof (**recs) * count);
|
||||
|
||||
for (i=0;i<count;i++) {
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
int l = parse_nmb_name (inbuf, *offset, length, &(*recs)[i].rr_name);
|
||||
(*offset) += l;
|
||||
if (!l || (*offset)+10 > length) {
|
||||
if (!l || (*offset) + 10 > length)
|
||||
{
|
||||
free (*recs);
|
||||
return (False);
|
||||
}
|
||||
@ -346,7 +364,8 @@ static BOOL parse_alloc_res_rec(char *inbuf,int *offset,int length,
|
||||
(*recs)[i].rdlength = RSVAL (inbuf, (*offset) + 8);
|
||||
(*offset) += 10;
|
||||
if ((size_t) (*recs)[i].rdlength > sizeof ((*recs)[i].rdata) ||
|
||||
(*offset)+(*recs)[i].rdlength > length) {
|
||||
(*offset) + (*recs)[i].rdlength > length)
|
||||
{
|
||||
free (*recs);
|
||||
return (False);
|
||||
}
|
||||
@ -359,12 +378,14 @@ static BOOL parse_alloc_res_rec(char *inbuf,int *offset,int length,
|
||||
/*******************************************************************
|
||||
put a resource record into a packet
|
||||
******************************************************************/
|
||||
static int put_res_rec(char *buf,int offset,struct res_rec *recs,int count)
|
||||
static int
|
||||
put_res_rec (char *buf, int offset, struct res_rec *recs, int count)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
for (i=0;i<count;i++) {
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
int l = put_nmb_name (buf, offset, &recs[i].rr_name);
|
||||
offset += l;
|
||||
ret += l;
|
||||
@ -383,7 +404,8 @@ static int put_res_rec(char *buf,int offset,struct res_rec *recs,int count)
|
||||
/*******************************************************************
|
||||
put a compressed name pointer record into a packet
|
||||
******************************************************************/
|
||||
static int put_compressed_name_ptr(unsigned char *buf,int offset,struct res_rec *rec,int ptr_offset)
|
||||
static int
|
||||
put_compressed_name_ptr (unsigned char *buf, int offset, struct res_rec *rec, int ptr_offset)
|
||||
{
|
||||
int ret = 0;
|
||||
buf[offset] = (0xC0 | ((ptr_offset >> 8) & 0xFF));
|
||||
@ -407,20 +429,24 @@ static int put_compressed_name_ptr(unsigned char *buf,int offset,struct res_rec
|
||||
|
||||
this is documented in section 4.4.1 of RFC1002
|
||||
******************************************************************/
|
||||
static BOOL parse_dgram(char *inbuf,int length,struct dgram_packet *dgram)
|
||||
static BOOL
|
||||
parse_dgram (char *inbuf, int length, struct dgram_packet *dgram)
|
||||
{
|
||||
int offset;
|
||||
int flags;
|
||||
|
||||
memset ((char *) dgram, '\0', sizeof (*dgram));
|
||||
|
||||
if (length < 14) return(False);
|
||||
if (length < 14)
|
||||
return (False);
|
||||
|
||||
dgram->header.msg_type = CVAL (inbuf, 0);
|
||||
flags = CVAL (inbuf, 1);
|
||||
dgram->header.flags.node_type = (enum node_type) ((flags >> 2) & 3);
|
||||
if (flags & 1) dgram->header.flags.more = True;
|
||||
if (flags & 2) dgram->header.flags.first = True;
|
||||
if (flags & 1)
|
||||
dgram->header.flags.more = True;
|
||||
if (flags & 2)
|
||||
dgram->header.flags.first = True;
|
||||
dgram->header.dgm_id = RSVAL (inbuf, 2);
|
||||
putip ((char *) &dgram->header.source_ip, inbuf + 4);
|
||||
dgram->header.source_port = RSVAL (inbuf, 8);
|
||||
@ -430,8 +456,8 @@ static BOOL parse_dgram(char *inbuf,int length,struct dgram_packet *dgram)
|
||||
offset = 14;
|
||||
|
||||
if (dgram->header.msg_type == 0x10 ||
|
||||
dgram->header.msg_type == 0x11 ||
|
||||
dgram->header.msg_type == 0x12) {
|
||||
dgram->header.msg_type == 0x11 || dgram->header.msg_type == 0x12)
|
||||
{
|
||||
offset += parse_nmb_name (inbuf, offset, length, &dgram->source_name);
|
||||
offset += parse_nmb_name (inbuf, offset, length, &dgram->dest_name);
|
||||
}
|
||||
@ -450,13 +476,15 @@ static BOOL parse_dgram(char *inbuf,int length,struct dgram_packet *dgram)
|
||||
parse a nmb packet. Return False if the packet can't be parsed
|
||||
or is invalid for some reason, True otherwise
|
||||
******************************************************************/
|
||||
static BOOL parse_nmb(char *inbuf,int length,struct nmb_packet *nmb)
|
||||
static BOOL
|
||||
parse_nmb (char *inbuf, int length, struct nmb_packet *nmb)
|
||||
{
|
||||
int nm_flags, offset;
|
||||
|
||||
memset ((char *) nmb, '\0', sizeof (*nmb));
|
||||
|
||||
if (length < 12) return(False);
|
||||
if (length < 12)
|
||||
return (False);
|
||||
|
||||
/* parse the header */
|
||||
nmb->header.name_trn_id = RSVAL (inbuf, 0);
|
||||
@ -477,42 +505,46 @@ static BOOL parse_nmb(char *inbuf,int length,struct nmb_packet *nmb)
|
||||
nmb->header.nscount = RSVAL (inbuf, 8);
|
||||
nmb->header.arcount = RSVAL (inbuf, 10);
|
||||
|
||||
if (nmb->header.qdcount) {
|
||||
if (nmb->header.qdcount)
|
||||
{
|
||||
offset = parse_nmb_name (inbuf, 12, length, &nmb->question.question_name);
|
||||
if (!offset) return(False);
|
||||
if (!offset)
|
||||
return (False);
|
||||
|
||||
if (length - (12+offset) < 4) return(False);
|
||||
if (length - (12 + offset) < 4)
|
||||
return (False);
|
||||
nmb->question.question_type = RSVAL (inbuf, 12 + offset);
|
||||
nmb->question.question_class = RSVAL (inbuf, 12 + offset + 2);
|
||||
|
||||
offset += 12 + 4;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = 12;
|
||||
}
|
||||
|
||||
/* and any resource records */
|
||||
if (nmb->header.ancount &&
|
||||
!parse_alloc_res_rec(inbuf,&offset,length,&nmb->answers,
|
||||
nmb->header.ancount))
|
||||
!parse_alloc_res_rec (inbuf, &offset, length, &nmb->answers, nmb->header.ancount))
|
||||
return (False);
|
||||
|
||||
if (nmb->header.nscount &&
|
||||
!parse_alloc_res_rec(inbuf,&offset,length,&nmb->nsrecs,
|
||||
nmb->header.nscount))
|
||||
!parse_alloc_res_rec (inbuf, &offset, length, &nmb->nsrecs, nmb->header.nscount))
|
||||
return (False);
|
||||
|
||||
if (nmb->header.arcount &&
|
||||
!parse_alloc_res_rec(inbuf,&offset,length,&nmb->additional,
|
||||
nmb->header.arcount))
|
||||
!parse_alloc_res_rec (inbuf, &offset, length, &nmb->additional, nmb->header.arcount))
|
||||
return (False);
|
||||
|
||||
return (True);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*******************************************************************
|
||||
'Copy constructor' for an nmb packet
|
||||
******************************************************************/
|
||||
static struct packet_struct *copy_nmb_packet(struct packet_struct *packet)
|
||||
static struct packet_struct *
|
||||
copy_nmb_packet (struct packet_struct *packet)
|
||||
{
|
||||
struct nmb_packet *nmb;
|
||||
struct nmb_packet *copy_nmb;
|
||||
@ -585,7 +617,8 @@ free_and_exit:
|
||||
/*******************************************************************
|
||||
'Copy constructor' for a dgram packet
|
||||
******************************************************************/
|
||||
static struct packet_struct *copy_dgram_packet(struct packet_struct *packet)
|
||||
static struct packet_struct *
|
||||
copy_dgram_packet (struct packet_struct *packet)
|
||||
{
|
||||
struct packet_struct *pkt_copy;
|
||||
|
||||
@ -610,7 +643,8 @@ static struct packet_struct *copy_dgram_packet(struct packet_struct *packet)
|
||||
/*******************************************************************
|
||||
'Copy constructor' for a generic packet
|
||||
******************************************************************/
|
||||
struct packet_struct *copy_packet(struct packet_struct *packet)
|
||||
struct packet_struct *
|
||||
copy_packet (struct packet_struct *packet)
|
||||
{
|
||||
if (packet->packet_type == NMB_PACKET)
|
||||
return copy_nmb_packet (packet);
|
||||
@ -622,17 +656,22 @@ struct packet_struct *copy_packet(struct packet_struct *packet)
|
||||
/*******************************************************************
|
||||
free up any resources associated with an nmb packet
|
||||
******************************************************************/
|
||||
static void free_nmb_packet(struct nmb_packet *nmb)
|
||||
static void
|
||||
free_nmb_packet (struct nmb_packet *nmb)
|
||||
{
|
||||
if (nmb->answers) free(nmb->answers);
|
||||
if (nmb->nsrecs) free(nmb->nsrecs);
|
||||
if (nmb->additional) free(nmb->additional);
|
||||
if (nmb->answers)
|
||||
free (nmb->answers);
|
||||
if (nmb->nsrecs)
|
||||
free (nmb->nsrecs);
|
||||
if (nmb->additional)
|
||||
free (nmb->additional);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
free up any resources associated with a dgram packet
|
||||
******************************************************************/
|
||||
static void free_dgram_packet(struct dgram_packet *nmb)
|
||||
static void
|
||||
free_dgram_packet (struct dgram_packet *nmb)
|
||||
{
|
||||
/* We have nothing to do for a dgram packet. */
|
||||
(void) nmb;
|
||||
@ -641,7 +680,8 @@ static void free_dgram_packet(struct dgram_packet *nmb)
|
||||
/*******************************************************************
|
||||
free up any resources associated with a packet
|
||||
******************************************************************/
|
||||
void free_packet(struct packet_struct *packet)
|
||||
void
|
||||
free_packet (struct packet_struct *packet)
|
||||
{
|
||||
if (packet->locked)
|
||||
return;
|
||||
@ -656,7 +696,8 @@ void free_packet(struct packet_struct *packet)
|
||||
read a packet from a socket and parse it, returning a packet ready
|
||||
to be used or put on the queue. This assumes a UDP socket
|
||||
******************************************************************/
|
||||
struct packet_struct *read_packet(int fd,enum packet_type packet_type)
|
||||
struct packet_struct *
|
||||
read_packet (int fd, enum packet_type packet_type)
|
||||
{
|
||||
extern struct in_addr lastip;
|
||||
extern int lastport;
|
||||
@ -666,10 +707,12 @@ struct packet_struct *read_packet(int fd,enum packet_type packet_type)
|
||||
BOOL ok = False;
|
||||
|
||||
length = read_udp_socket (fd, buf, sizeof (buf));
|
||||
if (length < MIN_DGRAM_SIZE) return(NULL);
|
||||
if (length < MIN_DGRAM_SIZE)
|
||||
return (NULL);
|
||||
|
||||
packet = (struct packet_struct *) malloc (sizeof (*packet));
|
||||
if (!packet) return(NULL);
|
||||
if (!packet)
|
||||
return (NULL);
|
||||
|
||||
packet->next = NULL;
|
||||
packet->prev = NULL;
|
||||
@ -689,7 +732,8 @@ struct packet_struct *read_packet(int fd,enum packet_type packet_type)
|
||||
ok = parse_dgram (buf, length, &packet->packet.dgram);
|
||||
break;
|
||||
}
|
||||
if (!ok) {
|
||||
if (!ok)
|
||||
{
|
||||
DEBUG (10, ("read_packet: discarding packet id = %d\n",
|
||||
packet->packet.nmb.header.name_trn_id));
|
||||
free_packet (packet);
|
||||
@ -708,7 +752,8 @@ struct packet_struct *read_packet(int fd,enum packet_type packet_type)
|
||||
/*******************************************************************
|
||||
send a udp packet on a already open socket
|
||||
******************************************************************/
|
||||
static BOOL send_udp(int fd,char *buf,int len,struct in_addr ip,int port)
|
||||
static BOOL
|
||||
send_udp (int fd, char *buf, int len, struct in_addr ip, int port)
|
||||
{
|
||||
BOOL ret;
|
||||
struct sockaddr_in sock_out;
|
||||
@ -719,11 +764,9 @@ static BOOL send_udp(int fd,char *buf,int len,struct in_addr ip,int port)
|
||||
sock_out.sin_port = htons (port);
|
||||
sock_out.sin_family = AF_INET;
|
||||
|
||||
DEBUG( 5, ( "Sending a packet of len %d to (%s) on port %d\n",
|
||||
len, inet_ntoa(ip), port ) );
|
||||
DEBUG (5, ("Sending a packet of len %d to (%s) on port %d\n", len, inet_ntoa (ip), port));
|
||||
|
||||
ret = (sendto(fd,buf,len,0,(struct sockaddr *)&sock_out,
|
||||
sizeof(sock_out)) >= 0);
|
||||
ret = (sendto (fd, buf, len, 0, (struct sockaddr *) &sock_out, sizeof (sock_out)) >= 0);
|
||||
|
||||
if (!ret)
|
||||
DEBUG (0, ("Packet send failed to %s(%d) ERRNO=%s\n",
|
||||
@ -742,7 +785,8 @@ static BOOL send_udp(int fd,char *buf,int len,struct in_addr ip,int port)
|
||||
datagram. It should split them and use the packet_offset, more and
|
||||
first flags to handle the fragmentation. Yuck.
|
||||
******************************************************************/
|
||||
static int build_dgram(char *buf,struct packet_struct *p)
|
||||
static int
|
||||
build_dgram (char *buf, struct packet_struct *p)
|
||||
{
|
||||
struct dgram_packet *dgram = &p->packet.dgram;
|
||||
unsigned char *ubuf = (unsigned char *) buf;
|
||||
@ -751,8 +795,10 @@ static int build_dgram(char *buf,struct packet_struct *p)
|
||||
/* put in the header */
|
||||
ubuf[0] = dgram->header.msg_type;
|
||||
ubuf[1] = (((int) dgram->header.flags.node_type) << 2);
|
||||
if (dgram->header.flags.more) ubuf[1] |= 1;
|
||||
if (dgram->header.flags.first) ubuf[1] |= 2;
|
||||
if (dgram->header.flags.more)
|
||||
ubuf[1] |= 1;
|
||||
if (dgram->header.flags.first)
|
||||
ubuf[1] |= 2;
|
||||
RSSVAL (ubuf, 2, dgram->header.dgm_id);
|
||||
putip (ubuf + 4, (char *) &dgram->header.source_ip);
|
||||
RSSVAL (ubuf, 8, dgram->header.source_port);
|
||||
@ -761,8 +807,8 @@ static int build_dgram(char *buf,struct packet_struct *p)
|
||||
offset = 14;
|
||||
|
||||
if (dgram->header.msg_type == 0x10 ||
|
||||
dgram->header.msg_type == 0x11 ||
|
||||
dgram->header.msg_type == 0x12) {
|
||||
dgram->header.msg_type == 0x11 || dgram->header.msg_type == 0x12)
|
||||
{
|
||||
offset += put_nmb_name ((char *) ubuf, offset, &dgram->source_name);
|
||||
offset += put_nmb_name ((char *) ubuf, offset, &dgram->dest_name);
|
||||
}
|
||||
@ -780,7 +826,8 @@ static int build_dgram(char *buf,struct packet_struct *p)
|
||||
/*******************************************************************
|
||||
build a nmb name
|
||||
*******************************************************************/
|
||||
void make_nmb_name( struct nmb_name *n, const char *name, int type )
|
||||
void
|
||||
make_nmb_name (struct nmb_name *n, const char *name, int type)
|
||||
{
|
||||
extern pstring global_scope;
|
||||
memset ((char *) n, '\0', sizeof (struct nmb_name));
|
||||
@ -795,11 +842,11 @@ void make_nmb_name( struct nmb_name *n, const char *name, int type )
|
||||
Compare two nmb names
|
||||
******************************************************************/
|
||||
#if 0
|
||||
BOOL nmb_name_equal(struct nmb_name *n1, struct nmb_name *n2)
|
||||
BOOL
|
||||
nmb_name_equal (struct nmb_name *n1, struct nmb_name *n2)
|
||||
{
|
||||
return ((n1->name_type == n2->name_type) &&
|
||||
strequal(n1->name ,n2->name ) &&
|
||||
strequal(n1->scope,n2->scope));
|
||||
strequal (n1->name, n2->name) && strequal (n1->scope, n2->scope));
|
||||
}
|
||||
#endif /* 0 */
|
||||
/*******************************************************************
|
||||
@ -810,7 +857,8 @@ BOOL nmb_name_equal(struct nmb_name *n1, struct nmb_name *n2)
|
||||
changed to set the trunc bit so the receiver can request the rest
|
||||
via tcp (when that becomes supported)
|
||||
******************************************************************/
|
||||
static int build_nmb(char *buf,struct packet_struct *p)
|
||||
static int
|
||||
build_nmb (char *buf, struct packet_struct *p)
|
||||
{
|
||||
struct nmb_packet *nmb = &p->packet.nmb;
|
||||
unsigned char *ubuf = (unsigned char *) buf;
|
||||
@ -819,14 +867,18 @@ static int build_nmb(char *buf,struct packet_struct *p)
|
||||
/* put in the header */
|
||||
RSSVAL (ubuf, offset, nmb->header.name_trn_id);
|
||||
ubuf[offset + 2] = (nmb->header.opcode & 0xF) << 3;
|
||||
if (nmb->header.response) ubuf[offset+2] |= (1<<7);
|
||||
if (nmb->header.nm_flags.authoritative &&
|
||||
nmb->header.response) ubuf[offset+2] |= 0x4;
|
||||
if (nmb->header.nm_flags.trunc) ubuf[offset+2] |= 0x2;
|
||||
if (nmb->header.nm_flags.recursion_desired) ubuf[offset+2] |= 0x1;
|
||||
if (nmb->header.nm_flags.recursion_available &&
|
||||
nmb->header.response) ubuf[offset+3] |= 0x80;
|
||||
if (nmb->header.nm_flags.bcast) ubuf[offset+3] |= 0x10;
|
||||
if (nmb->header.response)
|
||||
ubuf[offset + 2] |= (1 << 7);
|
||||
if (nmb->header.nm_flags.authoritative && nmb->header.response)
|
||||
ubuf[offset + 2] |= 0x4;
|
||||
if (nmb->header.nm_flags.trunc)
|
||||
ubuf[offset + 2] |= 0x2;
|
||||
if (nmb->header.nm_flags.recursion_desired)
|
||||
ubuf[offset + 2] |= 0x1;
|
||||
if (nmb->header.nm_flags.recursion_available && nmb->header.response)
|
||||
ubuf[offset + 3] |= 0x80;
|
||||
if (nmb->header.nm_flags.bcast)
|
||||
ubuf[offset + 3] |= 0x10;
|
||||
ubuf[offset + 3] |= (nmb->header.rcode & 0xF);
|
||||
|
||||
RSSVAL (ubuf, offset + 4, nmb->header.qdcount);
|
||||
@ -835,7 +887,8 @@ static int build_nmb(char *buf,struct packet_struct *p)
|
||||
RSSVAL (ubuf, offset + 10, nmb->header.arcount);
|
||||
|
||||
offset += 12;
|
||||
if (nmb->header.qdcount) {
|
||||
if (nmb->header.qdcount)
|
||||
{
|
||||
/* XXXX this doesn't handle a qdcount of > 1 */
|
||||
offset += put_nmb_name ((char *) ubuf, offset, &nmb->question.question_name);
|
||||
RSSVAL (ubuf, offset, nmb->question.question_type);
|
||||
@ -844,12 +897,10 @@ static int build_nmb(char *buf,struct packet_struct *p)
|
||||
}
|
||||
|
||||
if (nmb->header.ancount)
|
||||
offset += put_res_rec((char *)ubuf,offset,nmb->answers,
|
||||
nmb->header.ancount);
|
||||
offset += put_res_rec ((char *) ubuf, offset, nmb->answers, nmb->header.ancount);
|
||||
|
||||
if (nmb->header.nscount)
|
||||
offset += put_res_rec((char *)ubuf,offset,nmb->nsrecs,
|
||||
nmb->header.nscount);
|
||||
offset += put_res_rec ((char *) ubuf, offset, nmb->nsrecs, nmb->header.nscount);
|
||||
|
||||
/*
|
||||
* The spec says we must put compressed name pointers
|
||||
@ -863,14 +914,15 @@ static int build_nmb(char *buf,struct packet_struct *p)
|
||||
(nmb->header.opcode == NMB_NAME_RELEASE_OPCODE) ||
|
||||
(nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_8) ||
|
||||
(nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_9) ||
|
||||
(nmb->header.opcode == NMB_NAME_MULTIHOMED_REG_OPCODE)) &&
|
||||
(nmb->header.arcount == 1)) {
|
||||
(nmb->header.opcode == NMB_NAME_MULTIHOMED_REG_OPCODE)) && (nmb->header.arcount == 1))
|
||||
{
|
||||
|
||||
offset += put_compressed_name_ptr (ubuf, offset, nmb->additional, 12);
|
||||
|
||||
} else if (nmb->header.arcount) {
|
||||
offset += put_res_rec((char *)ubuf,offset,nmb->additional,
|
||||
nmb->header.arcount);
|
||||
}
|
||||
else if (nmb->header.arcount)
|
||||
{
|
||||
offset += put_res_rec ((char *) ubuf, offset, nmb->additional, nmb->header.arcount);
|
||||
}
|
||||
return (offset);
|
||||
}
|
||||
@ -879,7 +931,8 @@ static int build_nmb(char *buf,struct packet_struct *p)
|
||||
/*******************************************************************
|
||||
send a packet_struct
|
||||
******************************************************************/
|
||||
BOOL send_packet(struct packet_struct *p)
|
||||
BOOL
|
||||
send_packet (struct packet_struct * p)
|
||||
{
|
||||
char buf[1024];
|
||||
int len = 0;
|
||||
@ -898,7 +951,8 @@ BOOL send_packet(struct packet_struct *p)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!len) return(False);
|
||||
if (!len)
|
||||
return (False);
|
||||
|
||||
return (send_udp (p->fd, buf, len, p->ip, p->port));
|
||||
}
|
||||
@ -907,7 +961,8 @@ BOOL send_packet(struct packet_struct *p)
|
||||
receive a packet with timeout on a open UDP filedescriptor
|
||||
The timeout is in milliseconds
|
||||
***************************************************************************/
|
||||
struct packet_struct *receive_packet(int fd,enum packet_type type,int t)
|
||||
struct packet_struct *
|
||||
receive_packet (int fd, enum packet_type type, int t)
|
||||
{
|
||||
fd_set fds;
|
||||
struct timeval timeout;
|
||||
@ -929,18 +984,24 @@ struct packet_struct *receive_packet(int fd,enum packet_type type,int t)
|
||||
/****************************************************************************
|
||||
return the number of bits that match between two 4 character buffers
|
||||
***************************************************************************/
|
||||
static int matching_bits(uchar *p1, uchar *p2)
|
||||
static int
|
||||
matching_bits (uchar * p1, uchar * p2)
|
||||
{
|
||||
int i, j, ret = 0;
|
||||
for (i=0; i<4; i++) {
|
||||
if (p1[i] != p2[i]) break;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if (p1[i] != p2[i])
|
||||
break;
|
||||
ret += 8;
|
||||
}
|
||||
|
||||
if (i==4) return ret;
|
||||
if (i == 4)
|
||||
return ret;
|
||||
|
||||
for (j=0; j<8; j++) {
|
||||
if ((p1[i] & (1<<(7-j))) != (p2[i] & (1<<(7-j)))) break;
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
if ((p1[i] & (1 << (7 - j))) != (p2[i] & (1 << (7 - j))))
|
||||
break;
|
||||
ret++;
|
||||
}
|
||||
|
||||
@ -952,7 +1013,8 @@ static uchar sort_ip[4];
|
||||
/****************************************************************************
|
||||
compare two query reply records
|
||||
***************************************************************************/
|
||||
static int name_query_comp(uchar *p1, uchar *p2)
|
||||
static int
|
||||
name_query_comp (uchar * p1, uchar * p2)
|
||||
{
|
||||
return matching_bits (p2 + 2, sort_ip) - matching_bits (p1 + 2, sort_ip);
|
||||
}
|
||||
@ -961,9 +1023,11 @@ static int name_query_comp(uchar *p1, uchar *p2)
|
||||
sort a set of 6 byte name query response records so that the IPs that
|
||||
have the most leading bits in common with the specified address come first
|
||||
***************************************************************************/
|
||||
void sort_query_replies(char *data, int n, struct in_addr ip)
|
||||
void
|
||||
sort_query_replies (char *data, int n, struct in_addr ip)
|
||||
{
|
||||
if (n <= 1) return;
|
||||
if (n <= 1)
|
||||
return;
|
||||
|
||||
putip (sort_ip, (char *) &ip);
|
||||
|
||||
|
@ -29,8 +29,7 @@ typedef struct
|
||||
|
||||
} nt_err_code_struct;
|
||||
|
||||
nt_err_code_struct const nt_errs[] =
|
||||
{
|
||||
nt_err_code_struct const nt_errs[] = {
|
||||
{"NT_STATUS_UNSUCCESSFUL", NT_STATUS_UNSUCCESSFUL},
|
||||
{"NT_STATUS_NOT_IMPLEMENTED", NT_STATUS_NOT_IMPLEMENTED},
|
||||
{"NT_STATUS_INVALID_INFO_CLASS", NT_STATUS_INVALID_INFO_CLASS},
|
||||
@ -539,7 +538,8 @@ nt_err_code_struct const nt_errs[] =
|
||||
/*****************************************************************************
|
||||
returns an NT error message. not amazingly helpful, but better than a number.
|
||||
*****************************************************************************/
|
||||
const char *get_nt_error_msg(uint32 nt_code)
|
||||
const char *
|
||||
get_nt_error_msg (uint32 nt_code)
|
||||
{
|
||||
int idx = 0;
|
||||
|
||||
@ -555,4 +555,3 @@ const char *get_nt_error_msg(uint32 nt_code)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,8 @@ extern int DEBUGLEVEL;
|
||||
/****************************************************************************
|
||||
initialises a password structure
|
||||
****************************************************************************/
|
||||
void pwd_init(struct pwd_info *pwd)
|
||||
void
|
||||
pwd_init (struct pwd_info *pwd)
|
||||
{
|
||||
memset ((char *) pwd->password, '\0', sizeof (pwd->password));
|
||||
memset ((char *) pwd->smb_lm_pwd, '\0', sizeof (pwd->smb_lm_pwd));
|
||||
@ -48,7 +49,8 @@ void pwd_init(struct pwd_info *pwd)
|
||||
/****************************************************************************
|
||||
de-obfuscates a password
|
||||
****************************************************************************/
|
||||
static void pwd_deobfuscate(struct pwd_info *pwd)
|
||||
static void
|
||||
pwd_deobfuscate (struct pwd_info *pwd)
|
||||
{
|
||||
(void) pwd;
|
||||
}
|
||||
@ -56,7 +58,8 @@ static void pwd_deobfuscate(struct pwd_info *pwd)
|
||||
/****************************************************************************
|
||||
obfuscates a password
|
||||
****************************************************************************/
|
||||
static void pwd_obfuscate(struct pwd_info *pwd)
|
||||
static void
|
||||
pwd_obfuscate (struct pwd_info *pwd)
|
||||
{
|
||||
(void) pwd;
|
||||
}
|
||||
@ -64,7 +67,8 @@ static void pwd_obfuscate(struct pwd_info *pwd)
|
||||
/****************************************************************************
|
||||
sets the obfuscation key info
|
||||
****************************************************************************/
|
||||
void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key)
|
||||
void
|
||||
pwd_obfuscate_key (struct pwd_info *pwd, uint32 int_key, char *str_key)
|
||||
{
|
||||
(void) pwd;
|
||||
(void) int_key;
|
||||
@ -75,7 +79,8 @@ void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key)
|
||||
/****************************************************************************
|
||||
reads a password
|
||||
****************************************************************************/
|
||||
void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt)
|
||||
void
|
||||
pwd_read (struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt)
|
||||
{
|
||||
/* grab a password */
|
||||
char *user_pass;
|
||||
@ -102,7 +107,8 @@ void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt)
|
||||
/****************************************************************************
|
||||
stores a cleartext password
|
||||
****************************************************************************/
|
||||
void pwd_set_nullpwd(struct pwd_info *pwd)
|
||||
void
|
||||
pwd_set_nullpwd (struct pwd_info *pwd)
|
||||
{
|
||||
pwd_init (pwd);
|
||||
|
||||
@ -114,7 +120,8 @@ void pwd_set_nullpwd(struct pwd_info *pwd)
|
||||
/****************************************************************************
|
||||
stores a cleartext password
|
||||
****************************************************************************/
|
||||
void pwd_set_cleartext(struct pwd_info *pwd, char *clr)
|
||||
void
|
||||
pwd_set_cleartext (struct pwd_info *pwd, char *clr)
|
||||
{
|
||||
pwd_init (pwd);
|
||||
fstrcpy (pwd->password, clr);
|
||||
@ -128,7 +135,8 @@ void pwd_set_cleartext(struct pwd_info *pwd, char *clr)
|
||||
/****************************************************************************
|
||||
gets a cleartext password
|
||||
****************************************************************************/
|
||||
void pwd_get_cleartext(struct pwd_info *pwd, char *clr)
|
||||
void
|
||||
pwd_get_cleartext (struct pwd_info *pwd, char *clr)
|
||||
{
|
||||
pwd_deobfuscate (pwd);
|
||||
if (pwd->cleartext)
|
||||
@ -145,7 +153,8 @@ void pwd_get_cleartext(struct pwd_info *pwd, char *clr)
|
||||
/****************************************************************************
|
||||
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);
|
||||
|
||||
@ -177,7 +186,8 @@ void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
|
||||
/****************************************************************************
|
||||
gets lm and nt hashed passwords
|
||||
****************************************************************************/
|
||||
void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
|
||||
void
|
||||
pwd_get_lm_nt_16 (struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
|
||||
{
|
||||
pwd_deobfuscate (pwd);
|
||||
if (lm_pwd != NULL)
|
||||
@ -194,7 +204,8 @@ void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16])
|
||||
/****************************************************************************
|
||||
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);
|
||||
|
||||
@ -209,7 +220,8 @@ void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr)
|
||||
/****************************************************************************
|
||||
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);
|
||||
|
||||
@ -244,7 +256,8 @@ void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8])
|
||||
/****************************************************************************
|
||||
gets lm and nt crypts
|
||||
****************************************************************************/
|
||||
void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24])
|
||||
void
|
||||
pwd_get_lm_nt_owf (struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24])
|
||||
{
|
||||
pwd_deobfuscate (pwd);
|
||||
if (lm_owf != NULL)
|
||||
|
@ -60,7 +60,8 @@ static uchar perm1[56] = {57, 49, 41, 33, 25, 17, 9,
|
||||
63, 55, 47, 39, 31, 23, 15,
|
||||
7, 62, 54, 46, 38, 30, 22,
|
||||
14, 6, 61, 53, 45, 37, 29,
|
||||
21, 13, 5, 28, 20, 12, 4};
|
||||
21, 13, 5, 28, 20, 12, 4
|
||||
};
|
||||
|
||||
static uchar perm2[48] = { 14, 17, 11, 24, 1, 5,
|
||||
3, 28, 15, 6, 21, 10,
|
||||
@ -69,7 +70,8 @@ static uchar perm2[48] = {14, 17, 11, 24, 1, 5,
|
||||
41, 52, 31, 37, 47, 55,
|
||||
30, 40, 51, 45, 33, 48,
|
||||
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,
|
||||
60, 52, 44, 36, 28, 20, 12, 4,
|
||||
@ -78,7 +80,8 @@ static uchar perm3[64] = {58, 50, 42, 34, 26, 18, 10, 2,
|
||||
57, 49, 41, 33, 25, 17, 9, 1,
|
||||
59, 51, 43, 35, 27, 19, 11, 3,
|
||||
61, 53, 45, 37, 29, 21, 13, 5,
|
||||
63, 55, 47, 39, 31, 23, 15, 7};
|
||||
63, 55, 47, 39, 31, 23, 15, 7
|
||||
};
|
||||
|
||||
static uchar perm4[48] = { 32, 1, 2, 3, 4, 5,
|
||||
4, 5, 6, 7, 8, 9,
|
||||
@ -87,7 +90,8 @@ static uchar perm4[48] = { 32, 1, 2, 3, 4, 5,
|
||||
16, 17, 18, 19, 20, 21,
|
||||
20, 21, 22, 23, 24, 25,
|
||||
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,
|
||||
29, 12, 28, 17,
|
||||
@ -96,7 +100,8 @@ static uchar perm5[32] = { 16, 7, 20, 21,
|
||||
2, 8, 24, 14,
|
||||
32, 27, 3, 9,
|
||||
19, 13, 30, 6,
|
||||
22, 11, 4, 25};
|
||||
22, 11, 4, 25
|
||||
};
|
||||
|
||||
|
||||
static uchar perm6[64] = { 40, 8, 48, 16, 56, 24, 64, 32,
|
||||
@ -106,7 +111,8 @@ static uchar perm6[64] ={ 40, 8, 48, 16, 56, 24, 64, 32,
|
||||
36, 4, 44, 12, 52, 20, 60, 28,
|
||||
35, 3, 43, 11, 51, 19, 59, 27,
|
||||
34, 2, 42, 10, 50, 18, 58, 26,
|
||||
33, 1, 41, 9, 49, 17, 57, 25};
|
||||
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 };
|
||||
@ -150,16 +156,19 @@ static uchar sbox[8][4][16] = {
|
||||
{{13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7},
|
||||
{1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2},
|
||||
{7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8},
|
||||
{2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}}};
|
||||
{2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}}
|
||||
};
|
||||
|
||||
static void permute(char *out, char *in, uchar *p, int n)
|
||||
static void
|
||||
permute (char *out, char *in, uchar * p, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
out[i] = in[p[i] - 1];
|
||||
}
|
||||
|
||||
static void lshift(char *d, int count, int n)
|
||||
static void
|
||||
lshift (char *d, int count, int n)
|
||||
{
|
||||
char out[64];
|
||||
int i;
|
||||
@ -169,7 +178,8 @@ static void lshift(char *d, int count, int n)
|
||||
d[i] = out[i];
|
||||
}
|
||||
|
||||
static void concat(char *out, char *in1, char *in2, int l1, int l2)
|
||||
static void
|
||||
concat (char *out, char *in1, char *in2, int l1, int l2)
|
||||
{
|
||||
while (l1--)
|
||||
*out++ = *in1++;
|
||||
@ -177,14 +187,16 @@ static void concat(char *out, char *in1, char *in2, int l1, int l2)
|
||||
*out++ = *in2++;
|
||||
}
|
||||
|
||||
static void xor(char *out, char *in1, char *in2, int n)
|
||||
static void
|
||||
xor (char *out, char *in1, char *in2, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
out[i] = in1[i] ^ in2[i];
|
||||
}
|
||||
|
||||
static void dohash(char *out, char *in, char *key, int forw)
|
||||
static void
|
||||
dohash (char *out, char *in, char *key, int forw)
|
||||
{
|
||||
int i, j, k;
|
||||
char pk1[56];
|
||||
@ -203,7 +215,8 @@ static void dohash(char *out, char *in, char *key, int forw)
|
||||
for (i = 0; i < 28; i++)
|
||||
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);
|
||||
|
||||
@ -213,12 +226,14 @@ static void dohash(char *out, char *in, char *key, int forw)
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
for (i=0;i<16;i++) {
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
char er[48];
|
||||
char erk[48];
|
||||
char b[8][6];
|
||||
@ -234,7 +249,8 @@ static void dohash(char *out, char *in, char *key, int forw)
|
||||
for (k = 0; k < 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];
|
||||
|
||||
@ -263,7 +279,8 @@ static void dohash(char *out, char *in, char *key, int forw)
|
||||
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;
|
||||
|
||||
@ -275,13 +292,15 @@ static void str_to_key(unsigned char *str,unsigned char *key)
|
||||
key[5] = ((str[4] & 0x1F) << 2) | (str[5] >> 6);
|
||||
key[6] = ((str[5] & 0x3F) << 1) | (str[6] >> 7);
|
||||
key[7] = str[6] & 0x7F;
|
||||
for (i=0;i<8;i++) {
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
key[i] = (key[i] << 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void smbhash(unsigned char *out, unsigned char *in, unsigned char *key, int forw)
|
||||
static void
|
||||
smbhash (unsigned char *out, unsigned char *in, unsigned char *key, int forw)
|
||||
{
|
||||
int i;
|
||||
char outb[64];
|
||||
@ -291,7 +310,8 @@ static void smbhash(unsigned char *out, unsigned char *in, unsigned char *key, i
|
||||
|
||||
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;
|
||||
outb[i] = 0;
|
||||
@ -299,43 +319,50 @@ static void smbhash(unsigned char *out, unsigned char *in, unsigned char *key, i
|
||||
|
||||
dohash (outb, inb, keyb, forw);
|
||||
|
||||
for (i=0;i<8;i++) {
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
void E_P16(unsigned char *p14,unsigned char *p16)
|
||||
void
|
||||
E_P16 (unsigned char *p14, unsigned char *p16)
|
||||
{
|
||||
unsigned char sp8[8] = { 0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 };
|
||||
smbhash (p16, sp8, p14, 1);
|
||||
smbhash (p16 + 8, sp8, p14 + 7, 1);
|
||||
}
|
||||
|
||||
void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24)
|
||||
void
|
||||
E_P24 (unsigned char *p21, unsigned char *c8, unsigned char *p24)
|
||||
{
|
||||
smbhash (p24, c8, p21, 1);
|
||||
smbhash (p24 + 8, c8, p21 + 7, 1);
|
||||
smbhash (p24 + 16, c8, p21 + 14, 1);
|
||||
}
|
||||
|
||||
void D_P16(unsigned char *p14, unsigned char *in, unsigned char *out)
|
||||
void
|
||||
D_P16 (unsigned char *p14, unsigned char *in, unsigned char *out)
|
||||
{
|
||||
smbhash (out, in, p14, 0);
|
||||
smbhash (out + 8, in + 8, p14 + 7, 0);
|
||||
}
|
||||
|
||||
void E_old_pw_hash( unsigned char *p14, unsigned char *in, unsigned char *out)
|
||||
void
|
||||
E_old_pw_hash (unsigned char *p14, unsigned char *in, unsigned char *out)
|
||||
{
|
||||
smbhash (out, in, p14, 1);
|
||||
smbhash (out + 8, in + 8, p14 + 7, 1);
|
||||
}
|
||||
|
||||
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];
|
||||
|
||||
@ -343,7 +370,8 @@ void cred_hash1(unsigned char *out,unsigned char *in,unsigned char *key)
|
||||
smbhash (out, buf, key + 9, 1);
|
||||
}
|
||||
|
||||
void cred_hash2(unsigned char *out,unsigned char *in,unsigned char *key)
|
||||
void
|
||||
cred_hash2 (unsigned char *out, unsigned char *in, unsigned char *key)
|
||||
{
|
||||
unsigned char buf[8];
|
||||
static unsigned char key2[8];
|
||||
@ -353,7 +381,8 @@ void cred_hash2(unsigned char *out,unsigned char *in,unsigned char *key)
|
||||
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];
|
||||
|
||||
@ -362,7 +391,8 @@ void cred_hash3(unsigned char *out,unsigned char *in,unsigned char *key, int for
|
||||
smbhash (out + 8, in + 8, key2, forw);
|
||||
}
|
||||
|
||||
void SamOEMhash( unsigned char *data, unsigned char *key, int val)
|
||||
void
|
||||
SamOEMhash (unsigned char *data, unsigned char *key, int val)
|
||||
{
|
||||
unsigned char s_box[256];
|
||||
unsigned char index_i = 0;
|
||||
|
@ -36,7 +36,8 @@ extern int DEBUGLEVEL;
|
||||
This implements the X/Open SMB password encryption
|
||||
It takes a password, a 8 byte "crypt key" and puts 24 bytes of
|
||||
encrypted password into p24 */
|
||||
void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24)
|
||||
void
|
||||
SMBencrypt (uchar * passwd, uchar * c8, uchar * p24)
|
||||
{
|
||||
uchar p14[15], p21[21];
|
||||
|
||||
@ -58,7 +59,8 @@ void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24)
|
||||
}
|
||||
|
||||
/* Routines for Windows NT MD4 Hash functions. */
|
||||
static int _my_wcslen(int16 *str)
|
||||
static int
|
||||
_my_wcslen (int16 * str)
|
||||
{
|
||||
int len = 0;
|
||||
while (*str++ != 0)
|
||||
@ -73,12 +75,14 @@ static int _my_wcslen(int16 *str)
|
||||
* format.
|
||||
*/
|
||||
|
||||
static int _my_mbstowcs(int16 *dst, uchar *src, int len)
|
||||
static int
|
||||
_my_mbstowcs (int16 * dst, uchar * src, int len)
|
||||
{
|
||||
int i;
|
||||
int16 val;
|
||||
|
||||
for(i = 0; i < len; i++) {
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
val = *src;
|
||||
SSVAL (dst, 0, val);
|
||||
dst++;
|
||||
@ -93,7 +97,8 @@ static int _my_mbstowcs(int16 *dst, uchar *src, int len)
|
||||
* Creates the MD4 Hash of the users password in NT UNICODE.
|
||||
*/
|
||||
|
||||
void E_md4hash(uchar *passwd, uchar *p16)
|
||||
void
|
||||
E_md4hash (uchar * passwd, uchar * p16)
|
||||
{
|
||||
int len;
|
||||
int16 wpwd[129];
|
||||
@ -112,7 +117,8 @@ void E_md4hash(uchar *passwd, uchar *p16)
|
||||
}
|
||||
|
||||
/* 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];
|
||||
|
||||
@ -148,7 +154,8 @@ void nt_lm_owf_gen(char *pwd, uchar nt_p16[16], uchar p16[16])
|
||||
}
|
||||
|
||||
/* 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];
|
||||
|
||||
@ -159,7 +166,8 @@ void SMBOWFencrypt(uchar passwd[16], uchar *c8, uchar p24[24])
|
||||
}
|
||||
|
||||
/* 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];
|
||||
|
||||
@ -179,7 +187,8 @@ void NTLMSSPOWFencrypt(uchar passwd[8], uchar *ntlmchalresp, uchar p24[24])
|
||||
|
||||
/* 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];
|
||||
|
||||
|
@ -56,40 +56,51 @@ static err_code_struct const dos_msgs[] = {
|
||||
{"ERRbaddata", 13, "Invalid data."},
|
||||
{"ERR", 14, "reserved."},
|
||||
{"ERRbaddrive", 15, "Invalid drive specified."},
|
||||
{"ERRremcd",16,"A Delete Directory request attempted to remove the server's current directory."},
|
||||
{"ERRremcd", 16,
|
||||
"A Delete Directory request attempted to remove the server's current directory."},
|
||||
{"ERRdiffdevice", 17, "Not same device."},
|
||||
{"ERRnofiles",18,"A File Search command can find no more files matching the specified criteria."},
|
||||
{"ERRbadshare",32,"The sharing mode specified for an Open conflicts with existing FIDs on the file."},
|
||||
{"ERRlock",33,"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."},
|
||||
{"ERRnofiles", 18,
|
||||
"A File Search command can find no more files matching the specified criteria."},
|
||||
{"ERRbadshare", 32,
|
||||
"The sharing mode specified for an Open conflicts with existing FIDs on the file."},
|
||||
{"ERRlock", 33,
|
||||
"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."},
|
||||
{"ERRunsup", 50, "The operation is unsupported"},
|
||||
{"ERRnosuchshare", 67, "You specified an invalid share name"},
|
||||
{"ERRfilexists",80,"The file named in a Create Directory, Make New File or Link request already exists."},
|
||||
{"ERRfilexists", 80,
|
||||
"The file named in a Create Directory, Make New File or Link request already exists."},
|
||||
{"ERRbadpipe", 230, "Pipe invalid."},
|
||||
{"ERRpipebusy", 231, "All instances of the requested pipe are busy."},
|
||||
{"ERRpipeclosing", 232, "Pipe close in progress."},
|
||||
{"ERRnotconnected", 233, "No process on other end of pipe."},
|
||||
{"ERRmoredata", 234, "There is more data to be returned."},
|
||||
{"ERRinvgroup", 2455, "Invalid workgroup (try the -W option)"},
|
||||
{NULL,-1,NULL}};
|
||||
{NULL, -1, NULL}
|
||||
};
|
||||
|
||||
/* Server Error Messages */
|
||||
static err_code_struct const server_msgs[] = {
|
||||
{"ERRerror", 1, "Non-specific error code."},
|
||||
{"ERRbadpw",2,"Bad password - name/password pair in a Tree Connect or Session Setup are invalid."},
|
||||
{"ERRbadpw", 2,
|
||||
"Bad password - name/password pair in a Tree Connect or Session Setup are invalid."},
|
||||
{"ERRbadtype", 3, "reserved."},
|
||||
{"ERRaccess",4,"The requester does not have the necessary access rights within the specified context for the requested function. The context is defined by the TID or the UID."},
|
||||
{"ERRaccess", 4,
|
||||
"The requester does not have the necessary access rights within the specified context for the requested function. The context is defined by the TID or the UID."},
|
||||
{"ERRinvnid", 5, "The tree ID (TID) specified in a command was invalid."},
|
||||
{"ERRinvnetname", 6, "Invalid network name in tree connect."},
|
||||
{"ERRinvdevice",7,"Invalid device - printer request made to non-printer connection or non-printer request made to printer connection."},
|
||||
{"ERRinvdevice", 7,
|
||||
"Invalid device - printer request made to non-printer connection or non-printer request made to printer connection."},
|
||||
{"ERRqfull", 49, "Print queue full (files) -- returned by open print file."},
|
||||
{"ERRqtoobig", 50, "Print queue full -- no space."},
|
||||
{"ERRqeof", 51, "EOF on print queue dump."},
|
||||
{"ERRinvpfid", 52, "Invalid print file FID."},
|
||||
{"ERRsmbcmd", 64, "The server did not recognize the command received."},
|
||||
{"ERRsrverror", 65, "The server encountered an internal error, e.g., system file unavailable."},
|
||||
{"ERRfilespecs",67,"The file handle (FID) and pathname parameters contained an invalid combination of values."},
|
||||
{"ERRfilespecs", 67,
|
||||
"The file handle (FID) and pathname parameters contained an invalid combination of values."},
|
||||
{"ERRreserved", 68, "reserved."},
|
||||
{"ERRbadpermits",69,"The access permissions specified for a file or directory are not a valid combination. The server cannot set the requested attribute."},
|
||||
{"ERRbadpermits", 69,
|
||||
"The access permissions specified for a file or directory are not a valid combination. The server cannot set the requested attribute."},
|
||||
{"ERRreserved", 70, "reserved."},
|
||||
{"ERRsetattrmode", 71, "The attribute mode in the Set File Attribute request is invalid."},
|
||||
{"ERRpaused", 81, "Server is paused."},
|
||||
@ -106,7 +117,8 @@ static err_code_struct const server_msgs[] = {
|
||||
{"ERRreserved", 253, "reserved."},
|
||||
{"ERRreserved", 254, "reserved."},
|
||||
{"ERRnosupport", 0xFFFF, "Function not supported."},
|
||||
{NULL,-1,NULL}};
|
||||
{NULL, -1, NULL}
|
||||
};
|
||||
|
||||
/* Hard Error Messages */
|
||||
static err_code_struct const hard_msgs[] = {
|
||||
@ -124,11 +136,13 @@ static err_code_struct const hard_msgs[] = {
|
||||
{"ERRread", 30, "Read fault."},
|
||||
{"ERRgeneral", 31, "General failure."},
|
||||
{"ERRbadshare", 32, "An open conflicts with an existing open."},
|
||||
{"ERRlock",33,"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."},
|
||||
{"ERRlock", 33,
|
||||
"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."},
|
||||
{"ERRwrongdisk", 34, "The wrong disk was found in a drive."},
|
||||
{"ERRFCBUnavail", 35, "No FCBs are available to process request."},
|
||||
{"ERRsharebufexc", 36, "A sharing buffer has been exceeded."},
|
||||
{NULL,-1,NULL}};
|
||||
{NULL, -1, NULL}
|
||||
};
|
||||
|
||||
|
||||
struct
|
||||
@ -146,13 +160,15 @@ struct
|
||||
{0xE2, "ERRRMX2", NULL},
|
||||
{0xE3, "ERRRMX3", NULL},
|
||||
{0xFF, "ERRCMD", NULL},
|
||||
{-1,NULL,NULL}};
|
||||
{-1, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
return a SMB error string from a SMB buffer
|
||||
****************************************************************************/
|
||||
char *smb_errstr(char *inbuf)
|
||||
char *
|
||||
smb_errstr (char *inbuf)
|
||||
{
|
||||
static pstring ret;
|
||||
int class = CVAL (inbuf, smb_rcls);
|
||||
@ -172,7 +188,8 @@ char *smb_errstr(char *inbuf)
|
||||
slprintf (ret, sizeof (ret) - 1, "%s - %s (%s)", err_classes[i].class,
|
||||
err[j].name, err[j].message);
|
||||
else
|
||||
slprintf(ret, sizeof(ret) - 1, "%s - %s",err_classes[i].class,err[j].name);
|
||||
slprintf (ret, sizeof (ret) - 1, "%s - %s", err_classes[i].class,
|
||||
err[j].name);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -112,7 +112,8 @@ static int bSize = 0;
|
||||
* Functions...
|
||||
*/
|
||||
|
||||
static int EatWhitespace( FILE *InFile )
|
||||
static int
|
||||
EatWhitespace (FILE * InFile)
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Scan past whitespace (see ctype(3C)) and return the first non-whitespace
|
||||
* character, or newline, or EOF.
|
||||
@ -137,7 +138,8 @@ static int EatWhitespace( FILE *InFile )
|
||||
return (c);
|
||||
} /* EatWhitespace */
|
||||
|
||||
static int EatComment( FILE *InFile )
|
||||
static int
|
||||
EatComment (FILE * InFile)
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Scan to the end of a comment.
|
||||
*
|
||||
@ -162,7 +164,8 @@ static int EatComment( FILE *InFile )
|
||||
return (c);
|
||||
} /* EatComment */
|
||||
|
||||
static int Continuation( char *line, int pos )
|
||||
static int
|
||||
Continuation (char *line, int pos)
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Scan backards within a string to discover if the last non-whitespace
|
||||
* character is a line-continuation character ('\\').
|
||||
@ -186,7 +189,8 @@ static int Continuation( char *line, int pos )
|
||||
} /* 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().
|
||||
*
|
||||
@ -250,8 +254,7 @@ static BOOL Section( FILE *InFile, BOOL (*sfunc)(const char *) )
|
||||
if (i < 0)
|
||||
{
|
||||
bufr[end] = '\0';
|
||||
DEBUG(0, ("%s Badly formed line in configuration file: %s\n",
|
||||
func, bufr ));
|
||||
DEBUG (0, ("%s Badly formed line in configuration file: %s\n", func, bufr));
|
||||
return (False);
|
||||
}
|
||||
end = ((i > 0) && (' ' == bufr[i - 1])) ? (i - 1) : (i);
|
||||
@ -279,7 +282,8 @@ static BOOL Section( FILE *InFile, BOOL (*sfunc)(const char *) )
|
||||
return (False);
|
||||
} /* Section */
|
||||
|
||||
static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(const char *, const char *), int c )
|
||||
static BOOL
|
||||
Parameter (FILE * InFile, BOOL (*pfunc) (const char *, const char *), int c)
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Scan a parameter name and value, and pass these two fields to pfunc().
|
||||
*
|
||||
@ -420,9 +424,8 @@ static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(const char *, const char *),
|
||||
return (pfunc (bufr, &bufr[vstart])); /* Pass name & value to pfunc(). */
|
||||
} /* Parameter */
|
||||
|
||||
static BOOL Parse( FILE *InFile,
|
||||
BOOL (*sfunc)(const char *),
|
||||
BOOL (*pfunc)(const char *, const char *) )
|
||||
static BOOL
|
||||
Parse (FILE * InFile, BOOL (*sfunc) (const char *), BOOL (*pfunc) (const char *, const char *))
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Scan & parse the input.
|
||||
*
|
||||
@ -481,7 +484,8 @@ static BOOL Parse( FILE *InFile,
|
||||
return (True);
|
||||
} /* Parse */
|
||||
|
||||
static FILE *OpenConfFile( const char *FileName )
|
||||
static FILE *
|
||||
OpenConfFile (const char *FileName)
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Open a configuration file.
|
||||
*
|
||||
@ -515,9 +519,9 @@ static FILE *OpenConfFile( const char *FileName )
|
||||
return (OpenedFile);
|
||||
} /* OpenConfFile */
|
||||
|
||||
BOOL pm_process( const char *FileName,
|
||||
BOOL (*sfunc)(const char *),
|
||||
BOOL (*pfunc)(const char *, const char *) )
|
||||
BOOL
|
||||
pm_process (const char *FileName,
|
||||
BOOL (*sfunc) (const char *), BOOL (*pfunc) (const char *, const char *))
|
||||
/* ------------------------------------------------------------------------ **
|
||||
* Process the named parameter file.
|
||||
*
|
||||
|
@ -811,10 +811,9 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath,
|
||||
}
|
||||
|
||||
/* Record of zeroes */
|
||||
case STATUS_EOFMARK:
|
||||
status = prev_status; /* If error after 0's */
|
||||
case STATUS_EOFMARK: /* If error after 0's */
|
||||
/* FALL THRU */
|
||||
|
||||
/* exit from loop */
|
||||
case STATUS_EOF: /* End of archive */
|
||||
break;
|
||||
}
|
||||
|
@ -59,6 +59,8 @@
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define BUF_TRUNC_LEN 5 /* The length of the line displays the file size */
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
@ -134,7 +136,6 @@ mcview_display_status (mcview_t * view)
|
||||
const screen_dimen width = view->status_area.width;
|
||||
const screen_dimen height = view->status_area.height;
|
||||
const char *file_label;
|
||||
screen_dimen file_label_width;
|
||||
|
||||
if (height < 1)
|
||||
return;
|
||||
@ -147,26 +148,25 @@ mcview_display_status (mcview_t * view)
|
||||
view->filename_vpath != NULL ?
|
||||
vfs_path_get_last_path_str (view->filename_vpath) : view->command != NULL ?
|
||||
view->command : "";
|
||||
file_label_width = str_term_width1 (file_label) - 2;
|
||||
|
||||
if (width > 40)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
char buffer[BUF_TRUNC_LEN + 1];
|
||||
|
||||
widget_move (view, top, width - 32);
|
||||
if (view->hex_mode)
|
||||
tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor);
|
||||
else
|
||||
{
|
||||
size_trunc_len (buffer, 5, mcview_get_filesize (view), 0, panels_options.kilobyte_si);
|
||||
size_trunc_len (buffer, BUF_TRUNC_LEN, mcview_get_filesize (view), 0,
|
||||
panels_options.kilobyte_si);
|
||||
tty_printf ("%9" PRIuMAX "/%s%s %s", (uintmax_t) view->dpy_end,
|
||||
buffer, mcview_may_still_grow (view) ? "+" : " ",
|
||||
#ifdef HAVE_CHARSET
|
||||
mc_global.source_codepage >=
|
||||
0 ? get_codepage_id (mc_global.source_codepage) : ""
|
||||
#else
|
||||
""
|
||||
mc_global.source_codepage >= 0 ?
|
||||
get_codepage_id (mc_global.source_codepage) :
|
||||
#endif
|
||||
);
|
||||
"");
|
||||
}
|
||||
}
|
||||
widget_move (view, top, left);
|
||||
|
@ -88,31 +88,22 @@ utf8_to_int (char *str, int *char_width, gboolean * result)
|
||||
if (str == NULL)
|
||||
{
|
||||
*result = FALSE;
|
||||
width = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
|
||||
if (res < 0)
|
||||
{
|
||||
ch = *str;
|
||||
width = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = res;
|
||||
/* Calculate UTF-8 char width */
|
||||
next_ch = g_utf8_next_char (str);
|
||||
if (next_ch)
|
||||
{
|
||||
width = next_ch - str;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = 0;
|
||||
width = 0;
|
||||
}
|
||||
}
|
||||
*char_width = width;
|
||||
return ch;
|
||||
|
@ -407,7 +407,11 @@ mcview_moveto_eol (mcview_t * view)
|
||||
else
|
||||
view->dpy_text_column = eol - bol;
|
||||
}
|
||||
view->dpy_text_column = max (0, view->dpy_text_column - view->data_area.width);
|
||||
|
||||
if (view->dpy_text_column < (off_t) view->data_area.width)
|
||||
view->dpy_text_column = 0;
|
||||
else
|
||||
view->dpy_text_column = view->dpy_text_column - (off_t) view->data_area.width;
|
||||
}
|
||||
mcview_movement_fixups (view, FALSE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user