Example #1
0
void send_zgram(char *inst, char *msg)
{
#ifdef HAVE_ZEPHYR
  ZNotice_t znotice;

  memset(&znotice, 0, sizeof(znotice));
  znotice.z_kind = UNSAFE;
  znotice.z_class = "MOIRA";
  znotice.z_class_inst = inst;
  znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n";
  ZInitialize();
  znotice.z_message = msg;
  znotice.z_message_len = strlen(msg) + 1;
  znotice.z_opcode = "";
  znotice.z_recipient = "";
  ZSendNotice(&znotice, ZNOAUTH);
#else
  char *buf;

  buf = malloc(9 + strlen(inst) + strlen(msg));
  if (buf)
    {
      sprintf(buf, "MOIRA: %s %s", inst, msg);
      syslog(LOG_ERR, "%s", buf);
      free(buf);
    }
#endif
}
Example #2
0
void owl_zephyr_initialize()
{
  int ret;
  struct servent *sp;
  struct sockaddr_in sin;
  ZNotice_t req;
  Code_t code;
  owl_dispatch *dispatch;

  /*
   * Code modified from libzephyr's ZhmStat.c
   *
   * Modified to add the fd to our select loop, rather than hanging
   * until we get an ack.
   */

  if ((ret = ZOpenPort(NULL)) != ZERR_NONE) {
    owl_function_error("Error opening Zephyr port: %s", error_message(ret));
    return;
  }

  (void) memset((char *)&sin, 0, sizeof(struct sockaddr_in));

  sp = getservbyname(HM_SVCNAME, "udp");

  sin.sin_port = (sp) ? sp->s_port : HM_SVC_FALLBACK;
  sin.sin_family = AF_INET;

  sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

  (void) memset((char *)&req, 0, sizeof(req));
  req.z_kind = STAT;
  req.z_port = 0;
  req.z_class = HM_STAT_CLASS;
  req.z_class_inst = HM_STAT_CLIENT;
  req.z_opcode = HM_GIMMESTATS;
  req.z_sender = "";
  req.z_recipient = "";
  req.z_default_format = "";
  req.z_message_len = 0;

  if ((code = ZSetDestAddr(&sin)) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(code));
    return;
  }

  if ((code = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(code));
    return;
  }

  dispatch = owl_malloc(sizeof(*dispatch));
  dispatch->fd = ZGetFD();
  dispatch->cfunc = owl_zephyr_finish_initialization;
  dispatch->destroy = (void(*)(owl_dispatch*))owl_free;

  owl_select_add_dispatch(dispatch);
}
Example #3
0
void owl_zephyr_initialize(void)
{
  Code_t ret;
  struct servent *sp;
  struct sockaddr_in sin;
  ZNotice_t req;
  GIOChannel *channel;

  /*
   * Code modified from libzephyr's ZhmStat.c
   *
   * Modified to add the fd to our select loop, rather than hanging
   * until we get an ack.
   */

  if ((ret = ZOpenPort(NULL)) != ZERR_NONE) {
    owl_function_error("Error opening Zephyr port: %s", error_message(ret));
    return;
  }

  (void) memset(&sin, 0, sizeof(struct sockaddr_in));

  sp = getservbyname(HM_SVCNAME, "udp");

  sin.sin_port = (sp) ? sp->s_port : HM_SVC_FALLBACK;
  sin.sin_family = AF_INET;

  sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

  (void) memset(&req, 0, sizeof(req));
  req.z_kind = STAT;
  req.z_port = 0;
  req.z_class = zstr(HM_STAT_CLASS);
  req.z_class_inst = zstr(HM_STAT_CLIENT);
  req.z_opcode = zstr(HM_GIMMESTATS);
  req.z_sender = zstr("");
  req.z_recipient = zstr("");
  req.z_default_format = zstr("");
  req.z_message_len = 0;

  if ((ret = ZSetDestAddr(&sin)) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(ret));
    return;
  }

  if ((ret = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(ret));
    return;
  }

  channel = g_io_channel_unix_new(ZGetFD());
  g_io_add_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP,
		 &owl_zephyr_finish_initialization, NULL);
  g_io_channel_unref(channel);
}
Example #4
0
Code_t
ZRequestLocations(char *user,
		  register ZAsyncLocateData_t *zald,
		  ZNotice_Kind_t kind,                /* UNSAFE, UNACKED, or ACKED */
		  Z_AuthProc auth)
{
    int retval;
    ZNotice_t notice;

    if (ZGetFD() < 0)
	if ((retval = ZOpenPort((u_short *)0)) != ZERR_NONE)
	    return (retval);

    (void) memset((char *)&notice, 0, sizeof(notice));
    notice.z_kind = kind;
    notice.z_port = __Zephyr_port;
    notice.z_class = LOCATE_CLASS;
    notice.z_class_inst = user;
    notice.z_opcode = LOCATE_LOCATE;
    notice.z_sender = 0;
    notice.z_recipient = "";
    notice.z_default_format = "";
    notice.z_message_len = 0;

    if ((retval = ZSendNotice(&notice, auth)) != ZERR_NONE)
	return(retval);

    if ((zald->user = (char *) malloc(strlen(user)+1)) == NULL) {
	return(ENOMEM);
    }
    if ((zald->version = (char *) malloc(strlen(notice.z_version)+1)) == NULL) {
	free(zald->user);
	return(ENOMEM);
    }
    zald->uid = notice.z_multiuid;
    strcpy(zald->user,user);
    strcpy(zald->version,notice.z_version);

    return(ZERR_NONE);
}
Example #5
0
Code_t
ZFlushUserSubscriptions(char *recip)
{
    register Code_t retval;
    ZNotice_t notice, retnotice;

    (void)memset((char *)&notice, 0, sizeof(notice));
    notice.z_kind = ACKED;
    notice.z_class = ZEPHYR_CTL_CLASS;
    notice.z_class_inst = ZEPHYR_CTL_CLIENT;
    notice.z_opcode = CLIENT_FLUSHSUBS;
    notice.z_recipient = "";
    notice.z_default_format = "";
    if (recip) {
	notice.z_message = recip;
	notice.z_message_len = strlen(recip) + 1;
    } else {
	notice.z_message_len = 0;
    }

    if ((retval = ZSendNotice(&notice, ZAUTH)) != ZERR_NONE)
	return (retval);

    if ((retval = ZIfNotice(&retnotice, (struct sockaddr_in *)0,
			    ZCompareUIDPred, (char *)&notice.z_uid)) !=
	ZERR_NONE)
	return (retval);
    if (retnotice.z_kind == SERVNAK) {
	ZFreeNotice(&retnotice);
	return (ZERR_SERVNAK);
    }
    if (retnotice.z_kind != SERVACK) {
	ZFreeNotice(&retnotice);
	return (ZERR_INTERNAL);
    }
    ZFreeNotice(&retnotice);
    return (ZERR_NONE);
}
Example #6
0
int
srv_stat(char *host)
{
	char *line[20],*mp;
	int sock,i,nf,ret;
	struct hostent *hp;
	struct sockaddr_in sin;
	ZNotice_t notice;
	time_t runtime;
	struct tm *tim;
#ifdef _POSIX_VERSION
	struct sigaction sa;
#endif

	(void) memset((char *) &sin, 0, sizeof(struct sockaddr_in));

	sin.sin_port = srv_port;

	if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
		perror("socket:");
		exit(-1);
	}

	sin.sin_family = AF_INET;

	if ((sin.sin_addr.s_addr = inet_addr(host)) == (unsigned)(-1)) {
	    if ((hp = gethostbyname(host)) == NULL) {
		fprintf(stderr,"Unknown host: %s\n",host);
		exit(-1);
	    }
	    (void) memcpy((char *) &sin.sin_addr, hp->h_addr, hp->h_length);

	    printf("Server stats: %s\n", hp->h_name);
	} else {
	    printf("Server stats: %s\n", host);
	}

	(void) memset((char *)&notice, 0, sizeof(notice));
	notice.z_kind = UNSAFE;
	notice.z_port = 0;
	notice.z_charset = ZCHARSET_UNKNOWN;
	notice.z_class = ZEPHYR_ADMIN_CLASS;
	notice.z_class_inst = "";
	notice.z_opcode = ADMIN_STATUS;
	notice.z_sender = "";
	notice.z_recipient = "";
	notice.z_default_format = "";
	notice.z_message_len = 0;

	if ((ret = ZSetDestAddr(&sin)) != ZERR_NONE) {
		com_err("zstat", ret, "setting destination");
		exit(-1);
	}
	if ((ret = ZSendNotice(&notice, ZNOAUTH)) != ZERR_NONE) {
		com_err("zstat", ret, "sending notice");
		exit(-1);
	}

