<div dir="ltr">seems like my issue has to do with this bit of (unfinished? see the comment) code. Seems that the code is 3 years old.<div>I have a hunch that the difference in behavior i see is due to the Vsn difference. Any way to alter what's read as Vsn anywhere? (i presume it's a version of some sort)<br>
<div><br></div><div><pre style="margin-top:0px;margin-bottom:0px;padding:0px;border:0px;font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace;color:rgb(51,51,51);line-height:16px"><div class="" id="LC616" style="margin:0px;padding:0px 0px 0px 10px;border:0px">
<span class="" style="margin:0px;padding:0px;border:0px;color:rgb(153,0,0);font-weight:bold">open</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Vsn</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">ReqId</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Data</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">State</span><span class="" style="margin:0px;padding:0px;border:0px">)</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">when</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Vsn</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=<</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,153,153)">3</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span></div>
<div class="" id="LC617" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold"><<?</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">UINT32</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">BLen</span><span class="" style="margin:0px;padding:0px;border:0px">),</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">BPath</span><span class="" style="margin:0px;padding:0px;border:0px">:</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">BLen</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">/</span><span class="" style="margin:0px;padding:0px;border:0px">binary</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">?</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">UINT32</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">PFlags</span><span class="" style="margin:0px;padding:0px;border:0px">),</span></div>
<div class="" id="LC618" style="margin:0px;padding:0px 0px 0px 10px;border:0px">     <span class="" style="margin:0px;padding:0px;border:0px">_</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Attrs</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">/</span><span class="" style="margin:0px;padding:0px;border:0px">binary</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">>></span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Data</span><span class="" style="margin:0px;padding:0px;border:0px">,</span></div>
<div class="" id="LC619" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Path</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,134,179)">binary_to_list</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">BPath</span><span class="" style="margin:0px;padding:0px;border:0px">),</span></div>
<div class="" id="LC620" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Flags</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(85,85,85)">ssh_xfer</span><span class="" style="margin:0px;padding:0px;border:0px">:</span><span class="" style="margin:0px;padding:0px;border:0px">decode_open_flags</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Vsn</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">PFlags</span><span class="" style="margin:0px;padding:0px;border:0px">),</span></div>
<div class="" id="LC621" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px">do_open</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">ReqId</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">State</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Path</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Flags</span><span class="" style="margin:0px;padding:0px;border:0px">);</span></div>
<div class="" id="LC622" style="margin:0px;padding:0px 0px 0px 10px;border:0px"><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(153,0,0);font-weight:bold">open</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Vsn</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">ReqId</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Data</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">State</span><span class="" style="margin:0px;padding:0px;border:0px">)</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">when</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Vsn</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">>=</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,153,153)">4</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span></div>
<div class="" id="LC623" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold"><<?</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">UINT32</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">BLen</span><span class="" style="margin:0px;padding:0px;border:0px">),</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">BPath</span><span class="" style="margin:0px;padding:0px;border:0px">:</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">BLen</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">/</span><span class="" style="margin:0px;padding:0px;border:0px">binary</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">?</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">UINT32</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Access</span><span class="" style="margin:0px;padding:0px;border:0px">),</span></div>
<div class="" id="LC624" style="margin:0px;padding:0px 0px 0px 10px;border:0px">     <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">?</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">UINT32</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">PFlags</span><span class="" style="margin:0px;padding:0px;border:0px">),</span> <span class="" style="margin:0px;padding:0px;border:0px">_</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Attrs</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">/</span><span class="" style="margin:0px;padding:0px;border:0px">binary</span><span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">>></span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Data</span><span class="" style="margin:0px;padding:0px;border:0px">,</span></div>
<div class="" id="LC625" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Path</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,134,179)">binary_to_list</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">BPath</span><span class="" style="margin:0px;padding:0px;border:0px">),</span></div>
<div class="" id="LC626" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">FlagBits</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(85,85,85)">ssh_xfer</span><span class="" style="margin:0px;padding:0px;border:0px">:</span><span class="" style="margin:0px;padding:0px;border:0px">decode_open_flags</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Vsn</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">PFlags</span><span class="" style="margin:0px;padding:0px;border:0px">),</span></div>
<div class="" id="LC627" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">AcessBits</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(85,85,85)">ssh_xfer</span><span class="" style="margin:0px;padding:0px;border:0px">:</span><span class="" style="margin:0px;padding:0px;border:0px">decode_ace_mask</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Access</span><span class="" style="margin:0px;padding:0px;border:0px">),</span></div>
<div class="" id="LC628" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,136);font-style:italic">%% TODO: This is to make sure the Access flags are not ignored</span></div>
<div class="" id="LC629" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,136);font-style:italic">%% but this should be thought through better. This solution should</span></div>
<div class="" id="LC630" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,136);font-style:italic">%% be considered a hack in order to buy some time. At least</span></div>
<div class="" id="LC631" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,136);font-style:italic">%% it works better than when the Access flags where totally ignored.</span></div>
<div class="" id="LC632" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,136);font-style:italic">%% A better solution may need some code refactoring that we do</span></div>
<div class="" id="LC633" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(153,153,136);font-style:italic">%% not have time for right now.</span></div>
<div class="" id="LC634" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">AcessFlags</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px">decode_4_acess</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">AcessBits</span><span class="" style="margin:0px;padding:0px;border:0px">),</span></div>
<div class="" id="LC635" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Flags</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(85,85,85)">lists</span><span class="" style="margin:0px;padding:0px;border:0px">:</span><span class="" style="margin:0px;padding:0px;border:0px">append</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(85,85,85)">lists</span><span class="" style="margin:0px;padding:0px;border:0px">:</span><span class="" style="margin:0px;padding:0px;border:0px">umerge</span><span class="" style="margin:0px;padding:0px;border:0px">(</span></div>
<div class="" id="LC636" style="margin:0px;padding:0px 0px 0px 10px;border:0px">                       <span class="" style="margin:0px;padding:0px;border:0px">[[</span><span class="" style="margin:0px;padding:0px;border:0px">decode_4_flags</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">FlagBits</span><span class="" style="margin:0px;padding:0px;border:0px">)]</span> <span class="" style="margin:0px;padding:0px;border:0px">|</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">AcessFlags</span><span class="" style="margin:0px;padding:0px;border:0px">])),</span></div>
<div class="" id="LC637" style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span class="" style="margin:0px;padding:0px;border:0px">do_open</span><span class="" style="margin:0px;padding:0px;border:0px">(</span><span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">ReqId</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">State</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Path</span><span class="" style="margin:0px;padding:0px;border:0px">,</span> <span class="" style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Flags</span><span class="" style="margin:0px;padding:0px;border:0px">).</span><div>
<br></div></div></pre></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Dec 26, 2012 at 6:05 PM, Alex Babkin <span dir="ltr"><<a href="mailto:ababkin@gmail.com" target="_blank">ababkin@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi<div><br></div><div>I'm experimenting with using ssh:daemon using the ssh_sftpd subsystem (other words the standard erlang/otp sftp daemon) and i'm seeing some strange and inconsistent behavior:</div>

