Ignore:
Timestamp:
Nov 12, 2012, 4:35:55 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server 3.5: update branche to 3.5.12

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.5.x/source3/lib/util.c

    r599 r732  
    30763076        return ret;
    30773077}
     3078
     3079/*******************************************************************
     3080 Return True if the filename is one of the special executable types.
     3081********************************************************************/
     3082
     3083bool is_executable(const char *fname)
     3084{
     3085        if ((fname = strrchr_m(fname,'.'))) {
     3086                if (strequal(fname,".com") ||
     3087                    strequal(fname,".dll") ||
     3088                    strequal(fname,".exe") ||
     3089                    strequal(fname,".sym")) {
     3090                        return True;
     3091                }
     3092        }
     3093        return False;
     3094}
     3095
     3096/****************************************************************************
     3097 Open a file with a share mode - old openX method - map into NTCreate.
     3098****************************************************************************/
     3099
     3100bool map_open_params_to_ntcreate(const char *smb_base_fname,
     3101                                 int deny_mode, int open_func,
     3102                                 uint32 *paccess_mask,
     3103                                 uint32 *pshare_mode,
     3104                                 uint32 *pcreate_disposition,
     3105                                 uint32 *pcreate_options)
     3106{
     3107        uint32 access_mask;
     3108        uint32 share_mode;
     3109        uint32 create_disposition;
     3110        uint32 create_options = FILE_NON_DIRECTORY_FILE;
     3111
     3112        DEBUG(10,("map_open_params_to_ntcreate: fname = %s, deny_mode = 0x%x, "
     3113                  "open_func = 0x%x\n",
     3114                  smb_base_fname, (unsigned int)deny_mode,
     3115                  (unsigned int)open_func ));
     3116
     3117        /* Create the NT compatible access_mask. */
     3118        switch (GET_OPENX_MODE(deny_mode)) {
     3119                case DOS_OPEN_EXEC: /* Implies read-only - used to be FILE_READ_DATA */
     3120                case DOS_OPEN_RDONLY:
     3121                        access_mask = FILE_GENERIC_READ;
     3122                        break;
     3123                case DOS_OPEN_WRONLY:
     3124                        access_mask = FILE_GENERIC_WRITE;
     3125                        break;
     3126                case DOS_OPEN_RDWR:
     3127                case DOS_OPEN_FCB:
     3128                        access_mask = FILE_GENERIC_READ|FILE_GENERIC_WRITE;
     3129                        break;
     3130                default:
     3131                        DEBUG(10,("map_open_params_to_ntcreate: bad open mode = 0x%x\n",
     3132                                  (unsigned int)GET_OPENX_MODE(deny_mode)));
     3133                        return False;
     3134        }
     3135
     3136        /* Create the NT compatible create_disposition. */
     3137        switch (open_func) {
     3138                case OPENX_FILE_EXISTS_FAIL|OPENX_FILE_CREATE_IF_NOT_EXIST:
     3139                        create_disposition = FILE_CREATE;
     3140                        break;
     3141
     3142                case OPENX_FILE_EXISTS_OPEN:
     3143                        create_disposition = FILE_OPEN;
     3144                        break;
     3145
     3146                case OPENX_FILE_EXISTS_OPEN|OPENX_FILE_CREATE_IF_NOT_EXIST:
     3147                        create_disposition = FILE_OPEN_IF;
     3148                        break;
     3149
     3150                case OPENX_FILE_EXISTS_TRUNCATE:
     3151                        create_disposition = FILE_OVERWRITE;
     3152                        break;
     3153
     3154                case OPENX_FILE_EXISTS_TRUNCATE|OPENX_FILE_CREATE_IF_NOT_EXIST:
     3155                        create_disposition = FILE_OVERWRITE_IF;
     3156                        break;
     3157
     3158                default:
     3159                        /* From samba4 - to be confirmed. */
     3160                        if (GET_OPENX_MODE(deny_mode) == DOS_OPEN_EXEC) {
     3161                                create_disposition = FILE_CREATE;
     3162                                break;
     3163                        }
     3164                        DEBUG(10,("map_open_params_to_ntcreate: bad "
     3165                                  "open_func 0x%x\n", (unsigned int)open_func));
     3166                        return False;
     3167        }
     3168
     3169        /* Create the NT compatible share modes. */
     3170        switch (GET_DENY_MODE(deny_mode)) {
     3171                case DENY_ALL:
     3172                        share_mode = FILE_SHARE_NONE;
     3173                        break;
     3174
     3175                case DENY_WRITE:
     3176                        share_mode = FILE_SHARE_READ;
     3177                        break;
     3178
     3179                case DENY_READ:
     3180                        share_mode = FILE_SHARE_WRITE;
     3181                        break;
     3182
     3183                case DENY_NONE:
     3184                        share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE;
     3185                        break;
     3186
     3187                case DENY_DOS:
     3188                        create_options |= NTCREATEX_OPTIONS_PRIVATE_DENY_DOS;
     3189                        if (is_executable(smb_base_fname)) {
     3190                                share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE;
     3191                        } else {
     3192                                if (GET_OPENX_MODE(deny_mode) == DOS_OPEN_RDONLY) {
     3193                                        share_mode = FILE_SHARE_READ;
     3194                                } else {
     3195                                        share_mode = FILE_SHARE_NONE;
     3196                                }
     3197                        }
     3198                        break;
     3199
     3200                case DENY_FCB:
     3201                        create_options |= NTCREATEX_OPTIONS_PRIVATE_DENY_FCB;
     3202                        share_mode = FILE_SHARE_NONE;
     3203                        break;
     3204
     3205                default:
     3206                        DEBUG(10,("map_open_params_to_ntcreate: bad deny_mode 0x%x\n",
     3207                                (unsigned int)GET_DENY_MODE(deny_mode) ));
     3208                        return False;
     3209        }
     3210
     3211        DEBUG(10,("map_open_params_to_ntcreate: file %s, access_mask = 0x%x, "
     3212                  "share_mode = 0x%x, create_disposition = 0x%x, "
     3213                  "create_options = 0x%x\n",
     3214                  smb_base_fname,
     3215                  (unsigned int)access_mask,
     3216                  (unsigned int)share_mode,
     3217                  (unsigned int)create_disposition,
     3218                  (unsigned int)create_options ));
     3219
     3220        if (paccess_mask) {
     3221                *paccess_mask = access_mask;
     3222        }
     3223        if (pshare_mode) {
     3224                *pshare_mode = share_mode;
     3225        }
     3226        if (pcreate_disposition) {
     3227                *pcreate_disposition = create_disposition;
     3228        }
     3229        if (pcreate_options) {
     3230                *pcreate_options = create_options;
     3231        }
     3232
     3233        return True;
     3234
     3235}
Note: See TracChangeset for help on using the changeset viewer.