anyvar.patch
changeset 2 9c1ee7dfe89e
equal deleted inserted replaced
1:c3f2c8485f70 2:9c1ee7dfe89e
       
     1 # HG changeset patch
       
     2 # Parent  9e657f6cad9e122bf465a264f31e26a57fd27c60
       
     3 Anyvar module
       
     4 
       
     5 diff --git a/Makefile b/Makefile
       
     6 --- a/Makefile
       
     7 +++ b/Makefile
       
     8 @@ -153,7 +153,7 @@
       
     9  #     (which will cause the Makefiles to be regenerated when you run `make');
       
    10  # (2) otherwise, pass the desired values on the `make' command line.
       
    11  
       
    12 -MAKE=make
       
    13 +
       
    14  
       
    15  all-recursive install-data-recursive install-exec-recursive \
       
    16  installdirs-recursive install-recursive uninstall-recursive  \
       
    17 diff --git a/config.status b/config.status
       
    18 --- a/config.status
       
    19 +++ b/config.status
       
    20 @@ -512,7 +512,7 @@
       
    21  s,@AUTOMAKE@,/home/tzeman/dev/vmailmgr-0.97/missing automake-1.4,;t t
       
    22  s,@AUTOHEADER@,/home/tzeman/dev/vmailmgr-0.97/missing autoheader,;t t
       
    23  s,@MAKEINFO@,makeinfo,;t t
       
    24 -s,@SET_MAKE@,MAKE=make,;t t
       
    25 +s,@SET_MAKE@,,;t t
       
    26  s,@KRB5_TRUE@,#,;t t
       
    27  s,@KRB5_FALSE@,,;t t
       
    28  s,@VPWTABLE_CDB_TRUE@,,;t t
       
    29 diff --git a/daemon/Makefile b/daemon/Makefile
       
    30 --- a/daemon/Makefile
       
    31 +++ b/daemon/Makefile
       
    32 @@ -95,7 +95,7 @@
       
    33  
       
    34  INCLUDES = -I../lib
       
    35  
       
    36 -vmailmgrd_SOURCES = daemon.h 	adduser.cc 	autoresponse.cc 	chattr.cc 	check.cc 	command.h command.cc 	deluser.cc 	dispatch.cc 	listdomain.cc 	log.h log.cc 	lookup.cc 	main.cc 	stat.cc 	state.h state.cc
       
    37 +vmailmgrd_SOURCES = daemon.h 	adduser.cc 	anyvar.cc	autoresponse.cc 	chattr.cc 	check.cc 	command.h command.cc 	deluser.cc 	dispatch.cc 	listdomain.cc 	log.h log.cc 	lookup.cc 	main.cc 	stat.cc 	state.h state.cc
       
    38  
       
    39  vmailmgrd_LDADD = ../lib/libvmailmgr.a ../lib/cli++/libcli++.a
       
    40  mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
       
    41 @@ -108,7 +108,7 @@
       
    42  CPPFLAGS = 
       
    43  LDFLAGS = 
       
    44  LIBS = -lcrypt 
       
    45 -vmailmgrd_OBJECTS =  adduser.o autoresponse.o chattr.o check.o command.o \
       
    46 +vmailmgrd_OBJECTS =  adduser.o anyvar.o autoresponse.o chattr.o check.o command.o \
       
    47  deluser.o dispatch.o listdomain.o log.o lookup.o main.o stat.o state.o
       
    48  vmailmgrd_DEPENDENCIES =  ../lib/libvmailmgr.a ../lib/cli++/libcli++.a
       
    49  vmailmgrd_LDFLAGS = 
       
    50 @@ -288,6 +288,17 @@
       
    51  	../lib/vpwtable/vpwtable.h ../lib/misc/response.h command.h \
       
    52  	log.h ../lib/fdbuf/fdbuf.h ../lib/fdbuf/fdibuf.h \
       
    53  	../lib/fdbuf/fdobuf.h
       
    54 +anyvar.o: anyvar.cc ../config.h daemon.h \
       
    55 +	../lib/mystring/mystring.h ../lib/mystring/rep.h \
       
    56 +	../lib/mystring/iter.h ../lib/mystring/join.h \
       
    57 +	../lib/misc/pwentry.h ../lib/config/configrc.h \
       
    58 +	../lib/misc/strlist.h ../lib/vpwentry/vpwentry.h \
       
    59 +	../lib/misc/pwcrypt.h ../lib/misc/itoa.h state.h \
       
    60 +	../lib/vdomain/vdomain.h ../lib/vpwtable/vpwtable.h \
       
    61 +	../lib/misc/response.h command.h log.h ../lib/fdbuf/fdbuf.h \
       
    62 +	../lib/fdbuf/fdibuf.h ../lib/fdbuf/fdobuf.h \
       
    63 +	../lib/misc/lookup.h ../lib/misc/maildir.h \
       
    64 +	../lib/misc/pwentry_table.h ../lib/misc/stat_fns.h
       
    65  autoresponse.o: autoresponse.cc ../config.h daemon.h \
       
    66  	../lib/mystring/mystring.h ../lib/mystring/rep.h \
       
    67  	../lib/mystring/iter.h ../lib/mystring/join.h \
       
    68 diff --git a/daemon/Makefile.am b/daemon/Makefile.am
       
    69 --- a/daemon/Makefile.am
       
    70 +++ b/daemon/Makefile.am
       
    71 @@ -24,6 +24,7 @@
       
    72  
       
    73  vmailmgrd_SOURCES = daemon.h \
       
    74  	adduser.cc \
       
    75 +	anyvar.cc \
       
    76  	autoresponse.cc \
       
    77  	chattr.cc \
       
    78  	check.cc \
       
    79 diff --git a/daemon/Makefile.in b/daemon/Makefile.in
       
    80 --- a/daemon/Makefile.in
       
    81 +++ b/daemon/Makefile.in
       
    82 @@ -95,7 +95,7 @@
       
    83  
       
    84  INCLUDES = -I../lib
       
    85  
       
    86 -vmailmgrd_SOURCES = daemon.h 	adduser.cc 	autoresponse.cc 	chattr.cc 	check.cc 	command.h command.cc 	deluser.cc 	dispatch.cc 	listdomain.cc 	log.h log.cc 	lookup.cc 	main.cc 	stat.cc 	state.h state.cc
       
    87 +vmailmgrd_SOURCES = daemon.h 	adduser.cc 	anyvar.cc	autoresponse.cc 	chattr.cc 	check.cc 	command.h command.cc 	deluser.cc 	dispatch.cc 	listdomain.cc 	log.h log.cc 	lookup.cc 	main.cc 	stat.cc 	state.h state.cc
       
    88  
       
    89  vmailmgrd_LDADD = ../lib/libvmailmgr.a ../lib/cli++/libcli++.a
       
    90  mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
       
    91 @@ -108,7 +108,7 @@
       
    92  CPPFLAGS = @CPPFLAGS@
       
    93  LDFLAGS = @LDFLAGS@
       
    94  LIBS = @LIBS@
       
    95 -vmailmgrd_OBJECTS =  adduser.o autoresponse.o chattr.o check.o command.o \
       
    96 +vmailmgrd_OBJECTS =  adduser.o anyvar.o autoresponse.o chattr.o check.o command.o \
       
    97  deluser.o dispatch.o listdomain.o log.o lookup.o main.o stat.o state.o
       
    98  vmailmgrd_DEPENDENCIES =  ../lib/libvmailmgr.a ../lib/cli++/libcli++.a
       
    99  vmailmgrd_LDFLAGS = 
       
   100 @@ -288,6 +288,17 @@
       
   101  	../lib/vpwtable/vpwtable.h ../lib/misc/response.h command.h \
       
   102  	log.h ../lib/fdbuf/fdbuf.h ../lib/fdbuf/fdibuf.h \
       
   103  	../lib/fdbuf/fdobuf.h
       
   104 +anyvar.o: anyvar.cc ../config.h daemon.h \
       
   105 +	../lib/mystring/mystring.h ../lib/mystring/rep.h \
       
   106 +	../lib/mystring/iter.h ../lib/mystring/join.h \
       
   107 +	../lib/misc/pwentry.h ../lib/config/configrc.h \
       
   108 +	../lib/misc/strlist.h ../lib/vpwentry/vpwentry.h \
       
   109 +	../lib/misc/pwcrypt.h ../lib/misc/itoa.h state.h \
       
   110 +	../lib/vdomain/vdomain.h ../lib/vpwtable/vpwtable.h \
       
   111 +	../lib/misc/response.h command.h log.h ../lib/fdbuf/fdbuf.h \
       
   112 +	../lib/fdbuf/fdibuf.h ../lib/fdbuf/fdobuf.h \
       
   113 +	../lib/misc/lookup.h ../lib/misc/maildir.h \
       
   114 +	../lib/misc/pwentry_table.h ../lib/misc/stat_fns.h
       
   115  autoresponse.o: autoresponse.cc ../config.h daemon.h \
       
   116  	../lib/mystring/mystring.h ../lib/mystring/rep.h \
       
   117  	../lib/mystring/iter.h ../lib/mystring/join.h \
       
   118 diff --git a/daemon/autoresponse.cc b/daemon/anyvar.cc
       
   119 copy from daemon/autoresponse.cc
       
   120 copy to daemon/anyvar.cc
       
   121 --- a/daemon/autoresponse.cc
       
   122 +++ b/daemon/anyvar.cc
       
   123 @@ -27,7 +27,7 @@
       
   124  #include "misc/pwentry_table.h"
       
   125  #include "misc/stat_fns.h"
       
   126  
       
   127 -response autoresponse_write(const mystring& directory,
       
   128 +response anyvar_write(const mystring& directory,
       
   129  			    const mystring& location,
       
   130  			    const mystring& disabled,
       
   131  			    const mystring& msg)
       
   132 @@ -36,18 +36,18 @@
       
   133  
       
   134    if(!is_dir(directory.c_str())) {
       
   135      if(mkdir(directory.c_str(), 0755))
       
   136 -      RETURN(err, "Could not create autoresponse directory");
       
   137 +      RETURN(err, "Could not create anyvar directory");
       
   138    }
       
   139    
       
   140    if(is_exist(tmpfile.c_str()))
       
   141 -    RETURN(err, "Temporary autoresponse file already exists");
       
   142 +    RETURN(err, "Temporary anyvar file already exists");
       
   143  
       
   144    if(is_exist(disabled.c_str()))
       
   145      RETURN(err, "Autoresponse is disabled, reenable it before writing a new message");
       
   146    
       
   147    fdobuf out(tmpfile.c_str(), fdobuf::create | fdobuf::excl, 0644);
       
   148    if(!out)
       
   149 -    RETURN(err, "Unable to open temporary autoresponse file for writing");
       
   150 +    RETURN(err, "Unable to open temporary anyvar file for writing");
       
   151  
       
   152    out << msg;
       
   153    if(!out.flush() || !out.close()) {
       
   154 @@ -56,34 +56,34 @@
       
   155    }
       
   156    if(rename(tmpfile.c_str(), location.c_str())) {
       
   157      unlink(tmpfile.c_str());
       
   158 -    RETURN(err, "Unable to rename temporary autoresponse file");
       
   159 +    RETURN(err, "Unable to rename temporary anyvar file");
       
   160    }
       
   161  
       
   162 -  RETURN(ok, "Message successfully written to autoresponse file");
       
   163 +  RETURN(ok, "Message successfully written to anyvar file");
       
   164  }
       
   165  
       
   166 -response autoresponse_disable(const mystring& location,
       
   167 +response anyvar_disable(const mystring& location,
       
   168  			      const mystring& disabled)
       
   169  {
       
   170    if(!is_exist(location.c_str()))
       
   171 -    RETURN(ok, "Autoresponse file did not exist");
       
   172 +    RETURN(ok, "Anyvar file did not exist");
       
   173    if(is_exist(disabled.c_str()))
       
   174 -    RETURN(err, "Disabled autoresponse file already exists");
       
   175 +    RETURN(err, "Disabled anyvar file already exists");
       
   176    if(rename(location.c_str(), disabled.c_str()))
       
   177 -    RETURN(err, "Unable to rename autoresponse file");
       
   178 -  RETURN(ok, "Autoresponse file sucessfully disabled");
       
   179 +    RETURN(err, "Unable to rename anyvar file");
       
   180 +  RETURN(ok, "Anyvar file sucessfully disabled");
       
   181  }  
       
   182  
       
   183 -response autoresponse_enable(const mystring& location,
       
   184 +response anyvar_enable(const mystring& location,
       
   185  			     const mystring& disabled)
       
   186  {
       
   187    if(is_exist(location.c_str()))
       
   188 -    RETURN(ok, "Autoresponse is already enabled");
       
   189 +    RETURN(ok, "Anyvar is already enabled");
       
   190    if(!is_exist(disabled.c_str()))
       
   191 -    RETURN(err, "Disabled autoresponse file did not exist");
       
   192 +    RETURN(err, "Disabled anyvar file did not exist");
       
   193    if(rename(disabled.c_str(), location.c_str()))
       
   194 -    RETURN(err, "Unable to rename previously disabled autoresponse file");
       
   195 -  RETURN(ok, "Autoresponse file sucessfully restored");
       
   196 +    RETURN(err, "Unable to rename previously disabled anyvar file");
       
   197 +  RETURN(ok, "Anyvar file sucessfully restored");
       
   198  }  
       
   199  
       
   200  static bool read_file(const mystring& filename, mystring& out)
       
   201 @@ -99,33 +99,39 @@
       
   202    return true;
       
   203  }
       
   204  
       
   205 -response autoresponse_read(const mystring& location,
       
   206 +response anyvar_read(const mystring& location,
       
   207  			   const mystring& disabled, int fd)
       
   208  {
       
   209    mystring line;
       
   210    if(!is_exist(location.c_str()) &&
       
   211       !is_exist(disabled.c_str()))
       
   212 -    RETURN(err, "Autoresponder file does not exist");
       
   213 +    RETURN(err, "Anyvar file does not exist");
       
   214  
       
   215    mystring contents;
       
   216    if(!read_file(location, contents) &&
       
   217       !read_file(disabled, contents))
       
   218 -    RETURN(err, "Unable to read data from autoresponse file");
       
   219 +    RETURN(err, "Unable to read data from anyvar file");
       
   220    response resp(response::ok, contents);
       
   221    resp.write(fd);
       
   222 -  RETURN(ok, "Retrieved autoresponse file");
       
   223 +  RETURN(ok, "Retrieved anyvar file");
       
   224  }
       
   225  
       
   226 -response autoresponse_delete(const mystring& directory)
       
   227 +response anyvar_delete(const mystring& directory,
       
   228 +			     const mystring& location,
       
   229 +			     const mystring& disabled)
       
   230  {
       
   231    if(!is_dir(directory.c_str()))
       
   232 -    RETURN(err, "Autoresponse directory does not exist.");
       
   233 -  if(!delete_directory(directory))
       
   234 -    RETURN(err, "Could not delete autoresponse directory.");
       
   235 -  RETURN(ok, "Autoresponse directory deleted.");
       
   236 +    RETURN(err, "Anyvar directory does not exist.");
       
   237 +  const char* fn = is_file(location.c_str()) ? location.c_str() :
       
   238 +    is_file(disabled.c_str()) ? disabled.c_str() : NULL;
       
   239 +  if(fn == NULL)
       
   240 +    RETURN(err, "Anyvar file does not exist.");
       
   241 +  if(unlink(fn))
       
   242 +    RETURN(err, "Failed to remove anyvar file.");
       
   243 +  RETURN(ok, "Anyvar file deleted.");
       
   244  }
       
   245  
       
   246 -response autoresponse_status(const mystring& directory,
       
   247 +response anyvar_status(const mystring& directory,
       
   248  			     const mystring& location,
       
   249  			     const mystring& disabled)
       
   250  {
       
   251 @@ -141,18 +147,19 @@
       
   252    RETURN(ok, msg);
       
   253  }
       
   254  
       
   255 -CMD_FD(autoresponse)
       
   256 -  // Usage: autoresponse baseuser-virtuser pass action [autorespmessage]
       
   257 +CMD_FD(anyvar)
       
   258 +  // Usage: anyvar baseuser-virtuser pass action varname [value]
       
   259  {
       
   260  
       
   261    mystring user = args[0];
       
   262    mystring pass = args[1];
       
   263    args[1] = LOG_PASSWORD;
       
   264    mystring action = args[2];
       
   265 -  mystring message;
       
   266 -  if(args.count() == 4) {
       
   267 -    message = args[3];
       
   268 -    args[3] = LOG_MESSAGE;
       
   269 +  mystring varname = args[3];
       
   270 +  mystring value;
       
   271 +  if(args.count() == 5) {
       
   272 +    value = args[4];
       
   273 +    args[4] = LOG_MESSAGE;
       
   274    }
       
   275    logcommand(args);
       
   276  
       
   277 @@ -160,25 +167,25 @@
       
   278    vpwentry* vpw;
       
   279    OK_RESPONSE(lookup_and_validate(user, pw, vpw, pass, true, true));
       
   280  
       
   281 -  const mystring directory = vpw->directory + "/" + config->autoresponse_dir();
       
   282 -  const mystring filename = directory + "/" + config->autoresponse_file();
       
   283 +  const mystring directory = vpw->directory + "/anyvar"; // XXX: + config->anyvar_dir();
       
   284 +  const mystring filename = directory + "/" + varname;
       
   285    const mystring disabled = filename + ".disabled";
       
   286    
       
   287    if(action == "disable")
       
   288 -    return autoresponse_disable(filename, disabled);
       
   289 +    return anyvar_disable(filename, disabled);
       
   290    else if(action == "enable")
       
   291 -    return autoresponse_enable(filename, disabled);
       
   292 +    return anyvar_enable(filename, disabled);
       
   293    else if(action == "read")
       
   294 -    return autoresponse_read(filename, disabled, fd);
       
   295 +    return anyvar_read(filename, disabled, fd);
       
   296    else if(action == "write")
       
   297 -    if(!message)
       
   298 -      RETURN(bad, "Missing autoresponse message argument");
       
   299 +    if(!value)
       
   300 +      RETURN(bad, "Missing anyvar value argument");
       
   301      else
       
   302 -      return autoresponse_write(directory, filename, disabled, message);
       
   303 +      return anyvar_write(directory, filename, disabled, value);
       
   304    else if(action == "delete")
       
   305 -    return autoresponse_delete(directory);
       
   306 +    return anyvar_delete(directory, filename, disabled);
       
   307    else if(action == "status")
       
   308 -    return autoresponse_status(directory, filename, disabled);
       
   309 +    return anyvar_status(directory, filename, disabled);
       
   310    
       
   311    RETURN(err, "Unrecognized command");
       
   312  }
       
   313 diff --git a/daemon/dispatch.cc b/daemon/dispatch.cc
       
   314 --- a/daemon/dispatch.cc
       
   315 +++ b/daemon/dispatch.cc
       
   316 @@ -21,6 +21,7 @@
       
   317  // declare the commands
       
   318  extern CMD(adduser2);
       
   319  extern CMD(adduser3);
       
   320 +extern CMD(anyvar);
       
   321  extern CMD(autoresponse);
       
   322  extern CMD(chattr);
       
   323  extern CMD(check);
       
   324 @@ -72,6 +73,7 @@
       
   325    ENTRY(chattr,       5, -1, true),
       
   326    ENTRY(adduser2,     4, -1, true),
       
   327    ENTRY(adduser3,     5, -1, true),
       
   328 +  ENTRY(anyvar,       5,  6, true),
       
   329    ENTRY(autoresponse, 4,  5, true),
       
   330    ENTRY(deluser,      3,  3, true),
       
   331    ENTRY(stat,         3,  3, true),
       
   332 diff --git a/lib/Makefile b/lib/Makefile
       
   333 --- a/lib/Makefile
       
   334 +++ b/lib/Makefile
       
   335 @@ -166,7 +166,7 @@
       
   336  #     (which will cause the Makefiles to be regenerated when you run `make');
       
   337  # (2) otherwise, pass the desired values on the `make' command line.
       
   338  
       
   339 -MAKE=make
       
   340 +
       
   341  
       
   342  all-recursive install-data-recursive install-exec-recursive \
       
   343  installdirs-recursive install-recursive uninstall-recursive  \
       
   344 diff --git a/python/commands.py b/python/commands.py
       
   345 --- a/python/commands.py
       
   346 +++ b/python/commands.py
       
   347 @@ -45,6 +45,12 @@
       
   348  def lookup(domain, username, password):
       
   349      return types.VUser(execute('lookup', domain, username, password))
       
   350  
       
   351 +def anyvar(domain, user, password, action, varname, value=None):
       
   352 +    cmd = [ domain, user, password, action, varname ]
       
   353 +    if value:
       
   354 +        cmd.append(value)
       
   355 +    return daemon.execute('anyvar', cmd)
       
   356 +
       
   357  def autoresponse(domain, user, password, action, message=None):
       
   358      cmd = [ domain, user, password, action ]
       
   359      if message:
       
   360 diff --git a/python/config.py b/python/config.py
       
   361 --- a/python/config.py
       
   362 +++ b/python/config.py
       
   363 @@ -16,7 +16,7 @@
       
   364  
       
   365  import os
       
   366  import string
       
   367 -import local
       
   368 +#import local
       
   369  
       
   370  def read(name, default):
       
   371      try:
       
   372 diff --git a/python/types.py b/python/types.py
       
   373 --- a/python/types.py
       
   374 +++ b/python/types.py
       
   375 @@ -94,7 +94,8 @@
       
   376              if flag == ATTR_MAILBOX_ENABLED:
       
   377                  self.mailbox_enabled = Flag(val)
       
   378              else:
       
   379 -                raise ValueError, "Invalid flag number %d in vuser data" % flag
       
   380 +                #raise ValueError, "Invalid flag number %d in vuser data" % flag
       
   381 +                print "Invalid flag number %d in vuser data" % flag
       
   382          bin = string.split(bin[i+1:], '\0')
       
   383          self.password = bin[0]
       
   384          self.mailbox = bin[1]