+ if (RemoteMode){
+ if (argc>1 && strcmp("quit", argv[1]) == 0){
+ if (argc>2){
+ printf("ERROR: invalid parameter count for quit\n");
+ return(0);
+ }
+ exit(0);
+ }
+#if defined(HAVE_OPENDIR) && defined(HAVE_READDIR) && defined(HAVE_CHDIR)
+ if (argc>1 && strcmp("cd", argv[1]) == 0){
+ if (argc>3){
+ printf("ERROR: invalid parameter count for cd\n");
+ return(0);
+ }
+#if ! defined(HAVE_CHROOT) || ! defined(HAVE_GETUID)
+ if (getuid()==0 && ! ChangeRoot){
+ printf("ERROR: chdir security problem - rrdtool is runnig as "
+ "root an no chroot!\n");
+ return(0);
+ }
+#endif
+ chdir(argv[2]);
+ if (errno!=0){
+ printf("ERROR: %s\n",strerror(errno));
+ }
+ return(0);
+ }
+ if (argc>1 && strcmp("mkdir", argv[1]) == 0){
+ if (argc>3){
+ printf("ERROR: invalid parameter count for mkdir\n");
+ return(0);
+ }
+#if ! defined(HAVE_CHROOT) || ! defined(HAVE_GETUID)
+ if (getuid()==0 && ! ChangeRoot){
+ printf("ERROR: mkdir security problem - rrdtool is runnig as "
+ "root an no chroot!\n");
+ return(0);
+ }
+#endif
+ mkdir(argv[2],0777);
+ if (errno!=0){
+ printf("ERROR: %s\n",strerror(errno));
+ }
+ return(0);
+ }
+ if (argc>1 && strcmp("ls", argv[1]) == 0){
+ if (argc>2){
+ printf("ERROR: invalid parameter count for ls\n");
+ return(0);
+ }
+ if ((curdir=opendir("."))!=NULL){
+ while((dent=readdir(curdir))!=NULL){
+ if (!stat(dent->d_name,&st)){
+ if (S_ISDIR(st.st_mode)){
+ printf("d %s\n",dent->d_name);
+ }
+ if (strlen(dent->d_name)>4 && S_ISREG(st.st_mode)){
+ if (!strcmp(dent->d_name+NAMLEN(dent)-4,".rrd") ||
+ !strcmp(dent->d_name+NAMLEN(dent)-4,".RRD")){
+ printf("- %s\n",dent->d_name);
+ }
+ }
+ }
+ }
+ }
+ else{
+ printf("ERROR: %s\n",strerror(errno));
+ return(errno);
+ }
+ return(0);
+ }
+#endif /* opendir and readdir */
+
+ }