/// <exception cref="SharpCifs.Smb.SmbException"></exception> /// <exception cref="UnknownHostException"></exception> /// <exception cref="System.UriFormatException"></exception> internal virtual void DoNetServerEnum(List<object> list, bool files, string wildcard , int searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff) { int listType = Url.GetHost().Length == 0 ? 0 : GetType(); SmbComTransaction req; SmbComTransactionResponse resp; if (listType == 0) { Connect0(); req = new NetServerEnum2(Tree.Session.transport.Server.OemDomainName, NetServerEnum2 .SvTypeDomainEnum); resp = new NetServerEnum2Response(); } else { if (listType == TypeWorkgroup) { req = new NetServerEnum2(Url.GetHost(), NetServerEnum2.SvTypeAll); resp = new NetServerEnum2Response(); } else { throw new SmbException("The requested list operations is invalid: " + Url); } } bool more; do { int n; Send(req, resp); if (resp.Status != WinError.ErrorSuccess && resp.Status != WinError.ErrorMoreData) { throw new SmbException(resp.Status, true); } more = resp.Status == WinError.ErrorMoreData; n = more ? resp.NumEntries - 1 : resp.NumEntries; for (int i = 0; i < n; i++) { IFileEntry e = resp.Results[i]; string name = e.GetName(); if (fnf != null && fnf.Accept(this, name) == false) { continue; } if (name.Length > 0) { // if !files we don't need to create SmbFiles here SmbFile f = new SmbFile(this, name, e.GetType(), AttrReadonly | AttrDirectory, 0L, 0L, 0L); if (ff != null && ff.Accept(f) == false) { continue; } if (files) { list.Add(f); } else { list.Add(name); } } } if (GetType() != TypeWorkgroup) { break; } req.SubCommand = unchecked(SmbComTransaction.NetServerEnum3); req.Reset(0, ((NetServerEnum2Response)resp).LastName); resp.Reset(); } while (more); }
/// <exception cref="SharpCifs.Smb.SmbException"></exception> /// <exception cref="UnknownHostException"></exception> /// <exception cref="System.UriFormatException"></exception> internal virtual void DoFindFirstNext(List<object> list, bool files, string wildcard , int searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff) { SmbComTransaction req; Trans2FindFirst2Response resp; int sid; string path = GetUncPath0(); string p = Url.AbsolutePath; if (p.LastIndexOf('/') != (p.Length - 1)) { throw new SmbException(Url + " directory must end with '/'"); } req = new Trans2FindFirst2(path, wildcard, searchAttributes); resp = new Trans2FindFirst2Response(); if (Log.Level >= 3) { Log.WriteLine("doFindFirstNext: " + req.Path); } Send(req, resp); sid = resp.Sid; req = new Trans2FindNext2(sid, resp.ResumeKey, resp.LastName); resp.SubCommand = SmbComTransaction.Trans2FindNext2; for (; ; ) { for (int i = 0; i < resp.NumEntries; i++) { IFileEntry e = resp.Results[i]; string name = e.GetName(); if (name.Length < 3) { int h = name.GetHashCode(); if (h == HashDot || h == HashDotDot) { if (name.Equals(".") || name.Equals("..")) { continue; } } } if (fnf != null && fnf.Accept(this, name) == false) { continue; } if (name.Length > 0) { SmbFile f = new SmbFile(this, name, TypeFilesystem, e.GetAttributes (), e.CreateTime(), e.LastModified(), e.Length()); if (ff != null && ff.Accept(f) == false) { continue; } if (files) { list.Add(f); } else { list.Add(name); } } } if (resp.IsEndOfSearch || resp.NumEntries == 0) { break; } req.Reset(resp.ResumeKey, resp.LastName); resp.Reset(); Send(req, resp); } try { Send(new SmbComFindClose2(sid), Blank_resp()); } catch (SmbException se) { if (Log.Level >= 4) { Runtime.PrintStackTrace(se, Log); } } }
/// <exception cref="SharpCifs.Smb.SmbException"></exception> /// <exception cref="UnknownHostException"></exception> /// <exception cref="System.UriFormatException"></exception> internal virtual void DoShareEnum(List<object> list, bool files, string wildcard, int searchAttributes, ISmbFilenameFilter fnf, ISmbFileFilter ff) { string p = Url.AbsolutePath; IOException last = null; IFileEntry[] entries; UniAddress addr; IFileEntry e; Hashtable map; if (p.LastIndexOf('/') != (p.Length - 1)) { throw new SmbException(Url + " directory must end with '/'"); } if (GetType() != TypeServer) { throw new SmbException("The requested list operations is invalid: " + Url); } map = new Hashtable(); if (_enableDfs && Dfs.IsTrustedDomain(GetServer(), Auth)) { try { entries = DoDfsRootEnum(); for (int ei = 0; ei < entries.Length; ei++) { e = entries[ei]; if (map.ContainsKey(e) == false) { map.Put(e, e); } } } catch (IOException ioe) { if (Log.Level >= 4) { Runtime.PrintStackTrace(ioe, Log); } } } addr = GetFirstAddress(); while (addr != null) { try { last = null; DoConnect(); try { entries = DoMsrpcShareEnum(); } catch (IOException ioe) { if (Log.Level >= 3) { Runtime.PrintStackTrace(ioe, Log); } entries = DoNetShareEnum(); } for (int ei = 0; ei < entries.Length; ei++) { e = entries[ei]; if (map.ContainsKey(e) == false) { map.Put(e, e); } } break; } catch (IOException ioe) { if (Log.Level >= 3) { Runtime.PrintStackTrace(ioe, Log); } last = ioe; if (!(ioe is SmbAuthException)) { RemoveCurrentAddress(); addr = GetNextAddress(); } else { break; } } } if (last != null && map.Count == 0) { if (last is SmbException == false) { throw new SmbException(Url.ToString(), last); } throw (SmbException)last; } //Iterator iter = map.Keys.Iterator(); //while (iter.HasNext()) foreach (var item in map.Keys) { e = (IFileEntry)item; string name = e.GetName(); if (fnf != null && fnf.Accept(this, name) == false) { continue; } if (name.Length > 0) { // if !files we don't need to create SmbFiles here SmbFile f = new SmbFile(this, name, e.GetType(), AttrReadonly | AttrDirectory, 0L, 0L, 0L); if (ff != null && ff.Accept(f) == false) { continue; } if (files) { list.Add(f); } else { list.Add(name); } } } }