package p138.p329.p362.p369;

import com.hierynomus.mssmb2.SMBApiException;
import com.hierynomus.protocol.transport.TransportException;
import com.hierynomus.smbj.common.SMBRuntimeException;
import com.hierynomus.smbj.paths.PathResolveException;
import com.hierynomus.smbj.session.SMB2GuestSigningRequiredException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import p138.p176.p177.p242.p246.p251.C4303;
import p138.p329.p341.EnumC6158;
import p138.p329.p346.C6231;
import p138.p329.p346.C6237;
import p138.p329.p346.EnumC6233;
import p138.p329.p346.EnumC6241;
import p138.p329.p346.p347.C6252;
import p138.p329.p346.p347.C6263;
import p138.p329.p346.p347.C6269;
import p138.p329.p346.p347.C6270;
import p138.p329.p357.InterfaceC6312;
import p138.p329.p362.p363.C6343;
import p138.p329.p362.p364.C6353;
import p138.p329.p362.p365.C6354;
import p138.p329.p362.p366.C6365;
import p138.p329.p362.p366.C6368;
import p138.p329.p362.p368.InterfaceC6379;
import p138.p329.p362.p369.C6383.C6384;
import p138.p329.p362.p370.C6391;
import p138.p329.p362.p370.C6402;
import p138.p329.p362.p370.C6403;
import p138.p329.p362.p370.C6406;
import p138.p329.p362.p370.C6413;
import p421.p422.p423.p424.C6713;
import p463.p481.C7162;
import p463.p481.InterfaceC7161;

