Пример #1
0
int __om_unzip_makedir (om_unzip_archive_ptr archive, const char *rootExportPath, char *newdir) {
	
	char *buffer = om_string_copy(newdir);
	if( buffer==OM_NULL ) {
		return UNZ_INTERNALERROR;
	}
	char *p;
	int len = (int)strlen(newdir);
	
	if (len <= 0)
		return 0;
	
	// prefix with the location where we want to create the dir structure
	if( buffer[0]==OM_FS_FILE_SEP ) {
		p = om_string_append(rootExportPath,buffer);
	} else {
		p = om_string_format("%s%c%s",rootExportPath,OM_FS_FILE_SEP,buffer);
	}
	om_free(buffer);
	buffer = p;
	p = OM_NULL;
	
	// if the path ended with a '/',
	// then take that off
	if (buffer[len-1] == '/') {
		buffer[len-1] = '\0';
	}
	if (__om_unzip_mymkdir(archive,buffer) == 0) {
		om_free(buffer);
		return 1;
    }
	
	p = buffer+1;
	while (1) {
		char hold;
		
		// we shouldn't need to create the rootExportPath
		if( strcmp(rootExportPath,buffer)==0 )
			break;
		
		while(*p && *p != '\\' && *p != '/')
			p++;
		hold = *p;
		*p = 0;
		if ( (__om_unzip_mymkdir(archive,buffer) == -1) && (errno == ENOENT) ) {
			__om_unzip_append_error(archive,om_string_format("couldn't create directory %s\n",buffer));
			om_free(buffer);
			return 0;
        }
		if ( hold == 0 )
			break;
		*p++ = hold;
    }
	om_free(buffer);
	return 1;
}
Пример #2
0
void * __om_malloc_debug(uint32 length, const char *file, const int line) {
	
	void * toret = NULL;
	
	if( om_malloc_fail==OM_TRUE ) {
		return NULL;
	} else {
		
		toret = __om_malloc_regular(length);
		
		if( ! om_malloc_tracking && toret!=NULL ) {
			
			om_malloc_tracking = OM_TRUE;
			
			if( om_mallocs == NULL ) {
				om_mallocs = om_dict_new(40);
				((om_dict_ptr)om_mallocs)->release_func=__om_malloc_debug_release_func;
				((om_dict_ptr)om_mallocs)->hash_func=__om_malloc_debug_hash_func;
			}
				
			om_dict_put( om_mallocs, toret, om_string_format("%i:%s",line,file) );
			//printf("adding %8X %s\n",toret,om_dict_get(om_mallocs,toret));
			
			om_malloc_count++;
			
			om_malloc_tracking = OM_FALSE;
		}
	}
	
	return toret;
}
Пример #3
0
char * om_net_get_mac_address() {
    int                 mgmtInfoBase[6];
    char                *msgBuffer = NULL;
    size_t              length;
    unsigned char       macAddress[6];
    struct if_msghdr    *interfaceMsgStruct;
    struct sockaddr_dl  *socketStruct;
    char                *errorFlag = NULL;
    
    // Setup the management Information Base (mib)
    mgmtInfoBase[0] = CTL_NET;        // Request network subsystem
    mgmtInfoBase[1] = AF_ROUTE;       // Routing table info
    mgmtInfoBase[2] = 0;              
    mgmtInfoBase[3] = AF_LINK;        // Request link layer information
    mgmtInfoBase[4] = NET_RT_IFLIST;  // Request all configured interfaces
    
    // With all configured interfaces requested, get handle index
    if ((mgmtInfoBase[5] = if_nametoindex("en0")) == 0) 
        errorFlag = "if_nametoindex failure";
    else
    {
        // Get the size of the data available (store in len)
        if (sysctl(mgmtInfoBase, 6, NULL, &length, NULL, 0) < 0) 
            errorFlag = "sysctl mgmtInfoBase failure";
        else
        {
            // Alloc memory based on above call
            if ((msgBuffer = malloc(length)) == NULL)
                errorFlag = "buffer allocation failure";
            else
            {
                // Get system information, store in buffer
                if (sysctl(mgmtInfoBase, 6, msgBuffer, &length, NULL, 0) < 0)
                    errorFlag = "sysctl msgBuffer failure";
            }
        }
    }
    
    // Befor going any further...
    if (errorFlag != NULL) {
        return errorFlag;
    }
    
    // Map msgbuffer to interface message structure
    interfaceMsgStruct = (struct if_msghdr *) msgBuffer;
    
    // Map to link-level socket structure
    socketStruct = (struct sockaddr_dl *) (interfaceMsgStruct + 1);
    
    // Copy link layer address data in socket structure to an array
    memcpy(&macAddress, socketStruct->sdl_data + socketStruct->sdl_nlen, 6);
    
    // Read from char array into a string object, into traditional Mac address format
    char *macAddressString = om_string_format("%02X:%02X:%02X:%02X:%02X:%02X", 
                                  macAddress[0], macAddress[1], macAddress[2], 
                                  macAddress[3], macAddress[4], macAddress[5]);
    
    return macAddressString;
}
Пример #4
0
/**
 * Makes the first run hit to usage.openmeap.com.
 *
 * Dear Developer/Project Management,
 *
 * We've created this function to make a single hit to our tracking url
 * per unique install.  An effort has been made to make it secure and
 * non-reversible.  An effort has been made so that, even should it fail,
 * it only happens once.
 *
 * We're hoping you'll leave this code functional in your production 
 * release so that we can build-up value by tracking unique installs.
 *
 * Yours truly, OpenMEAP
 */
