Ejemplo n.º 1
0
void
getmailstatus()
{
	if(!mailbox && !(mailbox = nh_getenv("MAIL"))) {
#  ifdef MAILPATH
#   ifdef AMS
	        struct passwd ppasswd;

		(void) memcpy(&ppasswd, getpwuid(getuid()), sizeof(struct passwd));
		if (ppasswd.pw_dir) {
		     mailbox = (char *) alloc((unsigned) strlen(ppasswd.pw_dir)+sizeof(AMS_MAILBOX));
		     Strcpy(mailbox, ppasswd.pw_dir);
		     Strcat(mailbox, AMS_MAILBOX);
		} else
		  return;
#   else
		const char *pw_name = getpwuid(getuid())->pw_name;
		mailbox = (char *) alloc(sizeof(MAILPATH)+strlen(pw_name));
		Strcpy(mailbox, MAILPATH);
		Strcat(mailbox, pw_name);
#  endif /* AMS */
#  else
		return;
#  endif
	}
	if(stat(mailbox, &omstat)){
#  ifdef PERMANENT_MAILBOX
		pline("Cannot get status of MAIL=\"%s\".", mailbox);
		mailbox = 0;
#  else
		omstat.st_mtime = 0;
#  endif
	}
}
Ejemplo n.º 2
0
/*######################################################################
 *##
 *## NAME:  HttpSendRequest10
 *##
 *## PURPOSE: Send an http 1.0 method request-line  
 *##          Note: szReq can be "HEAD ", "POST ", "GET ", ..
 *##
 *####################################################################*/
static int HttpSendRequest10(SOCKET CSock,       /* socket decriptor   */
                             LPCSTR szReq,  /* request to be sent */
                             LPCSTR szURL   /* URL or URI         */)
{
LPSTR sRequest =  NULL;
int   Rc;

   Tcp4uLog (LOG4U_INTERN, "HttpSendRequest10");
  /* allocate buffer wide eough to contain all data */
  sRequest = Calloc (sizeof(" HTTP/1.0 ") + Strlen (szURL) + Strlen(szReq),
                     sizeof(char));
  if (sRequest == NULL)    return HTTP4U_INSMEMORY;

  /* compose request with reentrant functions */
  Strcpy(sRequest, szReq);
  Strcat(sRequest, szURL);
  Strcat(sRequest, " HTTP/1.0");

  /* send the request then forget it */
  Rc = TnSend (CSock, sRequest, FALSE, DO_NOT_LOG);
  Free (sRequest);
  if (Rc!=TCP4U_SUCCESS)    return HTTP4U_TCP_FAILED ;

  /* Send general-header */
return  HttpSendAdditionnalHeader(CSock);
} /* END HttpSendRequestHEAD10 */
Ejemplo n.º 3
0
INT_PTR CALLBACK CClassicCopyFolder::DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	if (uMsg==WM_INITDIALOG)
	{
		SetWindowText(hwndDlg,FindTranslation(L"Folder.Title",L"Confirm Folder Replace"));
		CClassicCopyFolder *pThis=(CClassicCopyFolder*)lParam;
		wchar_t text[2048];
		// find the link control and get its text
		HWND link=FindWindowEx(pThis->m_Original,NULL,WC_LINK,NULL);
		if (link)
			GetWindowText(link,text,_countof(text));
		else
			text[0]=0;
		Strcat(text,_countof(text),L"\r\n\r\n");
		Strcat(text,_countof(text),FindTranslation(L"Folder.Prompt",L"Do you still want to move or copy the folder?"));
		SetDlgItemText(hwndDlg,IDC_STATICFNAME,text);

		// load icon for file conflict (146) from Shell32.dll
		HMODULE hShell32=GetModuleHandle(L"Shell32.dll");
		pThis->m_Icon=LoadIcon(hShell32,MAKEINTRESOURCE(146));
		if (pThis->m_Icon)
			SendDlgItemMessage(hwndDlg,IDC_STATICICON1,STM_SETICON,(LPARAM)pThis->m_Icon,0);

		// set the localized text
		SetDlgItemText(hwndDlg,IDOK,FindTranslation(L"Copy.Yes",L"&Yes"));
		SetDlgItemText(hwndDlg,IDNO,FindTranslation(L"Copy.No",L"&No"));
		if (GetDlgItem(hwndDlg,IDYES))
			SetDlgItemText(hwndDlg,IDYES,FindTranslation(L"Copy.YesAll",L"Yes to &All"));
		if (GetDlgItem(hwndDlg,IDCANCEL))
			SetDlgItemText(hwndDlg,IDCANCEL,FindTranslation(L"Copy.Cancel",L"Cancel"));
		Sprintf(text,_countof(text),L"<a>%s</a>",FindTranslation(L"Copy.More",L"&More..."));
		SetDlgItemText(hwndDlg,IDC_LINKMORE,text);
		PostMessage(hwndDlg,WM_BRINGFOREGROUND,0,0);
		return TRUE;
	}
	if (uMsg==WM_BRINGFOREGROUND)
	{
		// bring window to front (sometimes on Windows7 it shows up behind Explorer)
		SetForegroundWindow(hwndDlg);
		return TRUE;
	}
	if (uMsg==WM_COMMAND && (wParam==IDOK || wParam==IDYES || wParam==IDNO || wParam==IDCANCEL))
	{
		EndDialog(hwndDlg,wParam);
		return TRUE;
	}
	if (uMsg==WM_NOTIFY)
	{
		NMHDR *pHdr=(NMHDR*)lParam;
		if (pHdr->idFrom==IDC_LINKMORE && (pHdr->code==NM_CLICK || pHdr->code==NM_RETURN))
		{
			EndDialog(hwndDlg,IDC_LINKMORE);
			return TRUE;
		}
	}
	return FALSE;
}
Ejemplo n.º 4
0
int CLobbyApp::OnMessageBox(const char * strText, const char * strCaption, UINT nType)
{
  char sz[256];
  if (strCaption && *strCaption)
  {
    Strcpy(sz, strCaption);
    Strcat(sz, ": ");
  }
  Strcat(sz, strText);
  return m_plas->LogEvent(EVENTLOG_ERROR_TYPE, LE_ODBC_Error, strText);
}
Ejemplo n.º 5
0
char *
s_suffix(const char *s)		/* return a name converted to possessive */
              
