Exemplo n.º 1
0
static const char *
get_os_version (struct id_value *idv)
{
  struct utsname uts;
  uname(&uts);
  return idv->value = mu_strdup (uts.version);
}
Exemplo n.º 2
0
static const char *
get_os (struct id_value *idv)
{
  struct utsname uts;
  uname(&uts);
  return idv->value = mu_strdup (uts.sysname);
}
Exemplo n.º 3
0
struct imap4d_tokbuf *
imap4d_tokbuf_from_string (char *str)
{
  struct imap4d_tokbuf *tok = imap4d_tokbuf_init ();
  tok->buffer = mu_strdup (str);
  if (!tok->buffer)
    imap4d_bye (ERR_NO_MEM);
  tok->level = strlen (str);
  tok->size = tok->level + 1;
  imap4d_tokbuf_tokenize (tok, 0);
  return tok;
}
Exemplo n.º 4
0
static void
pop3d_append_capa_string (struct pop3d_session *sess, const char *name,
			  const char *value)
{
  struct pop3d_capa *cp;

  cp = mu_alloc (sizeof (*cp));
  cp->type = capa_string;
  cp->name = name;
  cp->value.string = value ? mu_strdup (value) : NULL;
  if (mu_list_append (sess->capa, cp))
    mu_alloc_die ();
}
Exemplo n.º 5
0
int
imap4d_session_setup0 ()
{
  real_homedir = mu_normalize_path (mu_strdup (auth_data->dir));
  if (imap4d_check_home_dir (real_homedir, auth_data->uid, auth_data->gid))
    return 1;

  if (modify_homedir)
    {
      int rc;
      mu_vartab_t vtab;
      char *expr = mu_tilde_expansion (modify_homedir, "/", real_homedir);

      mu_vartab_create (&vtab);
      mu_vartab_define (vtab, "user", auth_data->name, 0);
      mu_vartab_define (vtab, "home", real_homedir, 0);
      rc = mu_vartab_expand (vtab, expr, &imap4d_homedir);
      mu_vartab_destroy (&vtab);
      free (expr);
      if (rc)
	{
	  free (real_homedir);
	  mu_diag_funcall (MU_DIAG_ERROR, "mu_vartab_expand",
			   modify_homedir, rc);
	  return 1;
	}
    }
  else
    imap4d_homedir = strdup (real_homedir);

  if (strcmp (imap4d_homedir, real_homedir)
      && imap4d_check_home_dir (imap4d_homedir,
				auth_data->uid, auth_data->gid))
    {
      free (imap4d_homedir);
      free (real_homedir);
      return 1;
    }
  
  if (auth_data->change_uid)
    setuid (auth_data->uid);

  util_chdir (imap4d_homedir);
  namespace_init_session (imap4d_homedir);
  mu_diag_output (MU_DIAG_INFO,
		  _("user `%s' logged in (source: %s)"), auth_data->name,
		  auth_data->source);
  return 0;
}
Exemplo n.º 6
0
/* Send NIL if empty string, change the quoted string to a literal if the
   string contains: double quotes, CR, LF, and '/'.  CR, LF will be changed
   to spaces.  */
int
io_send_qstring (const char *buffer)
{
  if (buffer == NULL || *buffer == '\0')
    return io_sendf ("NIL");
  if (strchr (buffer, '"') || strchr (buffer, '\r') || strchr (buffer, '\n')
      || strchr (buffer, '\\'))
    {
      char *s;
      int ret;
      char *b = mu_strdup (buffer);
      while ((s = strchr (b, '\n')) || (s = strchr (b, '\r')))
	*s = ' ';
      ret = io_send_literal (b);
      free (b);
      return ret;
    }
  return io_sendf ("\"%s\"", buffer);
}
Exemplo n.º 7
0
int
imap4d_list (struct imap4d_session *session,
             struct imap4d_command *command, imap4d_tokbuf_t tok)
{
  char *ref;
  char *wcard;

  if (imap4d_tokbuf_argc (tok) != 4)
    return io_completion_response (command, RESP_BAD, "Invalid arguments");
  
