Пример #1
0
int ticketCtl2Press(Control *pCtl,int ch,long lParam)
{   /* 实时刷新button的按键消息处理 */
    /* Add your self code here: */
Control *List;
if (ch == '\r') {
	signal( SIGINT,  NULL);
	signal( SIGINT,  (void (*)(int))TicketMonitorEnd );
	g_ticket_monitor_flag = 1;
	List = GetCtlByID (ticket_handle, 6);
	while ( g_ticket_monitor_flag ) {
		l_lpnum = GetTicketInfo();
		if (l_lpnum < 0) {
			prtmsg (pCtl, 20, 41, "获取统计信息失败");
			return 0;
		}
		else if(l_lpnum == 0)
		{
			prtmsg (pCtl, 20, 41, "没有统计信息");
			return 0;
		}
		List->iAdditional = l_lpnum;
		List->pData = ticket_list_index;	
		CtlShow(List);
		sleep(1);
	}
	CtlAtv( pCtl,pCtl );
}

return ch;
}
Пример #2
0
static int verify_single_result(LDAP *l, int always_log, char *reason, LDAPMessage *messages)
{
  int rc, erc, num_entries;
  char *errmsg;

  rc = ldap_parse_result(l, messages, &erc, NULL, &errmsg,
			 NULL, NULL, 0);
  if (rc != LDAP_SUCCESS) {
    prtmsg("Failed to %s (parse_result): %s", reason, ldap_err2string(rc));
    return 0;
  }
  if (erc != LDAP_SUCCESS) {
    prtmsg("Failed to %s (server response): %s%s%s", reason, ldap_err2string(erc),
	   (errmsg?", ":""), (errmsg?errmsg:""));
    if (errmsg)
      ldap_memfree(errmsg);
    return 0;
  }
  if (errmsg)
    ldap_memfree(errmsg);
  num_entries=ldap_count_entries(l, messages);
  if (num_entries == 0) {
    if (always_log) 
      prtmsg("Failed to %s (no entries returned)", reason);
    return 0;
  }
  if (num_entries > 1) {
    prtmsg("Failed to %s (too many entries: %d)", reason, num_entries);
    return 0;
  }
  return 1;
}
Пример #3
0
int ticketCtl1Press(Control *pCtl,int ch,long lParam)
{   /* 刷新button的按键消息处理 */
    /* Add your self code here: */

	Control *pTicketList;
	
	if (ch == '\r') {
		l_lpnum = GetTicketInfo();
		if (l_lpnum < 0) {
			prtmsg (pCtl, 20, 41, "获取统计信息失败");
			return 0;
		}
		else if(l_lpnum == 0)
		{
			prtmsg (pCtl, 20, 41, "没有统计信息");
			return 0;
		}
		
		pTicketList = GetCtlByID (ticket_handle, 6);
		pTicketList->iAdditional = l_lpnum;
		pTicketList->pData = ticket_list_index;		
		CtlShow (pTicketList);
		CtlAtv (pCtl, pCtl);
		
	}
	
	return ch;
}
Пример #4
0
int msgqueueCtl4Press(Control *pCtl,int ch,long lParam)
{   /* 删除队列button的按键消息处理 */
    /* Add your self code here: */
    if (ch == '\r') {
        Control *pList = GetCtlByID (msgqueue_handle, 6);
        
        if (ListSelNum (pList) == 0) {
            prtmsg (pCtl, 20, 40, "请在队列列表框中按空格选择队列");
            return ch;
        }
        
        if (yorn (pCtl, 20, 40, "WARNING:确实要删除?(y/n)")==0) 
            return ch;
        
        for (int i=0; i<g_iMQListCount; i++) {
            if (ListItemState (pList, i) != SELECTED)
                continue;
            
            MessageQueue mq(g_tMQList[i].iMQID);
            mq.remove ();
        }
        
        SetMQListData ();
        CtlShow (pList);
        CtlAtv (pCtl, pCtl);    
    }
    
    return ch;

}
Пример #5
0
int processCtl8Press(Control *pCtl,int ch,long lParam)
{   /* 进程强制kill.button的按键消息处理 */
    /* Add your self code here: */
	Control *pList;
	int i, iFlag = 1;

	if (ch == '\r') {

		pList = GetCtlByID (process_handle, 6);

		for (i=0; i<l_lprocnum; i++) {
		    if (ListItemState (pList, i) != SELECTED)
		    	continue;

		    iFlag = 0;
		    if (InfoList[i]->iState==ST_RUNNING || InfoList[i]->iState==ST_INIT )
		        InfoList[i]->iState = ST_ENFORCE_DOWN;		    
		}
		if (iFlag)
		    prtmsg (pCtl, 20, 40, "请在进程列表中用空格选择进程");

		GetProcInfo ();
		CtlShow (pList);
		CtlAtv (pCtl, pCtl);
	}

	return ch;
}
Пример #6
0
int msgqueueCtl3Press(Control *pCtl,int ch,long lParam)
{   /* 创建队列button的按键消息处理 */
    /* Add your self code here: */
    if (ch == '\r') {
            Control *pList = GetCtlByID (msgqueue_handle, 6);
            
            if (ListSelNum (pList) == 0) {
                prtmsg (pCtl, 20, 40, "请在队列列表框中按空格选择队列");
                return ch;
            }
            
            for (int i=0; i<g_iMQListCount; i++) {
                if (ListItemState (pList, i) != SELECTED)
                    continue;
            
                MessageQueue mq(g_tMQList[i].iMQID);
                mq.open (true, true, sizeof (StdEvent), g_tMQList[i].iMaxMsgNum);
            }
            
            SetMQListData ();
            CtlShow (pList);
            CtlAtv (pCtl, pCtl);        
    }
    return ch;
}
Пример #7
0
void sess_finalize(struct rekey_session *sess) 
{
  OM_uint32 min;
  if (sess->state == REKEY_SESSION_SENDING)
    prtmsg("warning: session closed before reply sent");
  if (sess->ssl) {
    SSL_shutdown(sess->ssl);
    SSL_free(sess->ssl);
  }
  if (sess->kadm_handle)
    kadm5_destroy(sess->kadm_handle);
  if (sess->realm) {
#if defined(HAVE_KRB5_REALM)
    krb5_xfree(sess->realm);
#else
    krb5_free_default_realm(sess->kctx, sess->realm);
#endif
  }
  if (sess->princ)
    krb5_free_principal(sess->kctx, sess->princ);
  if (sess->kctx)
    krb5_free_context(sess->kctx);
  if (sess->gctx)
    (void)gss_delete_sec_context(&min, &sess->gctx, GSS_C_NO_BUFFER);
  if (sess->name)
    (void)gss_release_name(&min, &sess->name);
  if (sess->dbh)
    sqlite3_close(sess->dbh);
  free(sess->hostname);
  free(sess->plain_name);
  memset(&sess, 0, sizeof(sess));
}
Пример #8
0
int kadm_init(struct rekey_session *sess) 
{
  void *kadm_handle=NULL;
  kadm5_config_params kadm_param;
  int rc;

  rc = krealm_init(sess);
  if (rc)
    return rc;

  kadm_param.mask = KADM5_CONFIG_REALM;
  kadm_param.realm = sess->realm;

#ifdef HAVE_KADM5_INIT_WITH_SKEY_CTX
  rc = kadm5_init_with_skey_ctx(sess->kctx, "rekey/admin", NULL, KADM5_ADMIN_SERVICE,
			    &kadm_param, KADM5_STRUCT_VERSION, 
			    KADM5_API_VERSION_2, &kadm_handle);
#else
  rc = kadm5_init_with_skey(sess->kctx, "rekey/admin", NULL, KADM5_ADMIN_SERVICE,
			    &kadm_param, KADM5_STRUCT_VERSION, 
			    KADM5_API_VERSION_2, NULL, &kadm_handle);
#endif
  if (rc) {
    prtmsg("Unable to initialize kadm5 library: %s", krb5_get_err_text(sess->kctx, rc));
    return rc;
  }
   sess->kadm_handle = kadm_handle;
  return 0;
}
Пример #9
0
int processCtl2Press(Control *pCtl,int ch,long lParam)
{   /* 实时刷新button的按键消息处理 */
    /* Add your self code here: */
		Control *List;
		if (ch == '\r') {
		signal( SIGINT,  NULL);
		signal( SIGINT,  (void (*)(int))ProcMonitorEnd );
		g_proc_monitor_flag = 1;
		List = GetCtlByID (process_handle, 6);
		int rows = 0;
		
		while ( g_proc_monitor_flag ) {
		    if ((rows = GetProcInfo ()) < 0) {
		    prtmsg (pCtl, 20, 41, "连接共享内存错误");
		    return 0;
		    }
			List->iAdditional = rows;
			List->pData = proc_list_index;
		    CtlShow(List);
		    sleep(1);
		}
		CtlAtv( pCtl,pCtl );
		}
	
		return ch;

}
Пример #10
0
int sql_rollback_trans(struct rekey_session *sess) 
{
  char *errmsg;
  int rc;
  
  rc = sqlite3_exec(sess->dbh, "ROLLBACK TRANSACTION", NULL, NULL, &errmsg);
  if (rc != SQLITE_OK) {
    if (errmsg) {
      prtmsg("SQL ROLLBACK TRANSACTION failed: %s", errmsg);
      sqlite3_free(errmsg);
    } else {
      prtmsg("SQL ROLLBACK TRANSACTION failed: %d", rc);
    }
    return 1;
  }
  return 0;
}
Пример #11
0
void sess_send(struct rekey_session *sess, int opcode, mb_t buf) 
{
  if (sess->state != REKEY_SESSION_SENDING) {
    prtmsg("Cannot send message (of type %d) while in state %d\n", opcode,
           sess->state);
    return;
  }
  do_send(sess->ssl, opcode, buf);
  sess->state = REKEY_SESSION_IDLE;
}
Пример #12
0
static void send_gss_error_cb(void *rock, gss_buffer_t status_string) 
{
  mb_t outbuf = (mb_t)rock;
  int newsize = outbuf->length + status_string->length + 1;
  char *p;

  prtmsg("%.*s",
         (int)status_string->length,
         (char *)status_string->value);
  if (buf_grow(outbuf, newsize))
    return;

  p = ((char *)outbuf->value) + outbuf->length;
  memcpy(p, status_string->value, status_string->length);
  p += status_string->length;
  *p++=0;
  if (p != ((char *)outbuf->value) + newsize)
    prtmsg("Warning: send_gss_error_cb: pointer mismatch: %p + %d != %p",
           outbuf->value, newsize, p);
  outbuf->length = newsize; 
}
Пример #13
0
static int verify_op_success(LDAP *l, char *reason, LDAPMessage *messages)
{
  int rc, erc;
  char *errmsg;

  rc = ldap_parse_result(l, messages, &erc, NULL, &errmsg,
			 NULL, NULL, 0);
  if (rc != LDAP_SUCCESS) {
    prtmsg("Failed to %s (parse_result): %s", reason, ldap_err2string(rc));
    return 0;
  }
  if (erc != LDAP_SUCCESS) {
    prtmsg("Failed to %s (server response): %s%s%s", reason, ldap_err2string(erc),
	   (errmsg?", ":""), (errmsg?errmsg:""));
    if (errmsg)
      ldap_memfree(errmsg);
    return 0;
  }
  if (errmsg)
    ldap_memfree(errmsg);
  return 1;
}
Пример #14
0
int sess_recv(struct rekey_session *sess, mb_t buf) 
{
  int ret;
  if (sess->state != REKEY_SESSION_LISTENING) {
    prtmsg("Cannot read from session while in state %d\n",
           sess->state);
    return -1;
  }
  ret = do_recv(sess->ssl, buf);
  if (ret > 0)
    sess->state = REKEY_SESSION_SENDING;
  return ret;
}
Пример #15
0
int krealm_init(struct rekey_session *sess) {
  int rc;
  char *realm=NULL;  
  if (sess->realm) {
    return 0;
  }
  rc=krb5_get_default_realm(sess->kctx, &realm);
  if (rc) {
    prtmsg("Unable to get default realm: %s", krb5_get_err_text(sess->kctx, rc));
    return rc;
  }
  sess->realm = realm;
  return 0;
}
Пример #16
0
void send_gss_error(struct rekey_session *sess, gss_OID mech, int errmaj, int errmin) 
{
  mb_t msgbuf;
  msgbuf=buf_alloc(8);
  if (!msgbuf)
    return;
  buf_setlength(msgbuf, 8);
  do_gss_error(mech, errmaj, errmin, send_gss_error_cb, msgbuf);
  reset_cursor(msgbuf);
  if (buf_putint(msgbuf, ERR_AUTHN) ||
      buf_putint(msgbuf, msgbuf->length - 8)) {
    prtmsg("internal error in send_gss_error, cannot pack message");
    buf_free(msgbuf);
    return;
  }
  sess_send(sess, RESP_ERR, msgbuf);
  buf_free(msgbuf);
}
Пример #17
0
int main()
{
    /*printf("%d\n", sizeof(int));
    printf("%d\n", sizeof(char));
    printf("%d\n", sizeof("baby")); */
    char string[] = "We are the champion !!!";

    printf("address of string is : %p\n", string);
    printf("size of string : %i bytes\n", sizeof(string));

    prtmsg(string);
    /*
    char c = 'a';
    printf("%c:%p\n", c, &c);
    printf("%i:%i\n", sizeof(c), sizeof(&c));
    char *p = &c;
    printf("%p\n", p);
    *p = 'h';
    printf("char c is %c\n", c);

    int drinks[] = {4, 2, 3};

    printf("3rd order: %i drinks and the address is %p\n", 0[drinks], &0[drinks]); // print 4
    printf("3rd order: %i drinks and the address is %p\n", 1[drinks], &1[drinks]); // print 4
    printf("3rd order: %i drinks and the address is %p\n", 2[drinks], &2[drinks]); // print 4
    /*
    printf("3rd order: %i drinks and the address is %p\n", drinks[0], &drinks[0]); // print 4
    printf("3rd order: %i drinks and the address is %p\n", *drinks, drinks); // print 4
    printf("3rd order: %i drinks and the address is %p\n", drinks[1], &drinks[1]); // print 4
    printf("3rd order: %i drinks and the address is %p\n", *(drinks + 1), drinks + 1); // print 4
    printf("3rd order: %i drinks and the address is %p\n", drinks[2], &drinks[2]); // print 3
    printf("3rd order: %i drinks and the address is %p\n", *(drinks + 2), drinks + 2); // print 3
    printf("3rd order: %i drinks and the address is %p\n", *drinks + 2, drinks + 2); // print 6
    printf("3rd order: %i drinks and the address is %p\n", *(drinks + 2) + 2, drinks + 2); // print 5
    */
}
Пример #18
0
int processCtl1Press(Control *pCtl,int ch,long lParam)
{   /* 刷新button的按键消息处理 */
    /* Add your self code here: */
		Control *pProcList;
		
		int rows = 0;
		if (ch == '\r') {
			if ((rows = GetProcInfo ()) < 0) {
			    prtmsg (pCtl, 20, 41, "连接共享内存错误");
			    return 0;
			}
		
			pProcList = GetCtlByID (process_handle, 6);
		
			pProcList->iAdditional = rows;
			pProcList->pData = proc_list_index;
		
			CtlShow (pProcList);
			CtlAtv (pCtl, pCtl);
		}
		
		return ch;

}
Пример #19
0
int is_admin(struct rekey_session *sess)
{
  static int ldap_initialized=0;
  char *username=NULL;
  LDAP *l=NULL;
  int v, ssl_hard=LDAP_OPT_X_TLS_HARD, rc, ret=0;
  struct timeval tv;
  LDAPMessage *response=NULL;
  char *reason, *filter;
  char *ldap_url, *ldap_base, *ldap_filter, *ldap_binddn;
  char *ldap_pwfile, *ldap_cacertdir;
  char ldap_pwbuf[257];
#ifdef HAVE_KRB5_REALM
  krb5_realm *realm;
#else
  krb5_data rdata;
  krb5_data *realm = &rdata;
#endif
#if !defined(LDAP_OPT_X_TLS_PROTOCOL_MIN)
  SSL_CTX *sslctx;
#endif

  if (!princ_ncomp_eq(sess->kctx, sess->princ, 2) ||
      !compare_princ_comp(sess->kctx, sess->princ, 1, "admin")) {
    goto freeall;
  }

  if (!(username=dup_comp_string(sess->kctx, sess->princ, 0))) {
    prtmsg("Failed to extract username for admin check");
    goto freeall;
  }

#ifdef HAVE_KRB5_REALM
  realm=sess->realm;
#else
  rdata.data=sess->realm;
  rdata.length=strlen(sess->realm);
#endif
  krb5_appdefault_string(sess->kctx, "rekey", realm, "ldap_uri", LDAP_URI, &ldap_url);
  krb5_appdefault_string(sess->kctx, "rekey", realm, "ldap_base", LDAP_BASEDN, &ldap_base);
  krb5_appdefault_string(sess->kctx, "rekey", realm, "ldap_filter", USER_INGROUP_FILTER, &ldap_filter);
  krb5_appdefault_string(sess->kctx, "rekey", realm, "ldap_binddn", LDAP_BINDDN, &ldap_binddn);
  krb5_appdefault_string(sess->kctx, "rekey", realm, "ldap_pwfile", LDAP_PWFILE, &ldap_pwfile);
  krb5_appdefault_string(sess->kctx, "rekey", realm, "ldap_cacertdir", "/etc/andy/ldapcerts", &ldap_cacertdir);

  if (strlen(ldap_pwfile) > 0) {
    int fd=open(ldap_pwfile, O_RDONLY);
    ssize_t rsize;
    if (fd < 0) {
      prtmsg("Failed to open LDAP password file %s: %s", ldap_pwfile, strerror(errno));
      goto freeall;
    }
    rsize=read(fd, ldap_pwbuf, 256);
    if (rsize < 0) {
      prtmsg("Failed to read from LDAP password file %s: %s", ldap_pwfile, strerror(errno));
      goto freeall;
    }
    if (rsize > 255) {
      prtmsg("LDAP password file %s is too large. limit to 255 characters", ldap_pwfile);
      goto freeall;
    }
    while(rsize > 0 && isspace(ldap_pwbuf[rsize-1]))
      rsize--;
    ldap_pwbuf[rsize]=0;
  }
  if (!ldap_initialized) {
    LDAP_SET_OPTION(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &ssl_hard);
    LDAP_SET_OPTION(NULL, LDAP_OPT_X_TLS_CACERTDIR, ldap_cacertdir);
    LDAP_SET_OPTION(NULL, LDAP_OPT_X_TLS_CIPHER_SUITE, "HIGH:!ADH:!eNULL:-SSLv2");
#if defined(LDAP_OPT_X_TLS_PROTOCOL_MIN)
    v=LDAP_OPT_X_TLS_PROTOCOL_TLS1_0;
    LDAP_SET_OPTION(NULL, LDAP_OPT_X_TLS_PROTOCOL_MIN, &v);
#else
    extern int ldap_pvt_tls_init();
    extern int ldap_pvt_tls_init_def_ctx( int is_server );
    ldap_pvt_tls_init();
    ldap_pvt_tls_init_def_ctx(0);
    LDAP_GET_OPTION(NULL, LDAP_OPT_X_TLS_CTX, &sslctx);
    if (sslctx) {
      SSL_CTX_set_options(sslctx, SSL_OP_NO_SSLv2);
      SSL_CTX_set_options(sslctx, SSL_OP_NO_SSLv3);
    }
#endif
    ldap_initialized=1;
  }
  errno=0;
  rc = ldap_initialize(&l, ldap_url);

  
  if (rc!=LDAP_SUCCESS)
  {
    prtmsg("Failed to initialize ldap for %s: %s%s%s", ldap_url,
	   ldap_err2string(rc),(errno==0)?"":": ",
	   (errno==0)?"":strerror(errno));
    goto freeall;
  }
  v=LDAP_VERSION3;
  LDAP_SET_OPTION(l, LDAP_OPT_PROTOCOL_VERSION, &v);
  LDAP_SET_OPTION(l, LDAP_OPT_X_TLS, &ssl_hard);

  errno=0;
#if 0
  rc = ldap_sasl_interactive_bind_s(l, NULL, "GSSAPI", NULL, NULL,
				    LDAP_SASL_QUIET, do_sasl_interact, NULL);
#else
  rc = ldap_bind_s(l, ldap_binddn, ldap_pwbuf, LDAP_AUTH_SIMPLE);
#endif
  if (rc!=LDAP_SUCCESS)
  {
    prtmsg("Failed to connect or authenticate to ldap for %s: %s%s%s", LDAP_URI,
	   ldap_err2string(rc),(errno==0)?"":": ",
	   (errno==0)?"":strerror(errno));
    goto freeall;
  }

  tv.tv_sec=30;
  tv.tv_usec=0;
  rc = ldap_search_ext_s(l, rekey_admin_group, LDAP_SCOPE_BASE, NO_FILTER,
			 no_attrs, 0, NULL, NULL, &tv, LDAP_NO_LIMIT, &response);
  if (rc != LDAP_SUCCESS) {
      prtmsg("Failed to verify group %s existence (searching): %s%s%s", rekey_admin_group,
	   ldap_err2string(rc),(errno==0)?"":": ",
	   (errno==0)?"":strerror(errno));
      goto freeall;
  }

  reason=aasprintf("verify group %s existence", rekey_admin_group);
  if (!verify_op_success(l, reason, response))
    goto freeall;
  ldap_msgfree(response);
  response=NULL;

  filter=aasprintf(ldap_filter, username, rekey_admin_group);
  rc = ldap_search_ext_s(l, ldap_base, LDAP_SCOPE_SUB, filter,
			 no_attrs, 0, NULL, NULL, &tv, LDAP_NO_LIMIT, &response);
  if (rc != LDAP_SUCCESS) {
      prtmsg("Failed to check user %s admin permission (searching): %s%s%s", username,
	   ldap_err2string(rc),(errno==0)?"":": ",
	   (errno==0)?"":strerror(errno));
      goto freeall;
  }

  reason=aasprintf("check user %s admin permission", username);
  if (!verify_single_result(l, 0, reason, response))
    goto freeall;

  ret=1;
 freeall:
  ldap_msgfree(response);
  if (l)
    ldap_unbind_ext_s(l, NULL, NULL);
  free(username);
  return ret;
}
Пример #20
0
int sql_init(struct rekey_session *sess) 
{
  sqlite3 *dbh;
  int dblock, rc, i;
  char *sql, *errmsg;

  if (sess->dbh)
    return 0;
  
  dblock = open(REKEY_DATABASE_LOCK, O_WRONLY | O_CREAT, 0644);
  if (dblock < 0) {
    prtmsg("Cannot create/open database lock: %s", strerror(errno));
    return 1;
  }

  if (flock(dblock, LOCK_EX)) {
    prtmsg("Cannot obtain database lock: %s", strerror(errno));
    close(dblock);
    return 1;
  }

#if SQLITE_VERSION_NUMBER >= 3005000
  rc = sqlite3_open_v2(REKEY_LOCAL_DATABASE, &dbh, SQLITE_OPEN_READWRITE, NULL);
  if (rc == SQLITE_OK) {
    sess->db_lock = dblock;
    sess->dbh = dbh;
    return 0;
  }
  
  if (rc != SQLITE_ERROR && rc != SQLITE_CANTOPEN) {
    prtmsg("Cannot open database: %d", rc);
    close(dblock);
    return 1;
  }

  rc = sqlite3_open_v2(REKEY_LOCAL_DATABASE, &dbh, SQLITE_OPEN_READWRITE | 
                       SQLITE_OPEN_CREATE, NULL);
  if (rc != SQLITE_OK) { 
    prtmsg("Cannot create/open database: %d", rc);
    close(dblock);
    return 1;
  }
#else
  rc = sqlite3_open(REKEY_LOCAL_DATABASE, &dbh);
  if (rc != SQLITE_OK) { 
    prtmsg("Cannot create/open database: %d", rc);
    close(dblock);
    return 1;
  }
#endif

  rc = sqlite3_busy_timeout(dbh, 30000);
  if (rc != SQLITE_OK) {
    prtmsg("Failed setting database busy handler: %d", rc);
    sqlite3_close(dbh);
    close(dblock);
    return 1;
  }
    
#if SQLITE_VERSION_NUMBER >= 3003007 /* need support for CREATE TRIGGER IF NOT EXIST */
  for (sql=sql_embeded_init[i=0]; sql;sql=sql_embeded_init[++i]) {
    rc = sqlite3_exec(dbh, sql, NULL, NULL, &errmsg);
    if (rc != SQLITE_OK) {
      if (errmsg) {
        prtmsg("SQL Initialization action %d failed: %s", i, errmsg);
        sqlite3_free(errmsg);
      } else {
        prtmsg("SQL Initialization action %d failed: %d", i, rc);
      }
      sqlite3_close(dbh);
      close(dblock);
      return 1;
    }
  }
#else
#warning Automatic database initialization not available
#endif
  sess->db_lock = dblock;
  sess->dbh = dbh;
  return 0;
}
Пример #21
0
int dealParam(Control *pCtl,int ch,long lCMD,bool needFlag)
{
		if(!bRegister)
		{
			prtmsg (pCtl, 21, 12, "注册失败,请检查服务端以及跟服务端的连接");
			return 0;
		}
		Control *pList = GetCtlByID (param_handle, 6);
		Control *pSectEdit = GetCtlByID(param_handle, 13);//段
		Control *pParamEdit = GetCtlByID (param_handle, 15);//参数
		Control *pValEdit = GetCtlByID(param_handle, 17);//新值
		Control *pEffDateEdit = GetCtlByID (param_handle, 19);//生效日期
		AllTrims(pSectEdit->sData);
		AllTrims(pParamEdit->sData);
		AllTrims(pValEdit->sData);
		AllTrims(pEffDateEdit->sData);
		if(lCMD == MSG_PARAM_S_N)
		{
			Chang2Upper(pSectEdit->sData);
			Chang2Lower(pParamEdit->sData);
		}
		if(!pHBParamMonitor){
			pHBParamMonitor = new HBParamMonitor();
			pCommandCom = new CommandCom();
			pCommandCom->InitClient();
			pHBParamMonitor->init(15,pCommandCom);	
		}
		long result;
		bool bRes = true;
		int iLine = getLineSeq();
		char sErrInfo[80] = {0};
		char sFlashSectParam[MAX_SECTION_LEN+MAX_KEY_NAME_LEN+1] = {0};
		
		//参数是否符合基本规格
		char sSectInfo[MAX_SECTION_LEN+1] = {0};
		char sParamInfo[MAX_KEY_NAME_LEN+1] = {0};
		char sAllInfo[MAX_SECTION_LEN+MAX_KEY_NAME_LEN+MAX_KEY_VALUE_LEN*2+10] = {0};//段名.参数名=值,effdate=时间
		
		if(needFlag)
		{
			if(pSectEdit->sData[0] == '\0' || pParamEdit->sData[0] == '\0')
			{
				ParamHisRecord* pRecord = getRecordByLine(iLine);
				if(pRecord)
				{
					strncpy(sSectInfo,pRecord->sSectName,sizeof(sSectionInfo));
					strncpy(sParamInfo,pRecord->sParamName,sizeof(sParamInfo));
					bRes =  CheckAll(iLine,pValEdit->sData,pEffDateEdit->sData,lCMD,sAllInfo);
				} else {
					bRes = false;
					SETLOGPRINT;
					ALARMLOG28(0,MBC_COMMAND_hbmonitor,618,"%s",sAllInfo);
				}
			}
		} else {
			strncpy(sSectInfo,pSectEdit->sData,sizeof(sSectionInfo));
			strncpy(sParamInfo,pParamEdit->sData,sizeof(sParamInfo));
			if(pSectEdit->sData[0] || pParamEdit->sData[0])
			{
			  bRes = CheckAll(sSectInfo,sParamInfo,pValEdit->sData,pEffDateEdit->sData,lCMD,sAllInfo);
			}
			else
			{
				bRes = 1;
			}
		}
			
		if(!bRes)
		{
			prtmsg (pCtl, 21, 12, "参数格式不正确,操作失败");
			SETLOGPRINT;
			ALARMLOG28(0,MBC_COMMAND_hbmonitor,618,"%s",sAllInfo);
			return -1;
		}
		int iErrID;
		//参数规则检效
		if(lCMD == MSG_PARAM_CHANGE)
		{
			iErrID = ParamRuleCheck(sSectInfo,sParamInfo,pValEdit->sData,pEffDateEdit->sData,NULL);
			if(iErrID != 0){
				SETLOGPRINT;
				ALARMLOG28(0,MBC_COMMAND_hbmonitor,618,"%s",sAllInfo);
				bRes = false;
			}
		}
		
		if(!bRes)
		{			
			setErrInfo(iErrID,sErrInfo);			
			prtmsg (pCtl, 21, 12, sErrInfo);//"参数值不符合规则设定,操作失败");
			return -1;
		}
		
		result = pHBParamMonitor->dealParamOpera(sSectInfo,sAllInfo,lCMD);
		pSectEdit->sData[0] = '\0';
		pParamEdit->sData[0] = '\0';
		pValEdit->sData[0] = '\0';
		pEffDateEdit->sData[0] = '\0';
		switch(lCMD)
		{
			case MSG_PARAM_CHANGE:
			case MSG_PARAM_S_C:
			case MSG_PARAM_S_D:
			{
						if(result == 1)
						{
							prtmsg (pCtl, 21, 12, "操作成功");
						} else
						{ 							
							/*if(result == INIT_ERROR_NO_PARAM)
							{
								prtmsg (pCtl, 21, 12, "无对应参数");
							} else if(result == INIT_ERROR_UNRECOGNIZED){
								prtmsg (pCtl, 21, 12, "命令无法识别"); 
							} else if(result == -1){
								prtmsg (pCtl, 21, 12, "无连接"); 
							} else if(result == -2){
								prtmsg (pCtl, 21, 12, "超时,无返回结果"); 
							} else if(result == MSG__RETURN_ERROR){
								prtmsg (pCtl, 21, 12, "操作失败"); 
							} else {*/
								prtmsg (pCtl, 21, 12, "操作不成功");
							//}
							SETLOGPRINT;
							ALARMLOG28(0,MBC_COMMAND_hbmonitor,result,"%s","参数操作失败");
						}
						//pHBParamMonitor->clear();
						if(lCMD == MSG_PARAM_CHANGE)
						{
							if(sSectInfo[0]!='\0' && sParamInfo[0]!='\0')
						    {
								strcat(sFlashSectParam,sSectInfo);
								strcat(sFlashSectParam,".");
								strcat(sFlashSectParam,sParamInfo);
							}
							if(sFlashSectParam[0] != '\0')
							{
								flashParam(sSectInfo,sFlashSectParam);
							}
							return ch;
						}
						pList->iAdditional = 0;
						pList->pData = 0;
						return ch;
			}	
			case MSG_PARAM_S_N:
			case MSG_PARAM_S_ALL:						
			{						
						if(!pHBParamMonitor->param_list_index)
						{						
							pList->iAdditional = 0;
							pList->pData = 0;
							prtmsg (pCtl, 21, 12, "本次操作失败");
							SETLOGPRINT;
							ALARMLOG28(0,MBC_COMMAND_hbmonitor,580,"%s","参数操作失败");
							return ch;
						}
						pList->pData = pHBParamMonitor->param_list_index;
						pList->iAdditional = pHBParamMonitor->getRows();
						CtlShow (pList);
						CtlAtv (pCtl, pCtl);
			    		return ch;
			}
			default:
			{
						prtmsg (pCtl, 21, 12, "操作结果未知");
						SETLOGPRINT;
						ALARMLOG28(0,MBC_COMMAND_hbmonitor,581,"%s","参数操作失败");
						pList->iAdditional = 0;
						pList->pData = 0;
						break;
			}
		}
		return ch;
}
Пример #22
0
static void bit_dump (uint32_t eim) {
    std::bitset<sizeof(uint32_t)*8> mask (eim);
    for (size_t i = 0; i < sizeof(uint32_t)*8; ++i)
        prtmsg("%d", (int)mask.test(i));
    prtmsg("\n");
}