Skip to content

Commit db2ced2

Browse files
committed
add tinysmb and zlib
1 parent 1cae93a commit db2ced2

18 files changed

+4262
-0
lines changed

gc/ogc/lwp_heap.h

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifndef __LWP_HEAP_H__
2+
#define __LWP_HEAP_H__
3+
4+
#include <gctypes.h>
5+
#include <asm.h>
6+
7+
#define HEAP_BLOCK_USED 1
8+
#define HEAP_BLOCK_FREE 0
9+
10+
#define HEAP_DUMMY_FLAG (0+HEAP_BLOCK_USED)
11+
12+
#define HEAP_OVERHEAD (sizeof(u32)*2)
13+
#define HEAP_BLOCK_USED_OVERHEAD (sizeof(void*)*2)
14+
#define HEAP_MIN_SIZE (HEAP_OVERHEAD+sizeof(heap_block))
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
typedef struct _heap_block_st heap_block;
21+
struct _heap_block_st {
22+
u32 back_flag;
23+
u32 front_flag;
24+
heap_block *next;
25+
heap_block *prev;
26+
};
27+
28+
typedef struct _heap_iblock_st {
29+
u32 free_blocks;
30+
u32 free_size;
31+
u32 used_blocks;
32+
u32 used_size;
33+
} heap_iblock;
34+
35+
typedef struct _heap_cntrl_st {
36+
heap_block *start;
37+
heap_block *final;
38+
39+
heap_block *first;
40+
heap_block *perm_null;
41+
heap_block *last;
42+
u32 pg_size;
43+
u32 reserved;
44+
} heap_cntrl;
45+
46+
u32 __lwp_heap_init(heap_cntrl *theheap,void *start_addr,u32 size,u32 pg_size);
47+
void* __lwp_heap_allocate(heap_cntrl *theheap,u32 size);
48+
BOOL __lwp_heap_free(heap_cntrl *theheap,void *ptr);
49+
u32 __lwp_heap_getinfo(heap_cntrl *theheap,heap_iblock *theinfo);
50+
51+
#ifdef LIBOGC_INTERNAL
52+
#include <libogc/lwp_heap.inl>
53+
#endif
54+
55+
#ifdef __cplusplus
56+
}
57+
#endif
58+
59+
#endif

gc/smb.h

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/****************************************************************************
2+
* TinySMB-GC
3+
*
4+
* Nintendo Gamecube SaMBa implementation.
5+
*
6+
* Copyright [email protected]
7+
*
8+
* Authentication modules, LMhash and DES are
9+
*
10+
* Copyright Christopher R Hertel.
11+
* http://www.ubiqx.org
12+
*
13+
* You WILL find Ethereal, available from http://www.ethereal.com
14+
* invaluable for debugging each new SAMBA implementation.
15+
*
16+
* Recommended Reading
17+
* Implementing CIFS - Christopher R Hertel
18+
* SNIA CIFS Documentation - http://www.snia.org
19+
*
20+
* License:
21+
*
22+
* This library is free software; you can redistribute it and/or
23+
* modify it under the terms of the GNU Lesser General Public
24+
* License as published by the Free Software Foundation; either
25+
* version 2.1 of the License, or (at your option) any later version.
26+
*
27+
* This library is distributed in the hope that it will be useful,
28+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
29+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30+
* Lesser General Public License for more details.
31+
*
32+
* You should have received a copy of the GNU Lesser General Public
33+
* License along with this library; if not, write to the Free Software
34+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35+
****************************************************************************/
36+
#ifndef __NBTSMB_H__
37+
#define __NBTSMB_H__
38+
39+
#include <gctypes.h>
40+
41+
/**
42+
* SMB Error codes
43+
*/
44+
#define SMB_SUCCESS 0
45+
#define SMB_ERROR -1
46+
#define SMB_BAD_PROTOCOL -2
47+
#define SMB_BAD_COMMAND -3
48+
#define SMB_PROTO_FAIL -4
49+
#define SMB_NOT_USER -5
50+
#define SMB_BAD_KEYLEN -6
51+
#define SMB_BAD_DATALEN -7
52+
53+
/**
54+
* SMB File Open Function
55+
*/
56+
#define SMB_OF_OPEN 1
57+
#define SMB_OF_TRUNCATE 2
58+
#define SMB_OF_CREATE 16
59+
60+
/**
61+
* FileSearch
62+
*/
63+
#define SMB_SRCH_DIRECTORY 16
64+
#define SMB_SRCH_READONLY 1
65+
#define SMB_SRCH_HIDDEN 2
66+
#define SMB_SRCH_SYSTEM 4
67+
#define SMB_SRCH_VOLUME 8
68+
69+
/**
70+
* SMB File Access Modes
71+
*/
72+
#define SMB_OPEN_READING 0
73+
#define SMB_OPEN_WRITING 1
74+
#define SMB_OPEN_READWRITE 2
75+
#define SMB_OPEN_COMPATIBLE 0
76+
#define SMB_DENY_READWRITE 0x10
77+
#define SMB_DENY_WRITE 0x20
78+
#define SMB_DENY_READ 0x30
79+
#define SMB_DENY_NONE 0x40
80+
81+
#ifdef __cplusplus
82+
extern "C" {
83+
#endif
84+
85+
/***
86+
* SMB Connection Handle
87+
*/
88+
typedef u32 SMBCONN;
89+
90+
/***
91+
* SMB File Handle
92+
*/
93+
typedef void* SMBFILE;
94+
95+
/*** SMB_FILEENTRY
96+
SMB Long Filename Directory Entry
97+
***/
98+
typedef struct
99+
{
100+
u32 size_low;
101+
u32 size_high;
102+
u8 attributes;
103+
char name[256];
104+
} SMBDIRENTRY;
105+
106+
typedef struct
107+
{
108+
char gcip[16];
109+
char gwip[16];
110+
char mask[16];
111+
char smbip[16];
112+
char smbuser[20];
113+
char smbpwd[20];
114+
char smbgcid[20];
115+
char smbsvid[20];
116+
char smbshare[20];
117+
} SMBINFO;
118+
119+
/**
120+
* Prototypes
121+
*/
122+
123+
/*** Session ***/
124+
s32 SMB_Connect(SMBCONN *smbhndl, const char *user, const char *password, const char *client, const char *server, const char *share, const char *IP);
125+
void SMB_Close(SMBCONN smbhndl);
126+
127+
/*** File Find ***/
128+
s32 SMB_FindFirst(const char *filename, unsigned short flags, SMBDIRENTRY *sdir,SMBCONN smbhndl);
129+
s32 SMB_FindNext(SMBDIRENTRY *sdir,SMBCONN smbhndl);
130+
s32 SMB_FindClose(SMBCONN smbhndl);
131+
132+
/*** File I/O ***/
133+
SMBFILE SMB_OpenFile(const char *filename, unsigned short access, unsigned short creation,SMBCONN smbhndl);
134+
void SMB_CloseFile(SMBFILE sfid);
135+
s32 SMB_ReadFile(char *buffer, int size, int offset, SMBFILE sfid);
136+
s32 SMB_WriteFile(const char *buffer, int size, int offset, SMBFILE sfid);
137+
138+
#ifdef __cplusplus
139+
}
140+
#endif
141+
142+
#endif

