static char *get_basepath(TALLOC_CTX *ctx) { char *basepath = lp_usershare_path(ctx); if (!basepath) { return NULL; } if ((basepath[0] != '\0') && (basepath[strlen(basepath)-1] == '/')) { basepath[strlen(basepath)-1] = '\0'; } return basepath; }
static int net_usershare_delete(struct net_context *c, int argc, const char **argv) { char *us_path; char *sharename; if (argc != 1 || c->display_usage) { return net_usershare_delete_usage(c, argc, argv); } if ((sharename = strlower_talloc(talloc_tos(), argv[0])) == NULL) { d_fprintf(stderr, _("strlower_talloc failed\n")); return -1; } if (!validate_net_name(sharename, INVALID_SHARENAME_CHARS, strlen(sharename))) { d_fprintf(stderr, _("net usershare delete: share name %s contains " "invalid characters (any of %s)\n"), sharename, INVALID_SHARENAME_CHARS); TALLOC_FREE(sharename); return -1; } us_path = talloc_asprintf(talloc_tos(), "%s/%s", lp_usershare_path(talloc_tos()), sharename); if (!us_path) { TALLOC_FREE(sharename); return -1; } if (unlink(us_path) != 0) { d_fprintf(stderr, _("net usershare delete: unable to remove usershare %s. " "Error was %s\n"), us_path, strerror(errno)); TALLOC_FREE(sharename); return -1; } TALLOC_FREE(sharename); return 0; }
int find_service(fstring service) { int iService; struct smbd_server_connection *sconn = smbd_server_conn; all_string_sub(service,"\\","/",0); iService = lp_servicenumber(service); /* now handle the special case of a home directory */ if (iService < 0) { char *phome_dir = get_user_home_dir(talloc_tos(), service); if(!phome_dir) { /* * Try mapping the servicename, it may * be a Windows to unix mapped user name. */ if(map_username(sconn, service)) phome_dir = get_user_home_dir( talloc_tos(), service); } DEBUG(3,("checking for home directory %s gave %s\n",service, phome_dir?phome_dir:"(NULL)")); iService = add_home_service(service,service /* 'username' */, phome_dir); } /* If we still don't have a service, attempt to add it as a printer. */ if (iService < 0) { int iPrinterService; if ((iPrinterService = lp_servicenumber(PRINTERS_NAME)) < 0) { iPrinterService = load_registry_service(PRINTERS_NAME); } if (iPrinterService) { DEBUG(3,("checking whether %s is a valid printer name...\n", service)); if (pcap_printername_ok(service)) { DEBUG(3,("%s is a valid printer name\n", service)); DEBUG(3,("adding %s as a printer service\n", service)); lp_add_printer(service, iPrinterService); iService = lp_servicenumber(service); if (iService < 0) { DEBUG(0,("failed to add %s as a printer service!\n", service)); } } else { DEBUG(3,("%s is not a valid printer name\n", service)); } } } /* Check for default vfs service? Unsure whether to implement this */ if (iService < 0) { } if (iService < 0) { iService = load_registry_service(service); } /* Is it a usershare service ? */ if (iService < 0 && *lp_usershare_path()) { /* Ensure the name is canonicalized. */ strlower_m(service); iService = load_usershare_service(service); } /* just possibly it's a default service? */ if (iService < 0) { char *pdefservice = lp_defaultservice(); if (pdefservice && *pdefservice && !strequal(pdefservice,service) && !strstr_m(service,"..")) { /* * We need to do a local copy here as lp_defaultservice() * returns one of the rotating lp_string buffers that * could get overwritten by the recursive find_service() call * below. Fix from Josef Hinteregger <*****@*****.**>. */ char *defservice = SMB_STRDUP(pdefservice); if (!defservice) { goto fail; } /* Disallow anything except explicit share names. */ if (strequal(defservice,HOMES_NAME) || strequal(defservice, PRINTERS_NAME) || strequal(defservice, "IPC$")) { SAFE_FREE(defservice); goto fail; } iService = find_service(defservice); if (iService >= 0) { all_string_sub(service, "_","/",0); iService = lp_add_service(service, iService); } SAFE_FREE(defservice); } } if (iService >= 0) { if (!VALID_SNUM(iService)) { DEBUG(0,("Invalid snum %d for %s\n",iService, service)); iService = -1; } } fail: if (iService < 0) DEBUG(3,("find_service() failed to find service %s\n", service)); return (iService); }