Example #1
0
void Pipe::append_filter(Filter* filter)
   {
   if(m_outputs->message_count() != 0)
      throw Invalid_State("Cannot call Pipe::append_filter after start_msg");

   do_append(filter);
   }
Example #2
0
/*
* Pipe Constructor
*/
Pipe::Pipe(std::initializer_list<Filter*> args)
   {
   m_outputs.reset(new Output_Buffers);
   m_pipe = nullptr;
   m_default_read = 0;
   m_inside_msg = false;

   for(auto i = args.begin(); i != args.end(); ++i)
      do_append(*i);
   }
Example #3
0
int
main(int argc, char *argv[])
{
	PMEMlogpool *plp;

	START(argc, argv, "log_walker");

	if (argc != 2)
		UT_FATAL("usage: %s file-name", argv[0]);

	const char *path = argv[1];

	int fd = OPEN(path, O_RDWR);

	/* pre-allocate 2MB of persistent memory */
	errno = posix_fallocate(fd, (off_t)0, (size_t)(2 * 1024 * 1024));
	if (errno != 0)
		UT_FATAL("!posix_fallocate");

	CLOSE(fd);

	if ((plp = pmemlog_create(path, 0, S_IWUSR | S_IRUSR)) == NULL)
		UT_FATAL("!pmemlog_create: %s", path);

	/* append some data */
	do_append(plp);

	/* arrange to catch SEGV */
	struct sigaction v;
	sigemptyset(&v.sa_mask);
	v.sa_flags = 0;
	v.sa_handler = signal_handler;
	SIGACTION(SIGSEGV, &v, NULL);

	if (!sigsetjmp(Jmp, 1)) {
		do_walk(plp);
	}

	pmemlog_close(plp);

	DONE(NULL);
}
Example #4
0
int restore_line(const char *filename,uint64_t lv,char *line) {
	char *ptr;
	uint32_t ts;
	int status;
	char* errormsgs[]={ ERROR_STRINGS };

	status = ERROR_MISMATCH;
	ptr = line;

	EAT(ptr,filename,lv,':');
	EAT(ptr,filename,lv,' ');
	GETU32(ts,ptr);
	EAT(ptr,filename,lv,'|');
	switch (*ptr) {
		case 'A':
			if (strncmp(ptr,"ACCESS",6)==0) {
				status = do_access(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"ATTR",4)==0) {
				status = do_attr(filename,lv,ts,ptr+4);
			} else if (strncmp(ptr,"APPEND",6)==0) {
				status = do_append(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"ACQUIRE",7)==0) {
				status = do_acquire(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"AQUIRE",6)==0) {
				status = do_acquire(filename,lv,ts,ptr+6);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'C':
			if (strncmp(ptr,"CREATE",6)==0) {
				status = do_create(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"CUSTOMER",8)==0) {	// deprecated
				status = do_session(filename,lv,ts,ptr+8);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'E':
			if (strncmp(ptr,"EMPTYTRASH",10)==0) {
				status = do_emptytrash(filename,lv,ts,ptr+10);
			} else if (strncmp(ptr,"EMPTYRESERVED",13)==0) {
				status = do_emptyreserved(filename,lv,ts,ptr+13);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'F':
			if (strncmp(ptr,"FREEINODES",10)==0) {
				status = do_freeinodes(filename,lv,ts,ptr+10);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'I':
			if (strncmp(ptr,"INCVERSION",10)==0) {
				status = do_incversion(filename,lv,ts,ptr+10);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'L':
			if (strncmp(ptr,"LENGTH",6)==0) {
				status = do_length(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"LINK",4)==0) {
				status = do_link(filename,lv,ts,ptr+4);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'M':
			if (strncmp(ptr,"MOVE",4)==0) {
				status = do_move(filename,lv,ts,ptr+4);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'P':
			if (strncmp(ptr,"PURGE",5)==0) {
				status = do_purge(filename,lv,ts,ptr+5);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'Q':
			if (strncmp(ptr,"QUOTA",5)==0) {
				status = do_quota(filename,lv,ts,ptr+5);
			}
			break;
		case 'R':
			if (strncmp(ptr,"RELEASE",7)==0) {
				status = do_release(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"REPAIR",6)==0) {
				status = do_repair(filename,lv,ts,ptr+6);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'S':
			if (strncmp(ptr,"SETEATTR",8)==0) {
				status = do_seteattr(filename,lv,ts,ptr+8);
			} else if (strncmp(ptr,"SETGOAL",7)==0) {
				status = do_setgoal(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"SETPATH",7)==0) {
				status = do_setpath(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"SETTRASHTIME",12)==0) {
				status = do_settrashtime(filename,lv,ts,ptr+12);
			} else if (strncmp(ptr,"SETXATTR",8)==0) {
				status = do_setxattr(filename,lv,ts,ptr+8);
			} else if (strncmp(ptr,"SNAPSHOT",8)==0) {
				status = do_snapshot(filename,lv,ts,ptr+8);
			} else if (strncmp(ptr,"SYMLINK",7)==0) {
				status = do_symlink(filename,lv,ts,ptr+7);
			} else if (strncmp(ptr,"SESSION",7)==0) {
				status = do_session(filename,lv,ts,ptr+7);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'T':
			if (strncmp(ptr,"TRUNC",5)==0) {
				status = do_trunc(filename,lv,ts,ptr+5);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'U':
			if (strncmp(ptr,"UNLINK",6)==0) {
				status = do_unlink(filename,lv,ts,ptr+6);
			} else if (strncmp(ptr,"UNDEL",5)==0) {
				status = do_undel(filename,lv,ts,ptr+5);
			} else if (strncmp(ptr,"UNLOCK",6)==0) {
				status = do_unlock(filename,lv,ts,ptr+6);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		case 'W':
			if (strncmp(ptr,"WRITE",5)==0) {
				status = do_write(filename,lv,ts,ptr+5);
			} else {
				printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
			}
			break;
		default:
			printf("%s:%"PRIu64": unknown entry '%s'\n",filename,lv,ptr);
	}
	if (status>STATUS_OK) {
		printf("%s:%"PRIu64": error: %d (%s)\n",filename,lv,status,errormsgs[status]);
	}
	return status;
}
Example #5
0
/* The :insert, :append and :change command */
void do_ins_chg(PTR start, char *arg, int mode)
{
    int base;
    off_t buffer = BUFFER;
    off_t count = 0L;
    size_t len;
    long    val;
    char *tempbuf = NULL;
    char *poi, *epoi;
    if((mode == U_EDIT) && (current - mem >= filesize)) {
        beep();
        return;
    }
    len = strlen(arg);
    if(!strncmp("ascii", arg, len) && CMDLNG(5, 1)) {
        base = 1;
    } else if(!strncmp("binary", arg, len) && CMDLNG(6, 1)) {
        base = 2;
    } else if(!strncmp("octal", arg, len) && CMDLNG(5, 1)) {
        base = 8;
    } else if(!strncmp("decimal", arg, len) && CMDLNG(7, 1)) {
        base = 10;
    } else if(!strncmp("hexadecimal", arg, len) && CMDLNG(11, 1)) {
        base = 16;
    } else {
        emsg("No such option");
        return;
    }
    addch('\n');
    if(getcmdstr(cmdstr, 0) == 1) {
        repaint();
        return;
    }
    if(alloc_buf(buffer, &tempbuf) == 0L) {
        return;
    }
    while(strcmp(cmdstr, ".")) {
        poi = cmdstr;
        if(base == 1) {            /* ASCII */
            while(*poi != '\0') {
                if(*poi == '\\') {
                    switch(*(++poi)) {
                        case 'n':
                            val = '\n';
                            break;
                        case 'r':
                            val = '\r';
                            break;
                        case 't':
                            val = '\t';
                            break;
                        case '0':
                            val = '\0';
                            break;
                        case '\\':
                            val = '\\';
                            break;
                        default :
                            val = '\\';
                            poi--;
                    }
                    poi++;
                } else {
                    val = *poi++;
                }
                *(tempbuf + count++) = val;
            }
        } else {
            while(isspace(cmdstr[strlen(cmdstr) - 1])) {
                cmdstr[strlen(cmdstr) - 1] = '\0';
            }
            while(*poi != '\0') {
                val = strtol(poi, &epoi, base);
                if(val > 255 || val < 0 || poi == epoi) {
                    repaint();
                    emsg("Invalid value");
                    goto mfree;
                }
                poi = epoi;
                *(tempbuf + count++) = val;
            }
        }
        addch('\n');
        if(getcmdstr(cmdstr, 0) == 1) {
            repaint();
            goto mfree;
        }
    }
    if(count == 0) {
        repaint();
        goto mfree;
    }
    switch(mode) {
        case U_INSERT:
            do_put(start, count, tempbuf);
            break;
        case U_EDIT:
            do_over(start, count, tempbuf);
            break;
        case U_APPEND:
            if((undo_count = alloc_buf(count, &undo_buf)) == 0L) {
                repaint();
                goto mfree;
            }
            do_append((off_t)count, tempbuf);
            memcpy(undo_buf, tempbuf, count);
            repaint();
            break;
    }
mfree:
#if defined(__MSDOS__) && !defined(DJGPP)
    farfree(tempbuf);
#else
    free(tempbuf);
#endif
}
Example #6
0
int replay(const char *log_data) {
	uint64_t fv,lv; //fv = filesystem's version lv = log's version
	uint32_t ts;
	uint8_t status;
	char buff[10000];
	char *ptr;
	char* errormsgs[]={ ERROR_STRINGS };

	char *test_ptr;

	sprintf(buff,"%s",log_data);
	ptr = buff;
//for test
	test_ptr = buff;
	fv = shadow_fs_getversion();
	GETU64(lv,ptr);
	if(lv < fv) {
		MFSLOG(LOG_ERR,"the changelog's verison %lu is smaller than filesystem's version %lu",lv,fv);
		//more complicated method to ensure consistency
	} else {
		status = ERROR_MISMATCH; 
                EAT(ptr,lv,':');
                EAT(ptr,lv,' ');
                GETU32(ts,ptr);
                EAT(ptr,lv,'|');
                switch (*ptr) {
                	case 'A':
                                if (strncmp(ptr,"ACCESS",6)==0) {
                                        status = do_access(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"ATTR",4)==0) {
                                        status = do_attr(lv,ts,ptr+4);
                                } else if (strncmp(ptr,"APPEND",6)==0) {
                                        status = do_append(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"AQUIRE",6)==0) {
                                        status = do_aquire(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                } 
                                break;  
                        case 'C':
                                if (strncmp(ptr,"CREATE",6)==0) {
                                        status = do_create(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"CUSTOMER",8)==0) {      // deprecated
                                        status = do_session(lv,ts,ptr+8);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                } 
                                break;  
                        case 'E':
                                if (strncmp(ptr,"EMPTYTRASH",10)==0) {
                                        status = do_emptytrash(lv,ts,ptr+10);
                                } else if (strncmp(ptr,"EMPTYRESERVED",13)==0) {
                                        status = do_emptyreserved(lv,ts,ptr+13);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                } 
                                break;  
                        case 'F': 
                                if (strncmp(ptr,"FREEINODES",10)==0) {
                                        status = do_freeinodes(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'I':
                                if (strncmp(ptr,"INCVERSION",10)==0) {
                                        status = do_incversion(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'L':
                                if (strncmp(ptr,"LENGTH",6)==0) {
                                        status = do_length(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"LINK",4)==0) {
                                        status = do_link(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'M':
                                if (strncmp(ptr,"MOVE",4)==0) {
                                        status = do_move(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'P':
                                if (strncmp(ptr,"PURGE",5)==0) {
                                        status = do_purge(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'R':
                                if (strncmp(ptr,"RELEASE",7)==0) {
                                        status = do_release(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"REPAIR",6)==0) {
                                        status = do_repair(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'S':
                                if (strncmp(ptr,"SETEATTR",8)==0) {
                                        status = do_seteattr(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SETGOAL",7)==0) {
                                        status = do_setgoal(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETPATH",7)==0) {
                                        status = do_setpath(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETTRASHTIME",12)==0) {
                                        status = do_settrashtime(lv,ts,ptr+12);
                                } else if (strncmp(ptr,"SNAPSHOT",8)==0) {
                                        status = do_snapshot(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SYMLINK",7)==0) {
                                        status = do_symlink(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SESSION",7)==0) {
                                        status = do_session(lv,ts,ptr+7);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'T':
                                if (strncmp(ptr,"TRUNC",5)==0) {
                                        status = do_trunc(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'U':
                                if (strncmp(ptr,"UNLINK",6)==0) {
                                        status = do_unlink(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"UNDEL",5)==0) {
                                        status = do_undel(lv,ts,ptr+5);
                                } else if (strncmp(ptr,"UNLOCK",6)==0) {
                                        status = do_unlock(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'W':
                                if (strncmp(ptr,"WRITE",5)==0) {
                                        status = do_write(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        default:
                                MFSLOG(LOG_ERR,"%"PRIu64": unknown entry '%s'",lv,ptr);
                        }
			/**
			  * if master is down, slave switch, we may missed some metadata 
			  * return 0 to let the process continue, otherwise, we will reply the 
			  * log forever.
			  * 
			  * Dongyang, Zhang
			  */				
			if (status!=STATUS_OK) {
				MFSLOG(LOG_ERR,"%"PRIu64": error: %"PRIu8" (%s),the log is (%s)",lv,status,errormsgs[status],test_ptr);
//                                syslog(LOG_ERR,"%"PRIu64": error: %"PRIu8" (%s)",lv,status,errormsgs[status]);
                           return 1;
                        }               
                        fv = shadow_fs_getversion();
                        if (lv+1!=fv) {
                                MFSLOG(LOG_ERR,"%"PRIu64": version mismatch fsversion:%"PRIu64"",lv,fv);
                                return 1;
                        }
	}
	return 0;
}                
Example #7
0
int restore(void) {
        FILE *fd;
        char buff[10000];
        char *ptr;
        uint64_t v,lv;
        uint32_t ts;
        uint8_t status;
	uint32_t dplen;
	char *datapath = NULL;
	char *logpath = NULL;
        char* errormsgs[]={ ERROR_STRINGS };
        
        v = shadow_fs_getversion();
        lv = 0;

        MFSLOG(LOG_NOTICE,"meta data version: %"PRIu64"",v);
        
	datapath = strdup(DATA_PATH);
	dplen = strlen(datapath);
	logpath = malloc(dplen+sizeof("/changelog.0.mfs"));
	memcpy(logpath,datapath,dplen);
	memcpy(logpath+dplen,"/changelog.0.mfs",sizeof("/changelog.0.mfs"));
        fd = fopen(logpath,"r");
        if (fd==NULL) {
                MFSLOG(LOG_NOTICE,"can't open changemeta file: %s",logpath);
                return 1;
        }
        while (fgets(buff,10000,fd)) {
                ptr = buff;
                GETU64(lv,ptr);
                if (lv<v) {
                        // skip
                } else {
                        status = ERROR_MISMATCH;
                        EAT(ptr,lv,':');
                        EAT(ptr,lv,' ');
                        GETU32(ts,ptr);
                        EAT(ptr,lv,'|');
                        switch (*ptr) {
                        case 'A':
                                if (strncmp(ptr,"ACCESS",6)==0) {
                                        status = do_access(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"ATTR",4)==0) {
                                        status = do_attr(lv,ts,ptr+4);
                                } else if (strncmp(ptr,"APPEND",6)==0) {
                                        status = do_append(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"AQUIRE",6)==0) {
                                        status = do_aquire(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'C':
                                if (strncmp(ptr,"CREATE",6)==0) {
                                        status = do_create(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"CUSTOMER",8)==0) {      // deprecated
                                        status = do_session(lv,ts,ptr+8);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'E':
                                if (strncmp(ptr,"EMPTYTRASH",10)==0) {
                                        status = do_emptytrash(lv,ts,ptr+10);
                                } else if (strncmp(ptr,"EMPTYRESERVED",13)==0) {
                                        status = do_emptyreserved(lv,ts,ptr+13);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'F':
                                if (strncmp(ptr,"FREEINODES",10)==0) {
                                        status = do_freeinodes(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'I':
                                if (strncmp(ptr,"INCVERSION",10)==0) {
                                        status = do_incversion(lv,ts,ptr+10);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'L':
                                if (strncmp(ptr,"LENGTH",6)==0) {
                                        status = do_length(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"LINK",4)==0) {
                                        status = do_link(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'M':
                                if (strncmp(ptr,"MOVE",4)==0) {
                                        status = do_move(lv,ts,ptr+4);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'P':
                                if (strncmp(ptr,"PURGE",5)==0) {
                                        status = do_purge(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'R':
                                if (strncmp(ptr,"RELEASE",7)==0) {
                                        status = do_release(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"REPAIR",6)==0) {
                                        status = do_repair(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'S':
                                if (strncmp(ptr,"SETEATTR",8)==0) {
                                        status = do_seteattr(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SETGOAL",7)==0) {
                                        status = do_setgoal(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETPATH",7)==0) {
                                        status = do_setpath(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SETTRASHTIME",12)==0) {
                                        status = do_settrashtime(lv,ts,ptr+12);
                                } else if (strncmp(ptr,"SNAPSHOT",8)==0) {
                                        status = do_snapshot(lv,ts,ptr+8);
                                } else if (strncmp(ptr,"SYMLINK",7)==0) {
                                        status = do_symlink(lv,ts,ptr+7);
                                } else if (strncmp(ptr,"SESSION",7)==0) {
                                        status = do_session(lv,ts,ptr+7);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'T':
                                if (strncmp(ptr,"TRUNC",5)==0) {
                                        status = do_trunc(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'U':
                                if (strncmp(ptr,"UNLINK",6)==0) {
                                        status = do_unlink(lv,ts,ptr+6);
                                } else if (strncmp(ptr,"UNDEL",5)==0) {
                                        status = do_undel(lv,ts,ptr+5);
                                } else if (strncmp(ptr,"UNLOCK",6)==0) {
                                        status = do_unlock(lv,ts,ptr+6);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        case 'W':
                                if (strncmp(ptr,"WRITE",5)==0) {
                                        status = do_write(lv,ts,ptr+5);
                                } else {
                                        MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                                }
                                break;
                        default:
                                MFSLOG(LOG_NOTICE,"%"PRIu64": unknown entry '%s'",lv,ptr);
                        }
			    /**
			      *  let the restore continue if we missed some meta data, otherwise the 
			      *
			      * Dongyang Zhang
			      */
                        if (status!=STATUS_OK) {
                                MFSLOG(LOG_ERR,"%"PRIu64": error: %"PRIu8" (%s)",lv,status,errormsgs[status]);
                                return 1;
                        }
                        v = shadow_fs_getversion();
                        if (lv+1!=v) {
                                MFSLOG(LOG_ERR,"%"PRIu64": version mismatch",lv);
                                return 1;
                        }
                }
        }
        fclose(fd);
        MFSLOG(LOG_NOTICE,"version after applying changelog: %"PRIu64"",v);
        return 0;
}
Example #8
0
/**
 * Iterator over key-value pairs where the value
 * maybe made available in increments and/or may
 * not be zero-terminated.  Used for processing
 * POST data.
 *
 * @param cls user-specified closure
 * @param kind type of the value, always MHD_POSTDATA_KIND when called from MHD
 * @param key 0-terminated key for the value
 * @param filename name of the uploaded file, NULL if not known
 * @param content_type mime-type of the data, NULL if not known
 * @param transfer_encoding encoding of the data, NULL if not known
 * @param data pointer to size bytes of data at the
 *              specified offset
 * @param off offset of data in the overall value
 * @param size number of bytes in data available
 * @return MHD_YES to continue iterating,
 *         MHD_NO to abort the iteration
 */
static int
process_upload_data (void *cls,
		     enum MHD_ValueKind kind,
		     const char *key,
		     const char *filename,
		     const char *content_type,
		     const char *transfer_encoding,
		     const char *data,
		     uint64_t off,
		     size_t size)
{
  struct UploadContext *uc = cls;
  int i;

  if (0 == strcmp (key, "category"))
    return do_append (&uc->category, data, size);
  if (0 == strcmp (key, "language"))
    return do_append (&uc->language, data, size);
  if (0 != strcmp (key, "upload"))
    {
      fprintf (stderr,
	       "Ignoring unexpected form value `%s'\n",
	       key);
      return MHD_YES; /* ignore */
    }
  if (NULL == filename)
    {
      fprintf (stderr, "No filename, aborting upload\n");
      return MHD_NO; /* no filename, error */
    }
  if ( (NULL == uc->category) ||
       (NULL == uc->language) )
    {
      fprintf (stderr,
	       "Missing form data for upload `%s'\n",
	       filename);
      uc->response = request_refused_response;
      return MHD_NO;
    }
  if (-1 == uc->fd)
    {
      char fn[PATH_MAX];

      if ( (NULL != strstr (filename, "..")) ||
	   (NULL != strchr (filename, '/')) ||
	   (NULL != strchr (filename, '\\')) )
	{
	  uc->response = request_refused_response;
	  return MHD_NO;
	}
      /* create directories -- if they don't exist already */
#ifdef WINDOWS
      (void) mkdir (uc->language);
#else
      (void) mkdir (uc->language, S_IRWXU);
#endif
      snprintf (fn, sizeof (fn),
		"%s/%s",
		uc->language,
		uc->category);
#ifdef WINDOWS
      (void) mkdir (fn);
#else
      (void) mkdir (fn, S_IRWXU);
#endif
      /* open file */
      snprintf (fn, sizeof (fn),
		"%s/%s/%s",
		uc->language,
		uc->category,
		filename);
      for (i=strlen (fn)-1;i>=0;i--)
	if (! isprint ((int) fn[i]))
	  fn[i] = '_';
      uc->fd = open (fn,
		     O_CREAT | O_EXCL
#if O_LARGEFILE
		     | O_LARGEFILE
#endif
		     | O_WRONLY,
		     S_IRUSR | S_IWUSR);
      if (-1 == uc->fd)
	{
	  fprintf (stderr,
		   "Error opening file `%s' for upload: %s\n",
		   fn,
		   strerror (errno));
	  uc->response = request_refused_response;
	  return MHD_NO;
	}
      uc->filename = strdup (fn);
    }
  if ( (0 != size) &&
       (size != (size_t) write (uc->fd, data, size)) )
    {
      /* write failed; likely: disk full */
      fprintf (stderr,
	       "Error writing to file `%s': %s\n",
	       uc->filename,
	       strerror (errno));
      uc->response = internal_error_response;
      (void) close (uc->fd);
      uc->fd = -1;
      if (NULL != uc->filename)
	{
	  unlink (uc->filename);
	  free (uc->filename);
	  uc->filename = NULL;
	}
      return MHD_NO;
    }
  return MHD_YES;
}
Example #9
0
static int compute_auth(xcb_auth_info_t *info, Xauth *authptr, struct sockaddr *sockname)
{
    if (authname_match(AUTH_MC1, authptr->name, authptr->name_length)) {
        info->datalen = memdup(&info->data, authptr->data, authptr->data_length);
        if(!info->datalen)
            return 0;
        return 1;
    }
#ifdef HASXDMAUTH
#define APPEND(buf,idx,val) do_append((buf),&(idx),&(val),sizeof(val))
    if (authname_match(AUTH_XA1, authptr->name, authptr->name_length)) {
	int j;

	info->data = malloc(192 / 8);
	if(!info->data)
	    return 0;

	for (j = 0; j < 8; j++)
	    info->data[j] = authptr->data[j];
	switch(sockname->sa_family) {
        case AF_INET:
            /*block*/ {
	    struct sockaddr_in *si = (struct sockaddr_in *) sockname;
	    APPEND(info->data, j, si->sin_addr.s_addr);
	    APPEND(info->data, j, si->sin_port);
	}
	break;
#ifdef AF_INET6
        case AF_INET6:
            /*block*/ {
            struct sockaddr_in6 *si6 = (struct sockaddr_in6 *) sockname;
            if(IN6_IS_ADDR_V4MAPPED(SIN6_ADDR(sockname)))
            {
                do_append(info->data, &j, &si6->sin6_addr.s6_addr[12], 4);
                APPEND(info->data, j, si6->sin6_port);
            }
            else
            {
                /* XDM-AUTHORIZATION-1 does not handle IPv6 correctly.  Do the
                   same thing Xlib does: use all zeroes for the 4-byte address
                   and 2-byte port number. */
                uint32_t fakeaddr = 0;
                uint16_t fakeport = 0;
                APPEND(info->data, j, fakeaddr);
                APPEND(info->data, j, fakeport);
            }
        }
        break;
#endif
        case AF_UNIX:
            /*block*/ {
	    uint32_t fakeaddr = htonl(0xffffffff - next_nonce());
	    uint16_t fakeport = htons(getpid());
	    APPEND(info->data, j, fakeaddr);
	    APPEND(info->data, j, fakeport);
	}
	break;
        default:
            free(info->data);
            return 0;   /* do not know how to build this */
	}
	{
	    uint32_t now = htonl(time(0));
	    APPEND(info->data, j, now);
	}
	assert(j <= 192 / 8);
	while (j < 192 / 8)
	    info->data[j++] = 0;
	info->datalen = j;
	XdmcpWrap ((unsigned char *) info->data, (unsigned char *) authptr->data + 8, (unsigned char *) info->data, info->datalen);
	return 1;
    }
#undef APPEND
#endif

    return 0;   /* Unknown authorization type */
}
Example #10
0
/*
 * Terminate the line in the line buffer.
 */
void
pdone(int endline, int forw)
{
	(void) pflushmbc();

	if (pendc && (pendc != '\r' || !endline))
		/*
		 * If we had a pending character, put it in the buffer.
		 * But discard a pending CR if we are at end of line
		 * (that is, discard the CR in a CR/LF sequence).
		 */
		(void) do_append(pendc, NULL, pendpos);

	/*
	 * Make sure we've shifted the line, if we need to.
	 */
	if (cshift < hshift)
		pshift(hshift - cshift);

	if (ctldisp == OPT_ONPLUS && is_ansi_end('m')) {
		/* Switch to normal attribute at end of line. */
		char *p = "\033[m";
		for (; *p != '\0'; p++) {
			linebuf[curr] = *p;
			attr[curr++] = AT_ANSI;
		}
	}

	/*
	 * Add a newline if necessary,
	 * and append a '\0' to the end of the line.
	 * We output a newline if we're not at the right edge of the screen,
	 * or if the terminal doesn't auto wrap,
	 * or if this is really the end of the line AND the terminal ignores
	 * a newline at the right edge.
	 * (In the last case we don't want to output a newline if the terminal
	 * doesn't ignore it since that would produce an extra blank line.
	 * But we do want to output a newline if the terminal ignores it in case
	 * the next line is blank.  In that case the single newline output for
	 * that blank line would be ignored!)
	 */
	if (column < sc_width || !auto_wrap || (endline && ignaw) ||
	    ctldisp == OPT_ON) {
		linebuf[curr] = '\n';
		attr[curr] = AT_NORMAL;
		curr++;
	} else if (ignaw && column >= sc_width && forw) {
		/*
		 * Terminals with "ignaw" don't wrap until they *really* need
		 * to, i.e. when the character *after* the last one to fit on a
		 * line is output. But they are too hard to deal with when they
		 * get in the state where a full screen width of characters
		 * have been output but the cursor is sitting on the right edge
		 * instead of at the start of the next line.
		 * So we nudge them into wrapping by outputting a space
		 * character plus a backspace.  But do this only if moving
		 * forward; if we're moving backward and drawing this line at
		 * the top of the screen, the space would overwrite the first
		 * char on the next line.  We don't need to do this "nudge"
		 * at the top of the screen anyway.
		 */
		linebuf[curr] = ' ';
		attr[curr++] = AT_NORMAL;
		linebuf[curr] = '\b';
		attr[curr++] = AT_NORMAL;
	}
	linebuf[curr] = '\0';
	attr[curr] = AT_NORMAL;
}
Example #11
0
/*
 * Append a character to the line buffer.
 * Expand tabs into spaces, handle underlining, boldfacing, etc.
 * Returns 0 if ok, 1 if couldn't fit in buffer.
 */
int
pappend(char c, off_t pos)
{
	int r;

	if (pendc) {
		if (do_append(pendc, NULL, pendpos))
			/*
			 * Oops.  We've probably lost the char which
			 * was in pendc, since caller won't back up.
			 */
			return (1);
		pendc = '\0';
	}

	if (c == '\r' && bs_mode == BS_SPECIAL) {
		if (mbc_buf_len > 0)  /* utf_mode must be on. */ {
			/* Flush incomplete (truncated) sequence. */
			r = flush_mbc_buf(mbc_pos);
			mbc_buf_index = r + 1;
			mbc_buf_len = 0;
			if (r)
				return (mbc_buf_index);
		}

		/*
		 * Don't put the CR into the buffer until we see
		 * the next char.  If the next char is a newline,
		 * discard the CR.
		 */
		pendc = c;
		pendpos = pos;
		return (0);
	}

	if (!utf_mode) {
		r = do_append((LWCHAR) c, NULL, pos);
	} else {
		/* Perform strict validation in all possible cases. */
		if (mbc_buf_len == 0) {
retry:
			mbc_buf_index = 1;
			*mbc_buf = c;
			if (IS_ASCII_OCTET(c)) {
				r = do_append((LWCHAR) c, NULL, pos);
			} else if (IS_UTF8_LEAD(c)) {
				mbc_buf_len = utf_len(c);
				mbc_pos = pos;
				return (0);
			} else {
				/* UTF8_INVALID or stray UTF8_TRAIL */
				r = flush_mbc_buf(pos);
			}
		} else if (IS_UTF8_TRAIL(c)) {
			mbc_buf[mbc_buf_index++] = c;
			if (mbc_buf_index < mbc_buf_len)
				return (0);
			if (is_utf8_well_formed(mbc_buf))
				r = do_append(get_wchar(mbc_buf), mbc_buf,
				    mbc_pos);
			else
				/* Complete, but not shortest form, sequence. */
				mbc_buf_index = r = flush_mbc_buf(mbc_pos);
			mbc_buf_len = 0;
		} else {
			/* Flush incomplete (truncated) sequence.  */
			r = flush_mbc_buf(mbc_pos);
			mbc_buf_index = r + 1;
			mbc_buf_len = 0;
			/* Handle new char.  */
			if (!r)
				goto retry;
		}
	}

	/*
	 * If we need to shift the line, do it.
	 * But wait until we get to at least the middle of the screen,
	 * so shifting it doesn't affect the chars we're currently
	 * pappending.  (Bold & underline can get messed up otherwise.)
	 */
	if (cshift < hshift && column > sc_width / 2) {
		linebuf[curr] = '\0';
		pshift(hshift - cshift);
	}
	if (r) {
		/* How many chars should caller back up? */
		r = (!utf_mode) ? 1 : mbc_buf_index;
	}
	return (r);
}
Example #12
0
void Pipe::append(Filter* filter)
   {
   do_append(filter);
   }