Exemplo n.º 1
0
/**************************************************************************
 * TakeOwnershipOfFile [SETUPAPI.@]
 *
 * Takes the ownership of the given file.
 *
 * PARAMS
 *     lpFileName [I] Name of the file
 *
 * RETURNS
 *     Success: ERROR_SUCCESS
 *     Failure: other
 */
DWORD WINAPI TakeOwnershipOfFile(LPCWSTR lpFileName)
{
    SECURITY_DESCRIPTOR SecDesc;
    HANDLE hToken = NULL;
    PTOKEN_OWNER pOwner = NULL;
    DWORD dwError;
    DWORD dwSize;

    TRACE("%s\n", debugstr_w(lpFileName));

    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
        return GetLastError();

    if (!GetTokenInformation(hToken, TokenOwner, NULL, 0, &dwSize))
    {
        goto fail;
    }

    pOwner = (PTOKEN_OWNER)MyMalloc(dwSize);
    if (pOwner == NULL)
    {
        CloseHandle(hToken);
        return ERROR_NOT_ENOUGH_MEMORY;
    }

    if (!GetTokenInformation(hToken, TokenOwner, pOwner, dwSize, &dwSize))
    {
        goto fail;
    }

    if (!InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION))
    {
        goto fail;
    }

    if (!SetSecurityDescriptorOwner(&SecDesc, pOwner->Owner, FALSE))
    {
        goto fail;
    }

    if (!SetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION, &SecDesc))
    {
        goto fail;
    }

    MyFree(pOwner);
    CloseHandle(hToken);

    return ERROR_SUCCESS;

fail:;
    dwError = GetLastError();

    MyFree(pOwner);

    if (hToken != NULL)
        CloseHandle(hToken);

    return dwError;
}
Exemplo n.º 2
0
/***********************************************************************
 *      SetupGetFileCompressionInfoW  (SETUPAPI.@)
 *
 * Get compression type and compressed/uncompressed sizes of a given file.
 *
 * PARAMS
 *  source      [I] File to examine.
 *  name        [O] Actual filename used.
 *  source_size [O] Size of compressed file.
 *  target_size [O] Size of uncompressed file.
 *  type        [O] Compression type.
 *
 * RETURNS
 *  Success: ERROR_SUCCESS
 *  Failure: Win32 error code.
 */