{
    Static char buf[BUFSZ];

    Strcpy(buf, s);
    if(!strcmpi(buf, "it"))
        Strcat(buf, "s");
    else if(*(eos(buf)-1) == 's')
        Strcat(buf, "'");
    else
        Strcat(buf, "'s");
    return buf;
}
Ejemplo n.º 6
0
int dexpand_c(char *templat,char *output,int length)
/*
  This expands wildcards, matching them with files.

  Input:
    templat	The input character string, containing the wildcards.
    length	The length of the output buffer.
  Output:
    output	All the files matching "template". Filenames are separated
		by commas.
------------------------------------------------------------------------*/
{
  FILE *fd;
  char line[MAXPATH],*s;
  int l;

  Strcpy(line,"echo ");
  Strcat(line,templat);
  fd = popen(line,"r");
  if(fd == NULL) return(-1);
  s = output;
  while(fgets(s,length,fd)){
    l = strlen(s);
    if( length-l <= 1 ){(void)pclose(fd); return(-1);}
    *(s+l-1) = ',';
    s += l;
    length -= l;
  }
  if(s != output) *--s = 0;
  (void)pclose(fd);
  return(s-output);
}
Ejemplo n.º 7
0
void do_info(COMMAND_ARGS)
{
	ChanStats *stats;
	Chan	*chan;
	char	*p;
	char	text[MSGLEN];
	ulong	avg;

	if (current->chanlist == NULL)
	{
		to_user(from,ERR_NOCHANNELS);
		return;
	}
	to_user(from,"\037channel\037                            "
		"\037average\037 \037peak\037 \037low\037");
	for(chan=current->chanlist;chan;chan=chan->next)
	{
		*(p = text) = 0;
		p = Strcat(p,chan->name);
		if (chan == current->activechan)
			p = Strcat(p," (current)");
		if ((stats = chan->stats))
		{
			if (stats && stats->flags == CSTAT_PARTIAL)
				p = Strcat(p," (partial)");
			while(p < text+35)
				*(p++) = ' ';
			if (stats->LHuserseconds > 0)
			{
				avg = stats->LHuserseconds / (60*60);
			}
			else
			{
				avg = (stats->userpeak + stats->userlow) / 2;
			}
			sprintf(p,"%-7lu %-4i %i",avg,stats->userpeak,stats->userlow);
			to_user(from,FMT_PLAIN,text);
			sprintf(text,"Messages: %i   Notices: %i   Joins: %i   Parts: %i   Kicks: %i   Quits: %i",
				stats->privmsg,stats->notice,stats->joins,stats->parts,stats->kicks,stats->quits);
		}
		else
		{
			Strcpy(p," (no current data)");
		}
		to_user(from,FMT_PLAIN,text);
	}
}
Ejemplo n.º 8
0
static Str
make_cookie(struct cookie *cookie)
{
    Str tmp = Strdup(cookie->name);
    Strcat_char(tmp, '=');
    Strcat(tmp, cookie->value);
    return tmp;
}
Ejemplo n.º 9
0
HRESULT CLobbyApp::Init()
{
  HRESULT hr = E_FAIL;
  m_plas->LogEvent(EVENTLOG_INFORMATION_TYPE, LE_Initializing);
  ZVerify(m_perfshare.Initialize());
  m_pCounters = (LOBBY_COUNTERS *)m_perfshare.AllocateCounters(
                      "AllLobby", "0",    // if there are ever multiple lobbies running, change this
                      sizeof(LOBBY_COUNTERS));
  ZeroMemory(m_pCounters, sizeof(LOBBY_COUNTERS));

#ifdef USECLUB
  hr = m_sql.Init(m_strSQLConfig.m_str, GetCurrentThreadId(), m_csqlSilentThreads, m_csqlNotifyThreads);
  if (FAILED(hr))
  {
    m_plas->LogEvent(EVENTLOG_ERROR_TYPE, LE_SQLInitFailed);
    return hr;
  }
#endif

  // TODO: Make keep-alives an option
  if (FAILED(hr = m_fmServers.HostSession(m_fFreeLobby ? FEDFREELOBBYSERVERS_GUID : FEDLOBBYSERVERS_GUID, false, 0, m_fProtocol, m_sPort + 1)) ||	// Mdvalley: I don't know what happens if you try to host 2 servers on one port. Let's not find out.
      FAILED(hr = m_fmClients.HostSession(m_fFreeLobby ? FEDFREELOBBYCLIENTS_GUID : FEDLOBBYCLIENTS_GUID, true, 0, m_fProtocol, m_sPort)))			// The first session doesn't need the port fixed, but I don't want to risk having it take the one the second is going to use.
  {
    m_plas->LogEvent(EVENTLOG_ERROR_TYPE, LE_HostSessionFailure);
    return hr;
  }

  //
  // Read Registry
  //
  DWORD dw; // Gets result of whether it opened or created...
  HKEY  hk;
  if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, HKLM_AllLobby, 0, L"", REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &hk, &dw) == ERROR_SUCCESS)
  {
    // read AutoUpdate portion of registry
    DWORD dwWantAutoDownload;
    bool bSuccess = _Module.ReadFromRegistry(hk, false, "AutoUpdateActive", &dwWantAutoDownload, 0);

    if(bSuccess && dwWantAutoDownload)
    {
      char szFileName[MAX_PATH+16];
	  strcpy(szFileName, _Module.GetModulePath());
	  Strcat(szFileName, "FileList.txt");

	  // BT - 7/15 - Enable to lobby to use a FileList.txt from the AutoUpdate folder instead of from the lobby folder. This way, only a single FileList.txt is required.
	  _Module.ReadFromRegistry(hk, true, "AutoUpdateFileListLocation", szFileName, (DWORD)szFileName, false);

      CreateAutoUpdate(hk, szFileName);
    }
    else 
      g_pAutoUpdate = NULL;

    RegCloseKey(hk);

  }

  return hr;
}
Ejemplo n.º 10
0
void preappend_nand_dev_name(const char *origname, char *newname)
{
	if (emulationType == 1) 
		Strcpy(newname, "sd:");
	else if (emulationType == 2)
		Strcpy(newname, "usb:");

	Strcat(newname, origname);
}
Ejemplo n.º 11
0
static void
add_news_message(Str str, int index, char *date, char *name, char *subject,
		 char *mid, char *scheme, char *group)
{
    time_t t;
    struct tm *tm;

    name = name_from_address(name, 16);
    t = mymktime(date);
    tm = localtime(&t);
    Strcat(str,
	   Sprintf("<tr valign=top><td>%d<td nowrap>(%02d/%02d)<td nowrap>%s",
		   index, tm->tm_mon + 1, tm->tm_mday, html_quote_s(name)));
    if (group)
	Strcat(str, Sprintf("<td><a href=\"%s%s/%d\">%s</a>\n", scheme, group,
			    index, html_quote(subject)));
    else
	Strcat(str, Sprintf("<td><a href=\"%s%s\">%s</a>\n", scheme,
			    html_quote(file_quote(mid)), html_quote(subject)));
}
Ejemplo n.º 12
0
static Str
portlist2str(struct portlist *first)
{
    struct portlist *pl;
    Str tmp;

    tmp = Sprintf("%d", first->port);
    for (pl = first->next; pl; pl = pl->next)
	Strcat(tmp, Sprintf(", %d", pl->port));
    return tmp;
}
Ejemplo n.º 13
0
Str
Stralign_right(Str s, int width)
{
    Str n;
    int i;

    STR_LENGTH_CHECK(s);
    if (s->length >= width)
	return Strdup(s);
    n = Strnew_size(width);
    for (i = s->length; i < width; i++)
	Strcat_char(n, ' ');
    Strcat(n, s);
    return n;
}
Ejemplo n.º 14
0
/*ARGSUSED*/
void dreaddir_c(char *contxt,char *path,int length)
/*
  Read a directory entry.
------------------------------------------------------------------------*/
{
  struct dent *d;
  struct direct *dp;
  struct stat buf;
  char npath[MAXPATH];

  d = (struct dent *)contxt;

  do dp = readdir(d->dir);
  while(dp != NULL && (!strcmp(dp->d_name,".") || !strcmp(dp->d_name,"..")));

  if(dp == NULL)
    *path = 0;
  else{
    Strcpy(path,dp->d_name);
    Strcpy(npath,d->path);    Strcat(npath,path);
    (void)stat(npath,&buf);
    if(S_IFDIR & buf.st_mode)Strcat(path,"/");
  }
}
Ejemplo n.º 15
0
/*######################################################################
 *##
 *## NAME:  HttpRecvHeaders10
 *##
 *## PURPOSE:  Return the headers section of the http respons
 *##           sBufHeaders Can not be NULL, but sBufHeadersLen can !! 
 *##
 *####################################################################*/