void om_first_run_check(om_config_ptr cfg) {
    
    // don't bother doing this in development mode.
    uint32 *d = om_config_get(cfg,OM_CFG_DEV_MODE);
    if( d!=OM_NULL ) {
        if( *d==1 ) {
            om_free(d);
            return;
        } else {
            om_free(d);
        }
    }
    
    uint32 *n = om_config_get(cfg,OM_CFG_NOT_FIRST_RUN);
    if( n==OM_NULL ) {
        
        // set this first, so even if the request fails
        // it never happens again.
        n = om_malloc(sizeof(uint32));
        *n=1;
        om_config_set(cfg,OM_CFG_NOT_FIRST_RUN,n);
        
        // TODO: determine MAC hash and request to usage.openmeap.com/tracker.gif
        char * mac_address = om_net_get_mac_address();
        char * mac_with_salt = om_string_format("%s.OPENMEAP#$!@3__234",mac_address);
        char * hash = om_digest_hash_string(mac_with_salt,OM_HASH_MD5);
        char * url = om_string_format("http://usage.openmeap.com/tracker.gif?hash=%s",hash);
        om_free(mac_with_salt);
        om_free(mac_address);
        om_free(hash);
        
        om_net_do_http_post(url,OM_NULL);
        om_free(url);
        
    } else {
        
        om_free(n);
    }
}
Пример #5
0
int __om_unzip_extract(
	om_unzip_archive_ptr archive, 
	const char* rootExtractPath,
	om_uint32 options, 
	const char* password
)
{
	unzFile uf = archive->file;
    uLong i;
    unz_global_info * gi = archive->global_info_ptr;
    int err;
	
	err = unzGoToFirstFile(uf);
	if (err!=UNZ_OK)	
	{
		__om_unzip_append_error(archive,om_string_format("error %d with zipfile in unzGoToNextFile\n",err));
		return err;
	}
	
    for (i=0;i<gi->number_entry;i++)
    {
        if ( (err=__om_unzip_extract_currentfile(archive,rootExtractPath,options,password)) != UNZ_OK )
            break;
		
        if ((i+1)<gi->number_entry)
        {
            err = unzGoToNextFile(uf);
            if (err!=UNZ_OK)
            {
                __om_unzip_append_error(archive,om_string_format("error %d with zipfile in unzGoToNextFile\n",err));
                break;
            }
        }
    }
	
    return err;
}
Пример #6
0
int __om_unzip_extract_currentfile(
		om_unzip_archive_ptr archive,
		const char *rootExportPath, 
		om_uint32 options,
		const char *password
) {
	unzFile uf = archive->file;
    char filename_inzip[256];
    char *filename_withoutpath;
    char *p;
    int err=UNZ_OK;
    FILE *fout=NULL;
    void *buf;
    uInt size_buf;
	
    unz_file_info file_info;
    uLong ratio = 0;
	
    err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
    if (err!=UNZ_OK) {
        __om_unzip_append_error(archive,om_string_format("error %d with zipfile in unzGetCurrentFileInfo\n",err));
        return err;
    }
	
    size_buf = OM_ZIP_WRITEBUFFERSIZE;
    buf = (void*)om_malloc(size_buf);
    if (buf==NULL) {
        // Error allocating memory for the write buffer
        return UNZ_INTERNALERROR;
    }
	
	// this appears to be a string copy
	// some zip files do not put in a path
    p = filename_withoutpath = filename_inzip;
    while ((*p) != '\0') {
		// if the current character is a dir path separator
		// then the next character starts either a directory segment
		// or a file name
        if (((*p)=='/') || ((*p)=='\\'))
            filename_withoutpath = p+1;
        p++;
    }
	
	// if the element after the last '/' was a '\0', then this is a directory
    if ( (*filename_withoutpath) == '\0' ) {
        if( ! options & OM_ZIP_OPTS_NOPATH ) {
			char * full_file_path = om_string_format("%s%c%s",rootExportPath,OM_FS_FILE_SEP,filename_inzip);
			if(full_file_path==OM_NULL) {
				om_free(buf);
				return UNZ_INTERNALERROR;
			}
            __om_unzip_mymkdir(archive,full_file_path);
			om_free(full_file_path);
        }
    }
	// otherwise it was a file name
	else {
        char* write_filename;
        int skip=0;
		
		if( options & OM_ZIP_OPTS_NOPATH ) {
			write_filename = filename_withoutpath;
		} else {
			write_filename = filename_inzip;
		}
		
        err = unzOpenCurrentFilePassword(uf,password);
        if ( err != UNZ_OK ) {
            __om_unzip_append_error(archive,om_string_format("error %d with zipfile in unzOpenCurrentFilePassword\n",err));
			return err;
        }
		
		// removed a file existence test here
		
        if ( skip == 0 && err == UNZ_OK )
        {			
			// the write_filename should, at this point,
			// have the relative directory on it
			// now we have to prepend with our rootExportPath
			char * full_file_path = om_string_format("%s%c%s",rootExportPath,OM_FS_FILE_SEP,write_filename);
            fout = fopen(full_file_path,"wb");
			
            // some zipfile don't contain the directory alone before file
            if ( 
				(fout==NULL) 
				&& (!(options & OM_ZIP_OPTS_NOPATH)) 
				&& (filename_withoutpath!=(char*)filename_inzip)
			) {
                char c = *(filename_withoutpath-1);
                *(filename_withoutpath-1)='\0';
                __om_unzip_makedir(archive,rootExportPath,write_filename);
                *(filename_withoutpath-1)=c;
				
                fout=fopen(full_file_path,"wb");
            }
			
			om_free(full_file_path);
			
            if (fout==NULL) {
				__om_unzip_append_error(archive,om_string_format("error opening %s",write_filename));
				om_free(buf);
				return UNZ_INTERNALERROR;
            }
        }
		
        if (fout!=NULL) {
            //printf(" extracting: %s\n",write_filename);
			
            do {
                err = unzReadCurrentFile(uf,buf,size_buf);
                if (err<0) {
					__om_unzip_append_error(archive,om_string_format("error %d with zipfile in unzReadCurrentFile\n",err));
                    break;
                }
                if (err>0) {
                    if (fwrite(buf,err,1,fout)!=1) {
                        __om_unzip_append_error(archive,om_string_format("error in writing extracted file\n"));
                        err=UNZ_ERRNO;
                        break;
                    }
				}
            } while (err>0);
            if (fout)
				fclose(fout);
			
			// OpenMEAP doesn't care if the date of the files on the device
			// are the same as in the archive.
            // if (err==0)
            //    change_file_date(write_filename,file_info.dosDate, file_info.tmu_date);
        }
		
        if (err==UNZ_OK) {
            err = unzCloseCurrentFile (uf);
            if (err!=UNZ_OK) {
                __om_unzip_append_error(archive,om_string_format("error %d with zipfile in unzCloseCurrentFile\n",err));
            }
        } else {
			unzCloseCurrentFile(uf); /* don't lose the error */
		}
    }
	
    om_free(buf);
    return err;
}