#include #include #include #include #include "internal.h" #include "samba.m" #include "keyword.h" #include #include #include extern SAMBA_HELP_FILE help_samba; static SAMBA_HELP_FILE help_share ("share"); static SAMBA_HELP_FILE help_homes ("homes"); static SAMBA_HELP_FILE help_printers ("printers"); static SAMBA_HELP_FILE help_global ("global"); static SAMBA_HELP_FILE help_netlogon ("netlogon"); static SAMBA_HELP_FILE help_ldap ("ldap"); // Dialog IDs for the virtual registry static char ID_MAIN[]="main"; static char ID_SHARE[]="share"; static char ID_LOGON[]="logon"; struct SMB_FIELD_LOOKUP{ const char **keywords; const char **titles; }; static int samedit_lookup ( const char *val, const char *lk[]) { int ret = 0; // Remove extra spaces in the value so the lookup works all the time char tmp[strlen(val)+1]; char *pt = tmp; bool last_was_blank = false; while (*val != '\0'){ if (isspace(*val)){ if (!last_was_blank){ *pt++ = ' '; last_was_blank=true; } }else{ *pt++ = *val; last_was_blank=false; } val++; } *pt = '\0'; for (int i=0; lk[i] != NULL; i++){ if (strcmp(tmp,lk[i])==0){ ret = i; break; } } return ret; } PRIVATE void SMB_SHARE::setdia ( DIALOG &dia, SMB_FIELD tbf[], int nbf, SMB_FIELD_VAL tbv[], PRIVATE_MESSAGE tbmsg[]) { for (int i=0; itype; const char *title = pt->title; if (type == SMB_BOOK){ dia.newf_title (title,1,"",title); }else if (type == SMB_BUTTON){ dia.new_button (title,"",tbmsg[i]); }else{ const char *val = getval (pt->key1,pt->key2,pt->key3); if (type == SMB_STR || type == SMB_USERS){ tbv[i].str.setfrom (val); dia.newf_str (title,tbv[i].str); }else if (type == SMB_NUM){ tbv[i].num = atoi(val); dia.newf_num (title,tbv[i].num); }else if (type == SMB_CHK){ tbv[i].chk = stricmp(val,K_YES)==0; dia.newf_chk ("",tbv[i].chk,title); }else if (type == SMB_CHKON){ // Like SMB_CHK, except that the default is yes tbv[i].chk = stricmp(val,K_YES)==0 || val[0] == '\0'; dia.newf_chk ("",tbv[i].chk,title); }else if (type == SMB_ENUMH){ SMB_FIELD_LOOKUP *lk = (SMB_FIELD_LOOKUP*)pt->extra; tbv[i].enm = samedit_lookup (val,lk->keywords); dia.newf_chkm (title,tbv[i].enm,lk->titles); }else if (type == SMB_COMBO){ const char **opts = (const char **)pt->extra; tbv[i].str.setfrom (val); FIELD_COMBO *comb = dia.newf_combo (title,tbv[i].str); for (int i=0; opts[i] != NULL; i++){ comb->addopt (opts[i]); } } } } } PRIVATE void SMB_SHARE::savedia( SMB_FIELD tbf[], int nbf, SMB_FIELD_VAL tbv[]) { for (int i=0; itype; const char *key1 = pt->key1; const char *key2 = pt->key2; const char *key3 = pt->key3; if (type == SMB_STR || type == SMB_COMBO || type == SMB_USERS){ setval (key1,key2,key3,tbv[i].str); }else if (type == SMB_NUM){ setval (key1,key2,key3,tbv[i].num); }else if (type == SMB_CHK || type == SMB_CHKON){ setval (key1,key2,key3,tbv[i].chk ? K_YES : K_NO); }else if (type == SMB_ENUMH){ SMB_FIELD_LOOKUP *lk = (SMB_FIELD_LOOKUP*)pt->extra; const char *val = lk->keywords[tbv[i].enm]; setval (key1,key2,key3,val); } } } /* Split a line containing users and groups. The users may be separated either by space or comma. Users with spaces using quotes are supported. */ static int samedit_splitusers (const char *s, SSTRINGS &tb) { int ret = 0; char tmp[strlen(s)+1]; strcpy (tmp,s); { char *pt; // Turn all commas to spaces while ((pt=strchr(tmp,','))!=NULL) *pt = ' '; } const char *pt = tmp; while (*pt != '\0'){ SSTRING *s = new SSTRING; pt = str_extract (pt,*s); if (s->is_filled()){ tb.add (s); ret ++; }else{ delete s; } } return ret; } /* Validate the various fields. Return -1 if any error. nof is positionned on the offending field */ PRIVATE int SMB_SHARE::validdia( SMB_FIELD tbf[], int nbf, SMB_FIELD_VAL tbv[], int &nof) { int ret = 0; for (int i=0; itype; if (type == SMB_STR || type == SMB_COMBO){ // Nothing to validate }else if (type == SMB_USERS){ const char *s = tbv[i].str.get(); SSTRINGS tb; samedit_splitusers (s,tb); SSTRING errors; for (int j=0; jget(); if (u[0] == '@'){ if (getgrnam(u+1)==NULL){ errors.appendf (MSG_U(E_UNKNOWNGRP,"Unknown group %s\n"),u+1); } }else if (getpwnam(u)==NULL){ errors.appendf (MSG_U(E_UNKNOWNUSER,"Unknown user %s\n"),u); } } if (errors.is_filled()){ xconf_error ("%s",errors.get()); nof = i; ret = -1; break; } }else if (type == SMB_NUM){ // Nothing to validate for now }else if (type == SMB_CHK || type == SMB_CHKON){ // Nothing to validate }else if (type == SMB_ENUMH){ // Nothing to validate } } return ret; } PUBLIC int SMB_SHARE::editgen( DIALOG &dia, SMB_FIELD tbf[], int nbf, bool may_del, // May delete this share SAMBA_HELP_FILE &help_file) { int ret = -1; SMB_FIELD_VAL tbv[nbf]; PRIVATE_MESSAGE tbmsg[nbf]; setdia (dia,tbf,nbf,tbv,tbmsg); int nof = 0; while (1){ int menubut = MENUBUT_ACCEPT|MENUBUT_CANCEL; if (may_del) menubut |= MENUBUT_DEL; MENU_STATUS code = dia.edit (MSG_U(T_SHARE,"Share setup") ,MSG_U(I_SHARE,"You are allowed to enter configurations\n" "for one disk share\n") ,help_file ,nof,menubut); if (code == MENU_ESCAPE || code == MENU_CANCEL){ break; }else if (code == MENU_DEL){ if (xconf_delok()){ ret = 1; break; } }else if (code == MENU_MESSAGE){ for (int i=0; isyncpass,tbsmbpass); static const char *tbsecurity_keywords[]={ K_USER, K_SERVER, K_DOMAIN, K_SHARE, NULL, }; static const char *tbsecurity_titles[]={ MSG_U(I_SECURITYUSER,"User"), MSG_U(I_SECURITYSERVER,"Server"), MSG_U(I_SECURITYDOMAIN,"Domain"), MSG_U(I_SECURITYSHARE,"Share"), NULL }; static SMB_FIELD_LOOKUP tbsecurity={ tbsecurity_keywords, tbsecurity_titles }; static const char *tbmaptoguest_keywords[]={ K_NEVER, K_BADUSER, K_BADPASSWORD }; static const char *tbmaptoguest_titles[]={ MSG_U(I_NEVER,"Never"), MSG_U(I_BADUSER,"Bad user"), MSG_U(I_BADPASSWORD,"Bad password"), NULL }; static SMB_FIELD_LOOKUP tbmaptoguest={ tbmaptoguest_keywords, tbmaptoguest_titles }; static const char *adduserscripts[]={ "/usr/sbin/adduser -s /bin/false -g popusers -c \"smb account %u\" %u", NULL }; static const char *deluserscripts[]={ "/usr/sbin/deluser %u", NULL }; static char *nameorder[]={ "lmhosts, host, wins, bcast", "lmhosts, wins, bcast", "lmhosts, bcast", "lmhosts", NULL }; static char *winpopupcommand[]={ "/bin/mail -s 'Message from %f at %m' root < %s; rm %s", NULL }; static SMB_FIELD tbf[]={ {K_UNIX,K_PASSWORD,K_SYNC,SMB_CHK,NULL,MSG_U(F_SYNCPASSFROMSMB,"Synchronise Linux from SMB passwords")}, {K_SERVER,K_STRING,NULL,SMB_STR,NULL,MSG_U(F_SERVERDESC,"Server description")}, {K_WORKGROUP,NULL,NULL,SMB_STR,NULL,MSG_U(F_WORKGROUP,"Work group")}, {K_NETBIOS,K_NAME,NULL,SMB_STR,NULL,MSG_U(F_NETBIOSNAME,"Netbios name (opt)")}, {K_NETBIOS,K_ALIASES,NULL,SMB_STR,NULL,MSG_U(F_NETBIOSALIASES,"Netbios aliases (opt)")}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_U(T_PASSWORDS,"Passwords")}, {K_ENCRYPT,K_PASSWORDS,NULL,SMB_CHK,NULL,MSG_U(F_ENGRYPTPASS,"Encrypted password required")}, {K_SECURITY,NULL,NULL,SMB_ENUMH,(void*)&tbsecurity ,MSG_U(F_SECURITY,"Authentication mode")}, {K_MAP,K_TO,K_GUEST,SMB_ENUMH,(void*)&tbmaptoguest ,MSG_U(F_MAPGUEST,"Map to guest")}, {K_PASSWORD,K_SERVER,NULL,SMB_STR,NULL,MSG_U(F_PASSSERVER,"Password server")}, {K_PASSWORD,K_LEVEL,NULL,SMB_NUM,NULL,MSG_U(F_PASSLEVEL,"Password level")}, {K_PASSWD,K_PROGRAM,NULL,SMB_STR,NULL,MSG_U(F_PASSPROG,"Passwd program")}, {K_NULL,K_PASSWORDS,NULL,SMB_CHK,NULL,MSG_U(F_NULLPASSWORDS,"Allow null passwords account")}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_R(T_ACCESS)}, {K_ALLOW,K_HOSTS,NULL,SMB_STR,NULL,MSG_R(F_ALLOWHOSTS)}, {K_DENY,K_HOSTS,NULL,SMB_STR,NULL,MSG_R(F_DENYHOSTS)}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_U(T_NETWORKING,"Networking")}, {K_OS,K_LEVEL,NULL,SMB_NUM,NULL,MSG_U(F_OSLEVEL,"OS level")}, {K_PREFERRED,K_MASTER,NULL,SMB_CHK,NULL,MSG_U(F_PREFMASTER,"Preferred master")}, {K_DOMAIN,K_MASTER,NULL,SMB_CHK,NULL,MSG_U(F_DOMMASTER,"Domain master")}, {K_REMOTE,K_ANNOUNCE,NULL,SMB_STR,NULL,MSG_U(F_REMANNOUNCE,"Remote announce")}, {K_REMOTE,K_BROWSE,K_SYNC,SMB_STR,NULL,MSG_U(F_BROWSESYNC,"Sync. remote browsers")}, {K_WINS,K_SUPPORT,NULL,SMB_CHK,NULL,MSG_U(F_WINSSUPPORT,"Enable samba as a WINS server")}, {K_WINS,K_SERVER,NULL,SMB_STR,NULL,MSG_U(F_WINSSERVER,"WINS server")}, {K_INTERFACES,NULL,NULL,SMB_STR,NULL,MSG_U(F_INTERFACES,"Interfaces")}, {K_BIND,K_INTERFACES,K_ONLY,SMB_CHK,NULL,MSG_U(F_BINDINTERFACESONLY,"Bind interfaces only")}, {K_NAME,K_RESOLVE,K_ORDER,SMB_COMBO,(void*)nameorder ,MSG_U(F_RESOLVEORDER,"Name resolve order")}, {K_DOMAIN,K_ADMIN,K_GROUP,SMB_USERS,NULL,MSG_U(F_DOMAINADMINGROUP ,"Domain admin group")}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_U(T_AUTOCREATE,"Auto-accounts")}, {K_ADD,K_USER,K_SCRIPT,SMB_COMBO,(void*)adduserscripts ,MSG_U(F_ADDUSERSCRIPT,"Add user script")}, {K_DELETE,K_USER,K_SCRIPT,SMB_COMBO,(void*)deluserscripts ,MSG_U(F_DELUSERSCRIPT,"Delete user script")}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_R(T_FEATURES)}, {K_GUEST,K_ACCOUNT,NULL,SMB_STR,NULL,MSG_U(F_GUESTACCOUNT,"Guest account")}, {K_DEAD,K_TIME,NULL,SMB_NUM,NULL,MSG_U(F_DEADTIME,"Dead time")}, {K_DEBUG,K_LEVEL,NULL,SMB_NUM,NULL,MSG_U(F_DBGLEVEL,"Debug level")}, {K_DEFAULT,K_SERVICE,NULL,SMB_STR,NULL,MSG_U(F_DEFSERVICE,"Default service")}, {K_LOAD,K_PRINTERS,NULL,SMB_CHKON,NULL,MSG_U(F_LOADPRINTERS,"Show all available printers")}, {K_MESSAGE,K_COMMAND,NULL,SMB_COMBO,(void*)winpopupcommand, MSG_U(F_MSGCOMMAND,"WinPopup command")}, {K_HIDE,K_DOT,K_FILES,SMB_CHKON,NULL,MSG_R(F_HIDEDOTFILES)}, {K_VETO,K_FILES,NULL,SMB_STR,NULL,MSG_R(F_VETOFILES)}, {K_CHARACTER,K_SET,NULL,SMB_STR,NULL,MSG_U(F_CHARACTERSET,"Character set")}, //{K_STATUS,NULL,NULL,SMB_CHKON,NULL,MSG_U(F_STATUSFILE,"Update the status database")}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_U(T_LDAP,"LDAP")}, {K_LDAP,K_SERVER,NULL,SMB_STR,NULL,MSG_U(F_LDAPSERVER,"Server")}, {K_LDAP,K_SUFFIX,NULL,SMB_STR,NULL,MSG_U(F_LDAPSUFFIX,"Suffix")}, {K_LDAP,K_ADMIN,K_DN,SMB_STR,NULL,MSG_U(F_LDAPADMINDN,"Admin. distinguished name (dn)")}, {K_LDAP,K_SSL,NULL,SMB_CHKON,NULL,MSG_U(F_LDAPSSL,"Connect using SSL")}, {K_LDAP,K_PORT,NULL,SMB_STR,NULL,MSG_U(F_LDAPPORT,"TCP port")}, {NULL,NULL,NULL,SMB_BUTTON,(void*)samba_setdnpasswd,MSG_U(B_SETDNPASSWD,"Set DN password")}, }; int ret = editgen (dia,tbf,(int)(sizeof(tbf)/sizeof(tbf[0])),false,help_global); if (ret == 0) samba->write(); return ret; } PUBLIC int SMB_SHARE::editnetlogon(SMB_SHARE *glob, SMB_CONF *samba) { /* #Specification: netlogon / logon fields smb.conf requires the various logon information to be stored in the global section. It seems more appropriate to present this along the netlogon share definition. This is why we play some magic. We move this information from the global section to the netlogon section, edit it and move it back to the global section later. */ static const char *tbmove[][2]={ {K_LOGON,K_SCRIPT}, {K_LOGON,K_PATH}, {K_LOGON,K_DRIVE}, {K_LOGON,K_HOME}, {K_DOMAIN,K_LOGONS}, }; const int NBGLOBAL=sizeof(tbmove)/sizeof(tbmove[0]); if (glob != NULL){ for (int i=0; igetval (tbmove[i][0],tbmove[i][1],NULL); setval (tbmove[i][0],tbmove[i][1],NULL,val); } } DIALOG dia; dia.set_registry_id (ID_LOGON); static SMB_FIELD tbf[]={ {K_COMMENT,NULL,NULL,SMB_STR ,NULL,MSG_U(F_NETLOGONCOMMENT,"netlogon share title")}, {K_AVAILABLE,NULL,NULL,SMB_CHKON,NULL,MSG_R(F_ENABLE)}, {K_PATH,NULL,NULL,SMB_STR,NULL,MSG_R(F_PATH)}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_U(T_LOGON,"Logon")}, {K_DOMAIN,K_LOGONS,NULL,SMB_CHK,NULL,MSG_U(F_DOMLOGONS,"Workgroup Logon server")}, {K_LOGON,K_SCRIPT,NULL,SMB_STR,NULL,MSG_U(F_LOGONSCRIPT,"Logon script")}, {K_LOGON,K_PATH,NULL,SMB_STR,NULL,MSG_U(F_LOGONPATH,"Logon path")}, {K_LOGON,K_DRIVE,NULL,SMB_STR,NULL,MSG_U(F_LOGONDRIVE,"Logon drive")}, {K_LOGON,K_HOME,NULL,SMB_STR,NULL,MSG_U(F_LOGONHOME,"Logon home")}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_R(T_SCRIPTS)}, {K_PREEXEC,NULL,NULL,SMB_STR,NULL,MSG_R(F_PREEXEC)}, {K_PREEXEC,K_CLOSE,NULL,SMB_CHK,NULL,MSG_R(F_EXECCLOSE)}, {K_ROOT,K_PREEXEC,NULL,SMB_STR,NULL,MSG_R(F_ROOTPREEXEC)}, {K_ROOT,K_PREEXEC,K_CLOSE,SMB_CHK,NULL,MSG_R(F_ROOTEXECCLOSE)}, {K_POSTEXEC,NULL,NULL,SMB_STR,NULL,MSG_R(F_POSTEXEC)}, {K_ROOT,K_POSTEXEC,NULL,SMB_STR,NULL,MSG_R(F_ROOTPOSTEXEC)}, }; int ret = editgen (dia,tbf,(int)(sizeof(tbf)/sizeof(tbf[0])),false,help_netlogon); if (ret == 0){ for (int i=0; isetval (tbmove[i][0],tbmove[i][1],NULL,val); setval (tbmove[i][0],tbmove[i][1],NULL,""); } samba->write(); } return ret; } PUBLIC int SMB_SHARE::edithomes(SMB_CONF *samba) { DIALOG dia; static SMB_FIELD tbf[]={ {K_COMMENT,NULL,NULL,SMB_STR,NULL,MSG_R(F_COMMENT)}, {K_AVAILABLE,NULL,NULL,SMB_CHK,NULL,MSG_R(F_ENABLE)}, {K_BROWSEABLE,NULL,NULL,SMB_CHK,NULL,MSG_R(F_BROWSEABLE)}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_R(T_ACCESS)}, {K_PUBLIC,NULL,NULL,SMB_CHK,NULL,MSG_R(F_PUBLIC)}, {K_WRITABLE,NULL,NULL,SMB_CHK,NULL,MSG_R(F_WRITABLE)}, {K_ALLOW,K_HOSTS,NULL,SMB_STR,NULL,MSG_R(F_ALLOWHOSTS)}, {K_DENY,K_HOSTS,NULL,SMB_STR,NULL,MSG_R(F_DENYHOSTS)}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_R(T_USERS)}, {K_USER,NULL,NULL,SMB_STR,NULL,MSG_R(F_USERLIST)}, {K_ONLY,K_USER,NULL,SMB_CHK,NULL,MSG_R(F_ONLYUSER)}, {K_WRITE,K_LIST,NULL,SMB_STR,NULL,MSG_R(F_WRITELIST)}, {K_VALID,K_USERS,NULL,SMB_STR,NULL,MSG_R(F_VALIDUSERS)}, {K_INVALID,K_USERS,NULL,SMB_STR,NULL,MSG_R(F_IVLDUSERS)}, {K_MAX,K_CONNECTIONS,NULL,SMB_STR,NULL,MSG_R(F_MAXCONNECT)}, {K_READ,K_LIST,NULL,SMB_STR,NULL,MSG_R(F_READLIST)}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_R(T_SCRIPTS)}, {K_PREEXEC,NULL,NULL,SMB_STR,NULL,MSG_R(F_PREEXEC)}, {K_PREEXEC,K_CLOSE,NULL,SMB_CHK,NULL,MSG_R(F_EXECCLOSE)}, {K_ROOT,K_PREEXEC,NULL,SMB_STR,NULL,MSG_R(F_ROOTPREEXEC)}, {K_ROOT,K_PREEXEC,K_CLOSE,SMB_CHK,NULL,MSG_R(F_ROOTEXECCLOSE)}, {K_POSTEXEC,NULL,NULL,SMB_STR,NULL,MSG_R(F_POSTEXEC)}, {K_ROOT,K_POSTEXEC,NULL,SMB_STR,NULL,MSG_R(F_ROOTPOSTEXEC)}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_R(T_FILEPERMS)}, {K_CREATE,K_MASK,NULL,SMB_STR,NULL,MSG_R(F_CREATEMASK)}, {K_FORCE,K_CREATE,K_MODE,SMB_STR,NULL,MSG_R(F_CREATEMODE)}, {K_DIRECTORY,K_MASK,NULL,SMB_STR,NULL,MSG_R(F_DIRMASK)}, {K_FORCE,K_DIRECTORY,K_MODE,SMB_STR,NULL,MSG_R(F_DIRMODE)}, {K_INHERIT,K_PERMISSIONS,NULL,SMB_CHK,NULL,MSG_R(F_INHERITPERM)}, {NULL,NULL,NULL,SMB_BOOK,NULL,MSG_R(T_FILES)}, {K_HIDE,K_DOT,K_FILES,SMB_CHK,NULL,MSG_R(F_HIDEDOTFILES)}, {K_HIDE,K_FILES,NULL,SMB_STR,NULL,MSG_R(F_HIDEFILES)}, {K_VETO,K_FILES,NULL,SMB_STR,NULL,MSG_R(F_VETOFILES)}, }; int ret = editgen (dia,tbf,(int)(sizeof(tbf)/sizeof(tbf[0])),false,help_homes); if (ret == 0) samba->write(); return ret; } PUBLIC int SMB_SHARE::editprinters(SMB_CONF *samba) { DIALOG dia; static SMB_FIELD tbf[]={ {K_COMMENT,NULL,NULL,SMB_STR,NULL,MSG_R(F_COMMENT)}, {K_AVAILABLE,NULL,NULL,SMB_CHK,NULL,MSG_R(F_ENABLE)}, {K_PRINTABLE,NULL,NULL,SMB_CHKON,NULL,MSG_U(F_PRINTABLE,"Share is printable")}, {K_BROWSEABLE,NULL,NULL,SMB_CHKON,NULL,MSG_R(F_BROWSEABLE)}, {K_PUBLIC,NULL,NULL,SMB_CHK,NULL,MSG_R(F_PUBLIC)}, }; int ret = editgen (dia,tbf,(int)(sizeof(tbf)/sizeof(tbf[0])),false,help_printers); if (ret == 0) samba->write(); return 0; } PUBLIC int SMB_SHARES::write() { return samba->write(); } static int cmp_by_name (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { SMB_SHARE *s1 = (SMB_SHARE*)o1; SMB_SHARE *s2 = (SMB_SHARE*)o2; return s1->name.cmp(s2->name); } PUBLIC int SMB_CONF::editshares() { int ret = -1; int nof = 0; DIALOG_LISTE dia; dia.newf_head ("",MSG_U(H_SHARES,"Share name\tDescription")); dia.addwhat (MSG_U(I_NEWSHARE,"Select [Add] to add a new disk share")); while (1){ int n = shares.getnb(); SMB_SHARES sorted (this); sorted.neverdelete(); // We present the share sorted, but // keep the original ordering in smb.conf for (int i=0; iname.get(); if (strcmp(name,K_GLOBAL)!=0 && strcmp(name,K_PRINTERS)!=0 && strcmp(name,K_NETLOGON)!=0 && strcmp(name,K_HOMES)!=0){ sorted.add (d); } } sorted.sort (cmp_by_name); for (int i=0; iname.get(); dia.set_menuitem(i,name,d->getval(K_COMMENT)); } dia.remove_last (sorted.getnb()+1); MENU_STATUS code = dia.editmenu (MSG_U(T_SHARES,"Disk shares") ,MSG_U(I_SHARES ,"You can define multiple independant entry\n" "points in your file server") ,help_share ,nof,MENUBUT_ADD); if (code == MENU_ESCAPE || code == MENU_QUIT){ break; }else if (code == MENU_ADD){ SMB_SHARE *d = new SMB_SHARE; ret = shares.editone (d); }else if (nof < sorted.getnb() && nof >= 0){ ret = shares.editone (sorted.getitem(nof)); } } return ret; } PUBLIC void SMB_CONF::editdefaults() { SMB_SHARE *d = shares.getitem(K_GLOBAL); if (d != NULL) d->editglobal(this); } PUBLIC void SMB_CONF::edithomes() { SMB_SHARE *d = shares.getitem(K_HOMES); if (d != NULL) d->edithomes(this); } PUBLIC void SMB_CONF::editprinters() { SMB_SHARE *d = shares.getitem(K_PRINTERS); if (d != NULL) d->editprinters(this); } PUBLIC void SMB_CONF::editnetlogon() { bool was_created = false; SMB_SHARE *d = shares.getitem(K_NETLOGON); if (d == NULL){ d = new SMB_SHARE ("","netlogon"); shares.add (d); was_created = true; } if (d != NULL){ SMB_SHARE *glob = shares.getitem(K_GLOBAL); if (d->editnetlogon(glob,this) != 0 && was_created) shares.remove_del (d); } } PUBLIC void SMB_CONF::edit() { static const char *m_def = MSG_U(M_DEFAULT,"Defaults"); static const char *m_homes = MSG_U(M_HOMES,"Default setup for users's home"); static const char *m_printers = MSG_U(M_PRINTERS,"Default setup for printers"); static const char *m_netlogon = MSG_U(M_NETLOGON,"Netlogon setup"); static const char *m_shares = MSG_U(M_SHARES,"Disk shares"); static const char *m_status = MSG_R(M_SAMBASTATUS); static const char *m_passwd = MSG_U(M_SAMBAPASSWD,"Set user password"); static const char *menuopt[]={ "", m_def, "", m_homes, "", m_printers, "", m_netlogon, "", m_shares, "", m_passwd, NULL, }; DIALOG_MENU dia; dia.new_menuitems (menuopt); if (status_api_available("samba")){ static const char *menuopt2[]={ "", m_status, NULL, }; dia.new_menuitems (menuopt2); }; int choice=0; while (1){ MENU_STATUS code = dia.editmenu (MSG_U(T_SAMBA,"Samba administration") ,MSG_U(I_SAMBA,"This menu allows to configure the Samba SMB file server") ,help_samba ,choice,0); if (code == MENU_QUIT || code == MENU_ESCAPE){ break; }else if (netconf_mainaccess()){ const char *key = dia.getmenustr(choice); if (key == m_def){ editdefaults(); }else if (key == m_homes){ edithomes(); }else if (key == m_printers){ editprinters(); }else if (key == m_shares){ editshares(); }else if (key == m_netlogon){ editnetlogon(); }else if (key == m_status){ samba_status(); }else if (key == m_passwd){ samba_userpasswd(); } } } } void samba_edit () { CONTEXT_LOCK lk ("samba"); if (lk.isok()){ SMB_CONF smb; smb.edit(); if (dialog_mode != DIALOG_TREE) smb.sanitycheck(); } } static void samedit_global() { SMB_CONF smb; smb.editdefaults(); } static void samedit_netlogon() { SMB_CONF smb; smb.editnetlogon(); } static void samedit_editshare(const char *share, bool setting) { SMB_CONF smb; SMB_SHARE *d = smb.shares.getitem(share); if (d != NULL){ smb.shares.editone(d); }else if (setting){ SMB_SHARE *d = new SMB_SHARE; d->name.setfrom (share); smb.shares.editone(d); } } static void samedit_listshare(SSTRINGS &tb) { SMB_CONF smb; for (int i=0; iname.get(); if (strcmp(name,K_GLOBAL)!=0 && strcmp(name,K_PRINTERS)!=0 && strcmp(name,K_NETLOGON)!=0 && strcmp(name,K_HOMES)!=0){ tb.add (new SSTRING(name)); } } } #include static PUBLISH_VARIABLES_MSG samba_var_list1[]={ {"mngsmbpasswd",P_MSG_R(F_MNGSMBPASS)}, {"syncpasswds",P_MSG_R(F_SYNCPASSFROMSMB)}, {"servdesc",P_MSG_R(F_SERVERDESC)}, {"workgroup",P_MSG_R(F_WORKGROUP)}, {"netbiosname",P_MSG_R(F_NETBIOSNAME)}, {"netbiosaliases",P_MSG_R(F_NETBIOSALIASES)}, {"encryptpasswd",P_MSG_R(F_ENGRYPTPASS)}, {"security",P_MSG_R(F_SECURITY)}, {"maptoguest",P_MSG_R(F_MAPGUEST)}, {"passwdserver",P_MSG_R(F_PASSSERVER)}, {"passwdlevel",P_MSG_R(F_PASSLEVEL)}, {"passwdprogram",P_MSG_R(F_PASSPROG)}, {"nullpasswds",P_MSG_R(F_NULLPASSWORDS)}, {"allowhosts",P_MSG_R(F_ALLOWHOSTS)}, {"denyhosts",P_MSG_R(F_DENYHOSTS)}, {"oslevel",P_MSG_R(F_OSLEVEL)}, {"preferedmaster",P_MSG_R(F_PREFMASTER)}, {"domainmaster",P_MSG_R(F_DOMMASTER)}, {"remoteannounce",P_MSG_R(F_REMANNOUNCE)}, {"remotebrowsesync",P_MSG_R(F_BROWSESYNC)}, {"winssupport",P_MSG_R(F_WINSSUPPORT)}, {"winsserver",P_MSG_R(F_WINSSERVER)}, {"interfaces",P_MSG_R(F_INTERFACES)}, {"bindinterfacesonly",P_MSG_R(F_BINDINTERFACESONLY)}, {"resolveorder",P_MSG_R(F_RESOLVEORDER)}, {"adduserscript",P_MSG_R(F_ADDUSERSCRIPT)}, {"deluserscript",P_MSG_R(F_DELUSERSCRIPT)}, {"guestaccount",P_MSG_R(F_GUESTACCOUNT)}, {"deadtime",P_MSG_R(F_DEADTIME)}, {"debuglevel",P_MSG_R(F_DBGLEVEL)}, {"defaultservice",P_MSG_R(F_DEFSERVICE)}, {"loadprinters",P_MSG_R(F_LOADPRINTERS)}, {"msgcommand",P_MSG_R(F_MSGCOMMAND)}, {"ldapadmindn",P_MSG_R(F_LDAPADMINDN)}, {"ldapserver",P_MSG_R(F_LDAPSERVER)}, {"ldapsuffix",P_MSG_R(F_LDAPSUFFIX)}, {"ldapssl",P_MSG_R(F_LDAPSSL)}, {"ldapport",P_MSG_R(F_LDAPPORT)}, {"domainadmingroup",P_MSG_R(F_DOMAINADMINGROUP)}, {"hidedotfiles",P_MSG_R(F_HIDEDOTFILES)}, {"characterset",P_MSG_R(F_CHARACTERSET)}, {"vetofiles",P_MSG_R(F_VETOFILES)}, {NULL,NULL}, }; static REGISTER_VARIABLES samba_registry1("samba",samba_var_list1, ID_MAIN,samedit_global); static PUBLISH_VARIABLES_MSG samba_var_list2[]={ {"netlogon_comment",P_MSG_R(F_NETLOGONCOMMENT)}, {"netlogon_available",P_MSG_R(F_ENABLE)}, {"netlogon_path",P_MSG_R(F_PATH)}, {"netlogon_domain",P_MSG_R(F_DOMLOGONS)}, {"netlogon_logonscript",P_MSG_R(F_LOGONSCRIPT)}, {"netlogon_logonpath",P_MSG_R(F_LOGONPATH)}, {"netlogon_logondrive",P_MSG_R(F_LOGONDRIVE)}, {"netlogon_logonhome",P_MSG_R(F_LOGONHOME)}, {"netlogon_preexec",P_MSG_R(F_PREEXEC)}, {"netlogon_preexecclose",P_MSG_R(F_EXECCLOSE)}, {"netlogon_rootpreexec",P_MSG_R(F_ROOTPREEXEC)}, {"netlogon_rootpreexecclose",P_MSG_R(F_ROOTEXECCLOSE)}, {"netlogon_postexec",P_MSG_R(F_POSTEXEC)}, {"netlogon_rootpostexec",P_MSG_R(F_ROOTPOSTEXEC)}, {NULL,NULL}, }; static REGISTER_VARIABLES samba_registry2("samba",samba_var_list2, ID_LOGON,samedit_netlogon); static PUBLISH_VARIABLES_MSG samba_var_list3[]={ {"share_name",P_MSG_R(F_SHARENAME)}, {"share_path",P_MSG_R(F_PATH)}, {"share_available",P_MSG_R(F_ENABLE)}, {"share_browseable",P_MSG_R(F_BROWSEABLE)}, {"share_forceuser",P_MSG_R(F_FORCEUSER)}, {"share_comment",P_MSG_R(F_COMMENT)}, {"share_copy",P_MSG_R(F_INHERIT)}, {"share_public",P_MSG_R(F_PUBLIC)}, {"share_guestonly",P_MSG_R(F_GUESTONLY)}, {"share_writable",P_MSG_R(F_WRITABLE)}, {"share_allowhosts",P_MSG_R(F_ALLOWHOSTS)}, {"share_denyhosts",P_MSG_R(F_DENYHOSTS)}, {"share_users",P_MSG_R(F_USERLIST)}, {"share_onlyusers",P_MSG_R(F_ONLYUSER)}, {"share_adminusers",P_MSG_R(F_ADMINUSERS)}, {"share_writelist",P_MSG_R(F_WRITELIST)}, {"share_validusers",P_MSG_R(F_VALIDUSERS)}, {"share_invalidusers",P_MSG_R(F_IVLDUSERS)}, {"share_readlist",P_MSG_R(F_READLIST)}, {"share_preexec",P_MSG_R(F_PREEXEC)}, {"share_preexecclose",P_MSG_R(F_EXECCLOSE)}, {"share_rootpreexec",P_MSG_R(F_ROOTPREEXEC)}, {"share_rootpreexecclose",P_MSG_R(F_ROOTEXECCLOSE)}, {"share_postexec",P_MSG_R(F_POSTEXEC)}, {"share_rootpostexec",P_MSG_R(F_ROOTPOSTEXEC)}, {"share_magicscript",P_MSG_R(F_MAGICSCRIPT)}, {"share_forcegroup",P_MSG_R(F_FORCEGROUP)}, {"share_dontdescend",P_MSG_R(F_DONTDESCEND)}, {"share_guestaccount",P_MSG_R(F_GUESTACCOUNTSH)}, {"share_magicoutput",P_MSG_R(F_MAGICOUTPUT)}, {"share_maxconnections",P_MSG_R(F_MAXCONNECT)}, {"share_createmask",P_MSG_R(F_CREATEMASK)}, {"share_createmode",P_MSG_R(F_CREATEMODE)}, {"share_dirmask",P_MSG_R(F_DIRMASK)}, {"share_dirmode",P_MSG_R(F_DIRMODE)}, {"share_inheritperm",P_MSG_R(F_INHERITPERM)}, {"share_hidedotfiles",P_MSG_R(F_HIDEDOTFILES)}, {"share_hidefiles",P_MSG_R(F_HIDEFILES)}, {"share_vetofiles",P_MSG_R(F_VETOFILES)}, { NULL, NULL } }; static REGISTER_VARIABLES samba_registry3("samba","shares",samba_var_list3, ID_SHARE ,samedit_editshare,samedit_listshare);