r11404: Another torture test and a new WERR.
[kamenim/samba.git] / source4 / libcli / util / doserr.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  DOS error routines
4  *  Copyright (C) Tim Potter 2002.
5  *  
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 /* DOS error codes.  please read doserr.h */
22
23 #include "includes.h"
24 #include "pstring.h"
25
26 struct werror_code_struct {
27         const char *dos_errstr;
28         WERROR werror;
29 };
30
31 static const struct werror_code_struct dos_errs[] =
32 {
33         { "WERR_OK", WERR_OK },
34         { "WERR_BADFILE", WERR_BADFILE },
35         { "WERR_ACCESS_DENIED", WERR_ACCESS_DENIED },
36         { "WERR_BADFID", WERR_BADFID },
37         { "WERR_BADFUNC", WERR_BADFUNC },
38         { "WERR_BAD_NETPATH", WERR_BAD_NETPATH },
39         { "WERR_INSUFFICIENT_BUFFER", WERR_INSUFFICIENT_BUFFER },
40         { "WERR_NO_SUCH_SHARE", WERR_NO_SUCH_SHARE },
41         { "WERR_ALREADY_EXISTS", WERR_ALREADY_EXISTS },
42         { "WERR_INVALID_PARAM", WERR_INVALID_PARAM },
43         { "WERR_NOT_SUPPORTED", WERR_NOT_SUPPORTED },
44         { "WERR_BAD_PASSWORD", WERR_BAD_PASSWORD },
45         { "WERR_NOMEM", WERR_NOMEM },
46         { "WERR_INVALID_NAME", WERR_INVALID_NAME },
47         { "WERR_UNKNOWN_LEVEL", WERR_UNKNOWN_LEVEL },
48         { "WERR_OBJECT_PATH_INVALID", WERR_OBJECT_PATH_INVALID },
49         { "WERR_NO_MORE_ITEMS", WERR_NO_MORE_ITEMS },
50         { "WERR_MORE_DATA", WERR_MORE_DATA },
51         { "WERR_UNKNOWN_PRINTER_DRIVER", WERR_UNKNOWN_PRINTER_DRIVER },
52         { "WERR_INVALID_PRINTER_NAME", WERR_INVALID_PRINTER_NAME },
53         { "WERR_PRINTER_ALREADY_EXISTS", WERR_PRINTER_ALREADY_EXISTS },
54         { "WERR_INVALID_DATATYPE", WERR_INVALID_DATATYPE },
55         { "WERR_INVALID_ENVIRONMENT", WERR_INVALID_ENVIRONMENT },
56         { "WERR_INVALID_FORM_NAME", WERR_INVALID_FORM_NAME },
57         { "WERR_INVALID_FORM_SIZE", WERR_INVALID_FORM_SIZE },
58         { "WERR_BUF_TOO_SMALL", WERR_BUF_TOO_SMALL },
59         { "WERR_JOB_NOT_FOUND", WERR_JOB_NOT_FOUND },
60         { "WERR_DEST_NOT_FOUND", WERR_DEST_NOT_FOUND },
61         { "WERR_NOT_LOCAL_DOMAIN", WERR_NOT_LOCAL_DOMAIN },
62         { "WERR_PRINTER_DRIVER_IN_USE", WERR_PRINTER_DRIVER_IN_USE },
63         { "WERR_STATUS_MORE_ENTRIES", WERR_STATUS_MORE_ENTRIES },
64         { "WERR_NET_NAME_NOT_FOUND", WERR_NET_NAME_NOT_FOUND },
65         { "WERR_DEVICE_NOT_SHARED", WERR_DEVICE_NOT_SHARED },
66         { "WERR_DFS_NO_SUCH_VOL", WERR_DFS_NO_SUCH_VOL },
67         { "WERR_DFS_NO_SUCH_SHARE", WERR_DFS_NO_SUCH_SHARE },
68         { "WERR_DFS_NO_SUCH_SERVER", WERR_DFS_NO_SUCH_SERVER },
69         { "WERR_DFS_INTERNAL_ERROR", WERR_DFS_INTERNAL_ERROR },
70         { "WERR_DFS_CANT_CREATE_JUNCT", WERR_DFS_CANT_CREATE_JUNCT },
71         { "WERR_INVALID_SECURITY_DESCRIPTOR", WERR_INVALID_SECURITY_DESCRIPTOR },
72         { "WERR_UNKNOWN_REVISION", WERR_UNKNOWN_REVISION },
73         { "WERR_REVISION_MISMATCH", WERR_REVISION_MISMATCH },
74         { "WERR_INVALID_OWNER", WERR_INVALID_OWNER },
75         { "WERR_INVALID_COMPUTERNAME", WERR_INVALID_COMPUTERNAME },
76         { "WERR_INVALID_DOMAINNAME", WERR_INVALID_DOMAINNAME },
77         { "WERR_NO_SUCH_USER", WERR_NO_SUCH_USER },
78         { "WERR_NO_SUCH_DOMAIN", WERR_NO_SUCH_DOMAIN },
79         { "WERR_DS_SERVICE_BUSY", WERR_DS_SERVICE_BUSY },
80         { "WERR_DS_SERVICE_UNAVAILABLE", WERR_DS_SERVICE_UNAVAILABLE },
81         { "WERR_DS_NO_SUCH_OBJECT", WERR_DS_NO_SUCH_OBJECT },
82         { "WERR_DS_OBJ_NOT_FOUND", WERR_DS_OBJ_NOT_FOUND },
83         { "WERR_DS_DRA_INVALID_PARAMETER", WERR_DS_DRA_INVALID_PARAMETER },
84         { "WERR_DS_DRA_BAD_DN", WERR_DS_DRA_BAD_DN },
85         { "WERR_DS_DRA_BAD_NC", WERR_DS_DRA_BAD_NC },
86         { "WERR_DS_DRA_INTERNAL_ERROR", WERR_DS_DRA_INTERNAL_ERROR },
87         { "WERR_DS_SINGLE_VALUE_CONSTRAINT", WERR_DS_SINGLE_VALUE_CONSTRAINT },
88         { "WERR_DS_DRA_DB_ERROR", WERR_DS_DRA_DB_ERROR },
89         { "WERR_DS_DRA_NO_REPLICA", WERR_DS_DRA_NO_REPLICA },
90         { "WERR_DS_DNS_LOOKUP_FAILURE", WERR_DS_DNS_LOOKUP_FAILURE },
91         { "WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX", WERR_DS_WRONG_LINKED_ATTRIBUTE_SYNTAX },
92         { "WERR_GENERAL_FAILURE", WERR_GENERAL_FAILURE },
93         { "WERR_PRINTQ_FULL", WERR_PRINTQ_FULL },
94         { "WERR_NO_SPOOL_SPACE", WERR_NO_SPOOL_SPACE },
95         { "WERR_CAN_NOT_COMPLETE", WERR_CAN_NOT_COMPLETE },
96         { "WERR_SERVER_UNAVAILABLE", WERR_SERVER_UNAVAILABLE },
97         { "WERR_CLASS_NOT_REGISTERED", WERR_CLASS_NOT_REGISTERED },
98         { "WERR_NO_SHUTDOWN_IN_PROGRESS", WERR_NO_SHUTDOWN_IN_PROGRESS },
99         { "WERR_SHUTDOWN_ALREADY_IN_PROGRESS", WERR_SHUTDOWN_ALREADY_IN_PROGRESS },
100         { NULL, W_ERROR(0) }
101 };
102
103
104
105
106 /* DFS errors */
107
108 /*****************************************************************************
109  returns a windows error message.  not amazingly helpful, but better than a number.
110  *****************************************************************************/
111 const char *win_errstr(WERROR werror)
112 {
113         static pstring msg;
114         int idx = 0;
115
116         while (dos_errs[idx].dos_errstr != NULL) {
117                 if (W_ERROR_V(dos_errs[idx].werror) == 
118                     W_ERROR_V(werror))
119                         return dos_errs[idx].dos_errstr;
120                 idx++;
121         }
122
123         slprintf(msg, sizeof(msg), "DOS code 0x%08x", W_ERROR_V(werror));
124
125         return msg;
126 }