Home | History | Annotate | Download | only in smbsrv
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 /*
     22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     23  * Use is subject to license terms.
     24  */
     25 
     26 #include <smbsrv/smb_kproto.h>
     27 
     28 struct xlate_table {
     29 	int		code;
     30 	char		*str;
     31 };
     32 
     33 struct xlate_table smb_xlate_com[] = {
     34 	{	SMB_COM_CREATE_DIRECTORY,	"CREATE_DIRECTORY" },
     35 	{	SMB_COM_DELETE_DIRECTORY,	"DELETE_DIRECTORY" },
     36 	{	SMB_COM_OPEN,			"OPEN" },
     37 	{	SMB_COM_CREATE,			"COM_CREATE" },
     38 	{	SMB_COM_CLOSE,			"CLOSE" },
     39 	{	SMB_COM_FLUSH,			"FLUSH" },
     40 	{	SMB_COM_DELETE,			"DELETE" },
     41 	{	SMB_COM_RENAME,			"RENAME" },
     42 	{	SMB_COM_QUERY_INFORMATION,	"QUERY_INFORMATION" },
     43 	{	SMB_COM_SET_INFORMATION,	"SET_INFORMATION" },
     44 	{	SMB_COM_READ,			"READ" },
     45 	{	SMB_COM_WRITE,			"WRITE" },
     46 	{	SMB_COM_LOCK_BYTE_RANGE,	"LOCK_BYTE_RANGE" },
     47 	{	SMB_COM_UNLOCK_BYTE_RANGE,	"UNLOCK_BYTE_RANGE" },
     48 	{	SMB_COM_CREATE_TEMPORARY,	"CREATE_TEMPORARY" },
     49 	{	SMB_COM_CREATE_NEW,		"CREATE_NEW" },
     50 	{	SMB_COM_CHECK_DIRECTORY,	"CHECK_DIRECTORY" },
     51 	{	SMB_COM_PROCESS_EXIT,		"PROCESS_EXIT" },
     52 	{	SMB_COM_SEEK,			"SEEK" },
     53 	{	SMB_COM_LOCK_AND_READ,		"LOCK_AND_READ" },
     54 	{	SMB_COM_WRITE_AND_UNLOCK,	"WRITE_AND_UNLOCK" },
     55 	{	SMB_COM_READ_RAW,		"READ_RAW" },
     56 	{	SMB_COM_READ_MPX,		"READ_MPX" },
     57 	{	SMB_COM_READ_MPX_SECONDARY,	"READ_MPX_SECONDARY" },
     58 	{	SMB_COM_WRITE_RAW,		"WRITE_RAW" },
     59 	{	SMB_COM_WRITE_MPX,		"WRITE_MPX" },
     60 	{	SMB_COM_WRITE_COMPLETE,		"WRITE_COMPLETE" },
     61 	{	SMB_COM_SET_INFORMATION2,	"SET_INFORMATION2" },
     62 	{	SMB_COM_QUERY_INFORMATION2,	"QUERY_INFORMATION2" },
     63 	{	SMB_COM_LOCKING_ANDX,		"LOCKING_ANDX" },
     64 	{	SMB_COM_TRANSACTION,		"TRANSACTION" },
     65 	{	SMB_COM_TRANSACTION_SECONDARY,	"TRANSACTION_SECONDARY" },
     66 	{	SMB_COM_IOCTL,			"IOCTL" },
     67 	{	SMB_COM_IOCTL_SECONDARY,	"IOCTL_SECONDARY" },
     68 	{	SMB_COM_COPY,			"COPY" },
     69 	{	SMB_COM_MOVE,			"MOVE" },
     70 	{	SMB_COM_ECHO,			"ECHO" },
     71 	{	SMB_COM_WRITE_AND_CLOSE,	"WRITE_AND_CLOSE" },
     72 	{	SMB_COM_OPEN_ANDX,		"OPEN_ANDX" },
     73 	{	SMB_COM_READ_ANDX,		"READ_ANDX" },
     74 	{	SMB_COM_WRITE_ANDX,		"WRITE_ANDX" },
     75 	{	SMB_COM_CLOSE_AND_TREE_DISC,	"CLOSE_AND_TREE_DISC" },
     76 	{	SMB_COM_TRANSACTION2,		"TRANSACTION2" },
     77 	{	SMB_COM_TRANSACTION2_SECONDARY,	"TRANSACTION2_SECONDARY" },
     78 	{	SMB_COM_FIND_CLOSE2,		"FIND_CLOSE2" },
     79 	{	SMB_COM_FIND_NOTIFY_CLOSE,	"FIND_NOTIFY_CLOSE" },
     80 	{	SMB_COM_TREE_CONNECT,		"TREE_CONNECT" },
     81 	{	SMB_COM_TREE_DISCONNECT,	"TREE_DISCONNECT" },
     82 	{	SMB_COM_NEGOTIATE,		"NEGOTIATE" },
     83 	{	SMB_COM_SESSION_SETUP_ANDX,	"SESSION_SETUP_ANDX" },
     84 	{	SMB_COM_LOGOFF_ANDX,		"LOGOFF_ANDX" },
     85 	{	SMB_COM_TREE_CONNECT_ANDX,	"TREE_CONNECT_ANDX" },
     86 	{	SMB_COM_QUERY_INFORMATION_DISK,	"QUERY_INFORMATION_DISK" },
     87 	{	SMB_COM_SEARCH,			"SEARCH" },
     88 	{	SMB_COM_FIND,			"FIND" },
     89 	{	SMB_COM_FIND_UNIQUE,		"FIND_UNIQUE" },
     90 	{	SMB_COM_NT_TRANSACT,		"NT_TRANSACT" },
     91 	{	SMB_COM_NT_TRANSACT_SECONDARY,	"NT_TRANSACT_SECONDARY" },
     92 	{	SMB_COM_NT_CREATE_ANDX,		"NT_CREATE_ANDX" },
     93 	{	SMB_COM_NT_CANCEL,		"NT_CANCEL" },
     94 	{	SMB_COM_OPEN_PRINT_FILE,	"OPEN_PRINT_FILE" },
     95 	{	SMB_COM_WRITE_PRINT_FILE,	"WRITE_PRINT_FILE" },
     96 	{	SMB_COM_CLOSE_PRINT_FILE,	"CLOSE_PRINT_FILE" },
     97 	{	SMB_COM_GET_PRINT_QUEUE,	"GET_PRINT_QUEUE" },
     98 	{ 0 }
     99 };
    100 
    101 struct xlate_table smb_xlate_rcls[] = {
    102 	{	SUCCESS,		"SUCCESS" },
    103 	{	ERRDOS,			"ERRDOS" },
    104 	{	ERRSRV,			"ERRSRV" },
    105 	{	ERRHRD,			"ERRHRD" },
    106 	{	ERRCMD,			"ERRCMD" },
    107 	{ 0 }
    108 };
    109 
    110 struct xlate_table smb_xlate_errdos[] = {
    111 	{	ERRbadfunc,			"ERRbadfunc" },
    112 	{	ERRbadfile,			"ERRbadfile" },
    113 	{	ERRbadpath,			"ERRbadpath" },
    114 	{	ERRnofids,			"ERRnofids" },
    115 	{	ERRnoaccess,			"ERRnoaccess" },
    116 	{	ERRbadfid,			"ERRbadfid" },
    117 	{	ERRbadmcb,			"ERRbadmcb" },
    118 	{	ERRnomem,			"ERRnomem" },
    119 	{	ERRbadmem,			"ERRbadmem" },
    120 	{	ERRbadenv,			"ERRbadenv" },
    121 	{	ERRbadformat,			"ERRbadformat" },
    122 	{	ERRbadaccess,			"ERRbadaccess" },
    123 	{	ERRbaddata,			"ERRbaddata" },
    124 	{	ERRbaddrive,			"ERRbaddrive" },
    125 	{	ERRremcd,			"ERRremcd" },
    126 	{	ERRdiffdevice,			"ERRdiffdevice" },
    127 	{	ERRnofiles,			"ERRnofiles" },
    128 	{	ERRbadshare,			"ERRbadshare" },
    129 	{	ERRlock,			"ERRlock" },
    130 	{	ERRfilexists,			"ERRfilexists" },
    131 	{	ERRbadpipe,			"ERRbadpipe" },
    132 	{	ERRpipebusy,			"ERRpipebusy" },
    133 	{	ERRpipeclosing,			"ERRpipeclosing" },
    134 	{	ERRnotconnected,		"ERRnotconnected" },
    135 	{	ERRmoredata,			"ERRmoredata" },
    136 	{ 0 }
    137 };
    138 
    139 struct xlate_table smb_xlate_errsrv[] = {
    140 	{	ERRerror,			"ERRerror" },
    141 	{	ERRbadpw,			"ERRbadpw" },
    142 	{	ERRaccess,			"ERRaccess" },
    143 	{	ERRinvnid,			"ERRinvnid" },
    144 	{	ERRinvnetname,			"ERRinvnetname" },
    145 	{	ERRinvdevice,			"ERRinvdevice" },
    146 	{	ERRqfull,			"ERRqfull" },
    147 	{	ERRqtoobig,			"ERRqtoobig" },
    148 	{	ERRqeof,			"ERRqeof" },
    149 	{	ERRinvpfid,			"ERRinvpfid" },
    150 	{	ERRsmbcmd,			"ERRsmbcmd" },
    151 	{	ERRsrverror,			"ERRsrverror" },
    152 	{	ERRfilespecs,			"ERRfilespecs" },
    153 	{	ERRbadpermits,			"ERRbadpermits" },
    154 	{	ERRsetattrmode,			"ERRsetattrmode" },
    155 	{	ERRpaused,			"ERRpaused" },
    156 	{	ERRmsgoff,			"ERRmsgoff" },
    157 	{	ERRnoroom,			"ERRnoroom" },
    158 	{	ERRrmuns,			"ERRrmuns" },
    159 	{	ERRtimeout,			"ERRtimeout" },
    160 	{	ERRnoresource,			"ERRnoresource" },
    161 	{	ERRtoomanyuids,			"ERRtoomanyuids" },
    162 	{	ERRbaduid,			"ERRbaduid" },
    163 	{	ERRusempx,			"ERRusempx" },
    164 	{	ERRusestd,			"ERRusestd" },
    165 	{	ERRcontmpx,			"ERRcontmpx" },
    166 	{	ERRnosupport,			"ERRnosupport" },
    167 	{ 0 }
    168 };
    169 
    170 struct xlate_table smb_xlate_errhrd[] = {
    171 	{	ERRnowrite,			"ERRnowrite" },
    172 	{	ERRbadunit,			"ERRbadunit" },
    173 	{	ERRnotready,			"ERRnotready" },
    174 	{	ERRbadcmd,			"ERRbadcmd" },
    175 	{	ERRdata,			"ERRdata" },
    176 	{	ERRbadreq,			"ERRbadreq" },
    177 	{	ERRseek,			"ERRseek" },
    178 	{	ERRbadmedia,			"ERRbadmedia" },
    179 	{	ERRbadsector,			"ERRbadsector" },
    180 	{	ERRnopaper,			"ERRnopaper" },
    181 	{	ERRwrite,			"ERRwrite" },
    182 	{	ERRread,			"ERRread" },
    183 	{	ERRgeneral,			"ERRgeneral" },
    184 	{	ERRbadshare,			"ERRbadshare" },
    185 	{	ERRlock,			"ERRlock" },
    186 	{	ERRwrongdisk,			"ERRwrongdisk" },
    187 	{	ERRFCBUnavail,			"ERRFCBUnavail" },
    188 	{	ERRsharebufexc,			"ERRsharebufexc" },
    189 	{ 0 }
    190 };
    191 
    192 struct xlate_table smb_xlate_dialect[] = {
    193 	{	DIALECT_UNKNOWN,		"DIALECT_UNKNOWN" },
    194 	{	PC_NETWORK_PROGRAM_1_0,		"PC NETWORK PROGRAM 1.0" },
    195 	{	PCLAN1_0,			"PCLAN1.0" },
    196 	{	MICROSOFT_NETWORKS_1_03,	"MICROSOFT NETWORKS 1.03" },
    197 	{	MICROSOFT_NETWORKS_3_0,		"MICROSOFT NETWORKS 3.0" },
    198 	{	LANMAN1_0,			"LANMAN1.0" },
    199 	{	LM1_2X002,			"LM1.2X002" },
    200 	{	DOS_LM1_2X002,			"DOS LM1.2X002" },
    201 	{	DOS_LANMAN2_1,			"DOS LANMAN2.1" },
    202 	{	LANMAN2_1,			"LANMAN2.1" },
    203 	{   Windows_for_Workgroups_3_1a,	"Windows for Workgroups 3.1a" },
    204 	{	NT_LM_0_12,			"NT LM 0.12" },
    205 	{ 0 }
    206 };
    207 
    208 static char *
    209 smb_xlate_cd_to_str(struct xlate_table *xl, int cd)
    210 {
    211 	static char	no_answer[32];
    212 
    213 	for (; xl->str; xl++)
    214 		if (xl->code == cd)
    215 			return (xl->str);
    216 
    217 	(void) sprintf(no_answer, "-%x-", cd);
    218 
    219 	return (no_answer);
    220 }
    221 
    222 static int
    223 smb_xlate_str_to_cd(struct xlate_table *xl, char *str)
    224 {
    225 	for (; xl->str; xl++)
    226 		if (strcmp(xl->str, str) == 0)
    227 			return (xl->code);
    228 	return (-1);
    229 }
    230 
    231 
    232 char *
    233 smb_xlate_com_cd_to_str(int com)
    234 {
    235 	return (smb_xlate_cd_to_str(smb_xlate_com, com));
    236 }
    237 
    238 char *
    239 smb_xlate_dialect_cd_to_str(int dialect)
    240 {
    241 	return (smb_xlate_cd_to_str(smb_xlate_dialect, dialect));
    242 }
    243 
    244 int
    245 smb_xlate_dialect_str_to_cd(char *str)
    246 {
    247 	return (smb_xlate_str_to_cd(smb_xlate_dialect, str));
    248 }
    249