#ifdef _POSIX_VERSION
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	sa.sa_handler = timeout;
	(void) sigaction(SIGALRM, &sa, (struct sigaction *)0);
#else
	(void) signal(SIGALRM,timeout);
#endif
	outoftime = 0;
	(void) alarm(10);
	if (((ret = ZReceiveNotice(&notice, (struct sockaddr_in *) 0))
	    != ZERR_NONE) &&
	    ret != EINTR) {
		com_err("zstat", ret, "receiving notice");
		return (1);
	}
	(void) alarm(0);
	if (outoftime) {
		fprintf(stderr,"No response after 10 seconds.\n");
		return (1);
	}

	mp = notice.z_message;
	for (nf=0;mp<notice.z_message+notice.z_message_len;nf++) {
		line[nf] = mp;
		mp += strlen(mp)+1;
	}

	printf("Server protocol version = %s\n",notice.z_version);

	for (i=0; i < nf; i++) {
		if (i < 2)
			printf("%s %s\n",srv_head[i],line[i]);
		else if (i == 2) { /* uptime field */
			runtime = atol(line[i]);
			tim = gmtime(&runtime);
			printf("%s %d days, %02d:%02d:%02d\n",
			       srv_head[i],
			       tim->tm_yday,
			       tim->tm_hour,
			       tim->tm_min,
			       tim->tm_sec);
		} else if (i == 3) {
			printf("%s\n",srv_head[i]);
			printf("%s\n",line[i]);
		} else printf("%s\n",line[i]);
	}
	printf("\n");

	(void) close(sock);
	ZFreeNotice(&notice);
	return(0);
}