/* JADX INFO: renamed from: ދ.ށ.މ.ވ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C6386 implements AutoCloseable {

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public static final InterfaceC7161 f17824 = C7162.m10575((Class<?>) C6386.class);

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public long f17825;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public C6383 f17826;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public boolean f17827;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public C6354 f17828;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public C6365 f17829;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public final InterfaceC6379 f17830;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public C6387 f17831 = new C6387();

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public List<C6386> f17832 = new ArrayList();

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public C6343 f17833;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public boolean f17834;

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public boolean f17835;

    public C6386(C6354 c6354, C6343 c6343, C6365 c6365, InterfaceC6379 interfaceC6379, InterfaceC6312 interfaceC6312) {
        this.f17828 = c6354;
        this.f17833 = c6343;
        this.f17829 = c6365;
        this.f17830 = interfaceC6379;
        this.f17826 = new C6383(c6354.f17739.f17759.f17764, interfaceC6312);
        if (c6365 != null) {
            c6365.m9587(this);
        }
    }

    @Override // java.lang.AutoCloseable
    public void close() {
        m9608();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public <T extends C6237> Future<T> m9606(C6237 c6237) {
        if (this.f17827) {
            if (!(this.f17826.f17819 != null)) {
                throw new TransportException("Message signing is required, but no signing key is negotiated");
            }
        }
        C6354 c6354 = this.f17828;
        C6383 c6383 = this.f17826;
        if (c6383.f17819 != null) {
            c6237 = c6383.new C6384(c6237);
        } else {
            C6383.f17815.mo10573("Not wrapping {} as signed, as no key is set.", c6237.mo9556().f17389);
        }
        return c6354.m9573(c6237);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public C6386 m9607(C6353 c6353) {
        try {
            C6386 c6386M9576 = this.f17828.f17746.m9559(c6353.f17734).m9576(this.f17833);
            this.f17832.add(c6386M9576);
            return c6386M9576;
        } catch (IOException e) {
            throw new SMBApiException(EnumC6158.STATUS_OTHER.f17193, EnumC6233.SMB2_NEGOTIATE, "Could not connect to DFS root " + c6353, e);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m9608() {
        try {
            f17824.mo10567("Logging off session {} from host {}", Long.valueOf(this.f17825), this.f17828.f17745);
            C6387 c6387 = this.f17831;
            c6387.f17836.readLock().lock();
            try {
                ArrayList<C6406> arrayList = new ArrayList(c6387.f17837.values());
                c6387.f17836.readLock().unlock();
                for (C6406 c6406 : arrayList) {
                    try {
                        c6406.close();
                    } catch (IOException e) {
                        f17824.mo10574("Caught exception while closing TreeConnect with id: {}", Long.valueOf(c6406.f17886.f17899), e);
                    }
                }
                for (C6386 c6386 : this.f17832) {
                    f17824.mo10567("Logging off nested session {} for session {}", Long.valueOf(c6386.f17825), Long.valueOf(this.f17825));
                    try {
                        c6386.m9608();
                    } catch (TransportException unused) {
                        f17824.mo10555("Caught exception while logging off nested session {}", Long.valueOf(c6386.f17825));
                    }
                }
                C6252 c6252 = (C6252) C4303.m7011(m9606(new C6252(this.f17828.f17739.f17759.f17764, this.f17825)), this.f17828.f17747.f17706, TimeUnit.MILLISECONDS, TransportException.f2172);
                if (EnumC6158.m9480(((C6231) c6252.f17677).f17394)) {
                    return;
                }
                throw new SMBApiException((C6231) c6252.f17677, "Could not logoff session <<" + this.f17825 + ">>");
            } catch (Throwable th) {
                c6387.f17836.readLock().unlock();
                throw th;
            }
        } finally {
            ((C6713) this.f17829.f17784).m9911(new C6368(this.f17825));
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m9609(C6263 c6263) {
        this.f17834 = c6263.f17516.contains(C6263.EnumC6265.SMB2_SESSION_FLAG_IS_GUEST);
        this.f17835 = c6263.f17516.contains(C6263.EnumC6265.SMB2_SESSION_FLAG_IS_NULL);
        C6354 c6354 = this.f17828;
        boolean z = c6354.f17747.f17696;
        boolean z2 = (c6354.f17739.f17763 & 2) > 0;
        if (z || z2) {
            this.f17827 = true;
        } else {
            this.f17827 = false;
        }
        if (this.f17835) {
            this.f17827 = false;
        }
        if (this.f17834 && this.f17827) {
            throw new SMB2GuestSigningRequiredException();
        }
        if (this.f17834 && !z) {
            this.f17827 = false;
        }
        if (this.f17828.f17739.f17759.f17764.m9498() && c6263.f17516.contains(C6263.EnumC6265.SMB2_SESSION_FLAG_ENCRYPT_DATA)) {
            this.f17827 = false;
        }
        if (this.f17834 || this.f17835) {
            this.f17826.m9605(null);
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public C6406 m9610(String str) {
        C6406 c6403;
        C6386 c6386M9607;
        if (str.contains("\\")) {
            throw new IllegalArgumentException(String.format("Share name (%s) cannot contain '\\' characters.", str));
        }
        C6387 c6387 = this.f17831;
        c6387.f17836.readLock().lock();
        try {
            C6406 c6406 = c6387.f17838.get(str);
            if (c6406 != null) {
                f17824.mo10556("Returning cached Share {} for {}", c6406, str);
                return c6406;
            }
            C6353 c6353 = new C6353(this.f17828.f17745, str);
            f17824.mo10567("Connecting to {} on session {}", c6353, Long.valueOf(this.f17825));
            try {
                C6269 c6269 = new C6269(this.f17828.f17739.f17759.f17764, c6353, this.f17825);
                ((C6231) c6269.f17677).f17387 = 256;
                C6270 c6270 = (C6270) C4303.m7011(m9606(c6269), this.f17828.f17747.f17706, TimeUnit.MILLISECONDS, TransportException.f2172);
                try {
                    C6353 c6353Mo9596 = this.f17830.mo9596(this, c6270, c6353);
                    if (c6353Mo9596.m9571(c6353)) {
                        c6386M9607 = this;
                    } else {
                        f17824.mo10561("Re-routing the connection to host {}", c6353Mo9596.f17734);
                        c6386M9607 = m9607(c6353Mo9596);
                    }
                    if (!c6353Mo9596.m9572(c6353)) {
                        return c6386M9607.m9610(c6353Mo9596.f17735);
                    }
                } catch (PathResolveException unused) {
                }
                if (EnumC6158.m9479(((C6231) c6270.f17677).f17394)) {
                    f17824.mo10565(((C6231) c6270.f17677).toString());
                    throw new SMBApiException((C6231) c6270.f17677, "Could not connect to " + c6353);
                }
                if (c6270.f17540.contains(EnumC6241.SMB2_SHARE_CAP_ASYMMETRIC)) {
                    throw new SMBRuntimeException("ASYMMETRIC capability unsupported");
                }
                C6413 c6413 = new C6413(((C6231) c6270.f17677).f17393, c6353, this, c6270.f17540, this.f17828, this.f17829, c6270.f17541);
                if (c6270.f17539 == 1) {
                    c6403 = new C6391(c6353, c6413, this.f17830);
                } else {
                    if (c6270.f17539 == 2) {
                        c6403 = new C6402(c6353, c6413);
                    } else {
                        if (!(c6270.f17539 == 3)) {
                            throw new SMBRuntimeException("Unknown ShareType returned in the TREE_CONNECT Response");
                        }
                        c6403 = new C6403(c6353, c6413);
                    }
                }
                this.f17831.m9611(c6403);
                return c6403;
            } catch (TransportException e) {
                throw new SMBRuntimeException(e);
            }
        } finally {
            c6387.f17836.readLock().unlock();
        }
    }
}
