list management

Emil Isberg emil.isberg at
Wed Dec 11 05:37:17 EST 2002

On Wed, 11 Dec 2002, Kirk Bailey wrote:

>I want to be able to add and delete email lsits to my email system. This
>means adding and deleting alias definitions to the aliases file in
>/etc/mail, and then running the newaliases command. To do this, the web
>server must run a program, a script. This is exeuted in my freebsd server
>as nobody. How may I accomplish this task?

I don't think sudo is what you are looking for...
I would set it up as several alias-files from the MTAs point of view and
then make sure that the right one is writeable by nobody (or a specific
user for the web-mail-handler-stuff).

Sendmails newaliases is runable by any user (including nobody) so you
should be able to run it from whatever script there is...

Else you might want to create a setuid application that only does an
append on a certain file and then calls newaliases.

How about the following? (Some checks on alias and stuff needs to be
added... Either here or before this program is called.)

#define MAX_LEN 1024
int main(int argc, char *argv[])
  FILE *fp=NULL;
  int len=0;
  char buf[MAX_LEN+1]="";

  if (argc!=3 || !argv[2] || !argv[3])
      printf("Usage: <addalias> <alias> <target>\r\n");

  if (len > MAX_LEN)

  strcpy(buf, argv[1]);
  strcat(buf, ":\t");
  strcat(buf, argv[2]);
  strcat(buf, "\r\n");

  if (!(fp=fopen("/etc/mail/mywebaliases", "wt+"))

  fputs(buf, fp);
  /* Make sure that newaliases is in the path. */
  execlp("newaliases", "newaliases", NULL);
  /* If we get here then I failed to find newaliases. */
  puts("Couldn't find and execute newaliases.");
  return 0;

Before destruction a man's heart is
haughty, but humility goes before honour.
		-- Psalms 18:12

More information about the sudo-users mailing list