static int HttpRecvHeaders10 (SOCKET   CSock,
                              LPSTR    sBufHeaders,
                              int      nBufHeadersLen)
{
int   Rc;
int   nRcvd, nLineLength;
LPSTR p;
#define EMPTY(s) ((s)[0]=='\r' || (s)[0]=='\n')

  Tcp4uLog (LOG4U_INTERN, "Http4RecvHeaders10");

  if (sBufHeaders==NULL) return HTTP4U_BAD_PARAM;
  memset(sBufHeaders, 0, nBufHeadersLen);
  /* Keep space for last ending line and nul character */
  nBufHeadersLen -= sizeof SYSTEM_EOL;
 
  /* receive data from distant http server. Must use loop on TcpRecvUntilStr */
  /* since some unix servers send  \n\n instead of regular \n\r\n....  */
  nRcvd = 0 ;  
  do
  { 
     p = & sBufHeaders[nRcvd];
     Rc = InternalTnReadLine (CSock,  
                              p, nBufHeadersLen-nRcvd,
                              s_uHttp4uTimeout, DO_NOT_LOG); 
     Strcat (p, SYSTEM_EOL);
     nLineLength = Strlen (p); /* 0 on error */
     nRcvd += nLineLength;
  } /* loop until error or empty line */
  while (Rc==TCP4U_SUCCESS && !EMPTY(p) && nRcvd < nBufHeadersLen);
  /* translate return code */
  switch(Rc) 
  {
     /* remember to put the last \n into destination string */
     case TCP4U_SUCCESS:       Tcp4uDump (sBufHeaders, nRcvd, DUMP4U_RCVD);
                               return nRcvd >= nBufHeadersLen ?
                                      HTTP4U_OVERFLOW : HTTP4U_SUCCESS;
     case TCP4U_OVERFLOW:      return HTTP4U_OVERFLOW;
     case TCP4U_TIMEOUT:       return HTTP4U_TIMEOUT;
     case TCP4U_CANCELLED:     return HTTP4U_CANCELLED;
     case TCP4U_ERROR:         return HTTP4U_TCP_FAILED;
     case TCP4U_INSMEMORY:     return HTTP4U_INSMEMORY;
     case TCP4U_SOCKETCLOSED:  return HTTP4U_PROTOCOL_ERROR;
     default:                  return HTTP4U_TCP_FAILED;
  } /* END switch(Rc) */
#undef EMPTY
} /* END HttpRecvHeaders10 */
Ejemplo n.º 16
0
void
appendTextLine(TextLineList *tl, Str line, int pos)
{
    TextLine *lbuf;

    if (tl->last == NULL) {
	pushTextLine(tl, newTextLine(Strdup(line), pos));
    }
    else {
	lbuf = tl->last->ptr;
	if (lbuf->line)
	    Strcat(lbuf->line, line);
	else
	    lbuf->line = line;
	lbuf->pos += pos;
    }
}
Ejemplo n.º 17
0
Archivo: cookie.c Proyecto: macks/w3m
Str
find_cookie(ParsedURL *pu)
{
    Str tmp;
    struct cookie *p, *p1, *fco = NULL;
    int version = 0;
    char *fq_domainname, *domainname;

    dump(Strnew_charp("GET"));

    load_cookies_sync();

    fq_domainname = FQDN(pu->host);
    check_expired_cookies();
    for (p = First_cookie; p; p = p->next) {
	domainname = (p->version == 0) ? fq_domainname : pu->host;
	if (p->flag & COO_USE && match_cookie(pu, p, domainname)) {
	    for (p1 = fco; p1 && Strcasecmp(p1->name, p->name);
		 p1 = p1->next) ;
	    if (p1)
		continue;
	    p1 = New(struct cookie);
	    bcopy(p, p1, sizeof(struct cookie));
	    p1->next = fco;
	    fco = p1;
	    if (p1->version > version)
		version = p1->version;
	}
    }

    if (!fco)
	return NULL;

    tmp = Strnew();
    if (version > 0)
	Strcat(tmp, Sprintf("$Version=\"%d\"; ", version));

    Strcat(tmp, make_cookie(fco));
    for (p1 = fco->next; p1; p1 = p1->next) {
	Strcat_charp(tmp, "; ");
	Strcat(tmp, make_cookie(p1));
	if (version > 0) {
	    if (p1->flag & COO_PATH)
		Strcat(tmp, Sprintf("; $Path=\"%s\"", p1->path->ptr));
	    if (p1->flag & COO_DOMAIN)
		Strcat(tmp, Sprintf("; $Domain=\"%s\"", p1->domain->ptr));
	    if (p1->portl)
		Strcat(tmp,
		       Sprintf("; $Port=\"%s\"", portlist2str(p1->portl)));
	}
    }
    return tmp;
}
Ejemplo n.º 18
0
Str
Stralign_center(Str s, int width)
{
    Str n;
    int i, w;

    STR_LENGTH_CHECK(s);
    if (s->length >= width)
	return Strdup(s);
    n = Strnew_size(width);
    w = (width - s->length) / 2;
    for (i = 0; i < w; i++)
	Strcat_char(n, ' ');
    Strcat(n, s);
    for (i = w + s->length; i < width; i++)
	Strcat_char(n, ' ');
    return n;
}
Ejemplo n.º 19
0
int read_bigcharset(char *fname)
{
	BigC	*bigc;
	Strp	*sp;
	int	fd;

	if ((fd = open(fname,O_RDONLY)) < 0)
	{
		Strcat(fname,FONT_EXTENSION);
		if ((fd = open(fname,O_RDONLY)) < 0)
			return(-1);
	}

	orig_fontlist = fontlist;
	orig_charlines = charlines;
	orig_charheight = charheight;
	orig_spacewidth = spacewidth;
	orig_kerning = kerning;

	charlines = 0;
	spacewidth = 0;
	charheight = 0;
	kerning = 0;

	readline(fd,&read_bigcharset_callback);		/* readline closes fd */

	/*
	 *  free the old font if there is one
	 */
	while(orig_fontlist)
	{
		bigc = orig_fontlist;
		orig_fontlist = bigc->next;
		while(bigc->data)
		{
			sp = bigc->data;
			bigc->data = sp->next;
			Free((char**)&sp);
		}
		Free((char**)&bigc);
	}

	return(0);
}
Ejemplo n.º 20
0
/*
outrip(winid, int)
	    -- The tombstone code.  If you want the traditional code use
	       genl_outrip for the value and check the #if in rip.c.
*/
void gnome_outrip(winid wid, int how)
{
    /* Follows roughly the same algorithm as genl_outrip() */
    char buf[BUFSZ];
    char ripString[BUFSZ]="\0";
    extern const char *killed_by_prefix[];

    /* Put name on stone */
    Sprintf(buf, "%s\n", plname);
    Strcat(ripString, buf);

    /* Put $ on stone */
    Sprintf(buf, "%ld Au\n",
#ifndef GOLDOBJ
            u.ugold);
#else
            done_money);
