Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

*** empty log message ***

  • Loading branch information...
commit b24b69a2d809abded5243fb9fce04940c07713d7 1 parent 398d444
etnt authored
View
10 lib/esmb/README
@@ -23,10 +23,12 @@ Finally, NetBIOS is described in RFC 1001,1002.
To see what protocols messages that are sent when using
the smbclient program. Try the following commands:
- smbclient //korp/tobbe -U tobbe -m LANMAN1
- smbclient korp -L -U tobbe -m LANMAN1
+ smbclient //korp/tobbe -U tobbe
+ smbclient korp -L -U tobbe
+
+A nice CIFS explanation can also be found here:
+
+ http://www.ubiqx.org/cifs/
-By using the -m switch you force smbclient to negotiate
-the same dialect that esmb currently is using.
Good luck, Tobbe
View
11 lib/esmb/c_src/Makefile
@@ -8,22 +8,13 @@ ICONV_DRV_SO = ../priv/iconv_drv.so
MD4_SHLIB_OBJS = md4_drv.o md4.o
ICONV_SHLIB_OBJS = iconv_drv.o
-all: md4 iconv
-
-md4: $(MD4_DRV_SO)
-
-iconv: $(ICONV_DRV_SO)
+all: $(MD4_DRV_SO) $(ICONV_DRV_SO)
$(MD4_DRV_SO): $(MD4_SHLIB_OBJS)
$(LD_SHARED) -o $@ $^
- #ld -G -o $@ $^
- # Symlink is only to help when using "jerl" script.
- -ln -s $(MD4_DRV_SO) ../ebin
$(ICONV_DRV_SO): $(ICONV_SHLIB_OBJS)
$(LD_SHARED) -o $@ $^
- # Symlink is only to help when using "jerl" script.
- -ln -s $(ICONV_DRV_SO) ../ebin
test: test.o md4.o
$(CC) -o md4test test.o md4.o
View
8 lib/esmb/c_src/iconv_drv.c
@@ -4,6 +4,7 @@
* $Id$
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <iconv.h>
#include <errno.h>
@@ -172,19 +173,20 @@ static int driver_send_error(t_iconvdrv *iv, ErlDrvTermData *am)
static void iv_open(t_iconvdrv *iv, char *tocode, char *fromcode)
{
int len;
- iconv_t *cd;
+ iconv_t cd;
ErlDrvBinary *bin;
- if ((*cd = iconv_open(tocode, fromcode)) == (iconv_t) -1) {
+ if ((cd = iconv_open(tocode, fromcode)) == (iconv_t) -1) {
driver_send_error(iv, &am_einval);
}
else {
len = sizeof(iconv_t);
if (!(bin = driver_alloc_binary(len))) {
+ iconv_close(cd);
driver_send_error(iv, &am_enomem);
}
else {
- memcpy(bin->orig_bytes, cd, len);
+ memcpy(bin->orig_bytes, &cd, len);
driver_send_bin(iv, bin, len);
driver_free_binary(bin);
}
View
32 lib/esmb/src/esmb.erl
@@ -7,7 +7,7 @@
%%% $Id$
%%% --------------------------------------------------------------------
-export([called_name/1, calling_name/1, ucase/1, lcase/1, check_dir/3,
- connect/2, connect/3, connect/4, close/1, user_logon/3, emsg/3,
+ connect/1, connect/2, connect/3, close/1, user_logon/3, emsg/3,
tree_connect/4, tree_connect/5, list_dir/3, called/1,
open_file_ro/3, open_file_rw/3, stream_read_file/3,
read_file/3, mkdir/3, rmdir/3, is_ok/2,
@@ -90,14 +90,12 @@ list_shares(Host, User, Passwd) ->
list_shares(Host, User, Passwd, ?DEFAULT_WORKGROUP, []).
list_shares(Host, User, Passwd, Workgroup, SockOpts) ->
- Called = called(Host),
- Caller = caller(),
- case connect(Caller, Called, SockOpts) of
+ case connect(Host, SockOpts) of
{ok,S,Neg} ->
U = #user{pw = Passwd, name = User, primary_domain = Workgroup},
Pdu0 = user_logon(S, Neg, U),
exit_if_error(Pdu0, "Login failed"),
- Path = "\\\\" ++ Called ++ "\\IPC" ++ [$$], % make the Emacs mode happy...
+ Path = "\\\\*SMBSERVER\\IPC" ++ [$$], % make the Emacs mode happy...
Pdu1 = tree_connect(S, Neg, Pdu0, ipc_path(Neg, Path), ?SERVICE_ANY_TYPE),
exit_if_error(Pdu1, "Tree connect failed"),
{Req, Pdu2} = smb_list_shares_pdu(Pdu1),
@@ -222,16 +220,15 @@ bf_list_shares(TransName) ->
%%% Setup a socket, initiate an NBSS session and
%%% negotiate the protocol dialect.
%%%---------------------------------------------------------------------
-connect(Caller, Called) -> connect(Caller, Called, []).
-connect(Caller, Called, SockOpts) -> connect(Caller, Called, SockOpts, ?PORT).
+connect(Host) -> connect(Host, []).
+connect(Host, SockOpts) -> connect(Host, SockOpts, ?PORT).
-connect(Caller, Called, SockOpts, Port) ->
- ?dbg("~w(~w): enter connect, Caller=~p Called=~p~n",
- [?MODULE, ?LINE, Caller, Called]),
+connect(Host, SockOpts, Port) ->
+ ?dbg("~w(~w): enter connect, Host=~p ~n", [?MODULE, ?LINE, Host]),
Opts = [binary, {packet, 0}|SockOpts],
- case gen_tcp:connect(lcase_host(Called), Port, Opts) of
+ case gen_tcp:connect(Host, Port, Opts) of
{ok,S} ->
- case nbss_session_request(S, Called, Caller) of
+ case nbss_session_request(S, "*SMBSERVER", caller()) of
{ok,_} ->
{ok, S, negotiate(S)};
_ ->
@@ -253,7 +250,6 @@ write_file(S, Neg, InReq, Finfo) ->
write_file(S, Neg, InReq, Finfo, Bin, Written) when ?LT_BUFSIZE(Neg,Bin) ->
{Req, Pdu} = smb_write_andx_pdu(InReq, Finfo, Bin, Written),
- %%io:format("~p(~p): writing ~p bytes~n",[?MODULE,?LINE,size(Bin)]),
case decode_smb_response(Req, nbss_session_service(S, Pdu)) of
{ok, Wrote} ->
{ok, Wrote + Written};
@@ -1102,8 +1098,6 @@ smb_check_directory_pdu(InReq, Path) ->
flags2 = InReq#smbpdu.flags2,
bc = size(Bf),
bf = Bf},
- %%io:format("check_directory: WordCount = ~p~n",[Rec#smbpdu.wc]),
- %%io:format("check_directory: ByteCount = ~p~n",[Rec#smbpdu.bc]),
{Rec, enc_smb(Rec)}.
bf_check_directory(InReq, Path) ->
@@ -1123,8 +1117,6 @@ smb_tree_connect_andx_pdu(Neg, InReq, Path, Service) ->
wp = Wp,
bc = size(Bf),
bf = Bf},
- %%io:format("tree_connect_andx: WordCount = ~p~n",[Rec#smbpdu.wc]),
- %%io:format("tree_connect_andx: ByteCount = ~p~n",[Rec#smbpdu.bc]),
{Rec, enc_smb(Rec)}.
wp_tree_connect_andx(Neg) ->
@@ -1177,7 +1169,6 @@ smb_session_setup_andx_pdu(Neg, U) when ?NTLM_0_12(Neg),
?USE_UNICODE(Neg) ->
?dbg("~w(~w): session_setup_andx, ntlm_0.12 + Unicode Capa=~w~n",
[?MODULE,?LINE, Neg#smb_negotiate_res.srv_capabilities]),
- %%{Passwd, PwLen} = enc_lm_passwd(Neg, U#user.pw),
{UPasswd, UPwLen} = enc_nt_passwd(Neg, U#user.pw, U#user.charset),
{Wc,Wp} = wp_session_setup_andx(Neg, U, 0, UPwLen),
Bf = bf_session_setup_andx(Neg, U, UPasswd),
@@ -1356,7 +1347,6 @@ ex(K, D) ->
exit("fatal_error").
e(K,D) ->
- %%io:format("crypto:des_cbc_encrypt(~p, 0, ~p) ~n", [K,D]),
B = crypto:des_cbc_encrypt(s2k(K), null_vector(), D).
null_vector() -> <<0,0,0,0,0,0,0,0>>.
@@ -1401,8 +1391,6 @@ s2k(<<B0:7/binary,B1:7/binary>>) ->
s16x(Passwd) ->
- %%io:format("====== ~p b(~p)~n", [p14(Passwd), swab(p14(Passwd))]),
- %%io:format("------ ~p b(~p)~n", [p14(Passwd), s2k(p14(Passwd))]),
ex(p14(Passwd), n8()).
p14(Passwd) when size(Passwd) =< 14 ->
@@ -1512,7 +1500,6 @@ recv(S) ->
{tcp,S,Bin} ->
case dec_msg(Bin) of
{ok, ?SESSION_KEEP_ALIVE} ->
- io:format("recv: got KEEP_ALIVE~n", []),
recv(S);
Else ->
Else
@@ -1618,7 +1605,6 @@ to_bool(_) -> true.
hexprint(L) ->
F = fun(H, Acc) ->
- %%io:format("~c~.16B",[Acc,H]),
io:format("~c~s",[Acc,i2x(H)]),
$,
end,
View
11 lib/esmb/src/esmb_client.erl
@@ -24,6 +24,8 @@ istart(Path, User) -> start(Path, User, "WORKGROUP", ?CSET_ISO_8859_1).
ustart(Path, User) -> start(Path, User, "WORKGROUP", ?CSET_UTF8).
start(Path, User, Wgroup, Charset) ->
+ md4:start(),
+ iconv:start(),
case host_share(Path) of
{Host, Share} ->
spawn(fun() -> init(Host, Share, User, Wgroup, Charset) end);
@@ -33,22 +35,17 @@ start(Path, User, Wgroup, Charset) ->
init(Host, Share, User, Wgroup, Charset) ->
put(charset, Charset),
- Called = ucase(Host),
- Caller = esmb:caller(),
- {ok,S,Neg} = esmb:connect(Caller, Called),
+ {ok,S,Neg} = esmb:connect(Host),
Pw = get_passwd(),
U = #user{pw = Pw, name = User, primary_domain = Wgroup},
Pdu0 = esmb:user_logon(S, Neg, U),
esmb:exit_if_error(Pdu0, "Login failed"),
- WinPath = mk_winpath(Neg, "//"++Called++"/"++User, Charset),
+ WinPath = mk_winpath(Neg, "//"++Host++"/"++User, Charset),
Path = to_ucs2(Neg, WinPath, Charset),
Pdu1 = esmb:tree_connect(S, Neg, Pdu0, Path),
esmb:exit_if_error(Pdu1, "Tree connect failed"),
shell(S, Neg, {Pdu1, "\\\\"}).
-mk_path(Called, User) ->
- "\\\\" ++ Called ++ "\\" ++ ucase(User).
-
shell(S, Neg, {_Pdu, Cwd} = State) ->
shell(S, Neg, cmd(read_line(Cwd), S, Neg, State)).
Please sign in to comment.
Something went wrong with that request. Please try again.