Ejemplo n.º 1
0
static int http_da_session_update(const char *realm, const char *nonce, const char *opaque, const char *cnonce, const char *ncount)
{
  struct http_da_session *session;

  if (!realm || !nonce || !opaque || !cnonce || !ncount)
  {
#ifdef SOAP_DEBUG
    fprintf(stderr, "Debug message: authentication update failed, missing authentication data\n");
#endif
    return SOAP_ERR;
  }
#ifdef SOAP_DEBUG
  fprintf(stderr, "Debug message: updating session realm=%s nonce=%s\n", realm, nonce);
#endif

  MUTEX_LOCK(http_da_session_lock);

  for (session = http_da_session; session; session = session->next)
    if (!strcmp(session->realm, realm) && !strcmp(session->nonce, nonce) && !strcmp(session->opaque, opaque))
      break;

  if (session)
  {
    unsigned long nc = soap_strtoul(ncount, NULL, 16);

    if (session->nc >= nc)
    {
      session->modified = 0; /* replay attack: terminate session */
      session = NULL;
    }
    else
    {
      session->nc = nc;
      session->modified = time(NULL);
    }
  }

  MUTEX_UNLOCK(http_da_session_lock);

  if (!session)
    return SOAP_ERR;

  return SOAP_OK;
}
Ejemplo n.º 2
0
int soap_s2xsd__dateTime(struct soap *soap, const char *s, struct timeval *a)
{ memset((void*)a, 0, sizeof(struct timeval));
  if (s)
  { char *t;
    unsigned long d;
    struct tm T;
    memset((void*)&T, 0, sizeof(T));
    d = soap_strtoul(s, &t, 10);
    if (*t == '-')
    { /* YYYY-MM-DD */
      T.tm_year = (int)d;
      T.tm_mon = (int)soap_strtoul(t + 1, &t, 10);
      T.tm_mday = (int)soap_strtoul(t + 1, &t, 10);
    }
    else
    { /* YYYYMMDD */
      T.tm_year = (int)(d / 10000);
      T.tm_mon = (int)(d / 100 % 100);
      T.tm_mday = (int)(d % 100);
    }
    if (*t == 'T')
    { d = soap_strtoul(t + 1, &t, 10);
      if (*t == ':')
      { /* Thh:mm:ss */
	T.tm_hour = (int)d;
	T.tm_min = (int)soap_strtoul(t + 1, &t, 10);
	T.tm_sec = (int)soap_strtoul(t + 1, &t, 10);
      }
      else
      { /* Thhmmss */
        T.tm_hour = (int)(d / 10000);
	T.tm_min = (int)(d / 100 % 100);
	T.tm_sec = (int)(d % 100);
      }
    }
    if (T.tm_year == 1)
      T.tm_year = 70;
    else
      T.tm_year -= 1900;
    T.tm_mon--;
    if (*t == '.')
    { for (t++; *t; t++)
        if (*t < '0' || *t > '9')
          break;
    }
    if (*t)
    {
#ifndef WITH_NOZONE
      if (*t == '+' || *t == '-')
      { int h = 0, m = 0;
        if (t[3] == ':')
        { /* +hh:mm */
	  h = (int)soap_strtol(t, NULL, 10);
	  m = (int)soap_strtol(t + 4, NULL, 10);
          if (h < 0)
            m = -m;
        }
        else
	{ /* +hhmm */
          m = (int)soap_strtol(t, NULL, 10);
          h = m / 100;
          m = m % 100;
        }
        T.tm_min -= m;
        T.tm_hour -= h;
        /* put hour and min in range */
        T.tm_hour += T.tm_min / 60;
        T.tm_min %= 60;
        if (T.tm_min < 0)
        { T.tm_min += 60;
          T.tm_hour--;
        }
        T.tm_mday += T.tm_hour / 24;
        T.tm_hour %= 24;
        if (T.tm_hour < 0)
        { T.tm_hour += 24;
          T.tm_mday--;
        }
        /* note: day of the month may be out of range, timegm() handles it */
      }
#endif
      a->tv_sec = soap_timegm(&T);
    }
    else
      a->tv_sec = mktime(&T);
  }
  return soap->error;
}
Ejemplo n.º 3
0
int soap_s2xsd__dateTime(struct soap *soap, const char *s, struct tm *a)
{ memset((void*)a, 0, sizeof(struct tm));
  if (s)
  { char *t;
    unsigned long d;
    d = soap_strtoul(s, &t, 10);
    if (*t == '-')
    { /* YYYY-MM-DD */
      a->tm_year = (int)d;
      a->tm_mon = (int)soap_strtoul(t + 1, &t, 10);
      a->tm_mday = (int)soap_strtoul(t + 1, &t, 10);
    }
    else if (!(soap->mode & SOAP_XML_STRICT))
    { /* YYYYMMDD */
      a->tm_year = (int)(d / 10000);
      a->tm_mon = (int)(d / 100 % 100);
      a->tm_mday = (int)(d % 100);
    }
    else
      return soap->error = SOAP_TYPE;
    if (*t == 'T' || ((*t == 't' || *t == ' ') && !(soap->mode & SOAP_XML_STRICT)))
    { d = soap_strtoul(t + 1, &t, 10);
      if (*t == ':')
      { /* Thh:mm:ss */
	a->tm_hour = (int)d;
	a->tm_min = (int)soap_strtoul(t + 1, &t, 10);
	a->tm_sec = (int)soap_strtoul(t + 1, &t, 10);
      }
      else if (!(soap->mode & SOAP_XML_STRICT))
      { /* Thhmmss */
        a->tm_hour = (int)(d / 10000);
	a->tm_min = (int)(d / 100 % 100);
	a->tm_sec = (int)(d % 100);
      }
      else
	return soap->error = SOAP_TYPE;
    }
    if (a->tm_year == 1)
      a->tm_year = 70;
    else
      a->tm_year -= 1900;
    a->tm_mon--;
    if (*t == '.')
    { for (t++; *t; t++)
        if (*t < '0' || *t > '9')
          break;
    }
    if (*t == ' ' && !(soap->mode & SOAP_XML_STRICT))
      t++;
    if (*t)
    {
#ifndef WITH_NOZONE
      if (*t == '+' || *t == '-')
      { int h, m;
	m = (int)soap_strtol(t, &t, 10);
        if (*t == ':')
        { /* +hh:mm */
	  h = m;
	  m = (int)soap_strtol(t + 1, &t, 10);
          if (h < 0)
            m = -m;
        }
        else if (!(soap->mode & SOAP_XML_STRICT))
	{ /* +hhmm */
          h = m / 100;
          m = m % 100;
        }
        else
	{ /* +hh */
          h = m;
	  m = 0;
        }
	if (*t)
	  return soap->error = SOAP_TYPE;
        a->tm_min -= m;
        a->tm_hour -= h;
        /* put hour and min in range */
        a->tm_hour += a->tm_min / 60;
        a->tm_min %= 60;
        if (a->tm_min < 0)
        { a->tm_min += 60;
          a->tm_hour--;
        }
        a->tm_mday += a->tm_hour / 24;
        a->tm_hour %= 24;
        if (a->tm_hour < 0)
        { a->tm_hour += 24;
          a->tm_mday--;
        }
        /* note: day of the month may be out of range, timegm() handles it */
      }
      else if (*t != 'Z')
	return soap->error = SOAP_TYPE;
#endif
    }
    else /* no UTC or timezone, so assume we got a localtime */
      a->tm_isdst = -1;
  }
  return soap->error;
}