<div><br></div><div>(all code is here: <a href="https://github.com/ababkin/hl7_pipeline" target="_blank">https://github.com/ababkin/hl7_pipeline</a>)</div><div><br></div><div>when i run the sftpd daemon and try to connect to it with an external sftp client (standard sftp cli on osx lion) to 'put' a file, it seems to try to open a new file for write with these modes/flags: [binary,write,creat,trunc], which results in error.</div>

<div><br></div><div>I intercept these in my custom file_handler for sftpd (essentially just log the arguments in the open callback)<br></div><div><br></div><div>Doing manually in erl shell:</div><div>
<div>> Result = file:open("/tmp/da.txt", [binary, write, creat, trunc]).</div><div>results in: </div><div>{error,badarg}</div><div><br></div><div>so it looks like file:open doesn't like 'creat' or 'trunc' flags that sftpd tries to pass to it</div>

<div><br></div><div>this is from the default file_handler sftpd uses:</div><div><br></div><div><pre style="margin-top:0px;margin-bottom:0px;padding:0px;border:0px;font-size:12px;font-family:Consolas,'Liberation Mono',Courier,monospace;color:rgb(51,51,51);line-height:16px">
<div style="margin:0px;padding:0px 0px 0px 10px;border:0px"><span style="margin:0px;padding:0px;border:0px;color:rgb(153,0,0);font-weight:bold">open</span><span style="margin:0px;padding:0px;border:0px">(</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Path</span><span style="margin:0px;padding:0px;border:0px">,</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Flags</span><span style="margin:0px;padding:0px;border:0px">,</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">State</span><span style="margin:0px;padding:0px;border:0px">)</span> <span style="margin:0px;padding:0px;border:0px;font-weight:bold">-></span></div>

<div style="margin:0px;padding:0px 0px 0px 10px;border:0px">    <span style="margin:0px;padding:0px;border:0px">{</span><span style="margin:0px;padding:0px;border:0px;color:rgb(85,85,85)">file</span><span style="margin:0px;padding:0px;border:0px">:</span><span style="margin:0px;padding:0px;border:0px">open</span><span style="margin:0px;padding:0px;border:0px">(</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Path</span><span style="margin:0px;padding:0px;border:0px">,</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">Flags</span><span style="margin:0px;padding:0px;border:0px">),</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">State</span><span style="margin:0px;padding:0px;border:0px">}.</span></div>

</pre></div><div><br></div><div>.. i.e just passes the flags as modes to file:open</div><div><br></div></div><div>these results are further compounded with inconsistent behavior while running on different systems</div>
<div><br></div><div>i've tried running sftpd on a mac (lion) and ubuntu, seeing the above results, but trying to run the sftpd on a DS211j (that uses marvell ARM cpu and a version of busybox distro and R15B01 probably somehow cross-compiled specifically for the ARM) is see a different behavior:</div>

<div><br></div><div>on the DS211j, if i try to perform same steps as on above systems, the flags i intercept are [raw,binary,write], which writes the file fine and doesn't throw an error like in above cases</div>
<div><br></div><div>Tried to run the otp testsuite, but seem to be failing on testsuite build step having to do with hipe </div><div><br></div><div>Any insights would be welcome. </div><div>For now i just overwrite the collection of modes/flags with [raw,binary,write] whenever there is 'write' present in the list, but this seems hacky</div>

<div><br></div><div><br></div><div><br></div><div><br></div></div>
</blockquote></div><br></div>