From 806d8089bfd7f032c5b46b34da89974a2fb210cf Mon Sep 17 00:00:00 2001 From: obarthel Date: Mon, 27 Aug 2018 15:06:45 +0200 Subject: [PATCH] Updated to version 1.177 Please keep in mind that this is still a development version and might surprise you (not necessarily in a good way). Do not let me discourage you to build and test this version, although there will be some risks involved such as data corruption or loss of data. --- README.md | 53 +- documentation/history.doc | 29 +- source_code/dump_smb.c | 2 + source_code/main.c | 1046 ++++++++++++++++----------------- source_code/proc.c | 75 +-- source_code/smb_abstraction.c | 18 +- source_code/smbfs_rev.h | 10 +- source_code/smbfs_rev.rev | 2 +- 8 files changed, 613 insertions(+), 622 deletions(-) diff --git a/README.md b/README.md index b5bf111..b34970e 100644 --- a/README.md +++ b/README.md @@ -212,19 +212,13 @@ Keep in mind that passwords like these really should not be exposed by storing t The authentication process only works if the machine you are connecting to knows about the user name and password you want to use. As of this writing, **smbfs** can only be used for authenticating against a password server that is the same machine as the one on which you wish to access a share. -#### 5.1.4. `NETBIOS/S` - -Older server software such as *Microsoft Windows XP* may not respond to the requests of the **smbfs** program to connect to the shared network file system. - -If the connection attempt fails immediately you may want to try the `NETBIOS` switch which tells the **smbfs** program to use an older protocol when trying to talk to the server. - -#### 5.1.5. `CHANGECASE/S` +#### 5.1.4. `CHANGECASE/S` By default the password you provide with the `PASSWORD` option will not be changed before it is used for accessing the server's shared network file system. However, it may be required to change the password to all-uppercase characters before it can be used. If this is necessary, you should either provide the password in this form or resort to the `CHANGECASE` option, which will cause it to be translated to all upper case characters. -#### 5.1.6. `DOMAIN=WORKGROUP/K` +#### 5.1.5. `DOMAIN=WORKGROUP/K` This option may be omitted, in which case the **smbfs** program will ask the file server about the work group which it is a member of. Should the server fail to respond with this information, the **smbfs** program will use `WORKGROUP` as the domain name. @@ -239,6 +233,12 @@ Copy ENV:smbfs_workgroup ENVARC: You may also use the `smbfs_domain` environment variable in place of the `smbfs_workgroup` variable. The two are aliases for one another, but **smbfs** will read only one of the two. +#### 5.1.6. `NETBIOS/S` + +Older server software such as *Microsoft Windows XP* may not respond to the requests of the **smbfs** program to connect to the shared network file system. + +If the connection attempt fails immediately you may want to try the `NETBIOS` switch which tells the **smbfs** program to use an older protocol when trying to talk to the server. + #### 5.1.7. `CLIENT=CLIENTNAME/K` The **smbfs** program will attempt to connect to the file server by providing the name of the computer you connect from. @@ -275,17 +275,17 @@ Also note that file and drawer names which cannot be represented on the Amiga du The built-in default translation method is restricted to the part of Unicode which is covered by the *ISO-8859-1* character set. It is enabled by default, as if `UNICODE=on` had been used. You can disable it with `UNICODE=off`, which completely disables the translation. -Note: some Samba versions will return corrupted file and drawer names unless Unicode support is enabled. Names which use only US-ASCII characters will not be corrupted. +Note: some *Samba* versions will return corrupted file and drawer names unless Unicode support is enabled. Names which use only US-ASCII characters appear to be generally safe to use and are unlikely to suffer from corruption. #### 5.2.2. `CP437/S` -The switch `CP437` enables a code page-based translation which works well enough with old Samba servers. "CP437" stands for *code page 437*, which is what the original IBM-PC would use. +The switch `CP437` enables a code page-based translation which works well enough with old *Samba* versions. "CP437" stands for *code page 437*, which is what the original IBM-PC would use. The `CP437` switch disables Unicode support. #### 5.2.3. `CP850/S` -The switch `CP850` enables a code page-based translation which works well enough with old Samba servers. "CP850" stands for *code page 850*, which is a variant of what the original IBM-PC would use. This variant is intended to be used in western Europe and is more compatible with the *ISO-8859-1* character set than the "CP437" variant. +The switch `CP850` enables a code page-based translation which works well enough with old *Samba* versions. "CP850" stands for *code page 850*, which is a variant of what the original IBM-PC would use. This variant is intended to be used in western Europe and is more compatible with the *ISO-8859-1* character set than the "CP437" variant. The `CP850` switch disables Unicode support. @@ -297,7 +297,7 @@ The first 256 bytes of each such file must consist of the mapping of Amiga chara In most cases the `L:FileSystem_Trans/INTL.crossdos` translation table file should be sufficient. -To specify which file contains the translation tables to use you would use the `TRANSLATIONFILE` parameter, e.g. `TRANSLATIONFILE=L:FileSystem_Trans/INTL.crossdos`. +To specify which file contains the translation tables to use you would use the `TRANSLATIONFILE` parameter, e.g. `TRANSLATIONFILE=L:FileSystem_Trans/INTL.crossdos`. However, you might want to try the `CP850` switch instead which should produce the same effect. The `TRANSLATE` option disables Unicode support. @@ -339,7 +339,7 @@ Some file servers treat files and drawers as different if their names differ onl For file servers which would see `File1` and `file1` as different names you should activate the `CASESENSITIVE` switch to treat those files as being different. -There is a catch though: the AmigaDOS file naming scheme does not follow this model and you may run into problems when you are trying to use it. +There is a catch though: the AmigaDOS file naming scheme does not follow this model and you may run into problems when you are trying to use it. For example, in case sensitive mode attempting to access a file called `FILENAME` as `filename` or `Filename` will fail; you can access it only under the original name `FILENAME`. By default, the **smbfs** program does not treat file and drawer names differently which only differ with respect to the case of letters. @@ -353,7 +353,7 @@ The second method ("ExAll"), introduced with Kickstart 2.0, can deliver more ent The **smbfs** program supports both methods, but there is a catch: Some Amiga software struggles to handle the number of entries delivered by the "ExAll" method, and names longer than 30 characters are a problem. Such software may malfunction and even crash. -To avoid problems with such software, the **smbfs** program can be made to pretend that it did not support the "ExAll" method. Use the `DISABLEEXALL` switch to disable the "ExAll" method. +To avoid problems with such software, the **smbfs** program can be made to pretend that it does not support the "ExAll" method. Use the `DISABLEEXALL` switch to disable the "ExAll" method. Please note that if the `DISABLEEXALL` switch is used, the **smbfs** program will make files and drawers appear to be "hidden" if their names are longer than 107 characters. @@ -397,20 +397,24 @@ The file server which the **smbfs** program connects to may not share the exact You can, and should tell the **smbfs** program how far the local Amiga time deviates from UTC. By default the **smbfs** program will try to use the time zone information configured in the "Locale" preferences. This may not be sufficient, or even the wrong choice. -#### 5.5.1. `DST=DSTOFFSET/N/K` - -This option can be used to adjust the file date stamps to take local daylight savings time into account. - -The number to specify here is by how many minutes local time has been moved ahead, which is typically 60. Note that **smbfs** does not know when daylight savings time begins and ends. It is up to you to select the correct adjustment value when appropriate. - -#### 5.5.2. `TZ=TIMEZONEOFFSET/N/K` +#### 5.5.1. `TZ=TIMEZONEOFFSET/N/K` By default the file system will use the current Locale settings to translate between the local time and the time used by the file server. -For some configurations, however, this is impractical since the server's time zone is not configured properly. For these rare cases you may want to hard code a certain time zone offset using the `TIMEZONEOFFSET` options. +For some configurations, however, this is impractical since the server's time zone is not configured properly. For these rare cases you may want to hard code a certain time zone offset using the `TIMEZONEOFFSET` option. You need to provide the number of minutes to subtract from the local time in order to translate it into the corresponding UTC value. For example, in central Europe using CET, you would use `TZ=60` since CET is one hour ahead of UTC. +If you use the `TIMEZONEOFFSET` option, then the **smbfs** program will ignore the time zone information configured in the "Locale" preferences. + +#### 5.5.2. `DST=DSTOFFSET/N/K` + +This option can be used to adjust the file date stamps to take local daylight savings time into account. + +The number to specify here is by how many minutes local time has been moved ahead, which is typically 60. + +Note that **smbfs** does not know when daylight savings time begins and ends. It is up to you to select the correct adjustment value when appropriate. + ### 5.6. Miscellaneous #### 5.6.1. `DEVICE=DEVICENAME/K` and `VOLUME=VOLUMENAME/K` @@ -462,8 +466,7 @@ If the file already exists, debug output will be appended to it. By default the **smbfs** program operates in silent mode. It does not report what it is doing, it just tries to respond to file system requests. To obtain debugging output you may want to use the `DEBUG` option and specify a debug level greater than 0, e.g. `DEBUG=2`. The larger the number you specify the more debugging output will be created. -Note that unless you state which file the debug output should be written to, -all debugging output will be sent to the shell. +Note that unless you state which file the debug output should be written to, all debugging output will be sent to the shell window. If you launched the **smbfs** program from *Workbench*, debug output will be produced using the operating system's debug output functionality which requires that you have a capturing program like *Sashimi* running in the background. @@ -495,7 +498,7 @@ The **smbfs** file system is based upon prior work by Pål-Kristian Engstad, Vol Version 1.80 incorporates changes from the *MorphOS* smbfs version 50.3, which was kindly provided by Frank Mariak. The individual changes came from Harry Sintonen, David Gerber and Frank Mariak. -The password encryption code was lifted from the Samba package. It was written by Andrew Tridgell and the Samba Team. +The password encryption code was lifted from the *Samba* package. It was written by Andrew Tridgell and the Samba Team. ## 8. Author diff --git a/documentation/history.doc b/documentation/history.doc index 1afcddc..9cc9ecb 100644 --- a/documentation/history.doc +++ b/documentation/history.doc @@ -2267,7 +2267,7 @@ smbfs 1.162 (7.7.2018) - The FHFromLock code did not verify if the FileLock in question actually did refer to a file. Fixed. - + - The RenameDisk code did not check if the new volume was sound and suitable for a volume. Fixed. @@ -2465,7 +2465,7 @@ smbfs 1.175 (9.8.2018) - The command line template would still include the PREFERREADRAW/S and PREFERWRITERAW/S entries. Fixed. - + - The debug options and the debug file are now taken care of as early as possible, so as to allow for the icon tool type/shell parameter processing to be logged. @@ -2511,3 +2511,28 @@ smbfs 1.176 (12.8.2018) - The default workgroup name of "WORKGROUP" could still be used even if the server had been queried to provide its current workgroup name. Fixed. + + +smbfs 1.177 (27.8.2018) + +- Implemented ACTION_CURRENT_VOLUME correctly. + +- Updated the documentation again. + +- Replacement stack should not be allocated as public memory. Fixed. + +- Clarified how Action_Parent(), Action_FreeLock() and + Action_ChangeMode() are supposed to work. + +- Action_CopyDir() now tests for an invalid lock much earlier, + which avoids testing the access mode first and then acting + upon it. + +- Action_SameLock() now uses case-sensitive path name comparison + if smbfs is required to. Previously, it would always use + case-insensitive comparison. + +- Unified and simplified commonly-used code. + +- Added more debug output in order to find that pesky AsyncWB + batch rename problem :-/ diff --git a/source_code/dump_smb.c b/source_code/dump_smb.c index 8f780f4..0106b1a 100644 --- a/source_code/dump_smb.c +++ b/source_code/dump_smb.c @@ -1157,6 +1157,8 @@ print_smb_contents(const struct smb_header * header,int command,enum smb_packet_ if(num_data_bytes < 0) num_data_bytes = 0; + memset(vwv,0,sizeof(vwv)); + for(i = j = 0 ; i < num_parameter_words ; i++, j += 2) vwv[i] = (((int)parameters[j+1]) << 8) + parameters[j]; diff --git a/source_code/main.c b/source_code/main.c index cfd3923..1a9a3f1 100644 --- a/source_code/main.c +++ b/source_code/main.c @@ -394,7 +394,7 @@ _start(STRPTR args, LONG args_length, struct ExecBase * exec_base) if(stk == NULL) goto out; - new_stack = AllocMem(new_stack_size,MEMF_PUBLIC|MEMF_ANY); + new_stack = AllocMem(new_stack_size,MEMF_ANY); if(new_stack == NULL) goto out; @@ -1789,6 +1789,62 @@ allocate_memory(LONG size) /****************************************************************************/ +/* Allocate memory for a new lock node and initialize it. */ +static struct LockNode * +allocate_lock_node( + LONG access_mode, + const TEXT * full_name, + const struct MsgPort * user) +{ + struct LockNode * ln; + + ln = allocate_memory(sizeof(*ln)); + if(ln != NULL) + { + memset(ln,0,sizeof(*ln)); + + ln->ln_FileLock.fl_Key = (LONG)ln; + ln->ln_Magic = ID_SMB_DISK; + ln->ln_FileLock.fl_Access = access_mode; + ln->ln_FileLock.fl_Task = FileSystemPort; + ln->ln_FileLock.fl_Volume = MKBADDR(VolumeNode); + ln->ln_FullName = (TEXT *)full_name; + ln->ln_LastUser = user; + } + + return(ln); +} + +/****************************************************************************/ + +/* Allocate memory for a new file node and initialize it. */ +static struct FileNode * +allocate_file_node( + LONG mode, + const TEXT * full_name, + const struct FileHandle * fh, + const smba_file_t * file) +{ + struct FileNode * fn; + + fn = allocate_memory(sizeof(*fn)); + if(fn != NULL) + { + memset(fn, 0, sizeof(*fn)); + + fn->fn_Handle = (struct FileHandle *)fh; + fn->fn_Magic = ID_SMB_DISK; + fn->fn_Volume = VolumeNode; + fn->fn_FullName = (TEXT *)full_name; + fn->fn_File = (smba_file_t *)file; + fn->fn_Mode = mode; + } + + return(fn); +} + +/****************************************************************************/ + /* Obtain the number of seconds to add to the current time * to translate local time into UTC. */ @@ -2561,7 +2617,7 @@ send_disk_change_notification(ULONG class) * skipping a particular entry if necessary. */ static struct FileNode * -find_file_node(const TEXT * name,const struct FileNode * skip) +find_file_node_by_name(const TEXT * name,const struct FileNode * skip) { struct FileNode * result = NULL; struct FileNode * fn; @@ -2584,7 +2640,7 @@ find_file_node(const TEXT * name,const struct FileNode * skip) * skipping a particular entry if necessary. */ static struct LockNode * -find_lock_node(const TEXT * name,const struct LockNode * skip) +find_lock_node_by_name(const TEXT * name,const struct LockNode * skip) { struct LockNode * result = NULL; struct LockNode * ln; @@ -2621,7 +2677,7 @@ check_access_mode_collision(const TEXT * name,LONG mode) D(("name = '%s'", escape_name(name))); - fn = find_file_node(name,NULL); + fn = find_file_node_by_name(name,NULL); if(fn != NULL) { if(mode != SHARED_LOCK || fn->fn_Mode != SHARED_LOCK) @@ -2631,7 +2687,7 @@ check_access_mode_collision(const TEXT * name,LONG mode) } } - ln = find_lock_node(name,NULL); + ln = find_lock_node_by_name(name,NULL); if(ln != NULL) { if(mode != SHARED_LOCK || ln->ln_FileLock.fl_Access != SHARED_LOCK) @@ -2655,13 +2711,29 @@ check_access_mode_collision(const TEXT * name,LONG mode) static int name_already_in_use(const TEXT * name) { - int error; + int error = ERROR_OBJECT_IN_USE; - if(find_file_node(name,NULL) != NULL || find_lock_node(name,NULL) != NULL) - error = ERROR_OBJECT_IN_USE; - else - error = OK; + ENTER(); + SHOWSTRING(name); + + if(find_file_node_by_name(name,NULL)) + { + SHOWMSG("found a file by that name"); + goto out; + } + + if(find_lock_node_by_name(name,NULL) != NULL) + { + SHOWMSG("found a lock by that name"); + goto out; + } + + error = OK; + + out: + + RETURN(error); return(error); } @@ -2826,11 +2898,11 @@ map_errno_to_ioerr(int error) smb_translate_error_class_and_code(error_class,error_code,&smb_class_name,&smb_code_text); - LOG(("Translated SMB %ld/%ld (%s/%s) -> POSIX %ld (%s) -> AmigaDOS error %ld (%s)\n", error_class, error_code, smb_class_name, smb_code_text, error, posix_strerror(error), result, amigados_error_text)); + D(("Translated SMB %ld/%ld (%s/%s) -> POSIX %ld (%s) -> AmigaDOS error %ld (%s)", error_class, error_code, smb_class_name, smb_code_text, error, posix_strerror(error), result, amigados_error_text)); } else { - LOG(("Translated POSIX %ld (%s) -> AmigaDOS error %ld (%s)\n", error, posix_strerror(error), result, amigados_error_text)); + D(("Translated POSIX %ld (%s) -> AmigaDOS error %ld (%s)", error, posix_strerror(error), result, amigados_error_text)); } } #endif /* DEBUG */ @@ -3596,6 +3668,9 @@ escape_name(const TEXT * name) int len; TEXT c; + if(name == NULL) + name = "***NULL POINTER***"; + len = 0; while((c = (*name++)) != '\0') @@ -3710,7 +3785,7 @@ escape_name(const TEXT * name) /****************************************************************************/ -/* Convert a BCPL string into a standard NUL terminated 'C' string. */ +/* Convert a BCPL string into a standard NUL-terminated 'C' string. */ static void convert_from_bcpl_to_c_string(STRPTR cstring,int cstring_size,const void * bstring) { @@ -3734,7 +3809,7 @@ convert_from_bcpl_to_c_string(STRPTR cstring,int cstring_size,const void * bstri } } -/* Convert a NUL terminated 'C' string into a BCPL string. */ +/* Convert a NUL-terminated 'C' string into a BCPL string. */ static void convert_from_c_to_bcpl_string(void * bstring,int bstring_size,const TEXT * cstring,int len) { @@ -3757,6 +3832,31 @@ convert_from_c_to_bcpl_string(void * bstring,int bstring_size,const TEXT * cstri /****************************************************************************/ +/* Allocate memory for storing a copy of a string with given + * length. Sufficient memory will be allocated for proper + * NUL-termination. + */ +static TEXT * +allocate_and_copy_string(const TEXT * original_str, int len) +{ + TEXT * copied_str; + + ASSERT( original_str != NULL && len >= 0 ); + + copied_str = allocate_memory(len + 1); + if(copied_str != NULL) + { + if(len > 0) + memcpy(copied_str, original_str, len); + + copied_str[len] = '\0'; + } + + return(copied_str); +} + +/****************************************************************************/ + /* Return the next part (segment) of an AmigaDOS path name, which * is either ":" (= go to root directory), "/" (= go to parent * directory) or the name of a file or directory. @@ -3898,9 +3998,9 @@ build_full_path_name( ENTER(); if(parent_name == NULL) - D(("parent_name = NULL")); + D(("parent name = NULL")); else - D(("parent_name = '%s'",escape_name(parent_name))); + D(("parent name = '%s'",escape_name(parent_name))); if(name == NULL) D(("name = NULL")); @@ -3922,41 +4022,22 @@ build_full_path_name( parent_name_len = strlen(parent_name); - /* Is the path name to be added an absolute path? If so, - * it will replace the parent path name. - */ - if(name_len > 0 && (*name) == ':') + size = parent_name_len + 1; + + if(name_len > 0) + size += name_len + 1; + + buffer = allocate_memory(size); + if(buffer == NULL) { - size = 1 + name_len + 1; - - buffer = allocate_memory(size); - if(buffer == NULL) - { - error = ERROR_NO_FREE_STORE; - goto out; - } - - to = buffer; - - (*to++) = SMB_PATH_SEPARATOR; + error = ERROR_NO_FREE_STORE; + goto out; } - /* Add the path name to the parent path name. */ - else - { - size = parent_name_len + 1 + name_len + 1; - buffer = allocate_memory(size); - if(buffer == NULL) - { - error = ERROR_NO_FREE_STORE; - goto out; - } + to = buffer; - to = buffer; - - memcpy(to,parent_name,parent_name_len); - to += parent_name_len; - } + memcpy(to,parent_name,parent_name_len); + to += parent_name_len; ASSERT( buffer <= to ); @@ -3969,17 +4050,21 @@ build_full_path_name( int segment_len; int offset; + ASSERT( strncmp(buffer,SMB_ROOT_DIR_NAME,1) == SAME ); + for(offset = 0 ; offset < name_len ; NOTHING) { offset = get_next_path_segment(name,name_len,offset,segment,sizeof(segment),&segment_len); - D(("segment = '%s', len=%ld, offset=%ld\n", segment, segment_len, offset)); + D(("segment = '%s', len=%ld, offset=%ld", segment, segment_len, offset)); if(segment_len > 0) { /* Segment Buffer overflow? */ if(segment_len > (int)sizeof(segment)) { + D(("segment length %ld overflows buffer", segment_len)); + error = ERROR_BUFFER_OVERFLOW; goto out; } @@ -3998,6 +4083,8 @@ build_full_path_name( /* Are we already at the root directory level? */ if(len == 1) { + D(("already at root level")); + /* Can't go any further. */ error = ERROR_OBJECT_NOT_FOUND; goto out; @@ -4052,7 +4139,7 @@ build_full_path_name( { buffer[len] = '\0'; - D(("full path name = '%s', length = %ld", buffer, len)); + D(("full path name = '%s', length = %ld", escape_name(buffer), len)); } #endif /* DEBUG */ } @@ -4063,7 +4150,7 @@ build_full_path_name( buffer[len] = '\0'; - D(("buffer = '%s'",escape_name(buffer))); + D(("full path name = '%s'",escape_name(buffer))); SHOWVALUE(size); SHOWVALUE(len); @@ -4123,15 +4210,7 @@ split_path_name( (*base_part_ptr) = NULL; /* Make a copy of the path string. */ - temp = allocate_memory(path_len+1); - if(temp == NULL) - { - error = ERROR_NO_FREE_STORE; - goto out; - } - - memcpy(temp,path,path_len); - temp[path_len] = '\0'; + temp = allocate_and_copy_string(path, path_len); /* Find the last '\' character which separates * the directory part from the base part. @@ -4176,7 +4255,7 @@ split_path_name( } /* Don't forget to free this when it is no longer needed. */ - (*temp_ptr) = temp; + (*temp_ptr) = temp; temp = NULL; if(dir_part_ptr != NULL) @@ -4287,7 +4366,7 @@ get_parent_dir_name(const TEXT * name,int name_len,STRPTR * parent_name_ptr) } } - parent_name = allocate_memory(name_len+1); + parent_name = allocate_and_copy_string(name, name_len); if(parent_name == NULL) { SHOWMSG("not enough memory"); @@ -4296,9 +4375,6 @@ get_parent_dir_name(const TEXT * name,int name_len,STRPTR * parent_name_ptr) goto out; } - memcpy(parent_name,name,name_len); - parent_name[name_len] = '\0'; - D(("parent directory = '%s'",escape_name(parent_name))); (*parent_name_ptr) = parent_name; @@ -4547,6 +4623,46 @@ file_is_invalid(const struct FileNode * fn,int * error_ptr) /****************************************************************************/ +/* Remove a device, volume or assignment name from the path name. If + * If necessary, the path following the ':' character will be copied + * to the beginning of the string, removing it, and the name length + * will be adjusted accordingly. + */ +static void +remove_device_name_from_path(TEXT * name, int * name_len_ptr) +{ + int name_len; + int i; + + ASSERT( name != NULL && name_len_ptr != NULL ); + + name_len = (*name_len_ptr); + + for(i = 0 ; i < name_len ; i++) + { + /* Stop at a path delimiter. A path delimiter + * cannot be part of a device name. + */ + if(name[i] == '/') + break; + + /* Remove the device/volume/assignment name + * including the ':' character. + */ + if(name[i] == ':' && i > 0) + { + name_len -= i+1; + + memmove(name,&name[i+1],name_len+1); + + (*name_len_ptr) = name_len; + break; + } + } +} + +/****************************************************************************/ + static BPTR Action_Parent( const struct MsgPort * user, @@ -4569,64 +4685,57 @@ Action_Parent( * directory (which must fail with the error code * ERROR_OBJECT_NOT_FOUND set). */ - if(parent == NULL) + if(parent != NULL) { - error = OK; - goto out; + if(lock_is_invalid(parent,&error)) + goto out; + + parent_ln = (struct LockNode *)parent->fl_Key; + + D(("parent lock on '%s'", escape_name(parent_ln->ln_FullName))); + + parent_ln->ln_LastUser = user; + + error = get_parent_dir_name(parent_ln->ln_FullName,strlen(parent_ln->ln_FullName),&full_name); + if(error != OK) + { + /* Check if we ended up having to return the parent of + * the root directory. This is indicated by the + * error code ERROR_OBJECT_NOT_FOUND. The parent directory + * of the root directory is the ZERO lock. + */ + if(error != ERROR_OBJECT_NOT_FOUND) + goto out; + + /* We return the ZERO lock. */ + } + else + { + ln = allocate_lock_node(SHARED_LOCK,full_name,user); + if(ln == NULL) + { + error = ERROR_NO_FREE_STORE; + goto out; + } + + D(("full_name = '%s'",escape_name(full_name))); + + if(smba_open(ServerData,full_name,open_read_only,open_dont_truncate,&ln->ln_File,&error) < 0) + { + error = map_errno_to_ioerr(error); + goto out; + } + + AddTail((struct List *)&LockList,(struct Node *)ln); + result = MKBADDR(&ln->ln_FileLock); + SHOWVALUE(&ln->ln_FileLock); + + full_name = NULL; + ln = NULL; + } } - if(lock_is_invalid(parent,&error)) - goto out; - - parent_ln = (struct LockNode *)parent->fl_Key; - - parent_ln->ln_LastUser = user; - - error = get_parent_dir_name(parent_ln->ln_FullName,strlen(parent_ln->ln_FullName),&full_name); - if(error != OK) - { - /* Check if we ended up having to return the parent of - * the root directory. This is indicated by the - * error code ERROR_OBJECT_NOT_FOUND. The parent directory - * of the root directory is the ZERO lock. - */ - if(error == ERROR_OBJECT_NOT_FOUND) - error = OK; - - goto out; - } - - ln = allocate_memory(sizeof(*ln)); - if(ln == NULL) - { - error = ERROR_NO_FREE_STORE; - goto out; - } - - memset(ln,0,sizeof(*ln)); - - ln->ln_FileLock.fl_Key = (LONG)ln; - ln->ln_Magic = ID_SMB_DISK; - ln->ln_FileLock.fl_Access = SHARED_LOCK; - ln->ln_FileLock.fl_Task = FileSystemPort; - ln->ln_FileLock.fl_Volume = MKBADDR(VolumeNode); - ln->ln_FullName = full_name; - ln->ln_LastUser = user; - - D(("full_name = '%s'",escape_name(full_name))); - - if(smba_open(ServerData,full_name,open_read_only,open_dont_truncate,&ln->ln_File,&error) < 0) - { - error = map_errno_to_ioerr(error); - goto out; - } - - AddTail((struct List *)&LockList,(struct Node *)ln); - result = MKBADDR(&ln->ln_FileLock); - SHOWVALUE(&ln->ln_FileLock); - - full_name = NULL; - ln = NULL; + error = OK; out: @@ -4669,6 +4778,15 @@ Action_DeleteObject( goto out; } + D(("name = '%b'",MKBADDR(bcpl_name))); + + /* Name string, as given in the DOS packet, is in + * BCPL format and needs to be converted into + * 'C' format. + */ + convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); + name_len = strlen(name); + SHOWVALUE(parent); if(parent != NULL) @@ -4680,6 +4798,8 @@ Action_DeleteObject( ln = (struct LockNode *)parent->fl_Key; + D(("parent lock on '%s'", escape_name(ln->ln_FullName))); + parent_name = ln->ln_FullName; ln->ln_LastUser = user; @@ -4689,38 +4809,10 @@ Action_DeleteObject( parent_name = NULL; } - D(("name = '%b'",MKBADDR(bcpl_name))); - - /* Name string, as given in the DOS packet, is in - * BCPL format and needs to be converted into - * 'C' format. - */ - convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); - - name_len = strlen(name); - /* Remove a device, volume or assignment name * from the path name. */ - for(i = 0 ; i < name_len ; i++) - { - /* Stop at a path delimiter. A path delimiter - * cannot be part of a device name. - */ - if(name[i] == '/') - break; - - /* Remove the device/volume/assignment name - * including the ':' character. - */ - if(name[i] == ':' && i > 0) - { - name_len -= i+1; - - memmove(name,&name[i+1],name_len+1); - break; - } - } + remove_device_name_from_path(name, &name_len); /* The SMB_COM_DELETE command supports deleting sets * of matching files/drawers through wildcards. Only @@ -4759,7 +4851,7 @@ Action_DeleteObject( /* Trying to delete the root directory, are you kidding? */ if(strcmp(full_name, SMB_ROOT_DIR_NAME) == SAME) { - LOG(("cannot delete the root directory\n")); + D(("cannot delete the root directory")); error = ERROR_OBJECT_IN_USE; goto out; @@ -4771,7 +4863,7 @@ Action_DeleteObject( error = check_access_mode_collision(full_name,EXCLUSIVE_LOCK); if(error != OK) { - LOG(("there is still a lock or file attached to '%s'\n", full_name)); + D(("there is still a lock or file attached to '%s'", full_name)); goto out; } @@ -4909,6 +5001,11 @@ Action_CreateDir( goto out; } + D(("name = '%b'",MKBADDR(bcpl_name))); + + convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); + name_len = strlen(name); + SHOWVALUE(parent); if(parent != NULL) @@ -4920,6 +5017,8 @@ Action_CreateDir( parent_ln = (struct LockNode *)parent->fl_Key; + D(("parent lock on '%s'", escape_name(parent_ln->ln_FullName))); + parent_ln->ln_LastUser = user; parent_name = parent_ln->ln_FullName; @@ -4929,34 +5028,10 @@ Action_CreateDir( parent_name = NULL; } - D(("name = '%b'",MKBADDR(bcpl_name))); - - convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); - - name_len = strlen(name); - /* Remove a device, volume or assignment name * from the path name. */ - for(i = 0 ; i < name_len ; i++) - { - /* Stop at a path delimiter. A path delimiter - * cannot be part of a device name. - */ - if(name[i] == '/') - break; - - /* Remove the device/volume/assignment name - * including the ':' character. - */ - if(name[i] == ':' && i > 0) - { - name_len -= i+1; - - memmove(name,&name[i+1],name_len+1); - break; - } - } + remove_device_name_from_path(name, &name_len); /* Do not allow for a directory to be created whose * name contains MS-DOS wildcard characters. This will @@ -4990,7 +5065,7 @@ Action_CreateDir( /* Trying to overwrite the root directory, are you kidding? */ if(strcmp(full_name, SMB_ROOT_DIR_NAME) == SAME) { - LOG(("cannot overwrite the root directory\n")); + D(("cannot overwrite the root directory")); error = ERROR_OBJECT_IN_USE; goto out; @@ -5004,26 +5079,16 @@ Action_CreateDir( } D(("path name = '%s'",escape_name(full_name))); - D(("directory name = '%s'\n", dir_name)); - D(("base name = '%s'\n", base_name)); + D(("directory name = '%s'", dir_name)); + D(("base name = '%s'", base_name)); - ln = allocate_memory(sizeof(*ln)); + ln = allocate_lock_node(EXCLUSIVE_LOCK,full_name,user); if(ln == NULL) { error = ERROR_NO_FREE_STORE; goto out; } - memset(ln,0,sizeof(*ln)); - - ln->ln_FileLock.fl_Key = (LONG)ln; - ln->ln_Magic = ID_SMB_DISK; - ln->ln_FileLock.fl_Access = EXCLUSIVE_LOCK; - ln->ln_FileLock.fl_Task = FileSystemPort; - ln->ln_FileLock.fl_Volume = MKBADDR(VolumeNode); - ln->ln_FullName = full_name; - ln->ln_LastUser = user; - if(smba_open(ServerData,dir_name,open_read_only,open_dont_truncate,&dir,&error) < 0) { error = map_errno_to_ioerr(error); @@ -5088,10 +5153,14 @@ Action_LocateObject( TEXT name[MAX_FILENAME_LEN+1]; int name_len; int error; - int i; ENTER(); + D(("name = '%b'",MKBADDR(bcpl_name))); + + convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); + name_len = strlen(name); + SHOWVALUE(parent); if(parent != NULL) @@ -5103,6 +5172,8 @@ Action_LocateObject( parent_ln = (struct LockNode *)parent->fl_Key; + D(("parent lock on '%s'", escape_name(parent_ln->ln_FullName))); + parent_ln->ln_LastUser = user; parent_name = parent_ln->ln_FullName; @@ -5112,34 +5183,10 @@ Action_LocateObject( parent_name = NULL; } - D(("name = '%b'",MKBADDR(bcpl_name))); - - convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); - - name_len = strlen(name); - /* Remove a device, volume or assignment name * from the path name. */ - for(i = 0 ; i < name_len ; i++) - { - /* Stop at a path delimiter. A path delimiter - * cannot be part of a device name. - */ - if(name[i] == '/') - break; - - /* Remove the device/volume/assignment name - * including the ':' character. - */ - if(name[i] == ':' && i > 0) - { - name_len -= i+1; - - memmove(name,&name[i+1],name_len+1); - break; - } - } + remove_device_name_from_path(name, &name_len); if (NOT ServerData->server.unicode_enabled) { @@ -5158,30 +5205,18 @@ Action_LocateObject( if(error != OK) goto out; - ln = allocate_memory(sizeof(*ln)); + ln = allocate_lock_node((mode != EXCLUSIVE_LOCK) ? SHARED_LOCK : EXCLUSIVE_LOCK,full_name,user); if(ln == NULL) { error = ERROR_NO_FREE_STORE; goto out; } - memset(ln,0,sizeof(*ln)); - - ln->ln_FileLock.fl_Key = (LONG)ln; - ln->ln_Magic = ID_SMB_DISK; - ln->ln_FileLock.fl_Access = (mode != EXCLUSIVE_LOCK) ? SHARED_LOCK : EXCLUSIVE_LOCK; - ln->ln_FileLock.fl_Task = FileSystemPort; - ln->ln_FileLock.fl_Volume = MKBADDR(VolumeNode); - ln->ln_FullName = full_name; - ln->ln_LastUser = user; - - error = check_access_mode_collision(full_name,ln->ln_FileLock.fl_Access); + error = check_access_mode_collision(ln->ln_FullName,ln->ln_FileLock.fl_Access); if(error != OK) goto out; - D(("full_name = '%s'",escape_name(full_name))); - - if(smba_open(ServerData,full_name,open_read_only,open_dont_truncate,&ln->ln_File,&error) < 0) + if(smba_open(ServerData,ln->ln_FullName,open_read_only,open_dont_truncate,&ln->ln_File,&error) < 0) { error = map_errno_to_ioerr(error); goto out; @@ -5191,6 +5226,10 @@ Action_LocateObject( result = MKBADDR(&ln->ln_FileLock); SHOWVALUE(&ln->ln_FileLock); + SHOWPOINTER(ln->ln_FullName); + + D(("full path name = '%s'",escape_name(ln->ln_FullName))); + full_name = NULL; ln = NULL; @@ -5217,40 +5256,39 @@ Action_CopyDir( STRPTR full_name = NULL; struct LockNode * ln = NULL; const TEXT * source_name; - int source_name_len; int error; ENTER(); SHOWVALUE(lock); + /* Fail fast if the lock is invalid. */ + if(lock != NULL && lock_is_invalid(lock,&error)) + goto out; + + if(lock != NULL) + { + const struct LockNode * key = (struct LockNode *)lock->fl_Key; + + D(("lock on '%s'", escape_name(key->ln_FullName))); + } + /* If a specific lock is to be duplicated, then that * better be a shared lock. */ if(lock != NULL && lock->fl_Access != SHARED_LOCK) { SHOWMSG("cannot duplicate exclusive lock"); + error = ERROR_OBJECT_IN_USE; goto out; } - ln = allocate_memory(sizeof(*ln)); - if(ln == NULL) - { - error = ERROR_NO_FREE_STORE; - goto out; - } - - memset(ln,0,sizeof(*ln)); - /* Duplicate a specific lock? */ if(lock != NULL) { struct LockNode * source; - if(lock_is_invalid(lock,&error)) - goto out; - source = (struct LockNode *)lock->fl_Key; source->ln_LastUser = user; @@ -5265,25 +5303,19 @@ Action_CopyDir( source_name = SMB_ROOT_DIR_NAME; } - source_name_len = strlen(source_name); - - full_name = allocate_memory(source_name_len+1); + full_name = allocate_and_copy_string(source_name, strlen(source_name)); if(full_name == NULL) { error = ERROR_NO_FREE_STORE; goto out; } - /* Length includes the terminating NUL byte. */ - memcpy(full_name,source_name,source_name_len+1); - - ln->ln_FileLock.fl_Key = (LONG)ln; - ln->ln_Magic = ID_SMB_DISK; - ln->ln_FileLock.fl_Access = SHARED_LOCK; - ln->ln_FileLock.fl_Task = FileSystemPort; - ln->ln_FileLock.fl_Volume = MKBADDR(VolumeNode); - ln->ln_FullName = full_name; - ln->ln_LastUser = user; + ln = allocate_lock_node(SHARED_LOCK,full_name,user); + if(ln == NULL) + { + error = ERROR_NO_FREE_STORE; + goto out; + } D(("full_name = '%s'",escape_name(full_name))); @@ -5319,51 +5351,51 @@ Action_FreeLock( LONG * error_ptr) { LONG result = DOSTRUE; - const struct LockNode * key; - struct LockNode * found; - struct LockNode * ln; ENTER(); SHOWVALUE(lock); - /* Passing ZERO is harmless. */ - if(lock == NULL) - goto out; - - /* Make sure that no lock is released twice, and that we - * know which locks are ours. + /* Passing ZERO is harmless. But we have to have + * a valid lock if we are to proceed with releasing + * it. */ - if(lock_is_invalid(lock,NULL)) - goto out; - - found = NULL; - - key = (struct LockNode *)lock->fl_Key; - - for(ln = (struct LockNode *)LockList.mlh_Head ; - ln->ln_MinNode.mln_Succ != NULL ; - ln = (struct LockNode *)ln->ln_MinNode.mln_Succ) + if(lock != NULL && NOT lock_is_invalid(lock,NULL)) { - if(ln == key) + const struct LockNode * key; + struct LockNode * found; + struct LockNode * ln; + + found = NULL; + + key = (struct LockNode *)lock->fl_Key; + + D(("lock on '%s'", escape_name(key->ln_FullName))); + + for(ln = (struct LockNode *)LockList.mlh_Head ; + ln->ln_MinNode.mln_Succ != NULL ; + ln = (struct LockNode *)ln->ln_MinNode.mln_Succ) { - found = ln; - break; + if(ln == key) + { + found = ln; + break; + } + } + + if(found != NULL) + { + Remove((struct Node *)found); + + smba_close(ServerData,found->ln_File); + + found->ln_Magic = 0; + + free_memory(found->ln_FullName); + free_memory(found); } } - if(found == NULL) - goto out; - - Remove((struct Node *)found); - - smba_close(ServerData,found->ln_File); - - found->ln_Magic = 0; - - free_memory(found->ln_FullName); - free_memory(found); - out: (*error_ptr) = OK; @@ -5400,6 +5432,8 @@ Action_SameLock( ln = (struct LockNode *)lock1->fl_Key; + D(("lock1 on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = user; name1 = ln->ln_FullName; @@ -5418,6 +5452,8 @@ Action_SameLock( ln = (struct LockNode *)lock2->fl_Key; + D(("lock2 on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = user; name2 = ln->ln_FullName; @@ -5430,7 +5466,7 @@ Action_SameLock( D(("name1 = '%s'",escape_name(name1))); D(("name2 = '%s'",escape_name(name2))); - if(Stricmp(name1,name2) == SAME) + if(compare_names(name1,name2) == SAME) result = DOSTRUE; out: @@ -5459,7 +5495,6 @@ Action_SetProtect( smba_stat_t st; int name_len; int error; - int i; ENTER(); @@ -5469,6 +5504,11 @@ Action_SetProtect( goto out; } + D(("name = '%b'",MKBADDR(bcpl_name))); + + convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); + name_len = strlen(name); + SHOWVALUE(parent); if(parent != NULL) @@ -5480,6 +5520,8 @@ Action_SetProtect( ln = (struct LockNode *)parent->fl_Key; + D(("parent lock on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = user; parent_name = ln->ln_FullName; @@ -5489,34 +5531,10 @@ Action_SetProtect( parent_name = NULL; } - D(("name = '%b'",MKBADDR(bcpl_name))); - - convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); - - name_len = strlen(name); - /* Remove a device, volume or assignment name * from the path name. */ - for(i = 0 ; i < name_len ; i++) - { - /* Stop at a path delimiter. A path delimiter - * cannot be part of a device name. - */ - if(name[i] == '/') - break; - - /* Remove the device/volume/assignment name - * including the ':' character. - */ - if(name[i] == ':' && i > 0) - { - name_len -= i+1; - - memmove(name,&name[i+1],name_len+1); - break; - } - } + remove_device_name_from_path(name, &name_len); if (NOT ServerData->server.unicode_enabled) { @@ -5534,7 +5552,7 @@ Action_SetProtect( */ if(strcmp(full_name, SMB_ROOT_DIR_NAME) == SAME) { - LOG(("cannot change protection bits of the root directory\n")); + D(("cannot change protection bits of the root directory")); error = ERROR_OBJECT_WRONG_TYPE; goto out; @@ -5668,6 +5686,9 @@ Action_RenameObject( D(("source name = '%b'",MKBADDR(source_bcpl_name))); D(("destination name = '%b'",MKBADDR(destination_bcpl_name))); + convert_from_bcpl_to_c_string(name,sizeof(name),source_bcpl_name); + name_len = strlen(name); + if(source_lock != NULL) { if(lock_is_invalid(source_lock,&error)) @@ -5675,6 +5696,8 @@ Action_RenameObject( ln = (struct LockNode *)source_lock->fl_Key; + D(("source lock on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = user; parent_name = ln->ln_FullName; @@ -5684,32 +5707,10 @@ Action_RenameObject( parent_name = NULL; } - convert_from_bcpl_to_c_string(name,sizeof(name),source_bcpl_name); - - name_len = strlen(name); - /* Remove a device, volume or assignment name * from the path name. */ - for(i = 0 ; i < name_len ; i++) - { - /* Stop at a path delimiter. A path delimiter - * cannot be part of a device name. - */ - if(name[i] == '/') - break; - - /* Remove the device/volume/assignment name - * including the ':' character. - */ - if(name[i] == ':' && i > 0) - { - name_len -= i+1; - - memmove(name,&name[i+1],name_len+1); - break; - } - } + remove_device_name_from_path(name, &name_len); /* The SMB_COM_RENAME command supports renaming through * wildcards. Only the last part of the path (the name @@ -5744,15 +5745,20 @@ Action_RenameObject( if(error != OK) goto out; + D(("full source path = '%s'",escape_name(full_source_name))); + /* Trying to rename the root directory, are you kidding? */ if(strcmp(full_source_name, SMB_ROOT_DIR_NAME) == SAME) { - LOG(("cannot rename the root directory\n")); + D(("cannot rename the root directory")); error = ERROR_OBJECT_IN_USE; goto out; } + convert_from_bcpl_to_c_string(name,sizeof(name),destination_bcpl_name); + name_len = strlen(name); + if(destination_lock != NULL) { if(lock_is_invalid(destination_lock,&error)) @@ -5760,6 +5766,8 @@ Action_RenameObject( ln = (struct LockNode *)destination_lock->fl_Key; + D(("destination lock on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = user; parent_name = ln->ln_FullName; @@ -5769,32 +5777,10 @@ Action_RenameObject( parent_name = NULL; } - convert_from_bcpl_to_c_string(name,sizeof(name),destination_bcpl_name); - - name_len = strlen(name); - /* Remove a device, volume or assignment name * from the path name. */ - for(i = 0 ; i < name_len ; i++) - { - /* Stop at a path delimiter. A path delimiter - * cannot be part of a device name. - */ - if(name[i] == '/') - break; - - /* Remove the device/volume/assignment name - * including the ':' character. - */ - if(name[i] == ':' && i > 0) - { - name_len -= i+1; - - memmove(name,&name[i+1],name_len+1); - break; - } - } + remove_device_name_from_path(name, &name_len); last_name = FilePart(name); last_name_len = strlen(last_name); @@ -5825,10 +5811,12 @@ Action_RenameObject( if(error != OK) goto out; + D(("full destination path = '%s'",escape_name(full_destination_name))); + /* Trying to replace the root directory, are you kidding? */ if(strcmp(full_destination_name, SMB_ROOT_DIR_NAME) == SAME) { - LOG(("cannot replace the root directory\n")); + D(("cannot replace the root directory")); error = ERROR_OBJECT_IN_USE; goto out; @@ -5840,14 +5828,19 @@ Action_RenameObject( */ error = name_already_in_use(full_source_name); if(error != OK) + { + D(("source '%s' is still in use",escape_name(full_source_name))); + goto out; + } error = name_already_in_use(full_destination_name); if(error != OK) - goto out; + { + D(("destination '%s' is still in use",escape_name(full_destination_name))); - D(("source name = '%s'",escape_name(full_source_name))); - D(("destination name = '%s'",escape_name(full_destination_name))); + goto out; + } if(smba_rename(ServerData,full_source_name,full_destination_name,&error) < 0) { @@ -5990,6 +5983,10 @@ Action_Info( ln = (struct LockNode *)lock->fl_Key; + SHOWPOINTER(ln->ln_FullName); + + D(("lock on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = user; } @@ -6038,6 +6035,8 @@ Action_ExamineObject( ln = (struct LockNode *)lock->fl_Key; + D(("lock on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = user; if(smba_getattr(ln->ln_File,&st,&error) < 0) @@ -6469,6 +6468,8 @@ Action_ExamineNext( ln = (struct LockNode *)lock->fl_Key; + D(("lock on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = user; /* Is the job finished already? */ @@ -6916,6 +6917,8 @@ Action_ExamineAll( ln = (struct LockNode *)lock->fl_Key; + D(("lock on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = last_user; /* The buffer has to be large enough for at @@ -7179,6 +7182,8 @@ Action_ExamineAllEnd( ln = (struct LockNode *)lock->fl_Key; + D(("lock on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = last_user; /* Make Action_ExamineAll() return no more entries. */ @@ -7221,6 +7226,9 @@ Action_Find( ENTER(); + convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); + name_len = strlen(name); + switch(action) { case ACTION_FINDINPUT: @@ -7252,6 +7260,8 @@ Action_Find( ln = (struct LockNode *)parent->fl_Key; + D(("parent lock on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = user; parent_name = ln->ln_FullName; @@ -7261,39 +7271,17 @@ Action_Find( parent_name = NULL; } - convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); - - name_len = strlen(name); - /* Remove a device, volume or assignment name * from the path name. */ - for(i = 0 ; i < name_len ; i++) - { - /* Stop at a path delimiter. A path delimiter - * cannot be part of a device name. - */ - if(name[i] == '/') - break; - - /* Remove the device/volume/assignment name - * including the ':' character. - */ - if(name[i] == ':' && i > 0) - { - name_len -= i+1; - - memmove(name,&name[i+1],name_len+1); - break; - } - } + remove_device_name_from_path(name, &name_len); /* Do not allow MS-DOS wildcard characters to be used * when creating a new file. */ if(action != ACTION_FINDINPUT) { - TEXT * last_name; + const TEXT * last_name; int last_name_len; last_name = FilePart(name); @@ -7342,32 +7330,24 @@ Action_Find( /* Trying to open the root directory? */ if(strcmp(full_name, SMB_ROOT_DIR_NAME) == SAME) { - LOG(("cannot open the root directory\n")); + D(("cannot open the root directory")); error = ERROR_OBJECT_WRONG_TYPE; goto out; } - fn = allocate_memory(sizeof(*fn)); + fn = allocate_file_node((action == ACTION_FINDOUTPUT) ? EXCLUSIVE_LOCK : SHARED_LOCK,full_name,fh,NULL); if(fn == NULL) { error = ERROR_NO_FREE_STORE; goto out; } - memset(fn,0,sizeof(*fn)); - - fn->fn_Handle = fh; - fn->fn_Magic = ID_SMB_DISK; - fn->fn_Volume = VolumeNode; - fn->fn_FullName = full_name; - fn->fn_Mode = (action == ACTION_FINDOUTPUT) ? EXCLUSIVE_LOCK : SHARED_LOCK; - error = check_access_mode_collision(full_name,fn->fn_Mode); if(error != OK) goto out; - D(("full_name = '%s'",escape_name(full_name))); + D(("full path name = '%s'",escape_name(fn->fn_FullName))); /* Open an existing file for write access, create it if * it doesn't exist yet? @@ -7524,6 +7504,8 @@ Action_Read( if(file_is_invalid(fn,&error)) goto out; + D(("file opened on '%s'", escape_name(fn->fn_FullName))); + SHOWVALUE(length); if(length > 0) @@ -7571,6 +7553,8 @@ Action_Write( if(file_is_invalid(fn,&error)) goto out; + D(("file opened on '%s'", escape_name(fn->fn_FullName))); + SHOWVALUE(length); if(length > 0) @@ -7610,6 +7594,8 @@ Action_End( if(file_is_invalid(which_fn,&error)) goto out; + D(("file opened on '%s'", escape_name(which_fn->fn_FullName))); + found = NULL; for(fn = (struct FileNode *)FileList.mlh_Head ; @@ -7670,6 +7656,8 @@ Action_Seek( if(file_is_invalid(fn,&error)) goto out; + D(("file opened on '%s'", escape_name(fn->fn_FullName))); + previous_position_quad = fn->fn_OffsetQuad; switch(mode) @@ -7773,6 +7761,8 @@ Action_SetFileSize( if(file_is_invalid(fn,&error)) goto out; + D(("file opened on '%s'", escape_name(fn->fn_FullName))); + previous_position_quad = fn->fn_OffsetQuad; switch(mode) @@ -7878,7 +7868,6 @@ Action_SetDate( LONG seconds; int name_len; int error; - int i; ENTER(); @@ -7890,6 +7879,11 @@ Action_SetDate( SHOWVALUE(parent); + D(("name = '%b'",MKBADDR(bcpl_name))); + + convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); + name_len = strlen(name); + if(parent != NULL) { struct LockNode * ln; @@ -7899,6 +7893,8 @@ Action_SetDate( ln = (struct LockNode *)parent->fl_Key; + D(("parent lock on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = user; parent_name = ln->ln_FullName; @@ -7908,34 +7904,10 @@ Action_SetDate( parent_name = NULL; } - D(("name = '%b'",MKBADDR(bcpl_name))); - - convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); - - name_len = strlen(name); - /* Remove a device, volume or assignment name * from the path name. */ - for(i = 0 ; i < name_len ; i++) - { - /* Stop at a path delimiter. A path delimiter - * cannot be part of a device name. - */ - if(name[i] == '/') - break; - - /* Remove the device/volume/assignment name - * including the ':' character. - */ - if(name[i] == ':' && i > 0) - { - name_len -= i+1; - - memmove(name,&name[i+1],name_len+1); - break; - } - } + remove_device_name_from_path(name, &name_len); if (NOT ServerData->server.unicode_enabled) { @@ -7951,7 +7923,7 @@ Action_SetDate( /* Trying to change the date of the root directory? */ if(strcmp(full_name, SMB_ROOT_DIR_NAME) == SAME) { - LOG(("cannot change the date of the root directory\n")); + D(("cannot change the date of the root directory")); error = ERROR_OBJECT_IN_USE; goto out; @@ -8053,6 +8025,8 @@ Action_ExamineFH( if(file_is_invalid(fn,&error)) goto out; + D(("file opened on '%s'", escape_name(fn->fn_FullName))); + if(smba_getattr(fn->fn_File,&st,&error) < 0) { error = map_errno_to_ioerr(error); @@ -8185,6 +8159,7 @@ Action_ExamineFH( static BPTR Action_ParentFH( + struct MsgPort * user, struct FileNode * fn, LONG * error_ptr) { @@ -8198,26 +8173,19 @@ Action_ParentFH( if(file_is_invalid(fn,&error)) goto out; + D(("file opened on '%s'", escape_name(fn->fn_FullName))); + error = get_parent_dir_name(fn->fn_FullName,strlen(fn->fn_FullName),&parent_dir_name); if(error != OK) goto out; - ln = allocate_memory(sizeof(*ln)); + ln = allocate_lock_node(SHARED_LOCK,parent_dir_name,user); if(ln == NULL) { error = ERROR_NO_FREE_STORE; goto out; } - memset(ln,0,sizeof(*ln)); - - ln->ln_FileLock.fl_Key = (LONG)ln; - ln->ln_Magic = ID_SMB_DISK; - ln->ln_FileLock.fl_Access = SHARED_LOCK; - ln->ln_FileLock.fl_Task = FileSystemPort; - ln->ln_FileLock.fl_Volume = MKBADDR(VolumeNode); - ln->ln_FullName = parent_dir_name; - D(("parent_dir_name = '%s'",escape_name(parent_dir_name))); if(smba_open(ServerData,parent_dir_name,open_read_only,open_dont_truncate,&ln->ln_File,&error) < 0) @@ -8255,7 +8223,6 @@ Action_CopyDirFH( BPTR result = ZERO; struct LockNode * ln = NULL; STRPTR full_name = NULL; - int full_name_len; int error; ENTER(); @@ -8263,41 +8230,28 @@ Action_CopyDirFH( if(file_is_invalid(fn,&error)) goto out; + D(("file opened on '%s'", escape_name(fn->fn_FullName))); + if(fn->fn_Mode != SHARED_LOCK) { error = ERROR_OBJECT_IN_USE; goto out; } - full_name_len = strlen(fn->fn_FullName); - - full_name = allocate_memory(full_name_len+1); + full_name = allocate_and_copy_string(fn->fn_FullName, strlen(fn->fn_FullName)); if(full_name == NULL) { error = ERROR_NO_FREE_STORE; goto out; } - /* Length includes the terminating NUL byte. */ - memcpy(full_name,fn->fn_FullName,full_name_len+1); - - ln = allocate_memory(sizeof(*ln)); + ln = allocate_lock_node(SHARED_LOCK,full_name,user); if(ln == NULL) { error = ERROR_NO_FREE_STORE; goto out; } - memset(ln,0,sizeof(*ln)); - - ln->ln_FileLock.fl_Key = (LONG)ln; - ln->ln_Magic = ID_SMB_DISK; - ln->ln_FileLock.fl_Access = SHARED_LOCK; - ln->ln_FileLock.fl_Task = FileSystemPort; - ln->ln_FileLock.fl_Volume = MKBADDR(VolumeNode); - ln->ln_FullName = full_name; - ln->ln_LastUser = user; - D(("full_name = '%s'",escape_name(full_name))); if (smba_open(ServerData,full_name,open_read_only,open_dont_truncate,&ln->ln_File,&error) < 0) @@ -8346,6 +8300,8 @@ Action_FHFromLock( ln = (struct LockNode *)fl->fl_Key; + D(("lock on '%s'", escape_name(ln->ln_FullName))); + /* Is this a directory and not a file? */ if((ln->ln_File->dirent.attr & SMB_FILE_ATTRIBUTE_DIRECTORY) != 0) { @@ -8355,7 +8311,7 @@ Action_FHFromLock( goto out; } - fn = allocate_memory(sizeof(*fn)); + fn = allocate_file_node(fl->fl_Access,ln->ln_FullName,fh,ln->ln_File); if(fn == NULL) { error = ERROR_NO_FREE_STORE; @@ -8363,18 +8319,11 @@ Action_FHFromLock( } /* The file handle absorbs the lock. */ - memset(fn,0,sizeof(*fn)); - - fn->fn_Handle = fh; - fn->fn_Magic = ID_SMB_DISK; - fn->fn_Volume = VolumeNode; - fn->fn_FullName = ln->ln_FullName; - fn->fn_File = ln->ln_File; - fn->fn_Mode = fl->fl_Access; - - /* The lock is no longer needed. */ - Remove((struct Node *)ln); + ln->ln_FullName = NULL; + ln->ln_File = NULL; ln->ln_Magic = 0; + + Remove((struct Node *)ln); free_memory(ln); fh->fh_Arg1 = (LONG)fn; @@ -8470,6 +8419,40 @@ Action_RenameDisk( /****************************************************************************/ +static LONG +Action_CurrentVolume( + struct FileNode * fn, + LONG * error_ptr) +{ + LONG result = ZERO; + int error; + + ENTER(); + + if(file_is_invalid(fn,&error)) + goto out; + + D(("file opened on '%s'", escape_name(fn->fn_FullName))); + + if(NOT DeviceNodeAdded) + { + error = ERROR_ACTION_NOT_KNOWN; + goto out; + } + + result = MKBADDR(DeviceNode); + error = 0; + + out: + + (*error_ptr) = error; + + RETURN(result); + return(result); +} + +/****************************************************************************/ + static LONG Action_ChangeMode( const struct MsgPort * user, @@ -8529,6 +8512,8 @@ Action_ChangeMode( ln = (struct LockNode *)fl->fl_Key; + D(("lock on '%s'", escape_name(ln->ln_FullName))); + name = ln->ln_FullName; old_mode = fl->fl_Access; @@ -8543,62 +8528,47 @@ Action_ChangeMode( if(file_is_invalid(fn,&error)) goto out; + D(("file opened on '%s'", escape_name(fn->fn_FullName))); + name = fn->fn_FullName; old_mode = fn->fn_Mode; } /* Do we need to change anything at all? */ - if(new_mode == old_mode) + if(new_mode != old_mode) { - result = DOSTRUE; - goto out; - } + /* Change from shared to exclusive access? */ + if(new_mode != SHARED_LOCK) + { + /* Is there another shared access lock + * which refers to the same object? + */ + if(find_lock_node_by_name(name,ln) != NULL) + { + error = ERROR_OBJECT_IN_USE; + goto out; + } - /* This is the easiest case; change an - * exclusive access mode to a shared - * access mode. Since the original mode - * can be used by one object only, - * we get away by updating the mode - * value. - */ - if(new_mode == SHARED_LOCK) - { + /* Is there another shared access file + * which refers to the same object? + */ + if(find_file_node_by_name(name,fn) != NULL) + { + error = ERROR_OBJECT_IN_USE; + goto out; + } + } + + /* There is either just one single reference + * to this object or the object in question + * is configured for exclusive access. + */ if(type == CHANGE_LOCK) fl->fl_Access = new_mode; else fn->fn_Mode = new_mode; - - result = DOSTRUE; - goto out; } - /* Is there another shared access lock - * which refers to the same object? - */ - if(find_lock_node(name,ln) != NULL) - { - error = ERROR_OBJECT_IN_USE; - goto out; - } - - /* Is there another shared access file - * which refers to the same object? - */ - if(find_file_node(name,fn) != NULL) - { - error = ERROR_OBJECT_IN_USE; - goto out; - } - - /* There is just one single reference - * to this object; change the mode - * and quit. - */ - if(type == CHANGE_LOCK) - fl->fl_Access = new_mode; - else - fn->fn_Mode = new_mode; - result = DOSTRUE; out: @@ -8713,7 +8683,6 @@ Action_SetComment( TEXT name[MAX_FILENAME_LEN+1]; int name_len; int error; - int i; ENTER(); @@ -8725,6 +8694,9 @@ Action_SetComment( D(("name = '%b', comment = '%s'",MKBADDR(bcpl_name),MKBADDR(bcpl_comment))); + convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); + name_len = strlen(name); + SHOWVALUE(parent); if(parent != NULL) @@ -8736,6 +8708,8 @@ Action_SetComment( ln = (struct LockNode *)parent->fl_Key; + D(("parent lock on '%s'", escape_name(ln->ln_FullName))); + ln->ln_LastUser = user; parent_name = ln->ln_FullName; @@ -8745,32 +8719,10 @@ Action_SetComment( parent_name = NULL; } - convert_from_bcpl_to_c_string(name,sizeof(name),bcpl_name); - - name_len = strlen(name); - /* Remove a device, volume or assignment name * from the path name. */ - for(i = 0 ; i < name_len ; i++) - { - /* Stop at a path delimiter. A path delimiter - * cannot be part of a device name. - */ - if(name[i] == '/') - break; - - /* Remove the device/volume/assignment name - * including the ':' character. - */ - if(name[i] == ':' && i > 0) - { - name_len -= i+1; - - memmove(name,&name[i+1],name_len+1); - break; - } - } + remove_device_name_from_path(name, &name_len); if (NOT ServerData->server.unicode_enabled) { @@ -8786,7 +8738,7 @@ Action_SetComment( /* Trying to change the comment of the root directory? */ if(strcmp(full_name, SMB_ROOT_DIR_NAME) == SAME) { - LOG(("cannot change the comment of the root directory\n")); + D(("cannot change the comment of the root directory")); error = ERROR_OBJECT_IN_USE; goto out; @@ -8836,6 +8788,8 @@ Action_LockRecord( if(file_is_invalid(fn,&error)) goto out; + D(("file opened on '%s'", escape_name(fn->fn_FullName))); + /* Sanity checks... */ if (mode < REC_EXCLUSIVE || mode > REC_SHARED_IMMED) { @@ -8899,6 +8853,8 @@ Action_FreeRecord( if(file_is_invalid(fn,&error)) goto out; + D(("file opened on '%s'", escape_name(fn->fn_FullName))); + /* Sanity checks... */ if(offset < 0 || length <= 0 || offset + length < offset) { @@ -9236,6 +9192,7 @@ file_system_handler( case ACTION_DIE: SHOWMSG("ACTION_DIE"); + if(IsListEmpty((struct List *)&FileList) && IsListEmpty((struct List *)&LockList)) { SHOWMSG("no locks or files pending; quitting"); @@ -9254,9 +9211,9 @@ file_system_handler( break; case ACTION_CURRENT_VOLUME: - /* (Ignore) -> VolumeNode */ + /* FileHandle->fh_Arg1 -> DeviceList, Unit */ - res1 = MKBADDR(VolumeNode); + res1 = Action_CurrentVolume((struct FileNode *)dp->dp_Arg1,&res2); break; case ACTION_LOCATE_OBJECT: @@ -9456,7 +9413,7 @@ file_system_handler( case ACTION_PARENT_FH: /* FileHandle->fh_Arg1 -> Bool */ - res1 = Action_ParentFH((struct FileNode *)dp->dp_Arg1,&res2); + res1 = Action_ParentFH(dp->dp_Port,(struct FileNode *)dp->dp_Arg1,&res2); break; case ACTION_EXAMINE_ALL: @@ -9520,12 +9477,9 @@ file_system_handler( break; } - SHOWVALUE(res1); - SHOWVALUE(res2); + D(("Returning packet with res1=%ld (0x%08lx) and res2=%ld (0x%08lx)\n",res1,res1,res2,res2)); ReplyPkt(dp,res1,res2); - - D(("\n")); } /* Let's get paranoid: check if we should quit. */ diff --git a/source_code/proc.c b/source_code/proc.c index 68e5edd..2fc27f6 100644 --- a/source_code/proc.c +++ b/source_code/proc.c @@ -116,7 +116,8 @@ static int smb_proc_reconnect (struct smb_server *server, int * error_ptr); /*****************************************************************************/ /* error code stuff - put together by Merik Karman - merik -at- blackadder -dot- dsh -dot- oz -dot- au */ + * merik -at- blackadder -dot- dsh -dot- oz -dot- au + */ typedef struct { const char * name; @@ -272,7 +273,7 @@ static void convert_time_t_to_long_date(time_t t, QUAD * long_date); * of the string. This works because the ISO-Latin-1 character sits * within the ASCII/BMP Latin-1 Unicode range. * - * This function creates a null-terminated UTF16-LE Unicode string and + * This function creates a NUL-terminated UTF16-LE Unicode string and * returns how many bytes were written to the buffer, including the * null-termination. * @@ -325,7 +326,7 @@ copy_latin1_to_utf16le(byte * to,int to_size, const byte * from,int len) * Note that the length is given as the number of 16 bit Unicode * characters, not the number of bytes required to store the string. * - * This function creates a null-terminated ISO-Latin-1 string and + * This function creates a NUL-terminated ISO-Latin-1 string and * returns how many bytes were written to the buffer, including the * null-termination. * @@ -702,7 +703,8 @@ smb_bcc (const byte * packet) } /* smb_valid_packet: We check if packet fulfills the basic - requirements of a smb packet */ + * requirements of a smb packet + */ static int smb_valid_packet (const byte * packet) { @@ -719,7 +721,8 @@ smb_valid_packet (const byte * packet) } /* smb_verify: We check if we got the answer we expected, and if we - got enough data. If bcc == -1, we don't care. */ + * got enough data. If bcc == -1, we don't care. + */ static int smb_verify (const byte * packet, int command, int wct, int bcc) { @@ -810,8 +813,8 @@ smb_errno (int errcls, int error) { ERRlock, EDEADLK }, { ERRfilexists, EEXIST }, { ERRinvalidparam, EINVAL }, - { 145, ENOTEMPTY},/* Directory is not empty; this is what Samba reports (2016-04-23) */ - { 183, EEXIST },/* This next error seems to occur on an mv when the destination exists ("object name collision") */ + { 145, ENOTEMPTY}, /* Directory is not empty; this is what Samba reports (2016-04-23) */ + { 183, EEXIST }, /* This next error seems to occur on an mv when the destination exists ("object name collision") */ { -1, -1 } }; @@ -1224,7 +1227,7 @@ smb_payload_size(const struct smb_server *server, int wct, int bcc) int smb_proc_open (struct smb_server *server, const char *pathname, int len, int writable, int truncate_file, struct smb_dirent *entry,int * error_ptr) { - int result; + int result = 0; char *p; char *buf = server->transmit_buffer; int retry_read_only; @@ -1370,7 +1373,7 @@ smb_proc_open (struct smb_server *server, const char *pathname, int len, int wri if (result < 0) { int access_error; - + SHOWMSG("that didn't work; retrying"); /* Try again in read-only mode? */ @@ -1462,7 +1465,7 @@ smb_proc_open (struct smb_server *server, const char *pathname, int len, int wri if(server->unicode_enabled) { - (*p++) = 4; /* A null-terminated string follows. */ + (*p++) = 4; /* A NUL-terminated string follows. */ copy_latin1_to_utf16le(p,2 * (len+1),pathname,len); } else @@ -1720,7 +1723,7 @@ smb_proc_write_raw (struct smb_server *server, struct smb_dirent *finfo, const Q LOG (("number of bytes to send = %ld\n", count)); - /* Calculate maximum number of bytes that could be transferred with + /* Calculate the maximum number of bytes that could be transferred with * a single SMB_COM_WRITE_RAW packet... * * 'max_buffer_size' is the maximum size of a complete SMB message @@ -2117,7 +2120,7 @@ smb_proc_create (struct smb_server *server, const char *path, int len, struct sm if(server->unicode_enabled) { - (*p++) = 4; /* A null-terminated string follows. */ + (*p++) = 4; /* A NUL-terminated string follows. */ copy_latin1_to_utf16le(p,2 * (len+1),path,len); } else @@ -2165,10 +2168,10 @@ smb_proc_mv (struct smb_server *server, const char *old_path, const int old_path if(server->unicode_enabled) { - (*p++) = 4; /* A null-terminated string follows. */ + (*p++) = 4; /* A NUL-terminated string follows. */ p += copy_latin1_to_utf16le(p,2 * (old_path_len+1),old_path,old_path_len); - (*p++) = 4; /* A null-terminated string follows. */ + (*p++) = 4; /* A NUL-terminated string follows. */ (*p++) = 0; /* Padding byte, allowing for the string to be word-aligned. */ (void) copy_latin1_to_utf16le(p,2 * (new_path_len+1),new_path,new_path_len); @@ -2209,7 +2212,7 @@ smb_proc_mkdir (struct smb_server *server, const char *path, const int len, int if(server->unicode_enabled) { - (*p++) = 4; /* A null-terminated string follows. */ + (*p++) = 4; /* A NUL-terminated string follows. */ (void) copy_latin1_to_utf16le(p,path_size,path,len); } else @@ -2249,7 +2252,7 @@ smb_proc_rmdir (struct smb_server *server, const char *path, const int len, int if(server->unicode_enabled) { - (*p++) = 4; /* A null-terminated string follows. */ + (*p++) = 4; /* A NUL-terminated string follows. */ (void) copy_latin1_to_utf16le(p,path_size,path,len); } else @@ -2293,7 +2296,7 @@ smb_proc_unlink (struct smb_server *server, const char *path, const int len, int if(server->unicode_enabled) { - (*p++) = 4; /* A null-terminated string follows. */ + (*p++) = 4; /* A NUL-terminated string follows. */ (void) copy_latin1_to_utf16le(p,path_size,path,len); } else @@ -2410,13 +2413,14 @@ smb_decode_dirent (const char *p, struct smb_dirent *entry) } /* This routine is used to read in directory entries from the network. - Note that it is for short directory name seeks, i.e.: protocol < PROTOCOL_LANMAN2 */ + * Note that it is for short directory name seeks, i.e.: protocol < PROTOCOL_LANMAN2 + */ static int smb_proc_readdir_short (struct smb_server *server, const char *path, int fpos, int cache_size, struct smb_dirent *entry, int * error_ptr) { char *p; char *buf; - int result; + int result = 0; int i; int first, total_count; struct smb_dirent *current_entry; @@ -2471,7 +2475,7 @@ smb_proc_readdir_short (struct smb_server *server, const char *path, int fpos, i if(server->unicode_enabled) { - (*p++) = 4; /* A null-terminated string follows. */ + (*p++) = 4; /* A NUL-terminated string follows. */ p += copy_latin1_to_utf16le(p,2 * (mask_len+1),mask,mask_len); } else @@ -2499,7 +2503,7 @@ smb_proc_readdir_short (struct smb_server *server, const char *path, int fpos, i if(server->unicode_enabled) { - (*p++) = 4; /* A null-terminated string follows. */ + (*p++) = 4; /* A NUL-terminated string follows. */ p += copy_latin1_to_utf16le(p,2 * (1),"",0); } else @@ -3341,7 +3345,7 @@ smb_proc_getattr_core (struct smb_server *server, const char *path, int len, str if(server->unicode_enabled) { - (*p++) = 4; /* A null-terminated string follows. */ + (*p++) = 4; /* A NUL-terminated string follows. */ copy_latin1_to_utf16le(p,2 * (len+1),path,len); } else @@ -3832,7 +3836,7 @@ smb_proc_setattr_core (struct smb_server *server, const char *path, int len, con if(server->unicode_enabled) { - (*p++) = 4; /* A null-terminated string follows. */ + (*p++) = 4; /* A NUL-terminated string follows. */ p += copy_latin1_to_utf16le(p,2 * (len+1),path,len); } else @@ -4448,7 +4452,7 @@ smb_proc_reconnect (struct smb_server *server, int * error_ptr) { /* We may be able to use Unicode strings during the session setup, * but the server may not understand it (Windows 7 seems to be - * unable to decode them), so we delay setting the SMB message + * unable to decode the strings), so we delay setting the SMB message * flag "this message may contain Unicode strings" until we have * completed the session setup. */ @@ -4477,7 +4481,7 @@ smb_proc_reconnect (struct smb_server *server, int * error_ptr) /* Use plain text passwords? Remember to transmit the * password in UTF16LE-encoding. Note that we have to * use the UTF16LE-encoded form, and not the OEM - * for. + * form. */ if((server->security_mode & NEGOTIATE_ENCRYPT_PASSWORDS) == 0) { @@ -4498,16 +4502,16 @@ smb_proc_reconnect (struct smb_server *server, int * error_ptr) smb_setup_header (server, SMBsesssetupX, 13, oem_password_len + unicode_password_len + user_len+1 + strlen (server->mount_data.workgroup_name)+1 + strlen (native_os)+1 + strlen (native_lanman)+1); } - WSET (packet, smb_vwv0, 0xff); /* AndXCommand+AndXReserved */ - WSET (packet, smb_vwv1, 0); /* AndXOffset */ - WSET (packet, smb_vwv2, given_max_xmit); /* MaxBufferSize */ - WSET (packet, smb_vwv3, 2); /* MaxMpxCount */ - WSET (packet, smb_vwv4, 0); /* VcNumber */ - DSET (packet, smb_vwv5, server_sesskey); /* SessionKey */ + WSET (packet, smb_vwv0, 0xff); /* AndXCommand+AndXReserved */ + WSET (packet, smb_vwv1, 0); /* AndXOffset */ + WSET (packet, smb_vwv2, given_max_xmit); /* MaxBufferSize */ + WSET (packet, smb_vwv3, 2); /* MaxMpxCount */ + WSET (packet, smb_vwv4, 0); /* VcNumber */ + DSET (packet, smb_vwv5, server_sesskey); /* SessionKey */ WSET (packet, smb_vwv7, oem_password_len); /* OEMPasswordLen */ WSET (packet, smb_vwv8, unicode_password_len); /* UnicodePasswordLen */ - DSET (packet, smb_vwv9, 0); /* Reserved */ - DSET (packet, smb_vwv11, client_capabilities); /* Capabilities */ + DSET (packet, smb_vwv9, 0); /* Reserved */ + DSET (packet, smb_vwv11, client_capabilities); /* Capabilities */ p = SMB_BUF (packet); @@ -4660,6 +4664,8 @@ smb_proc_reconnect (struct smb_server *server, int * error_ptr) #endif /* OVERRIDE_SERVER_MAX_BUFFER_SIZE */ server->capabilities = 0; + + oem_password_len = 0; } if(server->protocol > PROTOCOL_LANMAN1 && @@ -4865,7 +4871,8 @@ smb_proc_reconnect (struct smb_server *server, int * error_ptr) } /* smb_proc_reconnect: server->transmit_buffer is allocated with - server->max_buffer_size bytes if and only if we return >= 0 */ + * server->max_buffer_size bytes if and only if we return >= 0 + */ int smb_proc_connect (struct smb_server *server, int * error_ptr) { diff --git a/source_code/smb_abstraction.c b/source_code/smb_abstraction.c index 9bf0ed4..de4bec0 100644 --- a/source_code/smb_abstraction.c +++ b/source_code/smb_abstraction.c @@ -432,7 +432,7 @@ smba_open (smba_server_t * s, const char *name, int writable, int truncate_file, LOG(("open failed\n")); goto out; } - + AddTail ((struct List *)&s->open_files, (struct Node *)f); s->num_open_files++; @@ -585,7 +585,7 @@ smba_close (smba_server_t * s, smba_file_t * f) } found->server->num_open_files--; - + LOG(("file closed, number of open files = %ld\n",found->server->num_open_files)); free (found); @@ -618,7 +618,7 @@ smba_read (smba_file_t * f, char *data, long len, const QUAD * const offset, int int max_readx_size; int count; - /* Calculate maximum number of bytes that could be transferred with + /* Calculate the maximum number of bytes that could be transferred with * a single SMBreadX packet... * * The message header accounts for @@ -722,7 +722,7 @@ smba_read (smba_file_t * f, char *data, long len, const QUAD * const offset, int off_t position = offset->Low; int count; - /* Calculate maximum number of bytes that could be transferred with + /* Calculate the maximum number of bytes that could be transferred with * a single SMBread packet... * * 'max_buffer_size' is the maximum size of a complete SMB message @@ -816,7 +816,7 @@ smba_write (smba_file_t * f, const char *data, long len, const QUAD * const offs int max_writex_size; int n; - /* Calculate maximum number of bytes that could be transferred with + /* Calculate the maximum number of bytes that could be transferred with * a single SMB_COM_WRITE_ANDX packet... * * 'max_buffer_size' is the maximum size of a complete SMB message @@ -931,7 +931,7 @@ smba_write (smba_file_t * f, const char *data, long len, const QUAD * const offs int max_size_smb_com_write, count; off_t position = offset->Low; - /* Calculate maximum number of bytes that could be transferred with + /* Calculate the maximum number of bytes that could be transferred with * a single SMBwrite packet... * * 'max_buffer_size' is the maximum size of a complete SMB message @@ -1678,7 +1678,7 @@ extract_service ( char * root_start; char * complete_service; char * service_copy; - char * service_name = NULL; + char * service_name; int result = -1; service_copy = malloc(strlen(service)+1); @@ -1800,7 +1800,7 @@ smba_start( int opt_unicode, int opt_prefer_core_protocol, int opt_case_sensitive, - int opt_session_setup_delay_unicode, + int opt_session_setup_delay_unicode, int opt_write_behind, int * error_ptr, int * smb_error_class_ptr, @@ -1940,7 +1940,7 @@ smba_start( goto out; } - + name = h->h_name; LOG(("server host name found (%s)\n",name)); diff --git a/source_code/smbfs_rev.h b/source_code/smbfs_rev.h index 212a620..3ea714e 100644 --- a/source_code/smbfs_rev.h +++ b/source_code/smbfs_rev.h @@ -1,6 +1,6 @@ #define VERSION 1 -#define REVISION 176 -#define DATE "12.8.2018" -#define VERS "smbfs 1.176" -#define VSTRING "smbfs 1.176 (12.8.2018)\r\n" -#define VERSTAG "\0$VER: smbfs 1.176 (12.8.2018)" +#define REVISION 177 +#define DATE "27.8.2018" +#define VERS "smbfs 1.177" +#define VSTRING "smbfs 1.177 (27.8.2018)\r\n" +#define VERSTAG "\0$VER: smbfs 1.177 (27.8.2018)" diff --git a/source_code/smbfs_rev.rev b/source_code/smbfs_rev.rev index 1057e9a..eec4941 100644 --- a/source_code/smbfs_rev.rev +++ b/source_code/smbfs_rev.rev @@ -1 +1 @@ -176 +177