| | 918 | // ------------------------------------------------------------- |
| | 919 | |
| | 920 | /* check if the requested resource is available */ |
| | 921 | static int checkMountResource( Resource* pRes) |
| | 922 | { |
| | 923 | int rc; |
| | 924 | unsigned long action; |
| | 925 | smb_request req = {0}; |
| | 926 | smb_response resp = {0}; |
| | 927 | Connection Conn = {0}; |
| | 928 | |
| | 929 | debug_printf("checkMountResource in tid#%d\n", _gettid()); |
| | 930 | |
| | 931 | // open the pipe |
| | 932 | Conn.pRes = pRes; |
| | 933 | Conn.file.fd = -1; |
| | 934 | debug_printf("checkMountResource open pipe\n"); |
| | 935 | rc = openpipe(pRes, &Conn.pipe); |
| | 936 | if (rc) |
| | 937 | { |
| | 938 | debug_printf("checkMountResource open pipe failed rc=%d\n", rc); |
| | 939 | return rc; |
| | 940 | } |
| | 941 | |
| | 942 | // init, get client pid |
| | 943 | debug_printf("checkMountResource send INIT for '%s'\n", pRes->srv.share_name); |
| | 944 | req.request = SMBREQ_INIT; |
| | 945 | req.param = (char *)0xFFFFFFFF; |
| | 946 | rc = _DosTransactNPipe(&Conn, &req, sizeof(req), &resp, sizeof(resp), &action); |
| | 947 | if (rc || action < sizeof(resp) || resp.rc) |
| | 948 | { |
| | 949 | debug_printf("checkMountResource INIT failed rc=%d\n", rc); |
| | 950 | // close pipe |
| | 951 | DosClose( Conn.pipe); |
| | 952 | return rc; |
| | 953 | } |
| | 954 | Conn.clientpid = resp.value & 0xFFFF; |
| | 955 | |
| | 956 | // allocate shared memory |
| | 957 | rc = DosAllocSharedMem((PPVOID)&Conn.mem, NULL, pRes->memlen, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_GIVEABLE | pRes->objany); |
| | 958 | if (rc) |
| | 959 | { |
| | 960 | debug_printf("checkMountResource DosAllocSharedMem failed rc=%d\n", rc); |
| | 961 | // close pipe |
| | 962 | DosClose( Conn.pipe); |
| | 963 | return rc; |
| | 964 | } |
| | 965 | rc = DosGiveSharedMem( Conn.mem, Conn.clientpid, PAG_READ | PAG_WRITE); |
| | 966 | if (!rc) |
| | 967 | { |
| | 968 | // open connection with samba server, just to check share type |
| | 969 | debug_printf("checkMountResource send CONNECT\n"); |
| | 970 | MemCpy( Conn.mem, &pRes->srv, sizeof(pRes->srv)); |
| | 971 | req.request = SMBREQ_CONNECT; |
| | 972 | req.param = Conn.mem; |
| | 973 | req.paramlen = sizeof( Conn.srv); |
| | 974 | req.length = req.paramlen; |
| | 975 | rc = _DosTransactNPipe( &Conn, &req, sizeof(req), &resp, sizeof(resp), &action); |
| | 976 | if (rc || action < sizeof(resp) || resp.rc) |
| | 977 | { |
| | 978 | debug_printf("checkMountResource SMBREQ_CONNECT failed rc=%d, resp.rc=%d\n", rc, resp.rc); |
| | 979 | rc = (rc == NO_ERROR ? resp.rc : rc); |
| | 980 | } |
| | 981 | // no more data, close connection |
| | 982 | req.request = SMBREQ_DISCONNECT; |
| | 983 | req.param = Conn.mem; |
| | 984 | req.length = 0; |
| | 985 | req.paramlen = 0; |
| | 986 | _DosTransactNPipe( &Conn, &req, sizeof(req), &resp, sizeof(resp), &action); |
| | 987 | } |
| | 988 | |
| | 989 | // free memory |
| | 990 | DosFreeMem( Conn.mem); |
| | 991 | // close pipe |
| | 992 | DosClose( Conn.pipe); |
| | 993 | |
| | 994 | return rc; |
| | 995 | } |