コード例 #1
0
ファイル: srvbrws.c プロジェクト: layerfsd/cifssmb
RTSMB_STATIC int rtsmb_srv_browse_election_takeover (void)
{
    RTSMB_BROWSE_SERVER_INFO info;

    RTSMB_DEBUG_OUTPUT_STR("rtsmb_nbds_election_takeover: Taking over master browser role\n", RTSMB_DEBUG_TYPE_ASCII);

    rtsmb_srv_browse_election_win_count = 0;

    rtsmb_srv_browse_switch_role (RTSMB_SRV_BROWSE_ROLE_MASTER_BROWSER);

    rtsmb_srv_browse_announcement_next_base = rtp_get_system_msec();
    rtsmb_srv_browse_announcement_next_delay = 0;

    /* always request announcements, since our list from being a backup browser
       does not contain all the info a host announcement does */
/*  if (rtsmb_browse_server_list_is_empty ())   */
    {
        rtsmb_srv_browse_send_announcement_request ();
    }

    /* fill in one spot in our lists with ourselves   */
    rtsmb_srv_browse_our_info (&info);

    /* Except, change the periodicity to the maximum value
       so that we don't often try to remove ourselves from
       the list, which causes a costly comparison with the
       name to make sure it's not us. */
    info.periodicity = 0xFFFFFFFF;

    rtsmb_srv_browse_update_entry (prtsmb_srv_ctx->server_table,
        (rtsmb_size )prtsmb_srv_ctx->server_table_size, &info);

    tc_strcpy (info.name, rtsmb_srv_nbns_get_our_group ());
    tc_strcpy (info.comment, rtsmb_srv_nbns_get_our_name ());
    info.type |= SV_TYPE_DOMAIN_ENUM;

    rtsmb_srv_browse_update_entry (prtsmb_srv_ctx->domain_table,
        (rtsmb_size )prtsmb_srv_ctx->domain_table_size, &info);


    /* register master browser names for our group   */
    rtsmb_srv_nbns_add_name (rtsmb_srv_nbns_get_our_group (), FALSE, RTSMB_NB_NAME_TYPE_MASTER_BROWSER, TRUE);
    rtsmb_srv_nbns_add_name (RTSMB_NB_MASTER_BROWSER_NAME, TRUE, 0x1, TRUE);


    /* check if we have enough backup browsers   */
    rtsmb_srv_browse_ensure_backup_ratio ();


    /* make sure that we immediately announce our domain   */
    rtsmb_srv_browse_master_last_domain_announcement = rtp_get_system_msec() - RTSMB_SRV_BROWSE_DOMAIN_ANNOUNCE_DELAY;

    return 0;
}
コード例 #2
0
ファイル: srvbrws.c プロジェクト: layerfsd/cifssmb
RTSMB_STATIC void rtsmb_srv_browse_our_info (PRTSMB_BROWSE_SERVER_INFO pinfo)
{
    pinfo->update_count = 0;
    pinfo->periodicity = rtsmb_srv_browse_get_announcement_interval ();
    tc_strcpy (pinfo->name, rtsmb_srv_nbns_get_our_name ());
    tc_strcpy (pinfo->comment, CFG_RTSMB_DEFAULT_COMMENT);
    pinfo->version_major = 4;
    pinfo->version_minor = 0;
    pinfo->type = rtsmb_srv_browse_get_server_type ();
    pinfo->browse_version_major = RTSMB_NBDS_BROWSER_VERSION_MAJOR;
    pinfo->browse_version_minor = RTSMB_NBDS_BROWSER_VERSION_MINOR;
    pinfo->signature = 0xaa55;
    pinfo->time_received = rtp_get_system_msec();
}
コード例 #3
0
ファイル: psmbfile.c プロジェクト: layerfsd/cifssmb
BBOOL rtplatform_gfirst(PSMBDSTAT dirobj, char RTSMB_FAR * name_in)
{
char slashstar [] = {'\\', '*', '\0'};
char dotstar [] = {'.', '*', '\0'};
char name [SMBF_FILENAMESIZE + 1];
rtsmb_size len;
int rv;
void * rtp_dirobj;

    /* translate "*" to "*.*" becaues some file systems don't like "*" */
    len = (rtsmb_size) tc_strlen (name_in);
    tc_strcpy (name, name_in);
    if (len > 1 && len < SMBF_FILENAMESIZE - 2 && tc_strcmp (&name[len - 2], slashstar) == 0)
    {
       tc_strcat  (name, dotstar);
    }

    rv = rtp_file_gfirst(&rtp_dirobj, name);
    if (rv < 0)
    {
        dirobj->rtp_dirobj = (void*)0;
        return FALSE;
    }

    rtp_file_get_name(rtp_dirobj, dirobj->filename, SMBF_FILENAMESIZE);
    dirobj->filename[SMBF_FILENAMESIZE] = '\0';

    /*translate rtplatform dstat to smb dstat */
    rtplatform_translate_dstat (dirobj, rtp_dirobj);
    dirobj->unicode = 0;

    return TRUE;
}
コード例 #4
0
ファイル: wcache.cpp プロジェクト: peteratebs/webcwebbrowser
int _wcache_get_filename(char *fileName, struct wcache_ctx *cc, struct wcache_entry *entry)
{
char *name;

	tc_strcpy(fileName, cc->cachePrefix);
	name = &fileName[tc_strlen(fileName)];
	tc_itoa(entry->fileIndex, name, 16);
	tc_strcat(fileName, ".dat");

	return (0);
}
コード例 #5
0
ファイル: VT100C.C プロジェクト: Strongc/DC_source
/* *********************************************************************   */
static int vt100c_curposreport()
{
char numbuf[30];
char outbuf[50];

    tc_strcpy(outbuf,"\x27 [ ");
    tc_itoa(pcvid_wherex(),numbuf,10);
    tc_strcat(outbuf,numbuf);
    tc_strcat(outbuf,";");
    tc_itoa(pcvid_wherey(),numbuf,10);
    tc_strcat(outbuf,numbuf);
    tc_strcat(outbuf,"R");
    vt100c_sends(outbuf);
    return(0);
}
コード例 #6
0
ファイル: webcstr.cpp プロジェクト: peteratebs/webcwebbrowser
char *webc_malloc_string_copy_8(const char *str, const char *file, unsigned int line)
{
char *newstr;

	if (!str)
	{
		return 0;
	}

	newstr = (char *) WEBC_DEBUG_MALLOC(sizeof(char) * (tc_strlen(str) + 1), (char*) file, line,"webc_malloc_string_copy_8",0);
	if (newstr)
	{
		tc_strcpy(newstr,str);
	}

	return (newstr);
}
コード例 #7
0
char *webc_CreateVFile (const char *pName, int iMimeType, long lSize, WEBC_PFBYTE pData, WEBC_UINT16 wFlags, VFileDeleteFn Destructor)
{
#if (WEBC_SUPPORT_INTERNAL)
int n;
char unique_name[20];

	if (!pName)
	{
		tc_strcpy(unique_name, "\xffvfile");
		tc_itoa(_nextUniqueNum, &unique_name[tc_strlen(unique_name)], 10);
		pName = unique_name;
		_nextUniqueNum++;
	}

	for (n=0; n<NUM_VFILE_ENTRIES; n++)
	{
		if (!gWebcVFileTable[n].pName)
		{
			gWebcVFileTable[n].pName = webc_malloc_string_copy_8(pName, __FILE__, __LINE__);
			gWebcVFileTable[n].iMimeType = (WebcFileContentType) iMimeType;
			gWebcVFileTable[n].lSize = lSize;
			if (wFlags & WEBC_VFILE_COPY)
			{
				gWebcVFileTable[n].pData = (WEBC_PFBYTE) WEBC_MALLOC(lSize);
				if (!gWebcVFileTable[n].pData)
				{
					gWebcVFileTable[n].lSize = 0;
				}
				else
				{
					tc_movebytes(gWebcVFileTable[n].pData, pData, lSize);
				}
			}
			else
			{
				gWebcVFileTable[n].pData = pData;
			}
			gWebcVFileTable[n].wFlags = wFlags | WEBC_VFILE_CREATED;
			gWebcVFileTable[n].Destroy = Destructor;
			return (gWebcVFileTable[n].pName);
		}
	}
#endif

	return 0;
}
コード例 #8
0
ファイル: httpauth.c プロジェクト: maojxsir/upnp
/*---------------------------------------------------------------------------*/
HTTP_INT32 _HTTP_RealmPrintAuthorization (
		HTTPAuthenticationRealm *realm,
		const HTTP_CHAR* method,
		const HTTP_CHAR* path,
		HTTP_INT32 (*writeFn) (
				void* requestStream,
				const HTTP_CHAR* data,
				HTTP_INT32 len
			),
		void* requestStream
	)
{
	switch (realm->scheme)
	{
		case HTTP_AUTHENTICATION_BASIC:
			if (realm->userName[0])
			{
				HTTP_INT32 len = 0;
				char auth[HTTP_CFG_MAX_USERNAME_LEN + HTTP_CFG_MAX_PASSWORD_LEN];
				char encoded[((HTTP_CFG_MAX_USERNAME_LEN + HTTP_CFG_MAX_PASSWORD_LEN) * 4 + 2) /3];

				len =  sizeof(HTTP_CLIENT_BASIC_STR) / sizeof(HTTP_CHAR) - sizeof(HTTP_CHAR);
				writeFn(requestStream, HTTP_CLIENT_BASIC_STR, len);
				writeFn(requestStream, " ", 1);

				tc_strcpy(auth, realm->userName);
				tc_strcat(auth, ":");
				tc_strcat(auth, realm->password);

				len = _HTTP_Base64Encode(encoded, (HTTP_UINT8*) auth, (HTTP_INT32) tc_strlen(auth));

				writeFn(requestStream, encoded, len);

				return (len);
			}
			break;

		case HTTP_AUTHENTICATION_DIGEST:
			if (realm->userName[0])
			{
				HTTP_INT32 len = 0;
				HTTP_MD5_CTX md5Ctx;
				HTTP_CHAR hashA1[32];
				HTTP_CHAR hashA2[32];
				HTTP_CHAR finalHash[33];

				/* according to RFC 2617,
				      credentials = "Digest" digest-response

				   where
				      digest-response = "username=\"" + <user-name> +
					                    "\", realm=\"" + <realm-name> +
										"\", nonce=\"" + <server-nonce> +
										"\", uri=\"" + <path> +
										"\", response=\"" +
										   (qop == auth || qop == auth-int)?
										      KD(H(A1), <nonce> + ":" + <nonce-count> + ":" + <cnonce> + ":" + <qop> + ":" + H(A2)) :
											  KD(H(A1), <nonce> + ":" + H(A2))

				      A1 = <user-name> + ":" + <realm-name> + ":" + <password>

					  A2 = <method (GET,POST,etc)> + ":" + <path>

					  H(X) = MD5(X), as a 32-character HEX string

					  KD(I,J) = H(I + ":" + J);
				*/

				len = 17 /*Digest username="******", realm="*/ +
				      tc_strlen(realm->realmName) + 10 /*", nonce="*/ +
					  tc_strlen(realm->param.digest.serverNonce) + 8 /*", uri="*/ +
					  tc_strlen(path) + 13 /*", response="*/ + 32 /* MD5 hash */ + 1;

				writeFn(requestStream, "Digest username=\"", 17);
				writeFn(requestStream, realm->userName, tc_strlen(realm->userName));
				writeFn(requestStream, "\", realm=\"", 10);
				writeFn(requestStream, realm->realmName, tc_strlen(realm->realmName));
				writeFn(requestStream, "\", nonce=\"", 10);
				writeFn(requestStream, realm->param.digest.serverNonce, tc_strlen(realm->param.digest.serverNonce));
				writeFn(requestStream, "\", uri=\"", 8);
				writeFn(requestStream, path, tc_strlen(path));
				writeFn(requestStream, "\", response=\"", 13);

				/*-----------------------------------------------------*/
				/* find H(A1)                                          */
				/* if (algorithm == MD5) */
				HTTP_MD5_Init(&md5Ctx);
				HTTP_MD5_Update(&md5Ctx, realm->userName, tc_strlen(realm->userName)); /* TBD!!! - what if HTTP_CHAR is not ASCII 8bit ? */
				HTTP_MD5_Update(&md5Ctx, ":", 1);
				HTTP_MD5_Update(&md5Ctx, realm->realmName, tc_strlen(realm->realmName));
				HTTP_MD5_Update(&md5Ctx, ":", 1);
				HTTP_MD5_Update(&md5Ctx, realm->password, tc_strlen(realm->password));
				HTTP_MD5_Final(&md5Ctx);

     			if (realm->param.digest.hashAlgorithm == HTTP_ALGORITHM_MD5_SESS)
				{
					HTTP_UINT8 HA1[16];

					tc_memcpy(HA1, md5Ctx.digest, 16);

					HTTP_MD5_Init(&md5Ctx);
					HTTP_MD5_Update(&md5Ctx, HA1, 16);
					HTTP_MD5_Update(&md5Ctx, ":", 1);
					HTTP_MD5_Update(&md5Ctx, realm->param.digest.serverNonce, tc_strlen(realm->param.digest.serverNonce));
					HTTP_MD5_Update(&md5Ctx, ":", 1);
					HTTP_MD5_Update(&md5Ctx, realm->param.digest.clientNonce, tc_strlen(realm->param.digest.clientNonce));
					HTTP_MD5_Final(&md5Ctx);
				}

				_HTTP_HashToHex(hashA1, md5Ctx.digest, 16);

				/*-----------------------------------------------------*/
				/* find H(A2)                                          */
				/* if (QOP == auth || QOP == none) */
				HTTP_MD5_Init(&md5Ctx);
				HTTP_MD5_Update(&md5Ctx, method, tc_strlen(method));
				HTTP_MD5_Update(&md5Ctx, ":", 1);
				HTTP_MD5_Update(&md5Ctx, path, tc_strlen(path));

				if (realm->param.digest.qop == HTTP_QOP_AUTH_INT)
				{
					HTTP_MD5_Update(&md5Ctx, ":", 1);
					/* What is HEntity!?!? */
					/*HTTP_MD5_Update(&md5Ctx, HEntity, HASHHEXLEN);*/
				}

				HTTP_MD5_Final(&md5Ctx);
				_HTTP_HashToHex(hashA2, md5Ctx.digest, 16);

				HTTP_MD5_Init(&md5Ctx);
				HTTP_MD5_Update(&md5Ctx, hashA1, 32);
				HTTP_MD5_Update(&md5Ctx, ":", 1);
				HTTP_MD5_Update(&md5Ctx, realm->param.digest.serverNonce, tc_strlen(realm->param.digest.serverNonce));
				HTTP_MD5_Update(&md5Ctx, ":", 1);

				if (realm->param.digest.qop == HTTP_QOP_AUTH ||
					realm->param.digest.qop == HTTP_QOP_AUTH_INT)
				{
					HTTP_CHAR nonceCountStr[8];

					_HTTP_UINT32ToHex(nonceCountStr, realm->param.digest.nonceCount);

					HTTP_MD5_Update(&md5Ctx, nonceCountStr, 8);
					HTTP_MD5_Update(&md5Ctx, ":", 1);
					HTTP_MD5_Update(&md5Ctx, realm->param.digest.clientNonce, tc_strlen(realm->param.digest.clientNonce));
					HTTP_MD5_Update(&md5Ctx, ":", 1);
					HTTP_MD5_Update(&md5Ctx, httpAuthQoPNames[realm->param.digest.qop], tc_strlen(httpAuthQoPNames[realm->param.digest.qop]));
					HTTP_MD5_Update(&md5Ctx, ":", 1);
				}

				HTTP_MD5_Update(&md5Ctx, hashA2, 32);
				HTTP_MD5_Final(&md5Ctx);

				_HTTP_HashToHex(finalHash, md5Ctx.digest, 16);
				finalHash[32] = '\"';

				writeFn(requestStream, finalHash, 33);

				return (len);
			}
			break;

		default:
			break;
	}

	return (0);
}
コード例 #9
0
ファイル: srvrap.c プロジェクト: layerfsd/cifssmb
/*
================

================
*/
int NetServerEnum2 (PSMB_SESSIONCTX pCtx, PRTSMB_RAP_REQUEST pFunc,
    PRTSMB_HEADER pInHdr, PFVOID pInBuf,
    PRTSMB_HEADER pOutHdr,
    rtsmb_size size_left, PFWORD param_size)
{
    RTSMB_RAP_SERVER_ENUM2 command;
    RTSMB_RAP_ENUM_HEADER_R header;
    RTSMB_RAP_SERVER_INFO_1 info;
    PRTSMB_BROWSE_SERVER_INFO plist;
    PFVOID data_section;
    PFVOID pOutBuf = pCtx->tmpBuffer;
    int r, i, j, max_possible;
    rtsmb_char domain [RTSMB_NB_NAME_SIZE + 1];

    command.domain = domain;
    command.domain_size = RTSMB_NB_NAME_SIZE;
    r = srv_cmd_read_rap_server_enum2 (pCtx->write_origin, pInBuf,
        pCtx->current_body_size - (rtsmb_size)(PDIFF (pInBuf, pCtx->read_origin)), pInHdr,
        &command);
    if (r == -1)
        return -1;

    size_left = MIN (command.receive_size, size_left);

    // Fill out parameters
    header.status = RAP_ERROR_ACCESS_DENIED;
    header.converter = 0;
    header.entry_count = 0;
    header.available_entries = 0;

    r = srv_cmd_fill_rap_share_enum_header (pCtx->tmpBuffer, pCtx->tmpBuffer,
        size_left, pOutHdr, &header);
    if (r == -1)
        return r;
    size_left -= (rtsmb_size)r;
    *param_size = (word)r;

    pOutBuf = PADD (pCtx->tmpBuffer, r);
    data_section = pOutBuf;

    rtp_sig_mutex_claim((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    header.entry_count = 0;
    header.available_entries = 0;
    info.info_total = 0;

    if (pCtx->state == BROWSE_FAIL)
    {
        /* domain is invalid.   tell client */
        header.status = RAP_NERR_INVALID_DOMAIN;
        srv_cmd_fill_rap_share_enum_header (pCtx->tmpBuffer, pCtx->tmpBuffer,
            size_left, pOutHdr, &header);
        return r;
    }
    else if (pCtx->state == BROWSE_FINISH)
    {
        /* we have previously been here and punted our netenum2 to another
           server.  here, we have the data now and we want to ship it out. */
        plist = prtsmb_srv_ctx->enum_results;
        max_possible = prtsmb_srv_ctx->enum_results_size;
    }
    /* is this a domain enum or server enum? */
    else if (command.server_type == SV_TYPE_DOMAIN_ENUM)
    {
        plist = prtsmb_srv_ctx->domain_table;
        max_possible = prtsmb_srv_ctx->domain_table_size;
    }
    else
    {
        char group_name [RTSMB_NB_NAME_SIZE + 1];

        plist = prtsmb_srv_ctx->server_table;
        max_possible = prtsmb_srv_ctx->server_table_size;

        rtsmb_util_rtsmb_to_ascii (command.domain, group_name, CFG_RTSMB_USER_CODEPAGE);

        /* if the group name is null or the same as our group, we just get it from
           our own list.  else, we need to outsource the netenum2 */
        if (group_name[0] && rtsmb_strcasecmp (group_name, rtsmb_srv_nbns_get_our_group (), CFG_RTSMB_USER_CODEPAGE) != 0)
        {
            rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);

            /* we have a server enum request outside of our own workgroup. */
            /* punt it off to the browse layer, which will come up with something to hand over */
            pCtx->state = BROWSE_MUTEX;
            pCtx->server_enum_type = command.server_type;
            tc_strcpy (pCtx->server_enum_domain, group_name);

            rtsmb_srv_browse_finish_server_enum (pCtx);

            return -2; /* tell upper layers to not send response yet */
        }
    }

    // find out how many servers there are.
    for (i = 0; i < max_possible; i++)
    {
        if (plist[i].type & command.server_type)
        {
            info.info_total++;
        }
    }

    // pack each server into the buffer.
    for (i = 0, j = 0, r = 0; i < max_possible; i++)
    {
        int this_r;
        rtsmb_char comment [RTSMB_MAX_COMMENT_SIZE + 1];

        /* take care of non-used types (0-value 'type') and
           servers we aren't interested in */
        if ((plist[i].type & command.server_type) == 0)
        {
            continue;
        }

        info.info_num = info.info_total - (j++) - 1;

        rtsmb_util_ascii_to_rtsmb (plist[i].name, info.name, CFG_RTSMB_USER_CODEPAGE);
        info.type = plist[i].type;
        rtsmb_util_ascii_to_rtsmb (plist[i].comment, comment, CFG_RTSMB_USER_CODEPAGE);
        info.comment = comment;
        info.version_minor = plist[i].version_minor;
        info.version_major = plist[i].version_major;

        header.entry_count++;
        header.available_entries++;

        if (command.information_level == 0)
        {
            this_r = srv_cmd_fill_rap_server_enum_info_0 (pCtx->tmpBuffer, pOutBuf,
                size_left, pOutHdr, &info);
        }
        else /* must be one... */
        {
            this_r = srv_cmd_fill_rap_server_enum_info_1 (pCtx->tmpBuffer, pOutBuf,
                size_left, pOutHdr, &info);
        }

        if (this_r == -1)
            break;

        r += this_r;
    }

    rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    if (r == -1)
    {
        header.status = RAP_NERR_BUFTOOSMALL;
        header.converter = 0;
        r = 0;
    }
    else
    {
        header.status = RAP_NERR_SUCCESS;
        header.converter = (word)(((int) data_section) & 0xFFFF);
    }

    srv_cmd_fill_rap_share_enum_header (pCtx->tmpBuffer, pCtx->tmpBuffer,
        size_left, pOutHdr, &header);

    return r;
}
コード例 #10
0
ファイル: srvcfg.c プロジェクト: layerfsd/cifssmb
int rtsmb_server_config(void)
{
   int i;
   prtsmb_srv_ctx = &rtsmb_srv_cfg_core;

#if ALLOC_FROM_HEAP
   unsigned char    * bigBuffers     = safemalloc(sizeof(unsigned char   ) * CFG_RTSMB_BIG_BUFFER_SIZE * CFG_RTSMB_NUM_BIG_BUFFERS);
   char             * bigBufferInUse = safemalloc(sizeof(char            ) * CFG_RTSMB_NUM_BIG_BUFFERS);
   NET_THREAD_T     * threads        = safemalloc(sizeof(NET_THREAD_T    ) * (CFG_RTSMB_MAX_THREADS + 1));
   char             * threadsInUse   = safemalloc(sizeof(char            ) * (CFG_RTSMB_MAX_THREADS + 1));
   NET_SESSIONCTX_T * sessions       = safemalloc(sizeof(NET_SESSIONCTX_T) * CFG_RTSMB_MAX_SESSIONS);
   char             * sessionsInUse  = safemalloc(sizeof(char            ) * CFG_RTSMB_MAX_SESSIONS);
   unsigned long    * activeSessions = safemalloc(sizeof(unsigned long   ) * CFG_RTSMB_MAX_SESSIONS);
   USER_T           * uids           = safemalloc(sizeof(USER_T          ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_UIDS_PER_SESSION);
   SEARCH_T         * searches       = safemalloc(sizeof(SEARCH_T        ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_UIDS_PER_SESSION * CFG_RTSMB_MAX_SEARCHES_PER_UID);
   PFID             * uid_fids       = safemalloc(sizeof(PFID            ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_UIDS_PER_SESSION * CFG_RTSMB_MAX_FIDS_PER_UID);
   TREE_T           * trees          = safemalloc(sizeof(TREE_T          ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_TREES_PER_SESSION);
   PFID             * tree_fids      = safemalloc(sizeof(PFID            ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_TREES_PER_SESSION * CFG_RTSMB_MAX_FIDS_PER_TREE);
   FID_T            * fids           = safemalloc(sizeof(FID_T           ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_FIDS_PER_SESSION);
   PNET_SESSIONCTX  * sessionList    = safemalloc(sizeof(PNET_SESSIONCTX ) * (CFG_RTSMB_MAX_THREADS + 1) * CFG_RTSMB_MAX_SESSIONS);
   byte             * inBuffer       = safemalloc(sizeof(byte            ) * (CFG_RTSMB_MAX_THREADS + 1) * CFG_RTSMB_SMALL_BUFFER_SIZE);
   byte             * outBuffer      = safemalloc(sizeof(byte            ) * (CFG_RTSMB_MAX_THREADS + 1) * CFG_RTSMB_SMALL_BUFFER_SIZE);
   byte             * tmpBuffer      = safemalloc(sizeof(byte            ) * (CFG_RTSMB_MAX_THREADS + 1) * CFG_RTSMB_SMALL_BUFFER_SIZE);
   byte             * namesrvBuffer  = safemalloc(sizeof(byte            ) * CFG_RTSMB_SMALL_BUFFER_SIZE);
   byte             * client_buffer  = safemalloc(sizeof(byte            ) * CFG_RTSMB_SMALL_BUFFER_SIZE);
   SR_RESOURCE_T    * shareTable     = safemalloc(sizeof(SR_RESOURCE_T   ) * CFG_RTSMB_MAX_SHARES);
   USERDATA_T       * users          = safemalloc(sizeof(USERDATA_T      ) * CFG_RTSMB_MAX_USERS);
   BBOOL            * user_groups    = safemalloc(sizeof(BBOOL           ) * CFG_RTSMB_MAX_USERS * CFG_RTSMB_MAX_GROUPS);
   byte             * access_table   = safemalloc(sizeof(byte            ) * ((CFG_RTSMB_MAX_SHARES * BITS_PER_TABLE_ENTRY / 8) + 1) * CFG_RTSMB_MAX_GROUPS);
   ACCESS_TABLE_T   * groups         = safemalloc(sizeof(ACCESS_TABLE_T  ) * CFG_RTSMB_MAX_GROUPS);
   char             * local_master   = safemalloc(sizeof(char            ) * (RTSMB_NB_NAME_SIZE + 1));
   RTSMB_BROWSE_SERVER_INFO * server_table = safemalloc(sizeof(RTSMB_BROWSE_SERVER_INFO) * CFG_RTSMB_BROWSE_MAX_SERVER_INFOS);
   RTSMB_BROWSE_SERVER_INFO * domain_table = safemalloc(sizeof(RTSMB_BROWSE_SERVER_INFO) * CFG_RTSMB_BROWSE_MAX_DOMAIN_INFOS);
   RTSMB_BROWSE_SERVER_INFO * enum_results = safemalloc(sizeof(RTSMB_BROWSE_SERVER_INFO) * MAX(CFG_RTSMB_BROWSE_MAX_SERVER_INFOS, CFG_RTSMB_BROWSE_MAX_DOMAIN_INFOS));
#endif

   prtsmb_srv_ctx->max_threads           = CFG_RTSMB_MAX_THREADS;
   prtsmb_srv_ctx->max_sessions          = CFG_RTSMB_MAX_SESSIONS;
   prtsmb_srv_ctx->max_uids_per_session  = CFG_RTSMB_MAX_UIDS_PER_SESSION;
   prtsmb_srv_ctx->max_fids_per_tree     = CFG_RTSMB_MAX_FIDS_PER_TREE;
   prtsmb_srv_ctx->max_searches_per_uid  = CFG_RTSMB_MAX_SEARCHES_PER_UID;
   prtsmb_srv_ctx->max_shares            = CFG_RTSMB_MAX_SHARES;
   prtsmb_srv_ctx->max_groups            = CFG_RTSMB_MAX_GROUPS;
   prtsmb_srv_ctx->max_users             = CFG_RTSMB_MAX_USERS;
   prtsmb_srv_ctx->small_buffer_size     = CFG_RTSMB_SMALL_BUFFER_SIZE;
   prtsmb_srv_ctx->big_buffer_size       = CFG_RTSMB_BIG_BUFFER_SIZE;
   prtsmb_srv_ctx->num_big_buffers       = CFG_RTSMB_NUM_BIG_BUFFERS;
   prtsmb_srv_ctx->max_fids_per_uid      = CFG_RTSMB_MAX_FIDS_PER_UID;
   prtsmb_srv_ctx->max_fids_per_session  = CFG_RTSMB_MAX_FIDS_PER_SESSION;
   prtsmb_srv_ctx->max_trees_per_session = CFG_RTSMB_MAX_TREES_PER_SESSION;
   prtsmb_srv_ctx->server_table_size     = CFG_RTSMB_BROWSE_MAX_SERVER_INFOS;
   prtsmb_srv_ctx->domain_table_size     = CFG_RTSMB_BROWSE_MAX_DOMAIN_INFOS;
   prtsmb_srv_ctx->enum_results_size     = MAX (CFG_RTSMB_BROWSE_MAX_DOMAIN_INFOS, CFG_RTSMB_BROWSE_MAX_SERVER_INFOS);

   rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->bufsem, (const char*)0);
   rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->authsem, (const char*)0);
   rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->sharesem, (const char*)0);
   rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->printersem, (const char*)0);
   rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->cachesem, (const char*)0);
   rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->mailPDCNameSem, (const char*)0);
   rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->netsem, (const char*)0);
   rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->enum_results_mutex, (const char*)0);

  #if CFG_RTSMB_NUM_BIG_BUFFERS
   prtsmb_srv_ctx->bigBuffers           = bigBuffers;
   prtsmb_srv_ctx->bigBufferInUse       = bigBufferInUse;

  #endif
   prtsmb_srv_ctx->threads              = threads;
   prtsmb_srv_ctx->threadsInUse         = threadsInUse;

   prtsmb_srv_ctx->sessions             = sessions;
   prtsmb_srv_ctx->sessionsInUse        = sessionsInUse;

   prtsmb_srv_ctx->activeSessions       = activeSessions;
   prtsmb_srv_ctx->namesrvBuffer        = namesrvBuffer;
   prtsmb_srv_ctx->client_buffer        = client_buffer;
   prtsmb_srv_ctx->shareTable           = shareTable;
   prtsmb_srv_ctx->userList.users       = users;
   prtsmb_srv_ctx->groupList.groups     = groups;
   prtsmb_srv_ctx->local_master         = local_master;
   prtsmb_srv_ctx->server_table         = server_table;
   prtsmb_srv_ctx->domain_table         = domain_table;
   prtsmb_srv_ctx->enum_results         = enum_results;

   for (i = 0; i < CFG_RTSMB_MAX_GROUPS; i++)
   {
      prtsmb_srv_ctx->groupList.groups[i].table = &access_table[i * ((CFG_RTSMB_MAX_SHARES * BITS_PER_TABLE_ENTRY / 8) + 1)];
   }

   for (i = 0; i < CFG_RTSMB_MAX_USERS; i++)
   {
      prtsmb_srv_ctx->userList.users[i].groups = &user_groups[i * CFG_RTSMB_MAX_GROUPS];
   }

   for (i = 0; i < CFG_RTSMB_MAX_SESSIONS; i++)
   {
	  rtp_sig_mutex_alloc((RTP_MUTEX *) &prtsmb_srv_ctx->activeSessions[i], (const char*)0);

      prtsmb_srv_ctx->sessions[i].smbCtx.uids  = &uids  [i * CFG_RTSMB_MAX_UIDS_PER_SESSION];
      prtsmb_srv_ctx->sessions[i].smbCtx.trees = &trees [i * CFG_RTSMB_MAX_TREES_PER_SESSION];
      prtsmb_srv_ctx->sessions[i].smbCtx.fids  = &fids  [i * CFG_RTSMB_MAX_FIDS_PER_SESSION];
   }

   for (i=0; i < CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_UIDS_PER_SESSION; i++)
   {
      uids[i].searches = &searches [i * CFG_RTSMB_MAX_SEARCHES_PER_UID];
      uids[i].fids     = &uid_fids [i * CFG_RTSMB_MAX_FIDS_PER_UID];
   }

   for (i=0; i < CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_TREES_PER_SESSION; i++)
   {
      trees[i].fids = &tree_fids [i * CFG_RTSMB_MAX_FIDS_PER_TREE];
   }

   for (i=0; i < CFG_RTSMB_MAX_THREADS + 1; i++)
   {
      threads[i].sessionList = &sessionList [i * CFG_RTSMB_MAX_SESSIONS];
      threads[i].inBuffer    = &inBuffer    [i * CFG_RTSMB_SMALL_BUFFER_SIZE];
      threads[i].outBuffer   = &outBuffer   [i * CFG_RTSMB_SMALL_BUFFER_SIZE];
      threads[i].tmpBuffer   = &tmpBuffer   [i * CFG_RTSMB_SMALL_BUFFER_SIZE];
   }

   tc_strcpy (prtsmb_srv_ctx->local_master, "");
   prtsmb_srv_ctx->enum_results_in_use = FALSE;

   for (i = 0; i < prtsmb_srv_ctx->server_table_size; i++)
   {
      prtsmb_srv_ctx->server_table[i].type = 0;
   }

   for (i = 0; i < prtsmb_srv_ctx->domain_table_size; i++)
   {
      prtsmb_srv_ctx->domain_table[i].type = 0;
   }

   return 1;
}
コード例 #11
0
ファイル: wcache.cpp プロジェクト: peteratebs/webcwebbrowser
int wcache_flush(struct wcache_ctx *cc)
{
struct wcache_entry *entry;
WEBC_UINT16 saveFlags;
void *fp;
char filename[WEBC_CACHE_MAX_PATH_LEN];
#if (WEBC_CACHE_SAVE_DIRECTORY)
void *fpDir;
char lineBuffer[512];
#endif

	tc_strcpy(filename, cc->cachePrefix);
	tc_strcat(filename, "index.dat");

	if (cc->spec.sys_open(cc->sysPtr, filename, &fp, WEBC_CO_CREATE) < 0)
	{
		return (-1);
	}

#if (WEBC_CACHE_SAVE_DIRECTORY)
	tc_strcpy(filename, cc->cachePrefix);
	tc_strcat(filename, "index.txt");

	if (cc->spec.sys_open(cc->sysPtr, filename, &fpDir, WEBC_CO_CREATE) < 0)
	{
		cc->spec.sys_close(cc->sysPtr, fp);
		return (-1);
	}
#endif

	cc->spec.sys_write(cc->sysPtr, fp, (WEBC_PFBYTE) cc, sizeof(struct wcache_ctx));

#if (WEBC_CACHE_SAVE_DIRECTORY)
	rtp_sprintf(lineBuffer,
			"   index   mime-type          size   flags   date                            expires                         key\r\n"
			"   =====   =========          ====   =====   ====                            =======                         ===\r\n"
			"\r\n");
	cc->spec.sys_write(cc->sysPtr, fpDir, (WEBC_PFBYTE) lineBuffer, tc_strlen(lineBuffer));
#endif


	// reverse the order of all entries so we'll load it back in mru order
	entry = cc->lru;
	while (entry)
	{
		// if we dump the index in the middle of a cache op, then we don't want to have
		//  the entry marked as "open" when we re-load the index
		saveFlags = entry->flags;
		entry->flags &= ~(WEBC_CACHE_ENTRY_LOCKED | WEBC_CACHE_ENTRY_INUSE | WEBC_CACHE_ENTRY_LOCK_MASK);

		cc->spec.sys_write(cc->sysPtr, fp, (WEBC_PFBYTE) entry, sizeof(struct wcache_entry) - sizeof(char *));
		cc->spec.sys_write(cc->sysPtr, fp, (WEBC_PFBYTE) entry->key, entry->keyLen*sizeof(char));

#if (WEBC_CACHE_SAVE_DIRECTORY)
		rtp_sprintf(lineBuffer, "%8x   %9d  %12ld    %04hx   ",
		             entry->fileIndex,
		             entry->dataType,
		             entry->size,
		             entry->flags);

		ebs_print_time(lineBuffer + tc_strlen(lineBuffer), entry->date, 0);
		tc_strcat(lineBuffer, "   ");

		ebs_print_time(lineBuffer + tc_strlen(lineBuffer), entry->expires, 0);
		tc_strcat(lineBuffer, "   ");

		tc_strcat(lineBuffer, entry->key);
		tc_strcat(lineBuffer, "\r\n");

		cc->spec.sys_write(cc->sysPtr, fpDir, (WEBC_PFBYTE) lineBuffer, tc_strlen(lineBuffer));
#endif // WEBC_CACHE_SAVE_DIRECTORY

		entry->flags = saveFlags;
		entry = entry->prev;
	}

	cc->spec.sys_close(cc->sysPtr, fp);

#if (WEBC_CACHE_SAVE_DIRECTORY)
	cc->spec.sys_close(cc->sysPtr, fpDir);
#endif

	return (0);
}
コード例 #12
0
ファイル: wcache.cpp プロジェクト: peteratebs/webcwebbrowser
int wcache_init(struct wcache_ctx *cc, const char *cachePrefix, long size,
                long maxFiles, const struct wcache_system_spec *spec,
                void *sysPtr)
{
void *fp;
char indexfile[WEBC_CACHE_MAX_PATH_LEN];
int index;
struct wcache_entry *entry;
int resetCache = 1;
char keyTemp[WEBC_CACHE_MAX_KEY_LEN+1];

	tc_strcpy(indexfile, cachePrefix);
	tc_strcat(indexfile, "index.dat");

	if (spec->sys_open(sysPtr, indexfile, &fp, WEBC_CO_READ) >= 0)
	{
		if (spec->sys_read(sysPtr, fp, (WEBC_PFBYTE) cc, sizeof(struct wcache_ctx)) < sizeof(struct wcache_ctx))
		{
			spec->sys_close(sysPtr, fp);
			spec->sys_remove(sysPtr, indexfile);
		}
		else
		{
			long entrySize = sizeof(struct wcache_entry) - sizeof(char *);

			cc->index = 0;
			cc->lru = 0;
			for (index=0; index < cc->numFiles; index++)
			{
				entry = (struct wcache_entry *) WEBC_MALLOC(sizeof(struct wcache_entry));
				if (!entry)
				{
					wcache_free(cc);
					resetCache = 1;
					break;
				}

				if (spec->sys_read(sysPtr, fp, (WEBC_PFBYTE) entry, entrySize) < entrySize)
				{
					wcache_free(cc);
					resetCache = 1;
					break;
				}

				entry->keyLen = EBSMIN(entry->keyLen, WEBC_CACHE_MAX_KEY_LEN - 1);
				spec->sys_read(sysPtr, fp, (WEBC_PFBYTE) keyTemp, entry->keyLen*sizeof(char));
				keyTemp[entry->keyLen] = '\0';
				entry->key = webc_malloc_string_copy_8(keyTemp, __FILE__, __LINE__);
				if (!entry->key)
				{
					WEBC_FREE(entry);
					entry = 0;
					wcache_free(cc);
					resetCache = 1;
					break;
				}
				entry->next = 0;
				entry->prev = 0;
				INSERT_FRONT_CACHE(cc,entry);
			}

			if (index == cc->numFiles)
			{
				resetCache = 0;
			}

			spec->sys_close(sysPtr, fp);
		}
	}

	// just copy the system spec directly
	cc->spec = *spec;
	cc->sysPtr = sysPtr;

	if (resetCache)
	{
		// no index exists; create one
		tc_strncpy(cc->cachePrefix, cachePrefix, WEBC_CACHE_MAX_PREFIX_LEN-1);
		cc->cachePrefix[WEBC_CACHE_MAX_PREFIX_LEN-1] = 0;
		cc->bytesMax = size;
		cc->bytesUsed = sizeof(wcache_ctx);
		cc->numFiles = 0;
		cc->maxFiles = maxFiles;
		cc->initialized = 1;
		cc->index = 0;
		cc->lru = 0;
		wcache_flush(cc);
	}

	return (0);
}
コード例 #13
0
ファイル: SNTP.C プロジェクト: Strongc/DC_source
int xn_sntp_get_time(PEBS_SYS_TIME tme, PFBYTE ip_sntp_server, int version)
{
SOCKET socket_no;
NTP_TIME_FORMAT current_timestamp= {0, 0};  /* local time */
dword start_ticks;
int rel_val;
EBSTIME res_ebs_tod = {0,0};
int day_of_week;

    /* send the request                                                */
    /* NOTE: most servers respond to NTP_SYM_ACTIVE but some only      */
    /*       respond to NTP_REQUEST; it looks like NTP servers respond */
    /*       to NTP_SYM_ACTIVE and SNTP respond to NTP_REQUEST         */
    if (sntp_request_time(ip_sntp_server, &socket_no, &current_timestamp, 
                          version, NTP_SYM_ACTIVE, &start_ticks,
                          (PEBSTIME)&res_ebs_tod) < 0)

    {
            return(-1);
    }

    /* wait for response   */
    if (!do_read_select(socket_no, CFG_SNTP_RCV_TMO))
    {
        DEBUG_ERROR("xn_sntp_get_time: (NTP_SYM_ACTIVE)timed out waiting for response", NOVAR, 0, 0);
        closesocket(socket_no);
        if (sntp_request_time(ip_sntp_server, &socket_no, &current_timestamp, 
                              version, NTP_REQUEST, &start_ticks,
                              (PEBSTIME)&res_ebs_tod) < 0)
        {
            return(-1);
        }

        if (!do_read_select(socket_no, CFG_SNTP_RCV_TMO))
        {
            DEBUG_ERROR("xn_sntp_get_time: (NTP_REQUEST) timed out waiting for response", NOVAR, 0, 0);
            closesocket(socket_no);
            return(set_errno(ETIMEDOUT));
        }
    }

    /* process the response   */
    rel_val = sntp_process_result(socket_no, &current_timestamp, version,
                                  start_ticks, (PEBSTIME)&res_ebs_tod);
    if (rel_val == -1)
        return(-1);

#if (DISPLAY_TIMES)
    DEBUG_ERROR("xn_sntp: TIME: seconds, frac_sec ",
        DINT2, res_ebs_tod.year, res_ebs_tod.second);
#endif

    convert_ebs_to_time((PEBSTIME)&res_ebs_tod, 
                        &tme->year, &tme->month, &tme->day,
                        &tme->hour, &tme->minute, &tme->second);
    tme->month++;
    tme->msec = FRAC_TO_MSEC_CONV(current_timestamp.frac_sec);

    /* set day of the week name   */
    day_of_week = ebs_date_to_dayofweek(tme->day, tme->month, tme->year);
    tc_strcpy(tme->day_of_week, weekday_names[day_of_week % 7]);

#if (DISPLAY_TIMES)
    DEBUG_ERROR("xn_sntp: year, month: ",
                        DINT2, tme->year, tme->month);
    DEBUG_ERROR("xn_sntp: day, hour: ",
                        DINT2, tme->day, tme->hour);
    DEBUG_ERROR("xn_sntp: minute, second: ",
                        DINT2, tme->minute, tme->second);
#endif
    return(0);
}