#endif
    Strcat(ripString, buf);

    /* Put together death description */
    switch (killer_format) {
    default:
        impossible("bad killer format?");
    case KILLED_BY_AN:
        Strcpy(buf, killed_by_prefix[how]);
        Strcat(buf, an(killer));
        break;
    case KILLED_BY:
        Strcpy(buf, killed_by_prefix[how]);
        Strcat(buf, killer);
        break;
    case NO_KILLER_PREFIX:
        Strcpy(buf, killer);
        break;
    }
    /* Put death type on stone */
    Strcat(ripString, buf);
    Strcat(ripString, "\n");

    /* Put year on stone */
    Sprintf(buf, "%4d\n", getyear());
    Strcat(ripString, buf);

    ghack_text_window_rip_string( ripString);
}
Ejemplo n.º 21
0
void dtrans_c(char *inpath,char *outpath,int *iostat)
/*
  Translate a directory spec into the local format. On a UNIX machine,
  this merely involves adding a slash to the end of the name.

  Input:
    inpath	Input directory spec.
  Output:
    outpath	Output directory spec.
    iostat	Error return.
------------------------------------------------------------------------*/
{
  char *s;

  *iostat = 0;
  Strcpy(outpath,inpath);
  s = outpath + strlen(outpath) - 1;
  if(*s != '/')Strcat(outpath,"/");
}
Ejemplo n.º 22
0
void
rechist(void)
{
    Char buf[BUFSIZE], hbuf[BUFSIZE], *hfile;
    int fp, ftmp, oldidfds;
    struct varent *shist;

    if (!fast) {
	/*
	 * If $savehist is just set, we use the value of $history
	 * else we use the value in $savehist
	 */
	if ((shist = adrof(STRsavehist)) != NULL) {
	    if (shist->vec[0][0] != '\0')
		(void)Strcpy(hbuf, shist->vec[0]);
	    else if ((shist = adrof(STRhistory)) && shist->vec[0][0] != '\0')
		(void)Strcpy(hbuf, shist->vec[0]);
	    else
		return;
	}
	else
  	    return;

  	if ((hfile = value(STRhistfile)) == STRNULL) {
  	    hfile = Strcpy(buf, value(STRhome));
  	    (void) Strcat(buf, STRsldthist);
  	}

  	if ((fp = open(short2str(hfile), O_WRONLY | O_CREAT | O_TRUNC,
	    0600)) == -1) 
  	    return;

	oldidfds = didfds;
	didfds = 0;
	ftmp = SHOUT;
	SHOUT = fp;
	dumphist[2] = hbuf;
	dohist(dumphist, NULL);
	SHOUT = ftmp;
	(void)close(fp);
	didfds = oldidfds;
    }
}
Ejemplo n.º 23
0
void
push_symbol(Str str, char symbol, int width, int n)
{
    char buf[2], *p;
    int i;

#ifdef USE_M17N
    if (width == 2)
	p = alt2_symbol[(int)symbol];
    else
#endif
	p = alt_symbol[(int)symbol];
    for (i = 0; i < 2 && *p; i++, p++)
	buf[i] = (*p == ' ') ? NBSP_CODE : *p;

    Strcat(str, Sprintf("<_SYMBOL TYPE=%d>", symbol));
    for (; n > 0; n--)
	Strcat_charp_n(str, buf, i);
    Strcat_charp(str, "</_SYMBOL>");
}
Ejemplo n.º 24
0
static struct mailcap *
loadMailcap(char *filename)
{
    FILE *f;
    int i, n;
    Str tmp;
    struct mailcap *mcap;

    f = fopen(expandPath(filename), "r");
    if (f == NULL)
	return NULL;
    i = 0;
    while (tmp = Strfgets(f), tmp->length > 0) {
	if (tmp->ptr[0] != '#')
	    i++;
    }
    fseek(f, 0, 0);
    n = i;
    mcap = New_N(struct mailcap, n + 1);
    i = 0;
    while (tmp = Strfgets(f), tmp->length > 0) {
	if (tmp->ptr[0] == '#')
	    continue;
      redo:
	while (IS_SPACE(Strlastchar(tmp)))
	    Strshrink(tmp, 1);
	if (Strlastchar(tmp) == '\\') {
	    /* continuation */
	    Strshrink(tmp, 1);
	    Strcat(tmp, Strfgets(f));
	    goto redo;
	}
	if (extractMailcapEntry(tmp->ptr, &mcap[i]))
	    i++;
    }
    memset(&mcap[i], 0, sizeof(struct mailcap));
    fclose(f);
    return mcap;
}
Ejemplo n.º 25
0
        /* set height of the status box */
        sz->cy = tm.tmHeight * data->nhstat_format;

        SelectObject(hdc, saveFont);
        ReleaseDC(hWnd, hdc);
    }
}
extern const char *hu_stat[];  /* defined in eat.c */
extern const char *enc_stat[]; /* define in botl.c */
void
FormatStatusString(char *text, int format)
{
    register char *nb;
    int hp, hpmax;
    int cap = near_capacity();

    Strcpy(text, plname);
    if ('a' <= text[0] && text[0] <= 'z')
        text[0] += 'A' - 'a';
    text[10] = 0;
    Sprintf(nb = eos(text), " the ");

    if (Upolyd) {
        char mbot[BUFSZ];
        int k = 0;

        Strcpy(mbot, mons[u.umonnum].mname);
        while (mbot[k] != 0) {
            if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k]
                && mbot[k] <= 'z')
                mbot[k] += 'A' - 'a';
            k++;
        }
        Sprintf(nb = eos(nb), mbot);
    } else
        Sprintf(nb = eos(nb), rank_of(u.ulevel, Role_switch, flags.female));

    if (format == NHSTAT_LINES_4)
        Sprintf(nb = eos(nb), "\r\n");

    if (ACURR(A_STR) > 18) {
        if (ACURR(A_STR) > STR18(100))
            Sprintf(nb = eos(nb), "St:%2d ", ACURR(A_STR) - 100);
        else if (ACURR(A_STR) < STR18(100))
            Sprintf(nb = eos(nb), "St:18/%02d ", ACURR(A_STR) - 18);
        else
            Sprintf(nb = eos(nb), "St:18/** ");
    } else
        Sprintf(nb = eos(nb), "St:%-1d ", ACURR(A_STR));
    Sprintf(nb = eos(nb), "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
            ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS),
            ACURR(A_CHA));
    Sprintf(nb = eos(nb),
            (u.ualign.type == A_CHAOTIC)
                ? "  Chaotic"
                : (u.ualign.type == A_NEUTRAL) ? "  Neutral" : "  Lawful");
#ifdef SCORE_ON_BOTL
    if (flags.showscore)
        Sprintf(nb = eos(nb), " S:%ld", botl_score());