gc/tinysmb/des.h

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#ifndef AUTH_DES_H
2+
#define AUTH_DES_H
3+
/* ========================================================================== **
4+
*
5+
* DES.h
6+
*
7+
* Copyright:
8+
* Copyright (C) 2003, 2004 by Christopher R. Hertel
9+
*
10+
11+
*
12+
* $Id: des.h,v 1.1 2006-12-19 14:21:54 wntrmute Exp $
13+
*
14+
* -------------------------------------------------------------------------- **
15+
*
16+
* Description:
17+
*
18+
* Implements DES encryption, but not decryption.
19+
* DES is used to create LM password hashes and both LM and NTLM Responses.
20+
*
21+
* -------------------------------------------------------------------------- **
22+
*
23+
* License:
24+
*
25+
* This library is free software; you can redistribute it and/or
26+
* modify it under the terms of the GNU Lesser General Public
27+
* License as published by the Free Software Foundation; either
28+
* version 2.1 of the License, or (at your option) any later version.
29+
*
30+
* This library is distributed in the hope that it will be useful,
31+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
32+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33+
* Lesser General Public License for more details.
34+
*
35+
* You should have received a copy of the GNU Lesser General Public
36+
* License along with this library; if not, write to the Free Software
37+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38+
*
39+
* -------------------------------------------------------------------------- **
40+
*
41+
* Notes:
42+
*
43+
* This implementation was created by studying many existing examples
44+
* found in Open Source, in the public domain, and in various documentation.
45+
* The SMB protocol makes minimal use of the DES function, so this is a
46+
* minimal implementation. That which is not required has been removed.
47+
*
48+
* The SMB protocol uses the DES algorithm as a hash function, not an
49+
* encryption function. The auth_DEShash() implemented here is a one-way
50+
* function. The reverse is not implemented in this module. Also, there
51+
* is no attempt at making this either fast or efficient. There is no
52+
* need, as the auth)DEShash() function is used for generating the LM
53+
* Response from a 7-byte key and an 8-byte challenge. It is not intended
54+
* for use in encrypting large blocks of data or data streams.
55+
*
56+
* As stated above, this implementation is based on studying existing work
57+
* in the public domain or under Open Source (specifically LGPL) license.
58+
* The code, however, is written from scratch. Obviously, I make no claim
59+
* with regard to those earlier works (except to claim that I am grateful
60+
* to the previous implementors whose work I studied). See the list of
61+
* references below for resources I used.
62+
*
63+
* References:
64+
* I read through the libmcrypt code to see how they put the pieces
65+
* together. See: http://mcrypt.hellug.gr/
66+
* Libmcrypt is available under the terms of the LGPL.
67+
*
68+
* The libmcrypt implementation includes the following credits:
69+
* written 12 Dec 1986 by Phil Karn, KA9Q; large sections adapted
70+
* from the 1977 public-domain program by Jim Gillogly
71+
* Modified for additional speed - 6 December 1988 Phil Karn
72+
* Modified for parameterized key schedules - Jan 1991 Phil Karn
73+
* modified in order to use the libmcrypt API by Nikos Mavroyanopoulos
74+
* All modifications are placed under the license of libmcrypt.
75+
*
76+
* See also Phil Karn's privacy and security page:
77+
* http://www.ka9q.net/privacy.html
78+
*
79+
* I relied heavily upon:
80+
* Applied Cryptography, Second Edition:
81+
* Protocols, Algorithms, and Source Code in C
82+
* by Bruce Schneier. ISBN 0-471-11709-9, John Wiley & Sons, Inc., 1996
83+
* Particularly Chapter 12.
84+
*
85+
* Here's one more DES resource, which I found quite helpful (aside from
86+
* the Clinton jokes):
87+
* http://www.aci.net/kalliste/des.htm
88+
*
89+
* Finally, the use of DES in SMB is covered in:
90+
* Implementing CIFS - the Common Internet File System
91+
* by your truly. ISBN 0-13-047116-X, Prentice Hall PTR., August 2003
92+
* Section 15.3, in particular.
93+
* (Online at: http://ubiqx.org/cifs/SMB.html#SMB.8.3)
94+
*
95+
* ========================================================================== **
96+
*/
97+
98+
//#include "auth_common.h"
99+
#include <stdio.h>
100+
typedef unsigned char uchar;
101+
typedef unsigned char uint8_t;
102+
103+
/* -------------------------------------------------------------------------- **
104+
* Functions:
105+
*/
106+
107+
uchar *auth_DESkey8to7( uchar *dst, const uchar *key );
108+
/* ------------------------------------------------------------------------ **
109+
* Compress an 8-byte DES key to its 7-byte form.
110+
*
111+
* Input: dst - Pointer to a memory location (minimum 7 bytes) to accept
112+
* the compressed key.
113+
* key - Pointer to an 8-byte DES key. See the notes below.
114+
*
115+
* Output: A pointer to the compressed key (same as <dst>) or NULL if
116+
* either <src> or <dst> were NULL.
117+
*
118+
* Notes: There are no checks done to ensure that <dst> and <key> point
119+
* to sufficient space. Please be carefull.
120+
*
121+
* The two pointers, <dst> and <key> may point to the same
122+
* memory location. Internally, a temporary buffer is used and
123+
* the results are copied back to <dst>.
124+
*
125+
* The DES algorithm uses 8 byte keys by definition. The first
126+
* step in the algorithm, however, involves removing every eigth
127+
* bit to produce a 56-bit key (seven bytes). SMB authentication
128+
* skips this step and uses 7-byte keys. The <auth_DEShash()>
129+
* algorithm in this module expects 7-byte keys. This function
130+
* is used to convert an 8-byte DES key into a 7-byte SMB DES key.
131+
*
132+
* ------------------------------------------------------------------------ **
133+
*/
134+
135+
136+
uchar *auth_DEShash( uchar *dst, const uchar *key, const uchar *src );
137+
/* ------------------------------------------------------------------------ **
138+
* DES encryption of the input data using the input key.
139+
*
140+
* Input: dst - Destination buffer. It *must* be at least eight bytes
141+
* in length, to receive the encrypted result.
142+
* key - Encryption key. Exactly seven bytes will be used.
143+
* If your key is shorter, ensure that you pad it to seven
144+
* bytes.
145+
* src - Source data to be encrypted. Exactly eight bytes will
146+
* be used. If your source data is shorter, ensure that
147+
* you pad it to eight bytes.
148+
*
149+
* Output: A pointer to the encrpyted data (same as <dst>).
150+
*
151+
* Notes: In SMB, the DES function is used as a hashing function rather
152+
* than an encryption/decryption tool. When used for generating
153+
* the LM hash the <src> input is the known value "KGS!@#$%" and
154+
* the key is derived from the password entered by the user.
155+
* When used to generate the LM or NTLM response, the <key> is
156+
* derived from the LM or NTLM hash, and the challenge is used
157+
* as the <src> input.
158+
* See: http://ubiqx.org/cifs/SMB.html#SMB.8.3
159+
*
160+
* - This function is called "DEShash" rather than just "DES"
161+
* because it is only used for creating LM hashes and the
162+
* LM/NTLM responses. For all practical purposes, however, it
163+
* is a full DES encryption implementation.
164+
*
165+
* - This DES implementation does not need to be fast, nor is a
166+
* DES decryption function needed. The goal is to keep the
167+
* code small, simple, and well documented.
168+
*
169+
* - The input values are copied and refiddled within the module
170+
* and the result is not written to <dst> until the very last
171+
* step, so it's okay if <dst> points to the same memory as
172+
* <key> or <src>.
173+
*
174+
* ------------------------------------------------------------------------ **
175+
*/
176+
177+
178+
/* ========================================================================== */
179+
#endif /* AUTH_DES_H */

0 commit comments

Comments
 (0)