~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source3/lib/readline.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
   Unix SMB/CIFS implementation.
3
 
   Samba readline wrapper implementation
4
 
   Copyright (C) Simo Sorce 2001
5
 
   Copyright (C) Andrew Tridgell 2001
6
 
   
7
 
   This program is free software; you can redistribute it and/or modify
8
 
   it under the terms of the GNU General Public License as published by
9
 
   the Free Software Foundation; either version 3 of the License, or
10
 
   (at your option) any later version.
11
 
   
12
 
   This program is distributed in the hope that it will be useful,
13
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
   GNU General Public License for more details.
16
 
   
17
 
   You should have received a copy of the GNU General Public License
18
 
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
*/
20
 
 
21
 
#include "includes.h"
22
 
 
23
 
#ifdef HAVE_LIBREADLINE
24
 
#  ifdef HAVE_READLINE_READLINE_H
25
 
#    include <readline/readline.h>
26
 
#    ifdef HAVE_READLINE_HISTORY_H
27
 
#      include <readline/history.h>
28
 
#    endif
29
 
#  else
30
 
#    ifdef HAVE_READLINE_H
31
 
#      include <readline.h>
32
 
#      ifdef HAVE_HISTORY_H
33
 
#        include <history.h>
34
 
#      endif
35
 
#    else
36
 
#      undef HAVE_LIBREADLINE
37
 
#    endif
38
 
#  endif
39
 
#endif
40
 
 
41
 
#ifdef HAVE_NEW_LIBREADLINE
42
 
#  define RL_COMPLETION_CAST (rl_completion_func_t *)
43
 
#else
44
 
/* This type is missing from libreadline<4.0  (approximately) */
45
 
#  define RL_COMPLETION_CAST
46
 
#endif /* HAVE_NEW_LIBREADLINE */
47
 
 
48
 
static bool smb_rl_done;
49
 
 
50
 
#if HAVE_LIBREADLINE
51
 
/*
52
 
 * MacOS/X does not have rl_done in readline.h, but
53
 
 * readline.so has it
54
 
 */
55
 
extern int rl_done;
56
 
#endif
57
 
 
58
 
void smb_readline_done(void)
59
 
{
60
 
        smb_rl_done = true;
61
 
#if HAVE_LIBREADLINE
62
 
        rl_done = 1;
63
 
#endif
64
 
}
65
 
 
66
 
/****************************************************************************
67
 
 Display the prompt and wait for input. Call callback() regularly
68
 
****************************************************************************/
69
 
 
70
 
static char *smb_readline_replacement(const char *prompt, void (*callback)(void), 
71
 
                                char **(completion_fn)(const char *text, int start, int end))
72
 
{
73
 
        fd_set fds;
74
 
        char *line = NULL;
75
 
        struct timeval timeout;
76
 
        int fd = x_fileno(x_stdin);
77
 
        char *ret;
78
 
 
79
 
        /* Prompt might be NULL in non-interactive mode. */
80
 
        if (prompt) {
81
 
                x_fprintf(x_stdout, "%s", prompt);
82
 
                x_fflush(x_stdout);
83
 
        }
84
 
 
85
 
        line = (char *)SMB_MALLOC(BUFSIZ);
86
 
        if (!line) {
87
 
                return NULL;
88
 
        }
89
 
 
90
 
        while (!smb_rl_done) {
91
 
                timeout.tv_sec = 5;
92
 
                timeout.tv_usec = 0;
93
 
 
94
 
                if (fd < 0 || fd >= FD_SETSIZE) {
95
 
                        errno = EBADF;
96
 
                        break;
97
 
                }
98
 
 
99
 
                FD_ZERO(&fds);
100
 
                FD_SET(fd,&fds);
101
 
 
102
 
                if (sys_select_intr(fd+1,&fds,NULL,NULL,&timeout) == 1) {
103
 
                        ret = x_fgets(line, BUFSIZ, x_stdin);
104
 
                        if (ret == 0) {
105
 
                                SAFE_FREE(line);
106
 
                        }
107
 
                        return ret;
108
 
                }
109
 
                if (callback) {
110
 
                        callback();
111
 
                }
112
 
        }
113
 
        SAFE_FREE(line);
114
 
        return NULL;
115
 
}
116
 
 
117
 
/****************************************************************************
118
 
 Display the prompt and wait for input. Call callback() regularly.
119
 
****************************************************************************/
120
 
 
121
 
char *smb_readline(const char *prompt, void (*callback)(void),
122
 
                   char **(completion_fn)(const char *text, int start, int end))
123
 
{
124
 
        char *ret;
125
 
        bool interactive;
126
 
 
127
 
        interactive = isatty(x_fileno(x_stdin)) || getenv("CLI_FORCE_INTERACTIVE");
128
 
        if (!interactive) {
129
 
                return smb_readline_replacement(NULL, callback, completion_fn);
130
 
        }
131
 
 
132
 
#if HAVE_LIBREADLINE
133
 
 
134
 
        /* Aargh!  Readline does bizzare things with the terminal width
135
 
        that mucks up expect(1).  Set CLI_NO_READLINE in the environment
136
 
        to force readline not to be used. */
137
 
 
138
 
        if (getenv("CLI_NO_READLINE"))
139
 
                return smb_readline_replacement(prompt, callback, completion_fn);
140
 
 
141
 
        if (completion_fn) {
142
 
                /* The callback prototype has changed slightly between
143
 
                different versions of Readline, so the same function
144
 
                works in all of them to date, but we get compiler
145
 
                warnings in some.  */
146
 
                rl_attempted_completion_function = RL_COMPLETION_CAST completion_fn;
147
 
        }
148
 
 
149
 
#if HAVE_DECL_RL_EVENT_HOOK
150
 
        if (callback)
151
 
                rl_event_hook = (Function *)callback;
152
 
#endif
153
 
        ret = readline(prompt);
154
 
        if (ret && *ret)
155
 
                add_history(ret);
156
 
 
157
 
#else
158
 
        ret = smb_readline_replacement(prompt, callback, completion_fn);
159
 
#endif
160
 
 
161
 
        return ret;
162
 
}
163
 
 
164
 
/****************************************************************************
165
 
 * return line buffer text
166
 
 ****************************************************************************/
167
 
const char *smb_readline_get_line_buffer(void)
168
 
{
169
 
#if defined(HAVE_LIBREADLINE)
170
 
        return rl_line_buffer;
171
 
#else
172
 
        return NULL;
173
 
#endif
174
 
}
175
 
 
176
 
 
177
 
/****************************************************************************
178
 
 * set completion append character
179
 
 ***************************************************************************/
180
 
void smb_readline_ca_char(char c)
181
 
{
182
 
#if defined(HAVE_LIBREADLINE)
183
 
        rl_completion_append_character = c;
184
 
#endif
185
 
}
186
 
 
187
 
/****************************************************************************
188
 
history
189
 
****************************************************************************/
190
 
int cmd_history(void)
191
 
{
192
 
#if defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_LIST)
193
 
        HIST_ENTRY **hlist;
194
 
        int i;
195
 
 
196
 
        hlist = history_list();
197
 
 
198
 
        for (i = 0; hlist && hlist[i]; i++) {
199
 
                DEBUG(0, ("%d: %s\n", i, hlist[i]->line));
200
 
        }
201
 
#else
202
 
        DEBUG(0,("no history without readline support\n"));
203
 
#endif
204
 
 
205
 
        return 0;
206
 
}