DWORD WINAPI SetupGetFileCompressionInfoW( PCWSTR source, PWSTR *name, PDWORD source_size,
                                           PDWORD target_size, PUINT type )
{
    BOOL ret;
    DWORD error, required;
    LPWSTR actual_name;

    TRACE("%s, %p, %p, %p, %p\n", debugstr_w(source), name, source_size, target_size, type);

    if (!source || !name || !source_size || !target_size || !type)
        return ERROR_INVALID_PARAMETER;

    ret = SetupGetFileCompressionInfoExW( source, NULL, 0, &required, NULL, NULL, NULL );
    if (!(actual_name = MyMalloc( required*sizeof(WCHAR) ))) return ERROR_NOT_ENOUGH_MEMORY;

    ret = SetupGetFileCompressionInfoExW( source, actual_name, required, &required,
                                          source_size, target_size, type );
    if (!ret)
    {
        error = GetLastError();
        MyFree( actual_name );
        return error;
    }
    *name = actual_name;
    return ERROR_SUCCESS;
}
Exemplo n.º 3
0
aServer	*make_server(aClient *cptr)
{
	aServer	*serv = cptr->serv;

	if (!serv)
	    {
		serv = (aServer *)MyMalloc(sizeof(aServer));
		memset(serv, 0, sizeof(aServer));
#ifdef	DEBUGMODE
		servs.inuse++;
#endif
		cptr->serv = serv;
		cptr->name = serv->namebuf;
		*serv->namebuf = '\0';
		serv->user = NULL;
		serv->snum = -1;
		*serv->by = '\0';
		serv->up = NULL;
		serv->refcnt = 1;
		serv->nexts = NULL;
		serv->prevs = NULL;
		serv->bcptr = cptr;
		serv->lastload = 0;
	    }
	return cptr->serv;
}
Exemplo n.º 4
0
aClass *make_class()
{
  aClass        *tmp;

  tmp = (aClass *)MyMalloc(sizeof(aClass));
  return tmp;
}
Exemplo n.º 5
0
int
init_events()
{
  struct timeval tv;
  struct event *timer = MyMalloc(sizeof(struct event));
//  struct event *sigint = MyMalloc(sizeof(struct event));

  ev_base = event_init();

  event_set_log_callback(&libevent_log_cb);

  if(evdns_init() == -1)
  {
    ilog(L_ERROR, "libevent dns init failed");
    return FALSE;
  }

  ilog(L_DEBUG, "libevent init %p", ev_base);

  memset(&tv, 0, sizeof(tv));

  tv.tv_usec = 100;
  event_set(timer, -1, EV_PERSIST, timer_callback, timer);
  event_base_set(ev_base, timer);
  evtimer_add(timer, &tv);

/*  event_set(sigint, SIGINT, EV_SIGNAL|EV_PERSIST, sigint_callback, sigint);
  event_add(sigint, NULL);*/

  return TRUE;
}
Exemplo n.º 6
0
char *
crypt_pass(char *password, int encode)
{
  EVP_MD_CTX *mdctx;
  const EVP_MD *md;
  unsigned char md_value[EVP_MAX_MD_SIZE];
  char buffer[2*DIGEST_LEN + 1];
  char *ret;
  unsigned int md_len;

  md = EVP_get_digestbyname(DIGEST_FUNCTION);

  mdctx = EVP_MD_CTX_create();
  EVP_MD_CTX_init(mdctx);
  EVP_DigestInit_ex(mdctx, md, NULL);
  EVP_DigestUpdate(mdctx, password, strlen(password));
  EVP_DigestFinal_ex(mdctx, md_value, &md_len);
  EVP_MD_CTX_destroy(mdctx);

  if(encode)
  {
    base16_encode(buffer, sizeof(buffer), (char *)md_value, DIGEST_LEN);
    DupString(ret, buffer);
  }
  else
  {
    ret = MyMalloc(DIGEST_LEN);
    memcpy(ret, md_value, DIGEST_LEN);
  }
  return ret;
}
Exemplo n.º 7
0
int main(int argc, char **argv)
{
char* pw, *crypted_pw;

 crypt_mechs_root = (crypt_mechs_t*)MyMalloc(sizeof(crypt_mechs_t));
 crypt_mechs_root->mech = NULL;
 crypt_mechs_root->next = crypt_mechs_root->prev = NULL;

 if (argc < 2)
 {
  show_help();
  exit(0);
 }

 pw = parse_arguments(argc, argv);
 load_mechs();

 if (NULL == umkpasswd_conf->mech)
 {
  fprintf(stderr, "No mechanism specified.\n");
  abort();
 }

 if (NULL == pw)
 {
  pw = getpass("Password: "******"Crypted Pass: %s\n", crypted_pw);
 memset(pw, 0, strlen(pw));

return 0;
}
Exemplo n.º 8
0
aConfItem	*make_conf(void)
{
	Reg	aConfItem *aconf;

	aconf = (struct ConfItem *)MyMalloc(sizeof(aConfItem));

#ifdef	DEBUGMODE
	aconfs.inuse++;
#endif
	istat.is_conf++;
	istat.is_confmem += sizeof(aConfItem);

	bzero((char *)&aconf->ipnum, sizeof(struct IN_ADDR));
	aconf->clients = aconf->port = 0;
	aconf->next = NULL;
	aconf->host = aconf->passwd = aconf->name = aconf->name2 = NULL;
#ifdef XLINE
	aconf->name3 = NULL;
#endif
	aconf->ping = NULL;
	aconf->status = CONF_ILLEGAL;
	aconf->pref = -1;
	aconf->hold = time(NULL);
	aconf->source_ip = NULL;
	aconf->flags = 0L;
	Class(aconf) = NULL;
	return (aconf);
}
Exemplo n.º 9
0
void SndStreamCreate(BOOL bStereo,BOOL b16Bits, DWORD type, DWORD nStream)
{
    SNDMIXFORMAT fmt;
    DWORD sndType;
    DWORD i;
    DWORD iChn,iBits,iTypes;

    fmt.nSamplesPerSec=FREQ_DFLT;
    fmt.nChannels=(bStereo) ? 2: 1;
    iChn=(bStereo) ? 1 :0;
    fmt.wBitsPerSample=(b16Bits) ? 16 : 8;
    iBits=(b16Bits) ? 1: 0;

    iTypes=GETITYPES(type);
    //if it already initialized I destroy it I destroy it
    if(sndStream[iChn][iBits][iTypes].vlpss)
        SndStreamDestroyPerIndex(iChn,iBits,iTypes);
    sndType=SND_STREAMING;
    if(type & SND_3D )
        sndType|=SND_3D;
    if(type & SND_USECPURAM);
    sndType |= SND_USECPURAM; //
    sndStream[iChn][iBits][iTypes].vlpss=MyMalloc(LPSNDSTREAM,nStream);
    ASSERTOUTMEMORY(sndStream[iChn][iBits][iTypes].vlpss);

    for(i=0; i<nStream; i++) {
        sndStream[iChn][iBits][iTypes].vlpss[i]=HwSndStreamCreate(&fmt, sndType);
        if(!sndStream[iChn][iBits][iTypes].vlpss[i])
            break;
    }
    sndStream[iChn][iBits][iTypes].n=i;
}
Exemplo n.º 10
0
/* Initialize the msgtab parsing tree -orabidoo
 */
void init_tree_parse(struct Message *mptr)
{
  int i;
  struct Message *mpt = mptr;

  for (i=0; mpt->cmd; mpt++)
    i++;
  qsort((void *)mptr, i, sizeof(struct Message), 
                (int (*)(const void *, const void *)) mcmp);
  expect_malloc;
  msg_tree_root = (MESSAGE_TREE *)MyMalloc(sizeof(MESSAGE_TREE));
  malloc_log("init_tree_parse() allocating MESSAGE_TREE (%zd bytes) at %p",
             sizeof(MESSAGE_TREE), (void *)msg_tree_root);
  mpt = do_msg_tree(msg_tree_root, "", mptr);

  /*
   * this happens if one of the msgtab entries included characters
   * other than capital letters  -orabidoo
   */
  if (mpt->cmd)
    {
      logprintf(L_CRIT, "bad msgtab entry: ``%s''\n", mpt->cmd);
      exit(1);
    }
}
Exemplo n.º 11
0
void
AddBan(char *who, struct Channel *cptr, char *ban)

{
  time_t CurrTime = current_ts;
  struct ChannelBan *tempban;

  /* don't add any duplicates -- jilles */
  if (FindBan(cptr, ban) != NULL)
    return;

  tempban = (struct ChannelBan *) MyMalloc(sizeof(struct ChannelBan));
  memset(tempban, 0, sizeof(struct ChannelBan));

  if (who)
    tempban->who = MyStrdup(who);

  tempban->mask = MyStrdup(ban);
  tempban->when = CurrTime;
  tempban->next = cptr->firstban;
  tempban->prev = NULL;

  if (tempban->next)
    tempban->next->prev = tempban;
  cptr->firstban = tempban;
} /* AddBan() */
Exemplo n.º 12
0
/**************************************************************************
 * UnicodeToMultiByte [SETUPAPI.@]
 *
 * Converts a Unicode string to a multi-byte string.
 *
 * PARAMS
 *     lpUnicodeStr  [I] Unicode string to be converted
 *     uCodePage     [I] Code page
 *
 * RETURNS
 *     Success: pointer to the converted multi-byte string
 *     Failure: NULL
 *
 * NOTE
 *     Use MyFree to release the returned multi-byte string.
 */
LPSTR WINAPI UnicodeToMultiByte(LPCWSTR lpUnicodeStr, UINT uCodePage)
{
    LPSTR lpMultiByteStr;
    int nLength;

    TRACE("%s %d\n", debugstr_w(lpUnicodeStr), uCodePage);

    nLength = WideCharToMultiByte(uCodePage, 0, lpUnicodeStr, -1,
                                  NULL, 0, NULL, NULL);
    if (nLength == 0)
        return NULL;

    lpMultiByteStr = MyMalloc(nLength);
    if (lpMultiByteStr == NULL)
        return NULL;

    if (!WideCharToMultiByte(uCodePage, 0, lpUnicodeStr, -1,
                             lpMultiByteStr, nLength, NULL, NULL))
    {
        MyFree(lpMultiByteStr);
        return NULL;
    }

    return lpMultiByteStr;
}
Exemplo n.º 13
0
/***************************************************************************************************
*FunctionName: ReadLCDRegister
*Description: 读取屏幕寄存器值
*Input: reg -- 寄存器地址
*		len -- 读取长度
*Output: 
*Return: 
*Author: xsx
*Date: 2016年12月12日11:01:48
***************************************************************************************************/
static void ReadLCDRegister(unsigned char reg, unsigned char len)
{			
	char *q = NULL;
	
	txdat = MyMalloc(16);
	if(txdat == NULL)
		return;
	
	memset(txdat, 0, 16);
	q = txdat;
	
	*q++ = LCD_Head_1;
	*q++ = LCD_Head_2;
	*q++ = 1 + 4;
	
	*q++ = R_REGSITER;
	
	*q++ = reg;

	*q++ = len;
	
	CalModbusCRC16Fun2(txdat+3, 1 + 2, q);
	
	SendDataToQueue(GetUsart6TXQueue(), NULL, txdat, txdat[2]+3, 1, 50 / portTICK_RATE_MS, 100 / portTICK_RATE_MS, EnableUsart6TXInterrupt);
	
	MyFree(txdat);
}
Exemplo n.º 14
0
void
AddException(char *who, struct Channel *cptr, char *mask)

{
  struct Exception *tempe;

  /* don't add any duplicates -- jilles */
  if (FindException(cptr, mask) != NULL)
    return;

  tempe = (struct Exception *) MyMalloc(sizeof(struct Exception));
  memset(tempe, 0, sizeof(struct Exception));

  if (who)
    tempe->who = MyStrdup(who);

  tempe->mask = MyStrdup(mask);
  tempe->when = current_ts;

  tempe->next = cptr->exceptlist;
  tempe->prev = NULL;
  if (tempe->next)
    tempe->next->prev = tempe;

  cptr->exceptlist = tempe;
} /* AddException() */
Exemplo n.º 15
0
/***************************************************************************************************
*FunctionName: WriteRegister
*Description: 写寄存器
*Input: reg -- 寄存器地址
*		data -- 写入数据
*		datalen -- 写入数据的长度
*Output: 无
*Author: xsx
*Date: 2016年8月5日15:18:01
***************************************************************************************************/
static void WriteLCDRegister(unsigned char reg, void *data, unsigned char len)
{			
	char *q = NULL;
	unsigned char *p = (unsigned char *)data;
	unsigned char i=0;
	
	txdat = MyMalloc(len + 10);
	if(txdat == NULL)
		return;
	
	memset(txdat, 0, len + 10);
	q = txdat;
	
	*q++ = LCD_Head_1;
	*q++ = LCD_Head_2;
	*q++ = len+4;
	
	*q++ = W_REGSITER;
	
	*q++ = reg;

	for(i=0; i<len; i++)
		*q++ = *p++;
	
	CalModbusCRC16Fun2(txdat+3, len + 2, q);
	
	SendDataToQueue(GetUsart6TXQueue(), NULL, txdat, txdat[2]+3, 1, 50 / portTICK_RATE_MS, 100 / portTICK_RATE_MS, EnableUsart6TXInterrupt);
	
	MyFree(txdat);
}
Exemplo n.º 16
0
void	inithashtables(void)
{
	Reg int i;

	clear_client_hash_table((_HASHSIZE) ? _HASHSIZE : HASHSIZE);
	clear_uid_hash_table((_UIDSIZE) ? _UIDSIZE : UIDSIZE);
	clear_channel_hash_table((_CHANNELHASHSIZE) ? _CHANNELHASHSIZE
                                 : CHANNELHASHSIZE);
	clear_sid_hash_table((_SIDSIZE) ? _SIDSIZE : SIDSIZE);
#ifdef USE_HOSTHASH
	clear_hostname_hash_table((_HOSTNAMEHASHSIZE) ? _HOSTNAMEHASHSIZE : 
				   HOSTNAMEHASHSIZE);
#endif
#ifdef USE_IPHASH
	clear_ip_hash_table((_IPHASHSIZE) ? _IPHASHSIZE : IPHASHSIZE);
#endif

	/*
	 * Moved multiplication out from the hashfunctions and into
	 * a pre-generated lookup table. Should save some CPU usage
	 * even on machines with a fast mathprocessor.  -- Core
	 */
	hashtab = (u_int *) MyMalloc(256 * sizeof(u_int));
	for (i = 0; i < 256; i++)
		hashtab[i] = tolower((char)i) * 109;
}
Exemplo n.º 17
0
static int init_begin(adns_state *ads_r, adns_initflags flags, FBFILE *diagfile)
{
  adns_state ads;
  

  ads = MyMalloc(sizeof(*ads));

  /* Under hybrid, MyMalloc would have aborted already */
#if 0
 if (!ads) return errno;
#endif

  ads->iflags= flags;
  ads->diagfile= diagfile;
  ads->configerrno= 0;
  ADNS_LIST_INIT(ads->udpw);
  ADNS_LIST_INIT(ads->tcpw);
  ADNS_LIST_INIT(ads->childw);
  ADNS_LIST_INIT(ads->output);
  ads->forallnext= 0;
  ads->nextid= 0x311f;
  ads->udpsocket= ads->tcpsocket= -1;
  adns__vbuf_init(&ads->tcpsend);
  adns__vbuf_init(&ads->tcprecv);
  ads->tcprecv_skip= 0;
  ads->nservers= ads->nsortlist= ads->nsearchlist= ads->tcpserver= 0;
  ads->searchndots= 1;
  ads->tcpstate= server_disconnected;
  timerclear(&ads->tcptimeout);
  ads->searchlist= 0;

  *ads_r= ads;
  return 0;
}
Exemplo n.º 18
0
/**************************************************************************
 * QueryRegistryValue [SETUPAPI.@]
 *
 * Retrieves value data from the registry and allocates memory for the
 * value data.
 *
 * PARAMS
 *     hKey        [I] Handle of the key to query
 *     lpValueName [I] Name of value under hkey to query
 *     lpData      [O] Destination for the values contents,
 *     lpType      [O] Destination for the value type
 *     lpcbData    [O] Destination for the size of data
 *
 * RETURNS
 *     Success: ERROR_SUCCESS
 *     Failure: Otherwise
 *
 * NOTES
 *     Use MyFree to release the lpData buffer.
 */
LONG WINAPI QueryRegistryValue(HKEY hKey,
                               LPCWSTR lpValueName,
                               LPBYTE  *lpData,
                               LPDWORD lpType,
                               LPDWORD lpcbData)
{
    LONG lError;

    TRACE("%p %s %p %p %p\n",
          hKey, debugstr_w(lpValueName), lpData, lpType, lpcbData);

    /* Get required buffer size */
    *lpcbData = 0;
    lError = RegQueryValueExW(hKey, lpValueName, 0, lpType, NULL, lpcbData);
    if (lError != ERROR_SUCCESS)
        return lError;

    /* Allocate buffer */
    *lpData = MyMalloc(*lpcbData);
    if (*lpData == NULL)
        return ERROR_NOT_ENOUGH_MEMORY;

    /* Query registry value */
    lError = RegQueryValueExW(hKey, lpValueName, 0, lpType, *lpData, lpcbData);
    if (lError != ERROR_SUCCESS)
        MyFree(*lpData);

    return lError;
}
Exemplo n.º 19
0
/*
**  Get Channel block for i (and allocate a new channel
**  block, if it didn't exists before).
*/
aChannel *get_channel(aClient *cptr, char *chname, int flag)
{
	aChannel *chptr;
	int  len;

	if (BadPtr(chname))
		return NULL;

	len = strlen(chname);
	if (MyClient(cptr) && len > CHANNELLEN)
	{
		len = CHANNELLEN;
		*(chname + CHANNELLEN) = '\0';
	}
	if ((chptr = find_channel(chname, (aChannel *)NULL)))
		return (chptr);
	if (flag == CREATE)
	{
		chptr = (aChannel *)MyMalloc(sizeof(aChannel) + len);
		bzero((char *)chptr, sizeof(aChannel));
		strncpyzt(chptr->chname, chname, len + 1);
		if (channel)
			channel->prevch = chptr;
		chptr->topic = NULL;
		chptr->topic_nick = NULL;
		chptr->prevch = NULL;
		chptr->nextch = channel;
		chptr->creationtime = MyClient(cptr) ? TStime() : (TS)0;
		channel = chptr;
		(void)add_to_channel_hash_table(chname, chptr);
		IRCstats.channels++;
		RunHook2(HOOKTYPE_CHANNEL_CREATE, cptr, chptr);
	}
	return chptr;
}
Exemplo n.º 20
0
/***************************************************************************************************
*FunctionName: SystemReset
*Description: 恢复出厂设置
*Input: 
*Output: 
*Return: 
*Author: xsx
*Date: 2017年2月16日11:20:46
***************************************************************************************************/
MyState_TypeDef SystemReset(void)
{
	SystemSetData * systemSetData = NULL;
	
	systemSetData = MyMalloc(sizeof(SystemSetData));
	if(systemSetData)
	{
		//恢复默认
		setDefaultSystemSetData(systemSetData);
		//保留设备信息
		getDeviceInfo(&(systemSetData->deviceInfo));
		//保留已校准的led值
		systemSetData->testLedLightIntensity = getTestLedLightIntensity(getGBSystemSetData());

		if(My_Pass != SaveSystemSetData(systemSetData))
			return My_Fail;
	}
	else
		return My_Fail;
	
	//删除操作人
	if(My_Fail == ClearUsers())
		return My_Fail;
	
	//删除wifi数据
	if(My_Fail == ClearWifi())
		return My_Fail;
	
	return My_Pass;
}
Exemplo n.º 21
0
/** Registers a service mapping to the pseudocommand handler.
 * @param[in] map Service mapping to add.
 * @return Non-zero on success; zero if a command already used the name.
 */
int register_mapping(struct s_map *map)
{
  struct Message *msg;

  if (msg_tree_parse(map->command, &msg_tree))
    return 0;

  msg = (struct Message *)MyMalloc(sizeof(struct Message));
  msg->cmd = map->command;
  msg->tok = map->command;
  msg->count = 0;
  msg->parameters = 2;
  msg->flags = MFLG_EXTRA;
  if (!(map->flags & SMAP_FAST))
    msg->flags |= MFLG_SLOW;
  msg->bytes = 0;
  msg->extra = map;

  msg->handlers[UNREGISTERED_HANDLER] = m_ignore;
  msg->handlers[CLIENT_HANDLER] = m_pseudo;
  msg->handlers[SERVER_HANDLER] = m_ignore;
  msg->handlers[OPER_HANDLER]   = m_pseudo;
  msg->handlers[SERVICE_HANDLER] = m_ignore;

  add_msg_element(&msg_tree, msg, msg->cmd);
  map->msg = msg;

  return 1;
}
Exemplo n.º 22
0
/** Create a Zline structure.
 * @param[in] mask Mask.
 * @param[in] reason Reason for Z-line.
 * @param[in] expire Expiration timestamp.
 * @param[in] lastmod Last modification timestamp.
 * @param[in] flags Bitwise combination of ZLINE_* bits.
 * @return Newly allocated Z-line.
 */
static struct Zline *
make_zline(char *mask, char *reason, time_t expire, time_t lastmod,
	   time_t lifetime, unsigned int flags)
{
  struct Zline *zline;

  assert(0 != expire);

  zline = (struct Zline *)MyMalloc(sizeof(struct Zline)); /* alloc memory */
  assert(0 != zline);

  DupString(zline->zl_reason, reason); /* initialize zline... */
  zline->zl_expire = expire;
  zline->zl_lifetime = lifetime;
  zline->zl_lastmod = lastmod;
  zline->zl_flags = flags & ZLINE_MASK;
  zline->zl_state = ZLOCAL_GLOBAL; /* not locally modified */

  DupString(zline->zl_mask, mask);

  if (ipmask_parse(mask, &zline->zl_addr, &zline->zl_bits)) {
    zline->zl_flags |= ZLINE_IPMASK;
    zline->zl_addr = ipmask_clean(&zline->zl_addr, zline->zl_bits);
  }

  zline->zl_next = GlobalZlineList; /* then link it into list */
  zline->zl_prev_p = &GlobalZlineList;
  if (GlobalZlineList)
    GlobalZlineList->zl_prev_p = &zline->zl_next;
  GlobalZlineList = zline;

  return zline;
}
Exemplo n.º 23
0
/*
** 'make_user' add's an User information block to a client
** if it was not previously allocated.
** iplen is lenght of the IP we want to allocate.
*/
anUser	*make_user(aClient *cptr, int iplen)
{
	Reg	anUser	*user;

	user = cptr->user;
	if (!user)
	    {
		user = (anUser *)MyMalloc(sizeof(anUser) + iplen);
		memset(user, 0, sizeof(anUser) + iplen);

#ifdef	DEBUGMODE
		users.inuse++;
#endif
		user->away = NULL;
		user->refcnt = 1;
		user->joined = 0;
		user->flags = 0;
		user->channel = NULL;
		user->invited = NULL;
		user->uwas = NULL;
		cptr->user = user;
		user->hashv = 0;
		user->uhnext = NULL;
		user->uid[0] = '\0';
		user->servp = NULL;
		user->bcptr = cptr;
		if (cptr->next)	/* the only cptr->next == NULL is me */
			istat.is_users++;
	    }
	return user;
}
Exemplo n.º 24
0
/*
 * check for public repeating and keep/replace appropriate last phrase
 *													-demond
 */
static int check_repeat(struct Client *source_p,
						struct Channel *chptr,
						char *text)
{
	dlink_node *ptr;
	struct Repeat *repeatptr;

	for (ptr = source_p->user->repeat.head; ptr; ptr = ptr->next) {
		repeatptr = ptr->data;
		if (repeatptr->chptr == chptr)
			if (!strcmp(repeatptr->text, text)) {
				return 1;
			} else {
				MyFree(repeatptr->text);
				DupString(repeatptr->text, text);
				repeatptr->lastphrase = CurrentTime;
				return 0;
			}
	}

	repeatptr = (struct Repeat *)MyMalloc(sizeof(struct Repeat));
	repeatptr->chptr = chptr;
	DupString(repeatptr->text, text);
	repeatptr->lastphrase = CurrentTime;

	ptr = make_dlink_node();
	dlinkAdd(repeatptr, ptr, &source_p->user->repeat);

	return 0;
}
Exemplo n.º 25
0
/*
** dbuf_alloc - allocates a dbufbuf structure either from freelist or
** creates a new one.
*/
static dbufbuf *dbuf_alloc()
{
	Reg1	dbufbuf	*dbptr, *db2ptr;
	Reg2	int	num;

	dbufalloc++;
	if (dbptr = freelist)
	    {
		freelist = freelist->next;
		return dbptr;
	    }

#ifdef	VALLOC
	num = getpagesize()/sizeof(dbufbuf);
	if (num < 0)
		num = 1;

	dbufblocks += num;

	dbptr = (dbufbuf *)valloc(num*sizeof(dbufbuf));
	if (!dbptr)
		return (dbufbuf *)NULL;

	for (db2ptr = dbptr; num > 1; num--)
	    {
		db2ptr = (dbufbuf *)((char *)dbptr + sizeof(dbufbuf));
		db2ptr->next = freelist;
		freelist = db2ptr;
	    }
	return dbptr;
#else
	dbufblocks++;
	return (dbufbuf *)MyMalloc(sizeof(dbufbuf));
#endif
}
Exemplo n.º 26
0
char* crypt_pass(const char* pw, const char* mech)
{
crypt_mechs_t* crypt_mech;
char* salt, *untagged, *tagged;

 assert(NULL != pw);
 assert(NULL != mech);

 Debug((DEBUG_DEBUG, "pw = %s\n", pw));
 Debug((DEBUG_DEBUG, "mech = %s\n", mech));

 if (NULL == (crypt_mech = hunt_mech(mech)))
 {
  printf("Unable to find mechanism %s\n", mech);
  return NULL;
 }

 salt = make_salt(default_salts);

 untagged = (char *)CryptFunc(crypt_mech->mech)(pw, salt);
 tagged = (char *)MyMalloc(strlen(untagged)+CryptTokSize(crypt_mech->mech)+1);
 memset(tagged, 0, strlen(untagged)+CryptTokSize(crypt_mech->mech)+1);
 strncpy(tagged, CryptTok(crypt_mech->mech), CryptTokSize(crypt_mech->mech));
 strncpy(tagged+CryptTokSize(crypt_mech->mech), untagged, strlen(untagged));

return tagged;
}
Exemplo n.º 27
0
/*
 * How this works.
 *
 * The code first checks to see if its reached the end of the command
 * If so, that struct MessageTree has a msg pointer updated and the links
 * count incremented, since a msg pointer is a reference.
 * Then the code descends recursively, building the trie.
 * If a pointer index inside the struct MessageTree is NULL a new
 * child struct MessageTree has to be allocated.
 * The links (reference count) is incremented as they are created
 * in the parent.
 */
static void
add_msg_element(struct MessageTree *mtree_p, 
		struct Message *msg_p, const char *cmd)
{
  struct MessageTree *ntree_p;

  if (*cmd == '\0')
  {
    mtree_p->msg = msg_p;
    mtree_p->links++;		/* Have msg pointer, so up ref count */
  }
  else
  {
    /* *cmd & (MAXPTRLEN-1) 
     * convert the char pointed to at *cmd from ASCII to an integer
     * between 0 and MAXPTRLEN.
     * Thus 'A' -> 0x1 'B' -> 0x2 'c' -> 0x3 etc.
     */

    if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN-1)]) == NULL)
    {
      ntree_p = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
      mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = ntree_p;

      mtree_p->links++;		/* Have new pointer, so up ref count */
    }
    add_msg_element(ntree_p, msg_p, cmd+1);
  }
}
Exemplo n.º 28
0
/** Start sending upings to a server.
 * @param[in] sptr Client requesting the upings.
 * @param[in] aconf ConfItem containing the address to ping.
 * @param[in] port Port number to ping.
 * @param[in] count Number of times to ping (should be at least 20).
 * @return Zero.
 */