  ref = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1);
  wcard = imap4d_tokbuf_getarg (tok, IMAP4_ARG_2);

  /* If wildcard is empty, it is a special case: we have to
     return the hierarchy.  */
  if (*wcard == '\0')
    {
      if (*ref)
	io_untagged_response (RESP_NONE,
			      "LIST (\\NoSelect) \"%c\" \"%c\"",
			      MU_HIERARCHY_DELIMITER,
			      MU_HIERARCHY_DELIMITER);
      else
	io_untagged_response (RESP_NONE,
			      "LIST (\\NoSelect) \"%c\" \"\"",
			      MU_HIERARCHY_DELIMITER);
    }
  /* There is only one mailbox in the "INBOX" hierarchy ... INBOX.  */
  else if (mu_c_strcasecmp (ref, "INBOX") == 0
	   || (ref[0] == 0 && mu_c_strcasecmp (wcard, "INBOX") == 0))
    {
      io_untagged_response (RESP_NONE, "LIST (\\NoInferiors) NIL INBOX");
    }
  else
    {
      int status;
      mu_folder_t folder;
      char *cwd;
      char *p, *q;
      struct refinfo refinfo;
      
      switch (*wcard)
	{
	  /* Absolute Path in wcard, dump the old ref.  */
	case '/':
	  {
	    ref = calloc (2, 1);
	    ref[0] = *wcard;
	    wcard++;
	  }
	  break;

	  /* Absolute Path, but take care of things like ~guest/Mail,
	     ref becomes ref = ~guest.  */
	case '~':
	  {
	    char *s = strchr (wcard, '/');
	    if (s)
	      {
		ref = calloc (s - wcard + 1, 1);
		memcpy (ref, wcard, s - wcard);
		ref [s - wcard] = '\0';
		wcard = s + 1;
	      }
	    else
	      {
		ref = mu_strdup (wcard);
		wcard += strlen (wcard);
	      }
	  }
	  break;

	default:
	  ref = mu_strdup (ref);
	}

      /* Move any directory not containing a wildcard into the reference
	 So (ref = ~guest, wcard = Mail/folder1/%.vf) -->
	 (ref = ~guest/Mail/folder1, wcard = %.vf).  */
      for (p = wcard; (q = strpbrk (p, "/%*")) && *q == '/'; p = q + 1)
	;

      if (p > wcard)
	{
	  size_t seglen = p - wcard;
	  size_t reflen = strlen (ref);
	  int addslash = (reflen > 0 && ref[reflen-1] != '/'); 
	  size_t len = seglen + reflen + addslash + 1;

	  ref = realloc (ref, len);
	  if (addslash)
	    ref[reflen++] = '/';
	  memcpy (ref + reflen, wcard, seglen);
	  ref[reflen + seglen] = 0;
	  wcard += seglen;
	}

      /* Allocates.  */
      cwd = namespace_checkfullpath (ref, wcard, NULL);
      if (!cwd)
	{
	  free (ref);
	  return io_completion_response (command, RESP_NO,
			              "The requested item could not be found.");
	}
      status = mu_folder_create (&folder, cwd);
      if (status)
	{
	  free (ref);
	  free (cwd);
	  return io_completion_response (command, RESP_NO,
			              "The requested item could not be found.");
	}
      /* Force the right matcher */
      mu_folder_set_match (folder, mu_folder_imap_match);

      memset (&refinfo, 0, sizeof refinfo);

      refinfo.refptr = ref;
      refinfo.reflen = strlen (ref);
      refinfo.pfxlen = strlen (cwd);
      refinfo.homelen = strlen (imap4d_homedir);

      /* The special name INBOX is included in the output from LIST, if
	 INBOX is supported by this server for this user and if the
	 uppercase string "INBOX" matches the interpreted reference and
	 mailbox name arguments with wildcards as described above.  The
	 criteria for omitting INBOX is whether SELECT INBOX will return
	 failure; it is not relevant whether the user's real INBOX resides
	 on this or some other server. */

      if (!*ref &&
	  (mu_imap_wildmatch (wcard, "INBOX", MU_HIERARCHY_DELIMITER) == 0
	   || mu_imap_wildmatch (wcard, "inbox", MU_HIERARCHY_DELIMITER) == 0))
	io_untagged_response (RESP_NONE, "LIST (\\NoInferiors) NIL INBOX");

      mu_folder_enumerate (folder, NULL, wcard, 0, 0, NULL,
			   list_fun, &refinfo);
      mu_folder_destroy (&folder);
      free (refinfo.buf);
      free (cwd);
      free (ref);
    }

  return io_completion_response (command, RESP_OK, "Completed");
}