Beispiel #1
0
/**
   Setup a smb_fid:: structure for RPC

   \note Obtains fidp->mx */
afs_int32
smb_SetupRPCFid(smb_fid_t * fidp, const clientchar_t * _epnamep,
		unsigned short * file_type,
		unsigned short * device_state)
{
    smb_rpc_t *rpcp;
    afs_int32 code = 0;
    const clientchar_t * epnamep;

    epnamep = cm_ClientStrChr(_epnamep, _C('\\'));
    if (epnamep == NULL)
	epnamep = _epnamep;
    else
	epnamep = cm_ClientCharNext(epnamep);

    lock_ObtainMutex(&fidp->mx);
    fidp->flags |= SMB_FID_RPC;
    fidp->scp = &cm_data.fakeSCache;
    cm_HoldSCache(fidp->scp);
    if (fidp->rpcp == NULL) {
        rpcp = malloc(sizeof(*rpcp));
        memset(rpcp, 0, sizeof(*rpcp));
        fidp->rpcp = rpcp;
        rpcp->fidp = fidp;
    } else {
	rpcp = fidp->rpcp;
    }
    code = smb_RPC_SetupEndpointByname(rpcp, epnamep);
    lock_ReleaseMutex(&fidp->mx);

    if (code == 0) {
	*file_type = SMB_FILETYPE_MESSAGE_MODE_PIPE;
	*device_state =((0xff) |	/* instance count */
			SMB_DEVICESTATE_READMSGFROMPIPE |
			SMB_DEVICESTATE_MESSAGEMODEPIPE |
			SMB_DEVICESTATE_PIPECLIENTEND);
    }

    return code;
}
Beispiel #2
0
/*! \brief Compare 'pattern' (containing metacharacters '*' and '?') with the file name 'name'.

  \note This procedure works recursively calling itself.

  \param[in] pattern string containing metacharacters.
  \param[in] name File name to be compared with 'pattern'.

  \return BOOL : TRUE/FALSE (match/mistmatch)
*/
static BOOL 
szWildCardMatchFileName(clientchar_t * pattern, clientchar_t * name, int casefold) 
{
    clientchar_t upattern[MAX_PATH];
    clientchar_t uname[MAX_PATH];

    clientchar_t * pename;         // points to the last 'name' character
    clientchar_t * p;
    clientchar_t * pattern_next;

    if (casefold) {
        cm_ClientStrCpy(upattern, lengthof(upattern), pattern);
        cm_ClientStrUpr(upattern);
        pattern = upattern;

        cm_ClientStrCpy(uname, lengthof(uname), name);
        cm_ClientStrUpr(uname);
        name = uname;

        /* The following translations all work on single byte
           characters */
        for (p=upattern; *p; p++) {
            if (*p == '"') *p = '.'; continue;
            if (*p == '<') *p = '*'; continue;
            if (*p == '>') *p = '?'; continue;
        }

        for (p=uname; *p; p++) {
            if (*p == '"') *p = '.'; continue;
            if (*p == '<') *p = '*'; continue;
            if (*p == '>') *p = '?'; continue;
        }
    }

    pename = cm_ClientCharThis(name + cm_ClientStrLen(name));

    while (*name) {
        switch (*pattern) {
        case '?':
	    pattern = cm_ClientCharNext(pattern);
            if (*name == '.')
		continue;
            name = cm_ClientCharNext(name);
            break;

         case '*':
            pattern = cm_ClientCharNext(pattern);
            if (*pattern == '\0')
                return TRUE;

            pattern_next = cm_ClientCharNext(pattern);

            for (p = pename; p >= name; p = cm_ClientCharPrev(p)) {
                if (*p == *pattern &&
                    szWildCardMatchFileName(pattern_next,
                                            cm_ClientCharNext(p), FALSE))
                    return TRUE;
            } /* endfor */
            if (*pattern == '.' && *pattern_next == '\0') {
                for (p = name; p && *p; p = cm_ClientCharNext(p))
                    if (*p == '.')
                        break;
                if (p && *p)
                    return FALSE;
                return TRUE;
            }
            return FALSE;

        default:
            if (*name != *pattern)
                return FALSE;
            pattern = cm_ClientCharNext(pattern);
            name = cm_ClientCharNext(name);
            break;
        } /* endswitch */
    } /* endwhile */

    /* if all we have left are wildcards, then we match */
    for (;*pattern; pattern = cm_ClientCharNext(pattern)) {
	if (*pattern != '*' && *pattern != '?')
	    return FALSE;
    }
    return TRUE;
}