#endif
    if (format == NHSTAT_LINES_4 || format == NHSTAT_LINES_2)
        strcat(text, "\r\n");

    /* third line */
    hp = Upolyd ? u.mh : u.uhp;
    hpmax = Upolyd ? u.mhmax : u.uhpmax;

    if (hp < 0)
        hp = 0;
    (void) describe_level(nb = eos(nb));
    Sprintf(nb = eos(nb), "%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d",
            showsyms[COIN_CLASS + SYM_OFF_O], money_cnt(invent), hp, hpmax,
            u.uen, u.uenmax, u.uac);

    if (Upolyd)
        Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel);
    else if (flags.showexp)
        Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel, u.uexp);
    else
        Sprintf(nb = eos(nb), " Exp:%u", u.ulevel);
    if (format == NHSTAT_LINES_4)
        strcat(text, "\r\n");
    else
        strcat(text, " ");

    /* forth line */
    if (flags.time)
        Sprintf(nb = eos(nb), "T:%ld ", moves);

    if (strcmp(hu_stat[u.uhs], "        ")) {
        Strcat(text, hu_stat[u.uhs]);
        Sprintf(nb = eos(nb), " ");
    }
    if (Confusion)
        Sprintf(nb = eos(nb), "Conf");
    if (Sick) {
        if (u.usick_type & SICK_VOMITABLE)
            Sprintf(nb = eos(nb), " FoodPois");
        if (u.usick_type & SICK_NONVOMITABLE)
            Sprintf(nb = eos(nb), " Ill");
    }
    if (Blind)
        Sprintf(nb = eos(nb), " Blind");
    if (Stunned)
        Sprintf(nb = eos(nb), " Stun");
    if (Hallucination)
        Sprintf(nb = eos(nb), " Hallu");
    if (Slimed)
        Sprintf(nb = eos(nb), " Slime");
    if (cap > UNENCUMBERED)
        Sprintf(nb = eos(nb), " %s", enc_stat[cap]);
}
Ejemplo n.º 26
0
void do_kicksay(COMMAND_ARGS)
{
	/*
	 *  on_msg checks: CARGS
	 */
	KickSay *kick;
	char	*channel,*mask;
	int	inum;

	channel = chop(&rest);
	if (!channel)
	{
		if (!current->kicklist)
		{
			to_user(from,"Kicksay list is empty");
			return;
		}

		if (dcc_only_command(from))
			return;

		table_buffer("\037channel\037\t\037action\037\t\037string\037\t\037kick reason\037");
		for(kick=current->kicklist;kick;kick=kick->next)
		{
			table_buffer("%s\t%s\t%s\t%s",kick->chan,ks_actions[kick->action],kick->mask,kick->reason);
		}
		table_send(from,2);
		return;
	}

	if (ischannel(channel) || *channel == '*')
	{

		if (get_useraccess(from,channel) < cmdaccess)
			return;

		inum = DEFAULT_KS_LEVEL;
		if (*rest != '"')
		{
			inum = a2i(chop(&rest));
			if (errno || inum < 0 || inum > MAX_KS_LEVEL)
				return;
		}

		mask = get_token(&rest,"\"");

		if (!mask || !*mask)
			goto usage;

		/*
		 *  check for previously existing kicks
		 */
		if ((kick = find_kicksay(mask,channel)) != NULL)
		{
			to_user(from,"I'm already kicking on \"%s\"",kick->mask);
			return;
		}

		/*
		 *  dig out the reason (the rest)
		 */
		while(rest && *rest == ' ')
			rest++;
		if (!*rest)
			goto usage;

		/*
		 *  add it to the list
		 */
		set_mallocdoer(do_kicksay);
		kick = (KickSay*)Calloc(sizeof(KickSay) + Strlen(channel,mask,rest,NULL));

		kick->next = current->kicklist;
		current->kicklist = kick;
		kick->action = inum;

		if (!matches("\\*?*\\*",mask))
			kick->chan = Strcpy(kick->mask,mask) + 1;
		else
		{
			kick->mask[0] = '*';
			Strcpy(kick->mask+1,mask);
			kick->chan = Strcat(kick->mask,MATCH_ALL) + 1;
		}
		kick->reason = Strcpy(kick->chan,channel) + 1;
				Strcpy(kick->reason,rest);

		to_user(from,"Now kicking on \"%s\" on %s",mask,channel);
		current->ul_save++;
		return;
	}
usage:
	usage(from);	/* usage for CurrentCmd->name */
}
Ejemplo n.º 27
0
void noegnud_rip_outrip_finalize(winid tmpwin) {
	char buf[BUFSZ];
	char *bufs;
	char *bufc;
	int  stringwidth;

	noegnud_gui_ttext *widget_text;

	noegnud_optiontype_string *rip_image;
	noegnud_optiontype_string *rip_font;
	noegnud_optiontype_int *rip_width;
	noegnud_optiontype_int *rip_name_x;
	noegnud_optiontype_int *rip_name_y;
	noegnud_optiontype_int *rip_year_x;
	noegnud_optiontype_int *rip_year_y;
	noegnud_optiontype_int *rip_gold_x;
	noegnud_optiontype_int *rip_gold_y;
	noegnud_optiontype_int *rip_how_x;
	noegnud_optiontype_int *rip_how_y;
	noegnud_optiontype_rgb *rip_tomb_colour;

	noegnud_fonts_tfont *rip_font_font;

	rip_image=noegnud_collection_data(noegnud_options,"gui.window.tombstone.image");
	rip_font=noegnud_collection_data(noegnud_options,"gui.window.tombstone.font");

	rip_width=noegnud_collection_data(noegnud_options,"gui.window.tombstone.width");

	rip_name_x=noegnud_collection_data(noegnud_options,"gui.window.tombstone.name.x");
	rip_name_y=noegnud_collection_data(noegnud_options,"gui.window.tombstone.name.y");
	rip_year_x=noegnud_collection_data(noegnud_options,"gui.window.tombstone.year.x");
	rip_year_y=noegnud_collection_data(noegnud_options,"gui.window.tombstone.year.y");
	rip_gold_x=noegnud_collection_data(noegnud_options,"gui.window.tombstone.gold.x");
	rip_gold_y=noegnud_collection_data(noegnud_options,"gui.window.tombstone.gold.y");
	rip_how_x=noegnud_collection_data(noegnud_options,"gui.window.tombstone.how.x");
	rip_how_y=noegnud_collection_data(noegnud_options,"gui.window.tombstone.how.y");

	rip_tomb_colour=noegnud_collection_data(noegnud_options,"gui.window.tombstone.tomb.colour");

	((noegnud_gui_twindow *)tmpwin)->image=noegnud_glfuncs_loadimage(rip_image->value,TRUE,FALSE,FALSE);
	((noegnud_gui_twindow *)tmpwin)->localimage=1;
	if (((noegnud_gui_twindow *)tmpwin)->image) {
		((noegnud_gui_twindow *)tmpwin)->widget.width=((noegnud_gui_twindow *)tmpwin)->image->width;
		((noegnud_gui_twindow *)tmpwin)->widget.height=((noegnud_gui_twindow *)tmpwin)->image->height;
		((noegnud_gui_twindow *)tmpwin)->widget.r=((noegnud_gui_twindow *)tmpwin)->widget.g=((noegnud_gui_twindow *)tmpwin)->widget.b=((noegnud_gui_twindow *)tmpwin)->widget.a=1.0;
		((noegnud_gui_twindow *)tmpwin)->image_tiled=0;
		((noegnud_gui_twindow *)tmpwin)->autoresize=0;
	}
	((noegnud_gui_twindow *)tmpwin)->widget.x=(noegnud_options_screenwidth->value-((noegnud_gui_twindow *)tmpwin)->widget.width)/2;
	((noegnud_gui_twindow *)tmpwin)->widget.y=(noegnud_options_screenheight->value-((noegnud_gui_twindow *)tmpwin)->widget.height)/2;

	rip_font_font=noegnud_fonts_loadfont(rip_font->value);

	//name
	stringwidth=noegnud_width_dynamic(rip_font_font,plname);
	widget_text=noegnud_gui_create_text(
		((noegnud_gui_twidget *)tmpwin)->child,
		rip_name_x->value-(((float)stringwidth)/2),
		rip_name_y->value,
//		strlen(plname)*rip_font_font->width,
		stringwidth,
		rip_font_font->height,
		rip_tomb_colour->r,
		rip_tomb_colour->g,
		rip_tomb_colour->b,
		plname);
	widget_text->font=rip_font_font;
	widget_text->dynamiccharwidth=TRUE;

	//year
	Sprintf(buf, "%4d", getyear());
	stringwidth=noegnud_width_dynamic(rip_font_font,buf);
	widget_text=noegnud_gui_create_text(
		((noegnud_gui_twidget *)tmpwin)->child,
		rip_year_x->value-(((float)stringwidth)/2),
		rip_year_y->value,
//		strlen(buf)*rip_font_font->width,
		stringwidth,
		rip_font_font->height,
		rip_tomb_colour->r,
		rip_tomb_colour->g,
		rip_tomb_colour->b,
		buf);
	widget_text->font=rip_font_font;
	widget_text->dynamiccharwidth=TRUE;


	//gold
#ifndef GOLDOBJ
	Sprintf(buf, "%ld Au", u.ugold);
#else
	Sprintf(buf, "%ld Au", done_money);
#endif
	stringwidth=noegnud_width_dynamic(rip_font_font,buf);
	widget_text=noegnud_gui_create_text(
		((noegnud_gui_twidget *)tmpwin)->child,
		rip_gold_x->value-(((float)stringwidth)/2),
		rip_gold_y->value,
//		strlen(buf)*rip_font_font->width,
		stringwidth,
		rip_font_font->height,
		rip_tomb_colour->r,
		rip_tomb_colour->g,
		rip_tomb_colour->b,
		buf);
	widget_text->font=rip_font_font;
	widget_text->dynamiccharwidth=TRUE;


	//how
	switch (killer_format) {
		default: impossible("bad killer format?");
		case KILLED_BY_AN:
			Strcpy(buf, killed_by_prefix[((noegnud_gui_twindow *)tmpwin)->rip_how]);
			Strcat(buf, an(killer));
			break;
		case KILLED_BY:
			Strcpy(buf, killed_by_prefix[((noegnud_gui_twindow *)tmpwin)->rip_how]);
			Strcat(buf, killer);
			break;
		case NO_KILLER_PREFIX:
			Strcpy(buf, killer);
			break;
	}

//	if (rip_width->value<23) rip_width->value=23;
	bufs=(char *)&buf;
	if (strlen(buf)>rip_width->value) {
		while (strlen(bufs)>rip_width->value) {
			bufc=bufs+rip_width->value;
			while ((bufc>bufs)&&(*bufc!=' ')) bufc--;
			if (bufc==bufs) break;
			*bufc=0;

	stringwidth=noegnud_width_dynamic(rip_font_font,bufs);
	widget_text=noegnud_gui_create_text(
		((noegnud_gui_twidget *)tmpwin)->child,
		rip_how_x->value-(((float)stringwidth)/2),
		rip_how_y->value,
//		strlen(buf)*rip_font_font->width,
		stringwidth,
		rip_font_font->height,
		rip_tomb_colour->r,
		rip_tomb_colour->g,
		rip_tomb_colour->b,
		bufs);
	widget_text->font=rip_font_font;
	widget_text->dynamiccharwidth=TRUE;
			rip_how_y->value+=rip_font_font->height;

			bufs=bufc+1;
		}
	}

	stringwidth=noegnud_width_dynamic(rip_font_font,bufs);
	widget_text=noegnud_gui_create_text(
		((noegnud_gui_twidget *)tmpwin)->child,
		rip_how_x->value-(((float)stringwidth)/2),
		rip_how_y->value,
		stringwidth,
		rip_font_font->height,
		rip_tomb_colour->r,
		rip_tomb_colour->g,
		rip_tomb_colour->b,
		bufs);
	widget_text->font=rip_font_font;
	widget_text->dynamiccharwidth=TRUE;

}
Ejemplo n.º 28
0
int proc_tcm_activateidentity(void * sub_proc,void * recv_msg)
{
	int ret=0;
	int fd;

	BYTE Buf[DIGEST_SIZE*32];
	BYTE NameBuf[DIGEST_SIZE*4];
	BYTE KeyBuf[DIGEST_SIZE*4];
	BYTE digest[DIGEST_SIZE];
	UINT32 result;
	DB_RECORD * db_record;
	RECORD(TCM_PIK_DESC,USERINFO)  * pik_userinfo;
	RECORD(TCM_PIK_DESC,CADATA)  * pik_cadata;
	RECORD(TCM_PIK_DESC,PIKCERT)  * pik_cert;
        RECORD(VTCM_IN_KEY,TCM_BIN_KEY) tcm_pik;
        RECORD(VTCM_IN_KEY,TCM_BIN_PUBKEY) tcm_pikpub;
        RECORD(TCM_KEY_MANAGE,PRIVATE_KEY) * tcm_pik_info;
    	TCM_SYMMETRIC_KEY symmkey;
	void * new_msg;
	int key_len;
	void * tcm_key_template;

    	UINT32 smkHandle;
    	UINT32 ownerHandle;
    	UINT32 keyHandle;
    	UINT32 keyAuthHandle;
	char uuid[DIGEST_SIZE*2+1];
        

	printf("begin pik activateidentity!\n");

	// get pik cadata from message
	
	ret=message_get_record(recv_msg,&pik_cadata,0);
	if(ret<0)
		return -EINVAL;
	if(pik_cadata==NULL)
		return -EINVAL;
	
	// find pikinfo record
	
	db_record=memdb_find_first(TYPE_PAIR(TCM_KEY_MANAGE,PRIVATE_KEY),"pubkey_uuid",pik_cadata->pikpub_uuid);
	if(db_record==NULL)
	{
		print_cubeerr("can't find pik record!\n");
		return -EINVAL;
	}
	tcm_pik_info=db_record->record;	
	
	// get pik file name
	digest_to_uuid(tcm_pik_info->uuid,uuid);
	uuid[DIGEST_SIZE*2]=0;
	printf("get pik's uuid is %s!\n",uuid);	
	Strcpy(NameBuf,"tcmkey/");
	Strcat(NameBuf,uuid);
	ret=TCM_ExLoadTcmKey(&tcm_pik,NameBuf);
	if(ret!=0)
	{
		print_cubeerr("Load TCMKey from file failed!\n");
		return ret;
	}
	// Load pik to TCM 
    	ret=TCM_APCreate(TCM_ET_SMK, NULL, "sss", &smkHandle);
    	printf("smkHandle is : %x\n",smkHandle);
    	if(ret<0)
    	{
		printf("TCM_APCreate failed!\n");
		return -EINVAL;	
    	}	
    	ret=TCM_LoadKey(smkHandle,NameBuf,&keyHandle);
    	if(ret!=0)
    	{
		print_cubeerr("TCM_LoadKey failed!\n");
		return ret;	
    	}	
    	ret=TCM_APTerminate(smkHandle);
    	if(ret!=0)
    	{
		printf("TCM_APTerminate failed!\n");
		return ret;	
	}

	// do the activateidentity 
    	ret=TCM_APCreate(TCM_ET_OWNER, NULL, "ooo", &ownerHandle);
    	printf("ownerHandle is : %x\n",ownerHandle);
    	if(ret<0)
    	{
		print_cubeerr("TCM_APCreate failed!\n");
		return -EINVAL;	
    	}	

    	ret=TCM_APCreate(TCM_ET_KEYHANDLE,keyHandle, "kkk", &keyAuthHandle);
    	printf("pikHandle is : %x\n",keyAuthHandle);
    	if(ret!=0)
    	{
		printf("TCM_APCreate failed!\n");
		return -EINVAL;	
    	}	

    	ret=TCM_ActivateIdentity(keyHandle,keyAuthHandle,ownerHandle,
		pik_cadata->symmkey_len,pik_cadata->symmkey,&symmkey,"ooo","kkk");	
    	if(ret!=0)
    	{
		printf("TCM_ActivateIdentity failed!\n");
		return -EINVAL;	
    	}	
    	ret=TCM_APTerminate(ownerHandle);
    	if(ret<0)
    	{
		printf("TCM_APTerminate failed!\n");
		return -EINVAL;	
    	}	

    	ret=TCM_APTerminate(keyAuthHandle);
    	if(ret<0)
    	{
		printf("TCM_APTerminate failed!\n");
		return -EINVAL;	
    	}	

    	ret=TCM_EvictKey(keyHandle);
   	if(ret<0)
    	{
		printf("TCM_APTerminate failed!\n");
		return -EINVAL;	
    	}	

    	// decrypt cert blob
    	int blobsize;
    	BYTE * cert;
    	int certsize;

    	ret=TCM_ExSymmkeyDecrypt(&symmkey,pik_cadata->cert,pik_cadata->certlen,&cert,&certsize);
    	if(ret!=0)
    	{
		printf("decrypt cert blob file error!\n");
		return -EINVAL;	
    	}

	int offset;
	for(offset=0;cert[offset]==0;offset++)
	{
		if((offset>=16)|| (offset>=certsize))
		{
			print_cubeerr("cert data failed!\n");
			return -EINVAL;
		}
	}

	// build pik cert, it is organized by userinfo, pubkey and  ca_conts
	//
	pik_cert=Talloc0(sizeof(*pik_cert));
	if(pik_cert==NULL)
		return -ENOMEM;
	
	tcm_key_template=memdb_get_template(TYPE_PAIR(TCM_PIK_DESC,VERIFYDATA));
	if(tcm_key_template==NULL)
		return -EINVAL;
	ret=blob_2_struct(cert+offset,&pik_cert->verifydata,tcm_key_template);
	if(ret<0)
		return -EINVAL;
	
	db_record=memdb_find(pik_cadata->userinfo_uuid,TYPE_PAIR(TCM_PIK_DESC,USERINFO));
	if(db_record==NULL)
	{
		print_cubeerr("can't find user info data!\n");
		return -EINVAL;
	}
	
	pik_userinfo=db_record->record;

	tcm_key_template=memdb_get_template(TYPE_PAIR(TCM_PIK_DESC,USERINFO));
	if(tcm_key_template==NULL)
		return -EINVAL;
	ret=struct_clone(pik_userinfo,&pik_cert->userinfo,tcm_key_template);
	if(ret<0)
		return -EINVAL;

	ret=TCM_ExGetPubkeyFromTcmkey(&tcm_pikpub,&tcm_pik);
	if(ret!=0)
	{
		print_cubeerr("Get Pubpik failed!\n");
		return -EINVAL;
	}
	tcm_key_template=memdb_get_template(TYPE_PAIR(VTCM_IN_KEY,TCM_BIN_PUBKEY));
	if(tcm_key_template==NULL)
		return -EINVAL;
	ret=struct_clone(&tcm_pikpub,&pik_cert->pikpub,tcm_key_template);
	if(ret<0)
		return -EINVAL;

	// build a message and send it 
	new_msg=message_create(TYPE_PAIR(TCM_PIK_DESC,PIKCERT),recv_msg);
	if(new_msg==NULL)
		return -EINVAL;
	ret=message_add_record(new_msg,pik_cert);
	if(ret<0)
		return ret;
	
	ret=ex_module_sendmsg(sub_proc,new_msg);
	return ret;
}
Ejemplo n.º 29
0
int proc_tcm_makeidentity(void * sub_proc,void * recv_msg)
{
	int ret=0;
	int fd;

	BYTE local_uuid[DIGEST_SIZE];	
	
	BYTE Buf[DIGEST_SIZE*32];
	BYTE NameBuf[DIGEST_SIZE*4];
	UINT32 result;
	RECORD(TCM_PIK_DESC,USERINFO)  * pik_userinfo;
	RECORD(MESSAGE,SIZED_BINDATA) req_blob;
        RECORD(VTCM_IN_KEY,TCM_BIN_KEY) tcm_pik;
        RECORD(VTCM_IN_KEY,TCM_BIN_PUBKEY) tcm_pikpub;
        RECORD(TCM_KEY_MANAGE,PRIVATE_KEY) tcm_pik_info;
	void * new_msg;
	int key_len;
	void * tcm_key_template;

    	UINT32 smkHandle;
    	UINT32 ownerHandle;
    	UINT32 keyHandle;
    	UINT32 keyAuthHandle;
	char uuid[DIGEST_SIZE*2+1];
	DB_RECORD * db_record;
        

	printf("begin pik makeidentity!\n");

	// get pik_userinfo from message
	
	ret=message_get_record(recv_msg,&pik_userinfo,0);
	if(ret<0)
		return -EINVAL;
	if(pik_userinfo==NULL)
		return -EINVAL;

	// get this node's machine uuid
        ret=proc_share_data_getvalue("uuid",pik_userinfo->node_uuid);
	if(ret<0)
		return ret;

	// get this node's hostname
	
	ret=gethostname(pik_userinfo->node_name,DIGEST_SIZE);
	if(ret!=0)
		Memset(pik_userinfo->node_name,0,DIGEST_SIZE);

	// build tcm session
    	ret=TCM_APCreate(TCM_ET_OWNER, NULL, "ooo", &ownerHandle);
    	printf("ownerHandle is : %x\n",ownerHandle);
    	if(ret<0)
    	{
		print_cubeerr("TCM_APCreate failed!\n");
		return -EINVAL;	
    	}	

    	ret=TCM_APCreate(TCM_ET_SMK, NULL, "sss", &smkHandle);
    	printf("smkHandle is : %x\n",smkHandle);
    	if(ret<0)
    	{
		printf("TCM_APCreate failed!\n");
		return -EINVAL;	
    	}	

	int userinfolen;
    	BYTE * req;
    	int reqlen;	
	// get userinfo blob 

	tcm_key_template=memdb_get_template(TYPE_PAIR(TCM_PIK_DESC,USERINFO));
	if(tcm_key_template==NULL)
		return -EINVAL;
	userinfolen=struct_2_blob(pik_userinfo,Buf,tcm_key_template);
	if(userinfolen<0)
		return userinfolen;

	db_record=memdb_store(pik_userinfo,TYPE_PAIR(TCM_PIK_DESC,USERINFO),NULL);
	if(db_record==NULL)
		return -EINVAL;
	// do makeidentity   
    	ret = TCM_MakeIdentity(ownerHandle, smkHandle,
		userinfolen,Buf,"kkk",
		&tcm_pik, &req, &reqlen);
    	if(ret<0)
    	{
		print_cubeerr("TCM_MakeIdentity failed!\n");
		return -EINVAL;	
    	}

	// build an expand message record for req data
	req_blob.size=reqlen;
	req_blob.bindata=req;	

	// terminate session	
    	ret=TCM_APTerminate(ownerHandle);
    	if(ret<0)
    	{
		print_cubeerr("TCM_APTerminate failed!\n");
		return -EINVAL;	
    	}	

    	ret=TCM_APTerminate(smkHandle);
    	if(ret<0)
    	{
		print_cubeerr("TCM_APTerminate failed!\n");
		return -EINVAL;	
	}
	
	// generate TCM pik info ,left pubkey_uuid for fill
	tcm_key_template=memdb_get_template(TYPE_PAIR(VTCM_IN_KEY,TCM_BIN_KEY));
	if(tcm_key_template==NULL)
		return -EINVAL;
	key_len=struct_2_blob(&tcm_pik,Buf,tcm_key_template);
	if(key_len<0)
		return key_len;

	Memset(&tcm_pik_info,0,sizeof(tcm_pik_info));
	calculate_context_sm3(Buf,key_len,tcm_pik_info.uuid);
	Memcpy(tcm_pik_info.vtcm_uuid,local_uuid,DIGEST_SIZE);
	tcm_pik_info.issmkwrapped=1;
	tcm_pik_info.key_usage=TCM_KEY_IDENTITY;
	tcm_pik_info.key_flags=TCM_ISVOLATILE|TCM_PCRIGNOREDONREAD;

	// store pik file
	digest_to_uuid(tcm_pik_info.uuid,uuid);
	uuid[DIGEST_SIZE*2]=0;
	printf("get pik's uuid is %s!\n",uuid);	

	Strcpy(NameBuf,"tcmkey/");
	Strcat(NameBuf,uuid);

        fd=open(NameBuf,O_CREAT|O_WRONLY,0666);
        if(fd<0)
                return fd;
        write(fd,Buf,key_len);
        close(fd);

	// Get pikpub from pik 
	//
	ret=TCM_ExGetPubkeyFromTcmkey(&tcm_pikpub,&tcm_pik);
	if(ret!=0)
	{
		print_cubeerr("Get Pubpik failed!\n");
		return -EINVAL;
	}

	
	tcm_key_template=memdb_get_template(TYPE_PAIR(VTCM_IN_KEY,TCM_BIN_PUBKEY));
	if(tcm_key_template==NULL)
		return -EINVAL;
	key_len=struct_2_blob(&tcm_pikpub,Buf,tcm_key_template);
	if(key_len<0)
		return key_len;
	calculate_context_sm3(Buf,key_len,tcm_pik_info.pubkey_uuid);
	db_record=memdb_store(&tcm_pik_info,TYPE_PAIR(TCM_KEY_MANAGE,PRIVATE_KEY),NULL);

	// build a message and send it 
	new_msg=message_create(TYPE_PAIR(TCM_PIK_DESC,USERINFO),recv_msg);
	if(new_msg==NULL)
		return -EINVAL;
	ret=message_add_record(new_msg,pik_userinfo);
	if(ret<0)
		return ret;
	
	ret=message_add_expand_data(new_msg,TYPE_PAIR(MESSAGE,SIZED_BINDATA),&req_blob);
	if(ret<0)
		return -EINVAL;
	ret=message_add_expand_data(new_msg,TYPE_PAIR(VTCM_IN_KEY,TCM_BIN_PUBKEY),&tcm_pikpub);
	if(ret<0)
		return -EINVAL;

	ret=ex_module_sendmsg(sub_proc,new_msg);
	return ret;
}
Ejemplo n.º 30
0
Archivo: istream.c Proyecto: macks/w3m
Str
ssl_get_certificate(SSL * ssl, char *hostname)
{
    BIO *bp;
    X509 *x;
    X509_NAME *xn;
    char *p;
    int len;
    Str s;
    char buf[2048];
    Str amsg = NULL;
    Str emsg;
    char *ans;

    if (ssl == NULL)
	return NULL;
    x = SSL_get_peer_certificate(ssl);
    if (x == NULL) {
	if (accept_this_site
	    && strcasecmp(accept_this_site->ptr, hostname) == 0)
	    ans = "y";
	else {
	    /* FIXME: gettextize? */
	    emsg = Strnew_charp("No SSL peer certificate: accept? (y/n)");
	    ans = inputAnswer(emsg->ptr);
	}
	if (ans && TOLOWER(*ans) == 'y')
	    /* FIXME: gettextize? */
	    amsg = Strnew_charp
		("Accept SSL session without any peer certificate");
	else {
	    /* FIXME: gettextize? */
	    char *e = "This SSL session was rejected "
		"to prevent security violation: no peer certificate";
	    disp_err_message(e, FALSE);
	    free_ssl_ctx();
	    return NULL;
	}
	if (amsg)
	    disp_err_message(amsg->ptr, FALSE);
	ssl_accept_this_site(hostname);
	/* FIXME: gettextize? */
	s = amsg ? amsg : Strnew_charp("valid certificate");
	return s;
    }
#ifdef USE_SSL_VERIFY
    /* check the cert chain.
     * The chain length is automatically checked by OpenSSL when we
     * set the verify depth in the ctx.
     */
    if (ssl_verify_server) {
	long verr;
	if ((verr = SSL_get_verify_result(ssl))
	    != X509_V_OK) {
	    const char *em = X509_verify_cert_error_string(verr);
	    if (accept_this_site
		&& strcasecmp(accept_this_site->ptr, hostname) == 0)
		ans = "y";
	    else {
		/* FIXME: gettextize? */
		emsg = Sprintf("%s: accept? (y/n)", em);
		ans = inputAnswer(emsg->ptr);
	    }
	    if (ans && TOLOWER(*ans) == 'y') {
		/* FIXME: gettextize? */
		amsg = Sprintf("Accept unsecure SSL session: "
			       "unverified: %s", em);
	    }
	    else {
		/* FIXME: gettextize? */
		char *e =
		    Sprintf("This SSL session was rejected: %s", em)->ptr;
		disp_err_message(e, FALSE);
		free_ssl_ctx();
		return NULL;
	    }
	}
    }
#endif
    emsg = ssl_check_cert_ident(x, hostname);
    if (emsg != NULL) {
	if (accept_this_site
	    && strcasecmp(accept_this_site->ptr, hostname) == 0)
	    ans = "y";
	else {
	    Str ep = Strdup(emsg);
	    if (ep->length > COLS - 16)
		Strshrink(ep, ep->length - (COLS - 16));
	    Strcat_charp(ep, ": accept? (y/n)");
	    ans = inputAnswer(ep->ptr);
	}
	if (ans && TOLOWER(*ans) == 'y') {
	    /* FIXME: gettextize? */
	    amsg = Strnew_charp("Accept unsecure SSL session:");
	    Strcat(amsg, emsg);
	}
	else {
	    /* FIXME: gettextize? */
	    char *e = "This SSL session was rejected "
		"to prevent security violation";
	    disp_err_message(e, FALSE);
	    free_ssl_ctx();
	    return NULL;
	}
    }
    if (amsg)
	disp_err_message(amsg->ptr, FALSE);
    ssl_accept_this_site(hostname);
    /* FIXME: gettextize? */
    s = amsg ? amsg : Strnew_charp("valid certificate");
    Strcat_charp(s, "\n");
    xn = X509_get_subject_name(x);
    if (X509_NAME_get_text_by_NID(xn, NID_commonName, buf, sizeof(buf)) == -1)
	Strcat_charp(s, " subject=<unknown>");
    else
	Strcat_m_charp(s, " subject=", buf, NULL);
    xn = X509_get_issuer_name(x);
    if (X509_NAME_get_text_by_NID(xn, NID_commonName, buf, sizeof(buf)) == -1)
	Strcat_charp(s, ": issuer=<unknown>");
    else
	Strcat_m_charp(s, ": issuer=", buf, NULL);
    Strcat_charp(s, "\n\n");

    bp = BIO_new(BIO_s_mem());
    X509_print(bp, x);
    len = (int)BIO_ctrl(bp, BIO_CTRL_INFO, 0, (char *)&p);
    Strcat_charp_n(s, p, len);
    BIO_free_all(bp);
    X509_free(x);
    return s;
}