[151] | 1 | /*
|
---|
| 2 | Netdrive Samba client plugin
|
---|
| 3 | general utility functions
|
---|
[957] | 4 | Copyright (C) netlabs.org 2003-2012
|
---|
| 5 | Copyright (C) bww bitwise works GmbH 2012-2016
|
---|
[151] | 6 |
|
---|
| 7 | This program is free software; you can redistribute it and/or modify
|
---|
| 8 | it under the terms of the GNU General Public License as published by
|
---|
| 9 | the Free Software Foundation; either version 2 of the License, or
|
---|
| 10 | (at your option) any later version.
|
---|
| 11 |
|
---|
| 12 | This program is distributed in the hope that it will be useful,
|
---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | GNU General Public License for more details.
|
---|
| 16 |
|
---|
| 17 | You should have received a copy of the GNU General Public License
|
---|
| 18 | along with this program; if not, write to the Free Software
|
---|
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
[147] | 22 | #define INCL_DOS
|
---|
| 23 | #define INCL_DOSERRORS
|
---|
| 24 | #include <os2.h>
|
---|
| 25 | #include <errno.h>
|
---|
| 26 | #include <stdlib.h>
|
---|
[183] | 27 | #include <string.h>
|
---|
[959] | 28 | #include <stdio.h>
|
---|
[147] | 29 |
|
---|
| 30 | #include "smbwrp.h"
|
---|
| 31 |
|
---|
| 32 | // map errno errors to API errors
|
---|
| 33 | int maperror(int rc)
|
---|
| 34 | {
|
---|
[959] | 35 | switch (rc)
|
---|
| 36 | {
|
---|
| 37 | case 0 : // NO_ERROR
|
---|
| 38 | return NO_ERROR;
|
---|
| 39 | case 1 : // EPERM - Operation nt permitted
|
---|
| 40 | case 13 : // EACCES - Permission denied
|
---|
| 41 | return ERROR_ACCESS_DENIED;
|
---|
| 42 | case 2 : // ENOENT - No such file or directory
|
---|
| 43 | return ERROR_FILE_NOT_FOUND;
|
---|
| 44 | case 3 : // ESRCH - No such process
|
---|
| 45 | return ERROR_PID_MISMATCH;
|
---|
| 46 | case 4 : // EINTR - Interrupted system call
|
---|
| 47 | return ERROR_INTERRUPT;
|
---|
| 48 | case 5 : // EIO - I/O error
|
---|
| 49 | return ERROR_READ_FAULT;
|
---|
| 50 | case 6 : // ENXIO - No such device or address
|
---|
| 51 | return ERROR_BAD_UNIT;
|
---|
| 52 | case 7 : // E2BIG - Arguments or environment too big
|
---|
| 53 | return ERROR_INVALID_DATA;
|
---|
| 54 | case 8 : // ENOEXEC - Invalid executable file format
|
---|
| 55 | return ERROR_BAD_EXE_FORMAT;
|
---|
| 56 | case 9 : // EBADF - Bad file number
|
---|
| 57 | return ERROR_INVALID_HANDLE;
|
---|
| 58 | case 10 : // ECHILD - No child processes
|
---|
| 59 | return ERROR_NO_CHILD_PROCESS;
|
---|
| 60 | case 11 : // EAGAIN - Resource temporarily unavailable
|
---|
| 61 | case 16 : // EBUSY - Resource busy
|
---|
| 62 | return ERROR_BUSY;
|
---|
| 63 | case 12 : // ENOMEM - Not enough memory
|
---|
| 64 | return ERROR_NOT_ENOUGH_MEMORY;
|
---|
| 65 | case 14 : // EFAULT - Bad address
|
---|
| 66 | return ERROR_INVALID_ADDRESS;
|
---|
| 67 | case 15 : // ENOLCK - No locks available
|
---|
| 68 | return ERROR_NOT_LOCKED;
|
---|
| 69 | case 17 : // EEXIST - File exists
|
---|
| 70 | return ERROR_FILE_EXISTS;
|
---|
| 71 | case 18 : // EXDEV - Cross-device link
|
---|
| 72 | return ERROR_NOT_SAME_DEVICE;
|
---|
| 73 | case 19 : // ENODEV - No such device
|
---|
| 74 | case 57 : // ENOTCONN - Socket is not connected
|
---|
| 75 | return ERROR_REM_NOT_LIST;
|
---|
| 76 | case 20 : // ENOTDIR - Not a directory
|
---|
| 77 | return ERROR_PATH_NOT_FOUND;
|
---|
| 78 | case 21 : // EISDIR - Is a directory
|
---|
| 79 | return ERROR_DIRECTORY;
|
---|
| 80 | case 22 : // EINVAL - Invalid argument
|
---|
| 81 | return ERROR_INVALID_PARAMETER;
|
---|
| 82 | case 23 : // ENFILE - Too many open files in system
|
---|
| 83 | case 31 : // EMLINK - Too many links
|
---|
| 84 | return ERROR_TOO_MANY_OPEN_FILES;
|
---|
| 85 | case 24 : // EMFILE - Too many open files
|
---|
| 86 | return ERROR_TOO_MANY_OPENS;
|
---|
| 87 | case 25 : // ENOTTY - Inappropriate ioctl
|
---|
| 88 | return ERROR_MOD_NOT_FOUND;
|
---|
| 89 | case 26 : // EDEADLK - Resource deadlock avoided
|
---|
| 90 | return ERROR_LOCK_VIOLATION;
|
---|
| 91 | case 27 : // EFBIG - File too large
|
---|
| 92 | case 40 : // EMSGSIZE - Message too long
|
---|
| 93 | return ERROR_TRANSFER_TOO_LONG;
|
---|
| 94 | case 28 : // ENOSPC - Disk full
|
---|
| 95 | return ERROR_DISK_FULL;
|
---|
| 96 | case 29 : // ESPIPE - Invalid seek
|
---|
| 97 | return ERROR_SEEK;
|
---|
| 98 | case 30 : // EROFS - Read-only file system
|
---|
| 99 | return ERROR_WRITE_PROTECT;
|
---|
| 100 | case 32 : // EPIPE - Broken pipe
|
---|
| 101 | return ERROR_BROKEN_PIPE;
|
---|
| 102 | case 33 : // EDOM - Domain error
|
---|
| 103 | return ERROR_INVALID_LEVEL;
|
---|
| 104 | case 34 : // ENAMETOOLONG - File name too long
|
---|
| 105 | case 38 : // ERANGE - Result too large
|
---|
| 106 | return ERROR_FILENAME_EXCED_RANGE;
|
---|
| 107 | case 35 : // ENOTEMPTY - Directory not empty
|
---|
| 108 | return ERROR_DIR_NOT_EMPTY;
|
---|
| 109 | case 36 : // EINPROGRESS - Operation now in progress
|
---|
| 110 | case 66 : // EALREADY - Operation already in progress
|
---|
| 111 | return ERROR_BUSY_DRIVE;
|
---|
| 112 | case 37 : // ENOSYS - Function not implemented
|
---|
| 113 | return ERROR_INVALID_FUNCTION;
|
---|
| 114 | case 39 : // EDESTADDRREQ - Destination address required
|
---|
| 115 | return ERROR_KBD_FOCUS_REQUIRED;
|
---|
| 116 | case 48 : // EADDRINUSE - Address already in use
|
---|
| 117 | return ERROR_NETWORK_BUSY;
|
---|
| 118 | case 49 : // EADDRNOTAVAIL - Can't assigned requested address
|
---|
| 119 | return ERROR_INFO_NOT_AVAIL;
|
---|
| 120 | case 50 : // ENETDOWN - Network is down
|
---|
| 121 | case 51 : // ENETUNREACH - Network is unreachable
|
---|
| 122 | case 52 : // ENETRESET - Network dropped connection on reset
|
---|
| 123 | case 53 : // ECONNABORTED - Software caused connection abort
|
---|
| 124 | case 54 : // ECONNRESET - Connection reset by peer
|
---|
| 125 | return ERROR_NETWORK_ACCESS_DENIED;
|
---|
| 126 | case 55 : // ENOBUFS - No buffer space available
|
---|
| 127 | return ERROR_BUFFER_OVERFLOW;
|
---|
| 128 | case 56 : // EISCONN - Socket is already connected
|
---|
| 129 | return ERROR_PIPE_BUSY;
|
---|
| 130 | case 58 : // ESHUTDOWN - Can't send after socket shutdown
|
---|
| 131 | return ERROR_ALREADY_SHUTDOWN;
|
---|
| 132 | case 60 : // ETIMEDOUT - Connection timed out
|
---|
| 133 | return ERROR_TIMEOUT;
|
---|
| 134 | case 61 : // ECONNREFUSED - Connection refused
|
---|
| 135 | return ERROR_NETWORK_ACCESS_DENIED;
|
---|
| 136 | case 63 : // ENOTSOCK - Socket operation on non-socket
|
---|
| 137 | return ERROR_INVALID_BLOCK;
|
---|
| 138 | case 64 : // EHOSTDOWN - Host is down
|
---|
| 139 | return ERROR_BAD_FORMAT;
|
---|
| 140 | case 65 : // EHOSTUNREACH - No route to host
|
---|
| 141 | return ERROR_BAD_NETPATH;
|
---|
| 142 | }
|
---|
[189] | 143 | // debug_printf( "Unhandled return code %d\n");
|
---|
[959] | 144 | return rc + 40000;
|
---|
[147] | 145 | }
|
---|
| 146 |
|
---|
| 147 | char * getlastslash(char * path)
|
---|
| 148 | {
|
---|
[959] | 149 | char * p;
|
---|
| 150 | if (!path)
|
---|
| 151 | return NULL;
|
---|
| 152 |
|
---|
| 153 | for (p = path + strlen(path) - 1; p >= path; p--)
|
---|
| 154 | {
|
---|
| 155 | if (*p == '\\' || *p == '/')
|
---|
| 156 | return p;
|
---|
| 157 | }
|
---|
| 158 | return NULL;
|
---|
[147] | 159 | }
|
---|