int uping_server(struct Client* sptr, struct ConfItem* aconf, int port, int count)
{
  int fd;
  struct UPing* pptr;

  assert(0 != sptr);
  assert(0 != aconf);

  if (INADDR_NONE == aconf->ipnum.s_addr) {
    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :UPING: Host lookup failed for "
		  "%s", sptr, aconf->name);
    return 0;
  }

  if (IsUPing(sptr))
    uping_cancel(sptr, sptr);  /* Cancel previous ping request */

  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :UPING: Unable to create udp "
		  "ping socket", sptr);
    return 0;
  }

  if (!os_set_nonblocking(fd)) {
    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :UPING: Can't set fd non-"
		  "blocking", sptr);
    close(fd);
    return 0;
  }
  pptr = (struct UPing*) MyMalloc(sizeof(struct UPing));
  assert(0 != pptr);
  memset(pptr, 0, sizeof(struct UPing));

  if (!socket_add(&pptr->socket, uping_read_callback, (void*) pptr,
		  SS_DATAGRAM, SOCK_EVENT_READABLE, fd)) {
    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :UPING: Can't queue fd for "
		  "reading", sptr);
    close(fd);
    MyFree(pptr);
    return 0;
  }

  pptr->fd                  = fd;
  pptr->sin.sin_port        = htons(port);
  pptr->sin.sin_addr.s_addr = aconf->ipnum.s_addr;
  pptr->sin.sin_family      = AF_INET;
  pptr->count               = IRCD_MIN(20, count);
  pptr->client              = sptr;
  pptr->index               = -1;
  pptr->freeable            = UPING_PENDING_SOCKET;
  strcpy(pptr->name, aconf->name);

  pptr->next = pingList;
  pingList   = pptr;

  SetUPing(sptr);
  uping_start(pptr);
  return 0;
}
Exemplo n.º 29
0
OpenUtility::CStream::CStream(char car)
{
	taille=1;
	Stream=(char*)MyMalloc(2*sizeof(char));

	Stream[0]=car;
	Stream[taille]='\0';
}
Exemplo n.º 30
-1
/**************************************************************************
 * MultiByteToUnicode [SETUPAPI.@]
 *
 * Converts a multi-byte string to a Unicode string.
 *
 * PARAMS
 *     lpMultiByteStr  [I] Multi-byte string to be converted
 *     uCodePage       [I] Code page
 *
 * RETURNS
 *     Success: pointer to the converted Unicode string
 *     Failure: NULL
 *
 * NOTE
 *     Use MyFree to release the returned Unicode string.
 */
LPWSTR WINAPI MultiByteToUnicode(LPCSTR lpMultiByteStr, UINT uCodePage)
{
    LPWSTR lpUnicodeStr;
    int nLength;

    TRACE("%s %d\n", debugstr_a(lpMultiByteStr), uCodePage);

    nLength = MultiByteToWideChar(uCodePage, 0, lpMultiByteStr,
                                  -1, NULL, 0);
    if (nLength == 0)
        return NULL;

    lpUnicodeStr = MyMalloc(nLength * sizeof(WCHAR));
    if (lpUnicodeStr == NULL)
        return NULL;

    if (!MultiByteToWideChar(uCodePage, 0, lpMultiByteStr,
                             nLength, lpUnicodeStr, nLength))
    {
        MyFree(lpUnicodeStr);
        return NULL;
    }

    return lpUnicodeStr;
}