Hi, Almost a year ago I was looking at adding skel dir capability to vpopmail (check the archives - 23/11/04 !).
For one reason or another I never quite got round to it. However, tonight I've started putting something together. The thing is, I've not done much programming in C before. Pascal, sure. Perl - I'm a wizard :) So, I've put together a section of code, which may or may not be valid C, and would appreciate comments. Introduction ============ This code is intended to add skel dir functionality to vpopmail. It first looks for a domain-specific skel dir in: /home/vpopmail/etc/domains/<domain>/skel It then looks for a installation-specific skel dir in; /home/vpopmail/etc/skel If neither are found, it creates the default maildir structure. ===== snippet of vpopmail.c ========== /* Initialise a couple of strings to hold directory paths char skel_dir[MAX_BUFF]; char skel_location[MAX_BUFF]; /* initialise skel dir to empty */ strcpy(skel_dir,""); /* first directory to check */ snprintf(skel_location, sizeof(skel_location), "%s/etc/domains/%s/skel", VPOPMAILDIR, domain); /* check if it exists + is readable */ if (check_dir_readable(skel_location)) { /* set the skel dir */ snprintf(skel_dir, sizeof(skel_dir), "%s", skel_location) } else { /* next directory to check */ snprintf(skel_location, sizeof(skel_location), "%s/etc/skel", VPOPMAILDIR); /* check if it exists + is readable */ if (check_dir_readable(skel_location)) { /* set the skel dir */ snprintf(skel_dir, sizeof(skel_dir), "%s", skel_location); } }; /* if one of the skel dirs exists, use it */ if (skel_dir <> "") { /* copy it to the newly-created user dir */ copydir(skel_dir, "."); } else { /* otherwise, create the default dir structure */ /* (this is core vpopmail code) */ for (i = 0; i < sizeof(dirnames)/sizeof(dirnames[0]); i++) { if (mkdir(dirnames[i],VPOPMAIL_DIR_MODE) == -1){ fprintf(stderr, "make_user_dir: failed on %s\n", dirnames[i]); /* back out of changes made above */ chdir(".."); vdelfiles(username); chdir(calling_dir); return(NULL); } } } ===== snippet of vpopmail.c ========== I've not yet written the check_dir_readable() or copydir() functions; check_dir_readable may be really easy (it is in Perl :) ) but I've not looked into how to implement it. copydir() is probably already available somewhere if I have a quick google. I'd appreciate any comments before I go any further with this. Thanks, R.